clawsweeper icon indicating copy to clipboard operation
clawsweeper copied to clipboard

apply: ETag cache key omits the jq projection, so the requested-reviewer close guard reads another call site's body and fails open

Open yetval opened this issue 3 months ago • 1 comments

Summary

The durable ETag cache key does not include the --jq output projection, so two reads of the same GitHub route that ask for different projections share one durable entry. When the second read gets a 304, the broker returns the first read's body, digest-verified and treated as authoritative. In the apply lane this makes pullRequestHumanEngagementBlockReason read a {body} projection where it expects {requested_reviewers, requested_teams}, so the "requested reviewers or teams indicate active review signal" guard never fires and a pull request with a live requested reviewer becomes eligible for auto-close.

Environment

  • Commit: ed20a56037dc7e1141140513e0307df69f0d394a (origin/main at time of filing)
  • Surface: apply lane (apply-decisions) when the ETag read broker is active, which is EXACT_EVENT_PUBLICATION=true. That is set at .github/workflows/sweep.yml:1564 and :2608 for repair:publish-event-result, which spawns apply-decisions with env: process.env (src/repair/publish-event-result.ts:427, :832), so the broker is live in the event-review publication lane.

Steps to reproduce

  1. In an apply run with the broker active, let any call site read repos/{owner}/{repo}/pulls/{number} with --jq '{body}'. src/clawsweeper-apply-close-execution.ts:353 does this on the implemented-on-main close path.
  2. Let the inactivity guard read the same route with --jq '{requested_reviewers:[...],requested_teams:[...]}'. src/clawsweeper-apply-guard-activity.ts:199 does this.
  3. The second read hits the first read's durable entry, sends If-None-Match, and GitHub answers 304 because the resource itself has not changed.

Expected

Each call site receives the projection it asked for. A pull request with a requested reviewer raises the active-review-signal block reason and is not auto-closed.

Actual

The guard receives {"body":"Fixes #9"}. requested_reviewers is undefined, (pull.requested_reviewers ?? []).length > 0 is false, no block reason is returned, and the close proceeds.

Root cause

src/github-etag-cache-contract.ts:69-74 builds the key from four dimensions, none of which is the output projection:

const cacheKey = JSON.stringify([
  GITHUB_ETAG_CACHE_KEY_VERSION,
  options.credentialPool,
  route,
  mediaType,
]);

src/clawsweeper-github-runtime.ts:401-408 decides which invocations may use the broker, and its disqualifier list does not contain --jq or -q:

["-i", "--include", "--paginate", "--slurp", "-f", "--raw-field", "-F", "--field"]

githubApiEndpointForEtag (:437-458) additionally steps over -q, --jq, -t and --template as value flags, so projected reads deliberately reach the broker. The 304 path itself is rigorous: it verifies the etag and sha256(body) against the stored entry. That is exactly why the wrong body is trusted. The digest confirms the body matches what was stored, and what was stored was another call site's projection.

Sibling surfaces

Route pull_metadata is read with at least five incompatible shapes on origin/main: the full object (clawsweeper-apply-guard-policy.ts:54, clawsweeper-coverage-proof.ts:93, clawsweeper-close-promotion.ts:80), {body} (clawsweeper-apply-close-execution.ts:353, clawsweeper-status-context.ts:834), {requested_reviewers,requested_teams} (clawsweeper-apply-guard-activity.ts:199), a field subset (clawsweeper-status-context.ts:641, clawsweeper-context-hydration.ts:523), and .head.sha // empty, which is a bare string.

Route issue_metadata has the same problem and one worse case: clawsweeper-promotion-facts.ts:485 projects [.labels[].name], a JSON array, against sites that expect the full issue object. An array reaching asRecord() yields {}, so labels, state and author association all read empty and the protected-label and maintainer-association guards mis-evaluate.

The existing coverage at test/github-etag-read-broker.test.ts:25-50 enumerates four key dimensions (credential pool, media type, query, page) and does not mention output projection.

Real behavior proof

Behavior addressed: guard reads another call site's projection through the durable ETag entry and stops blocking an auto-close Real environment tested: real githubEtagCacheKey and real durableGithubEtagReadSync imported unmodified from the checkout at ed20a56037dc7e1141140513e0307df69f0d394a and driven directly under Node v24.18.0, with only the GitHub HTTP boundary and the durable store supplied; the store is keyed by key.cacheKey, which is how dashboard/github-etag-cache.ts:40,78,130 keys it Exact steps or command run after this patch: node repro.ts Evidence after fix:

STEP 1 - real githubEtagCacheKey() for the two call sites
  guard site (--jq '{requested_reviewers,requested_teams}')
    [1,"target_app","/repos/openclaw/openclaw/pulls/1234","application/vnd.github+json"]
  close site (--jq '{body}')
    [1,"target_app","/repos/openclaw/openclaw/pulls/1234","application/vnd.github+json"]
  identical: true

=== OBSERVED on origin/main (cache key omits the projection) ===
STEP 2 - real durableGithubEtagReadSync(), close site reads the route first
  read 1 - close site asked for {body}
  conditional request sent: no (live 200)
  body handed back to the caller: {"body":"Fixes #9"}

STEP 3 - guard site now reads the same route
  read 2 - guard site asked for {requested_reviewers,requested_teams}
  conditional request sent: yes (304 answered)
  body handed back to the caller: {"body":"Fixes #9"}

STEP 4 - guard predicate from clawsweeper-apply-guard-activity.ts:205
  live truth on GitHub: requested_reviewers = [{"login":"octocat"}]
  value the guard actually saw: requested_reviewers = undefined
  guard raises 'requested reviewers or teams indicate active review signal': false

RESULT: guard did NOT block. A pull request with a live requested reviewer is eligible for auto-close.

=== EXPECTED with the projection folded into the cache key ===
STEP 2 - real durableGithubEtagReadSync(), close site reads the route first
  read 1 - close site asked for {body}
  conditional request sent: no (live 200)
  body handed back to the caller: {"body":"Fixes #9"}

STEP 3 - guard site now reads the same route
  read 2 - guard site asked for {requested_reviewers,requested_teams}
  conditional request sent: no (live 200)
  body handed back to the caller: {"requested_reviewers":[{"login":"octocat"}],"requested_teams":[]}

STEP 4 - guard predicate from clawsweeper-apply-guard-activity.ts:205
  live truth on GitHub: requested_reviewers = [{"login":"octocat"}]
  value the guard actually saw: requested_reviewers = [{"login":"octocat"}]
  guard raises 'requested reviewers or teams indicate active review signal': true

RESULT: guard blocked the close (correct)

Observed result after fix: on origin/main the guard reads requested_reviewers = undefined for a pull request that has a requested reviewer and stops blocking the close; folding the output projection into the durable key on identical inputs restores the correct value and the block What was not tested: I did not run a live end-to-end apply-decisions job against a real repository, so the frequency of the two projections landing in the same durable entry within one entry lifetime in production is unmeasured. I also did not verify whether any later guard in the close chain independently re-reads reviewer state and would still block, and I did not exercise the issue_metadata array-projection variant described under Sibling surfaces.

Suggested direction

Either fold the --jq/-t argument, or a digest of it, into githubEtagCacheKey, or add the projection flags to the disqualifier list at src/clawsweeper-github-runtime.ts:402-408 the way -i and --paginate are already excluded.

yetval avatar Aug 24 '26 23:08 yetval

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 26, 2026, 6:17 PM ET / 22:17 UTC.

Summary Keep open: current main still admits projected GitHub reads to the durable ETag broker while cache identity omits projection shape, and the formally linked repair PR https://github.com/openclaw/clawsweeper/pull/1242 remains open.

Reproducibility: yes. from source: two projected reads of the same route remain broker-eligible but share an ETag key, while the reviewer guard expects fields absent from another projection.

Root-cause cluster Relationship: canonical Canonical: https://github.com/openclaw/clawsweeper/issues/1239 Summary: This issue is the canonical report; one open PR explicitly claims the bounded fix.

Members:

  • fixed_by_candidate: https://github.com/openclaw/clawsweeper/pull/1242 - The open PR explicitly closes this issue and changes projected-read admission to avoid the shared cache entry.

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Next step The explicitly linked open PR https://github.com/openclaw/clawsweeper/pull/1242 already owns this bounded repair, so another fix branch would duplicate active work.

Review details

Best possible solution:

Land the narrow projected-read broker bypass in https://github.com/openclaw/clawsweeper/pull/1242, retaining durable caching for full-resource GETs and focused coverage for supported projection flag forms.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: two projected reads of the same route remain broker-eligible but share an ETag key, while the reviewer guard expects fields absent from another projection.

Is this the best way to solve the issue?

Yes: the linked PR’s narrow bypass for projected reads avoids a durable-cache schema migration and preserves caching for full-resource GETs.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against afe976209aa5.

Label changes

Label justifications:

  • P1: A cached response with the wrong projection can bypass the active-review guard and make a pull request eligible for automated closure.
  • impact:other: The concrete impact is unsafe automation eligibility, which does not fit the more specific owned impact classes.
Evidence reviewed

What I checked:

Likely related people:

  • Martin Cleary: Git blame attributes the current cache-key and broker-admission logic to the commit that introduced the feature. (role: original implementation author; confidence: high; commits: 115abf8548e0; files: src/github-etag-cache-contract.ts, src/clawsweeper-github-runtime.ts, test/github-etag-read-broker.test.ts)
How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Aug 24 '26 23:08 clawsweeper[bot]