Skip to content

fix: scheduled reviews re-run on unchanged items because the review cache is unreachable - #1053

Closed
masatohoshino wants to merge 10 commits into
openclaw:mainfrom
masatohoshino:fix/review-cache-coordination-gate
Closed

masatohoshino wants to merge 10 commits into
openclaw:mainfrom
masatohoshino:fix/review-cache-coordination-gate

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1052.

What Problem This Solves

Fixes an issue where ClawSweeper re-reviews an unchanged item on every scheduled pass and can publish a different verdict each time, because the structural review cache is unreachable on the lane that runs those passes.

Terminology, because the two are easy to conflate: the exact-event workflow is the sweep.yml job that runs every review for a target repository, and a scheduled delivery is one class of payload that job carries — the queue's cadence work, as opposed to a webhook event or a maintainer command.

That workflow reserves the durable review lease in its own write-token step, so it must invoke the review command with --skip-start-comment. The same flag decided coordinationEnabled, which reviewStructuralCacheProbeDecision consults before anything else, so scheduled deliveries returned coordination_disabled and re-ran full hydration plus Codex. This is a property of the invocation rather than a sampled rate: .github/workflows/sweep.yml:1229 passes the flag unconditionally, so no delivery through that job could have had a different value.

Because the probe never ran, preHydrationStructuralRecord stayed null and the seeding branch could not persist a receipt for the next review either. The cache could not bootstrap even once.

Clearing that gate exposed two more conditions on the same path. All three had to go before a scheduled pass could reuse anything:

  • activity_changed — the reservation the workflow posts before invoking the command is itself the item's newest activity, landing after the sync markers the prior review recorded, so ClawSweeper's own write read as reporter activity.
  • target_changed — the decision compared the target repository's default branch head across reviews. That head advances for reasons unrelated to the item, so where it moves faster than the review cadence the key can never match. openclaw/openclaw advanced it 100 times in the 21h11m ending 2026-08-07T00:06Z — about once every 13 minutes — against a daily cadence over 5,536 open items (2,150 pull requests, 3,386 issues), so every scheduled pass there re-ran a full review.

Contributors see this as verdict churn on a frozen head. On openclaw/openclaw#118777 the head ed699913b2acf0ec158e705afa289cc2d4c59358 never moved and the body was never edited, yet re-scans walked the rating from 🦞 diamond to 🦪 silver and revoked proof: sufficient together with status: 👀 ready for maintainer look. Two of those re-reviews were scheduled deliveries: runs https://github.com/openclaw/clawsweeper/actions/runs/30955548730 and https://github.com/openclaw/clawsweeper/actions/runs/31049170523. The cost side is visible in the queue revision counters carried in clawsweeper run titles; read at 2026-08-07T00:12Z, openclaw/openclaw#84599 stood at 389, #40088 at 307, and #38283 at 293.

Why This Change Was Made

coordinationEnabled is now true when a reserved lease is supplied, the structural cache path claims that reserved lease instead of posting a second start comment, the validated reservation covers its own activity, and the target branch head is no longer compared across reviews.

Those are one change, not two. Widening the coordination decision alone would send the cache path into postReviewStartStatusComment, which is exactly the second lease that --skip-start-comment exists to prevent — prepareReviewCommand throws today if a supplied lease arrives without that flag. Making the cache path claim the reserved lease is what makes the widening safe.

Two things change together in src/clawsweeper-review-command-workflow.ts. The structural-cache probe calls read the preparation's coordination decision, and the cache's lease acquisition claims a supplied lease when there is one. The reservation is now validated before the cache decision rather than after it, and its timestamp is passed to that decision as ownedReservationUpdatedAt, because the workflow posts that comment before invoking this command — so on this lane the reservation is always the item's newest activity, and activityCoveredByReview would otherwise read ClawSweeper's own write as reporter activity and return activity_changed. Only the reservation this run has already validated as its lease winner may widen that window, and it widens it to its own timestamp and no further: activity after the reservation still forces hydration. The freshness and winner checks are not new — the hydrated claim path already ran them. They move into a helper because the cache path now needs the identical check before hydration; the alternative is a second copy of the same lease-election logic, which is the thing most likely to drift. The extraction moves those statements without changing their order or conditions.

The target branch head is dropped from the cross-review comparison rather than made conditional, so no new constant enters the code. The record still carries targetHeadSha, and a single run still uses it to check that main held still across its own pre- and post-hydration probes; what goes is only the comparison against the previous review. Periodic re-review is bounded by the ceiling the probe already enforces, REVIEW_STRUCTURAL_CACHE_MAX_AGE_DAYS: a recorded verdict is reused for at most that long before a full review runs regardless of what main did. The cost is that obsolescence caused by main — an implemented_on_main landing in files the item never touched — is noticed at that ceiling rather than on the next daily pass.

When the reserved lease no longer describes the item, the cache path takes the same action the hydrated path already took for that condition: increment leaseAcquisitionFailures, record the item in leaseAcquisitionFailureDetails, and let the run fail at the end so the recovery lane requeues it, rather than silently dropping the item from the batch. That branch is intended parity with the existing hydrated behavior and is not covered by a new test; it is called out here so a reviewer checks it by reading, and the shared helper is what makes the two paths comparable at a glance.

Which deliveries this affects

reviewStructuralCacheProbeDecision checks explicitDispatch before coordinationEnabled, and AUTOMATIC_REVIEW_SOURCE_ACTIONS in src/clawsweeper-review-preparation.ts contains exactly scheduled_hot_intake and scheduled_normal_backfill after #1036.

  • Those two source actions cleared explicit_dispatch after fix(review): stop scheduled review storms on unchanged issues #1036 and then stopped at coordination_disabled. They carry the cadence buckets in docs/scheduler.md — activity-driven hourly, recent-item and pull-request daily, older-issue weekly — and they are what this change fixes.
  • Every other source action, including webhook events, @clawsweeper commands, legacy_dispatch, and unknown or missing actions, is still classified explicit by that same set and still short-circuits one gate earlier, unchanged by this PR. That is the intended behavior for a requested review.

#118777's most recent re-review is therefore not covered here: it arrived with source_action: artifact_retention_recovery (run https://github.com/openclaw/clawsweeper/actions/runs/31081165269), which is not in the automatic set. Whether a publication-recovery requeue should re-derive a verdict rather than republish the recorded one is a separate question.

Why a pull request's base does not move with the default branch

A reasonable worry about dropping the target-head comparison is that pull requests would still miss, because sourceRevision hashes snapshot.pull.baseSha and a base change would invalidate them anyway. That does not happen, because baseRefOid is pinned at pull-request synchronisation rather than tracked to the base branch:

value dated
openclaw/openclaw#118777 baseRefOid d2c8fd2e710f9f20f08938502063170e8554c228 2026-08-03T16:46:14Z
openclaw/openclaw main head at time of writing 9aa24e8f2e822290a4c4f785d48031f93c3f9fbb 2026-08-07T05:02:50Z

That pull request's base has not moved in three and a half days, across roughly 450 commits on main. Four other open pull requests updated within the same hour report four different base oids (65d2222a, f87d8bb7, a6b20789, f87d8bb7); if the field tracked the branch they would all equal the current head.

So for a pull request, an advancing default branch changes neither baseSha nor the source revision that hashes it. What still invalidates is the pull request actually being synchronised onto a new base, which is a real change to the item. Both directions are pinned by a regression in test/review-structural-cache.test.ts.

Non-goals

  • This does not change the semantic or content cache stages, the review verdict itself, or the explicit-dispatch classification.
  • This introduces no new constant. Staleness stays bounded by the ceiling the probe already enforces (REVIEW_STRUCTURAL_CACHE_MAX_AGE_DAYS): a recorded verdict is reused for at most that long before a full review runs regardless of what main did.
  • OpenClaw Bay is unaffected: this changes review invocation coordination only, not observer schemas, status projections, or queue contracts.

User Impact

A scheduled delivery can now reach and use the structural cache instead of being turned away before it is consulted. Where the default branch advances between passes — the case that motivated this — no scheduled pass previously reused a verdict at all, so every one of them re-ran a full review. Where such a pass satisfies every existing eligibility check the cache already enforced — a completed keep-open review under the same policy and model and less than 14 days old, an unchanged bounded source revision, an unchanged target head and pull head, and a claimable lease — it reuses the recorded verdict rather than re-running Codex. This change adds no eligibility relaxation; it only stops the lane from failing the coordination precondition by construction.

Runs that create their own start comment behave exactly as before: the non-supplied-lease branch still calls postReviewStartStatusComment with the same arguments. Explicit dispatches, maintainer requests, and @clawsweeper re-review still force fresh work.

What the evidence below does and does not establish:

  • Established: with the workflow's own flags, the probe now returns hit where it returned coordination_disabled, on the shipped modules.
  • Established against a live GitHub item: the reserved-lease claim runs and elects the reserved lease, the structural receipt is persisted where it was previously written as unknown, and a subsequent scheduled delivery reuses the recorded verdict with hydrations=0 — no GitHub hydration and no Codex call.
  • Established from public production state: a scheduled delivery on an unchanged pull request, on a repository whose main was also unchanged and with a review already on file, was still hydrated and re-reviewed in full.
  • Not established: behaviour on a production target. The live runs use one repository I own; that the same code runs on production targets is inferred from the shipped path being identical, not observed.

Evidence

One caveat first: pnpm run check as a single aggregate command is not clean in my local sandbox. It also runs test/repair/target-validation.test.ts, which fails 13 tests there because the sandbox cannot create /tmp/node-coverage-* or spawn its contained commands. Those same 13 fail on unmodified main at 2eb1787e0d183a84f29e84614b84f228037ba69f in the same sandbox, so they are environmental rather than caused by this change. That suite is untouched here, and this PR's own CI check is where it executes in a clean environment.

pnpm run build:all
node --test test/review-preparation.test.ts test/review-structural-cache.test.ts \
  test/review-semantic-cache.test.ts test/review-content-cache.test.ts \
  test/sweep-workflow.test.ts test/local-review.test.ts \
  test/local-range-review.test.ts test/command.test.ts
pnpm run check:static
pnpm run lint
node docs/proof/review-cache-coordination-gate/run-proof.mjs

With that suite excluded, the focused run is clean: 269 tests, 0 failures on Node 24.18.0. Static policy checks, formatting, all three TypeScript builds, and lint pass.

Two tests are added:

  • test/review-preparation.test.ts — "a reserved review lease keeps coordination enabled under --skip-start-comment", covering the production pairing plus the three cases that must keep their existing answer.
  • test/review-structural-cache.test.ts — "an advanced target head alone does not force hydration" and "a pull request survives target-branch movement but not its own base sync", covering both item kinds plus the age ceiling that still bounds reuse.
  • test/review-structural-cache.test.ts — "the exact-event lane's own invocation reaches the structural receipt", composing the shipped preparation decisions into the real probe using the workflow's own flags.

Both are anchored to this change. Restoring the previous expression in isReviewCoordinationEnabled (return !skipStartComment;), rebuilding, and re-running node --test test/review-preparation.test.ts test/review-structural-cache.test.ts fails exactly those two and no existing test: 48 tests, 46 pass, 2 fail.

Real Behavior Proof

Claim: a scheduled delivery of an unchanged item reuses its recorded verdict without hydrating GitHub or calling Codex, including when the target branch has advanced since that verdict was recorded.

Level: module-level proof against the built dist/ output using production argument values, plus a production observation that narrows the pre-fix reason by elimination. Not a live end-to-end trace; see Limits.

Exercised surface: the built parseArgs, suppliedReviewStartLeaseFromArgs, isExplicitReviewDispatch, isReviewCoordinationEnabled, and reviewStructuralCacheProbeDecision. Post-fix captures taken at 5ba31b23; pre-fix capture taken from a clean checkout of 2eb1787e0d183a84f29e84614b84f228037ba69f.

Scenario and fixture: the harness parses the flag list out of .github/workflows/sweep.yml rather than restating it, and aborts if production stops passing --skip-start-comment, --review-lease-owner, and --review-source-action together. Every argument value comes from one real delivery — openclaw/clawscan#7, reviewed by clawsweeper run https://github.com/openclaw/clawsweeper/actions/runs/31131759207 with sourceAction: scheduled_hot_intake and the durable lease marker that run published — so the fixture is not assembled from different items. No production module is stubbed or replaced; the one synthetic value is the prior review record standing in for a completed keep-open review. The probe decision is the last thing the harness observes, which is why its final line is labelled as an implication.

Command and environment: pnpm run build && node docs/proof/review-cache-coordination-gate/run-proof.mjs, Node 24.18.0, Linux.

Observed result — pre-fix, at 2eb1787e0d183a84f29e84614b84f228037ba69f:

build                     pre-fix (upstream/main)
skipStartComment          true
suppliedReviewLease       {"owner":"github-run-31131759207-1","commentId":5210008452}
explicitDispatch          false
coordinationEnabled       false
structural probe          {"hit":false,"reason":"coordination_disabled"}
implied next step (not run here)  full hydration + Codex

Post-fix, same command, same workflow flags:

build                     post-fix
skipStartComment          true
suppliedReviewLease       {"owner":"github-run-31131759207-1","commentId":5210008452}
explicitDispatch          false
coordinationEnabled       true
structural probe          {"hit":true,"reason":"hit"}
implied next step (not run here)  reuse the recorded verdict

explicitDispatch is already false on both sides, which is #1036 working as intended.

Production observation for the pre-fix side: run https://github.com/openclaw/clawsweeper/actions/runs/31131759207 reviewed openclaw/clawscan#7 starting 2026-08-06T23:36:45Z, from clawsweeper head 3f368a3e394d76c31584fce700cee9a62485cb66 — after #1036 merged at 2026-08-06T18:01Z. The other reasons the probe could have returned are excluded by public state at that moment:

Candidate reason Excluded by
explicit_dispatch sourceAction: scheduled_hot_intake, which #1036 made automatic
missing_review / incomplete_review the durable review comment on that PR has existed since 2026-07-01
target_changed openclaw/clawscan main last moved 2026-08-03T16:01:55Z, three days earlier
pull_head_changed the PR has one commit, dated 2026-08-03T16:04:07Z; head bb644fe1646cbd7f74c81947259ec5b042fad776

That run logged --skip-start-comment taking effect and no cache reuse:

[review] shard=0/1 start-comment=skipped #7
[review] shard=0/1 complete reviewed=1 cache_hits=0 structural_cache_checks=1
  structural_cache_hits=0 structural_cache_revalidations=0 semantic_cache_checks=1
  semantic_cache_hits=0 semantic_cache_ineligible=1 semantic_cache_revalidations=0
  content_cache_hits=0 hydrations=1

A pull request whose head had not moved in three days, on a repository whose main had not moved in three days, with a review record already on file, was hydrated and re-reviewed in full.

End-to-end run against a live GitHub item

The captures above stop at the probe decision, so the reserved-lease claim and
the receipt-persistence path were driven through the shipped review command
against a real issue in a repository I own
(https://github.com/masatohoshino/clawsweeper-cache-proof issue 1). Nothing ran
against a production target. Leases came from pnpm run reserve-review-lease,
the same command sweep.yml uses, so no marker was hand-written. The runner was
the branch at 5ba31b23, built from a copy of that tree whose only difference is
one added generic_fallbacks entry so my own account is onboarded the way
openclaw/* and steipete/* already are; no source file differs and that entry
is not in this PR.

The claim branch this PR adds runs. Emitted only by that branch:

[review] shard=0/1 structural-cache-start-comment=reserved #1

Reaching it requires the probe to pass coordination, the structural decision to
hit, and the claim to elect the reserved lease through the same freshness checks
the hydrated path uses. On main the same invocation stops at
coordination_disabled first.

The receipt is persisted. Two runs differing only in whether a prior
completed review existed:

run 1 report:  review_structural_target_head_sha: unknown
run 2 report:  review_structural_target_head_sha: b575dc7ad47e96e62288ab26eb84d5c5b5b22adf
"structural_cache_revalidation_reasons": { "hydrated_anchor_match": 1, "verdict_input_match": 1 }

That reproduces the production symptom — reports published with
review_structural_target_head_sha: unknown — and then clears it.

The cache hits, with no hydration and no Codex. A run that stopped at
activity_changed before the reservation was recognised now reuses the recorded
verdict. Same item, same reserved lease:

[review] shard=0/1 structural-cache-start-comment=reserved #1
[review] shard=0/1 cache-hit structural-unchanged skip-hydration-model #1 (1/1)
[review] shard=0/1 complete reviewed=1 cache_hits=1 structural_cache_checks=1
  structural_cache_hits=1 structural_cache_revalidations=1 ... content_cache_hits=0
  hydrations=0

The carried report records review_cache_hit: true and
review_structural_cache_hit: true. hydrations=0 is the point: 8 seconds end to
end, against 70-150 seconds for the full reviews that preceded it.

An unrelated commit on the target branch no longer costs a full review. The runs above kept the target repository's main still. Advancing it by one commit that has nothing to do with the item — a comment appended to README.md, where the item is about src/slug.js — was enough to lose the hit before this change:

structural_cache_reasons: { "target_changed": 1 }
cache_hits=0  hydrations=1                      (103 s, full hydration + Codex)

Same item, same reserved-lease flow, same advanced main, after the change:

[review] shard=0/1 structural-cache-start-comment=reserved #1
[review] shard=0/1 cache-hit structural-unchanged skip-hydration-model #1 (1/1)
[review] shard=0/1 complete reviewed=1 cache_hits=1 structural_cache_checks=1
  structural_cache_hits=1 ... content_cache_hits=0 hydrations=0
"structural_cache_reasons": { "hit": 1 }

8 seconds instead of 103, with no Codex call.

Not attributed to this PR. An earlier run in the same sequence skipped the
model through the content stage (cache-hit content-unchanged skip-model),
whose coordination comes from Boolean(acquiredReviewLease) and is already
satisfied on main by the pre-existing post-hydration claim. It is mentioned
because it happened, not as evidence. The durable review comment these runs
needed was published with apply-decisions --sync-comments-only --skip-dashboard,
the documented local apply repro, not by the production publication lane.

Controlled environment run (Crabbox local-container)

The runs above executed on my host. This repeats the focused validation inside a Docker-backed Crabbox lease at the current head, which is the controlled envelope AGENTS.md asks for on code-bearing changes.

Field Value
Provider local-container (Docker)
Runtime Docker 29.4.2, context default
Image ubuntu:26.04 @ sha256:678c6550cc43645e08669028bc177f50be4e7c5b8cca677067b1914d4afc7a03
Lease cbx_bfb55b2eb06c (slug cache-gate-proof3, container c3bc5926759d, type ubuntu_26.04)
Head 5ba31b2373e0c2bd132e0d116d9ce1a3dcb69764 — the current PR head
Node v24.19.0, pnpm 11.10.0
Artifact cbx_bfb55b2eb06c-artifacts.tgz, 9147 bytes, sha256 fdf8e568d7bd83e8ddaf8eeaab4de0da070e2a5f355478c6051a88b304ddaa02
Captured 2026-08-07T06:23:16Z

The artifact tarball only exists on my machine, so the trace it holds is reproduced verbatim below. Nothing is elided; the three files are the whole capture.

env.txt:

os=Ubuntu 26.04 LTS
node=v24.19.0
pnpm=11.10.0
dist_built=2026-08-07 06:22:16.422405452 +0000
target_changed_in_dist=0
--- source under test (sha256) ---
2d86fd44d523a3ea86abcbc480898f20231cf97cb71adb2612476b4bbbe2c51c  src/review-structural-cache.ts
57ac6aee69c6008be1382bfb1a7e18f68a1656628c625fc79cd7c0c52be8df38  src/clawsweeper-review-command-workflow.ts
e9a8179fd25a8f98ce438ba2e02c8fe615838c8be2c3512a9833ee64352411e3  src/clawsweeper-review-preparation.ts
7767a232e7ff6f1b1722ad5f0fe5000a2373751d9e20bb0736a769c3fcffe8e4  test/review-structural-cache.test.ts
captured_at=2026-08-07T06:23:16Z

harness.txt:

build                     post-fix
workflow flags            --target-repo --target-dir --artifact-dir --batch-size --max-pages --codex-model --codex-reasoning-effort --codex-sandbox --codex-timeout-ms --item-numbers --readonly-openclaw --skip-start-comment --review-lease-owner --review-lease-comment-id --shard-index --shard-count --review-source-action
skipStartComment          true
suppliedReviewLease       {"owner":"github-run-31131759207-1","commentId":5210008452}
explicitDispatch          false
coordinationEnabled       true
structural probe          {"hit":true,"reason":"hit"}
implied next step (not run here)  reuse the recorded verdict

tests.txt, final block (tests_exit=0):

ℹ tests 271
ℹ suites 0
ℹ pass 271
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4837.506964

Crabbox syncs the working tree without .git, so the lease cannot report a commit id of its own. Rather than assert one, the capture hashes the files under test, and those hashes are checkable against this head's blobs by anyone with the branch.

for f in src/review-structural-cache.ts src/clawsweeper-review-command-workflow.ts          src/clawsweeper-review-preparation.ts test/review-structural-cache.test.ts; do
  printf '%s  %s\n' "$(git show 5ba31b23:$f | sha256sum | cut -d' ' -f1)" "$f"
done

All four match. The lease also built dist/ itself — dist/review-structural-cache.js is stamped 2026-08-07 06:22:16 +0000 and grep -c target_changed over it returns 0 — so the code that ran is this head's, not a synced build.

This capture lives in the PR body rather than in a commit on purpose. Recording it in the repository advances the head past the head it names, which is how the previous two revisions of this section ended up identifying an older commit. AGENTS.md asks for the proof to be kept current in the PR body, and a body edit does not move the head. docs/proof/review-cache-coordination-gate/README.md carries the method, the commands, and the limits; this table is the capture.

Artifact contents are env.txt, harness.txt, and tests.txt. Scanning all three for token|secret|password|ghp_|github_pat|api[_-]?key|bearer|authorization returns 11 matches, every one a test name (for example "local-review scrubs both GitHub and GitHub Enterprise token aliases"). No credential, endpoint, or private URL is present; the lease never held GitHub credentials.

Envelope limits, stated so the run is reproducible rather than flattering: the lease is a local Docker container on my machine rather than the organization's AWS Crabbox capacity, and .crabbox.yaml targets provider: aws — this run overrode it with --provider local-container, the Linux path the provider documentation describes. The base image ships without jq, zip, unzip, and gh; installing them is part of the run, because without them 29 workflow-shell assertions fail on missing tooling rather than on behaviour. --no-hydrate is used because the repository's Actions hydration rejects pnpm/[email protected] under local Actions emulation. The live-GitHub end-to-end runs are not repeated inside the lease, which is kept free of GitHub credentials.

Artifact: docs/proof/review-cache-coordination-gate/ — the runnable harness plus a README holding both captures and this observation.

Limits:

  • No live claimed-delivery trace through the GitHub receipt-cache boundary. That requires the organization's App installation token, which only repository operators can exercise. fix(review): stop scheduled review storms on unchanged issues #1036 disclosed the same limit. The production observation narrows the pre-fix reason by elimination from public state; it does not read the probe's returned reason directly.
  • The proof establishes that the probe is reached. Lease claiming against live GitHub, receipt persistence, and reuse in the deployed lane are not exercised.
  • No production review jobs were dispatched, no model capacity was consumed, and no contributor notifications were generated while validating this change.

Disclosure: AI was used to investigate the lane, write the fix, and review it.

The exact-event workflow reserves the durable review lease in its own
write-token step, so it must invoke the review command with
`--skip-start-comment`. The same flag decided `coordinationEnabled`,
which `reviewStructuralCacheProbeDecision` consults before anything
else, so scheduled deliveries returned `coordination_disabled` and
re-ran full hydration plus Codex on unchanged items.

Because the probe never ran, `preHydrationStructuralRecord` stayed null
and the seeding branch could not persist a receipt for the next review
either, so the cache could not bootstrap even once.

Coordination now also holds when a reserved lease is supplied, and the
structural cache path claims that lease instead of posting a second
start comment. The single-lease invariant that `--skip-start-comment`
protects is unchanged: the claim reuses the freshness and winner checks
the hydrated path already ran, now shared through one helper, and a
reservation that no longer describes the item fails the run for the
recovery lane exactly as before.

openclaw#1036 landed the `explicit_dispatch` half of this; the two flags that
produce both gates sit on adjacent lines of the same invocation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clawsweeper clawsweeper Bot added the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Aug 7, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. labels Aug 7, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 8, 2026, 12:07 AM ET / 04:07 UTC.

ClawSweeper review

What this changes

This PR lets scheduled review deliveries claim their workflow-reserved lease and reuse eligible structural-cache receipts rather than rehydrate and rerun Codex for unchanged items.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 6 items remain

Keep open: the patch still permits a structural-cache hit when the target head changes between the initial probe and lease-held revalidation, so it can reuse a verdict whose within-run target context changed.

Priority: P1
Reviewed head: 5ba31b2373e0c2bd132e0d116d9ce1a3dcb69764

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The change has a concrete P1 cache-safety defect and its current-head controlled proof remains insufficient.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR contains claimed live output, but the current review context still lacks an inspectable redacted Docker-backed Crabbox envelope tied to the current head; add it to the PR body with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR contains claimed live output, but the current review context still lacks an inspectable redacted Docker-backed Crabbox envelope tied to the current head; add it to the PR body with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 4 items Missing within-run target check: The patch deliberately removes target-head comparison from the shared cache decision, so this function reports a hit when only the target head differs.
Revalidation uses the relaxed decision: The lease-held revalidation calls the same relaxed decision with the initial and newly fetched records and has no separate target-head equality check.
Existing precise safeguard: The existing same-verdict-input helper already requires equal target heads and is used for hydrated-path revalidation, showing the intended distinction between cross-review reuse and within-run stability.
Findings 1 actionable finding [P1] Preserve target-head validation during revalidation
Security None None.

How this fits together

The exact-event workflow turns scheduled queue work into a review command and supplies a durable lease. The review command checks a structural receipt, then either republishes the prior verdict or hydrates GitHub context and runs a new review.

flowchart LR
  A[Scheduled queue delivery] --> B[Exact-event workflow]
  B --> C[Reserved review lease]
  C --> D[Structural cache check]
  D --> E[Lease-held revalidation]
  E -->|unchanged inputs| F[Reuse prior verdict]
  E -->|changed inputs| G[Hydrate and review]
  F --> H[Publish review state]
  G --> H
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR contains claimed live output, but the current review context still lacks an inspectable redacted Docker-backed Crabbox envelope tied to the current head; add it to the PR body with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve target-head validation during revalidation (P1) - The new cross-review relaxation also applies to the lease-held second probe at src/clawsweeper-review-command-workflow.ts:598. If the target head changes after the initial record is fetched, this decision can still hit and carry the old verdict. Keep the intended cross-review behavior, but require equality for the two records in this one run (the existing same-verdict-input helper already includes that check) and cover it with a regression.
  • Resolve merge risk (P1) - A target default-branch change during the initial probe-to-revalidation window can be treated as unchanged and publish a cached verdict based on an obsolete target context.
  • Complete next step (P2) - The P1 defect has a narrow mechanical repair in the changed revalidation path and can be addressed without changing product direction.
  • Improve patch quality - Restore the initial-to-revalidation target-head guard and add the focused regression.
  • Improve patch quality - Attach the current-head Crabbox provider, image, lease, artifact, command, result, and limits in the PR body, redacting private data.

Findings

  • [P1] Preserve target-head validation during revalidation — src/review-structural-cache.ts:1292-1300
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Runtime, tests, and proof scope runtime +187/-59; tests +163/-3; proof docs +487 The PR changes the shared review-cache path and carries substantial proof material, so the narrow revalidation safeguard deserves focused review.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #1052
Summary: This PR is the linked candidate fix for the scheduled structural-cache reachability issue.

Members:

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

Merge-risk options

Maintainer options:

  1. Restore within-run target validation (recommended)
    Keep the cross-review relaxation, but reject cache reuse when the target head differs between the initial and revalidated structural records and add a focused regression.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve cross-review target-head tolerance, restore target-head equality for the initial-to-revalidation cache path, add focused coverage, and keep CHANGELOG.md untouched.

Technical review

Best possible solution:

Retain the intended cross-review tolerance for unrelated default-branch progress, but require target-head equality between the initial structural record and the lease-held revalidation record before reusing a verdict.

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

Yes, by source: two otherwise identical structural records with different target heads pass the revalidation call at src/clawsweeper-review-command-workflow.ts:598 because the changed decision no longer compares that field.

Is this the best way to solve the issue?

No: ignoring target movement across separate scheduled reviews is reasonable, but using that same relaxed comparison during a single lease-held revalidation loses the existing within-run stability safeguard.

Full review comments:

  • [P1] Preserve target-head validation during revalidation — src/review-structural-cache.ts:1292-1300
    The new cross-review relaxation also applies to the lease-held second probe at src/clawsweeper-review-command-workflow.ts:598. If the target head changes after the initial record is fetched, this decision can still hit and carry the old verdict. Keep the intended cross-review behavior, but require equality for the two records in this one run (the existing same-verdict-input helper already includes that check) and cover it with a regression.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A cache hit after an in-run target change can publish stale review state for scheduled deliveries.
  • merge-risk: 🚨 automation: The modified lease and cache-revalidation path directly controls scheduled review execution and verdict reuse.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR contains claimed live output, but the current review context still lacks an inspectable redacted Docker-backed Crabbox envelope tied to the current head; add it to the PR body with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Acceptance criteria:

  • [P1] pnpm run build:all.
  • [P1] node --test test/review-structural-cache.test.ts test/review-preparation.test.ts.
  • [P1] pnpm run check.
  • [P1] Run and record the current-head controlled Crabbox cache proof with the provider, image, lease, artifact, result, and limits.

What I checked:

Likely related people:

  • goutamadwant: Authored the merged scheduled receipt-reuse change that this PR extends. (role: introduced adjacent scheduled-cache behavior; confidence: high; commits: 138ee2f96ea7; files: src/clawsweeper-review-preparation.ts, test/review-structural-cache.test.ts)
  • PollyBot13: Available file history identifies this contributor on the owned-activity cache behavior adjacent to the modified decision path. (role: recent structural-cache contributor; confidence: medium; commits: b83f2983da6b; files: src/review-structural-cache.ts)
  • Peter Steinberger: Recent main history includes review-command workflow maintenance immediately before this PR base. (role: recent workflow-area contributor; confidence: medium; commits: 2eb1787e0d18; files: src/clawsweeper-review-command-workflow.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (19 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-07T11:24:08.958Z sha 5ba31b2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-07T13:17:28.127Z sha 5ba31b2 :: needs real behavior proof before merge. :: [P2] Update the documented structural-cache freshness contract
  • reviewed 2026-08-07T14:22:24.547Z sha 5ba31b2 :: needs real behavior proof before merge. :: [P1] Preserve the within-run target-head revalidation
  • reviewed 2026-08-07T16:23:24.244Z sha 5ba31b2 :: needs real behavior proof before merge. :: [P1] Preserve target-head validation during lease revalidation
  • reviewed 2026-08-07T17:37:58.793Z sha 5ba31b2 :: needs real behavior proof before merge. :: [P1] Retain target-head validation during revalidation
  • reviewed 2026-08-07T20:10:09.179Z sha 5ba31b2 :: needs real behavior proof before merge. :: [P1] Preserve target-head validation during revalidation
  • reviewed 2026-08-07T21:43:59.813Z sha 5ba31b2 :: needs real behavior proof before merge. :: [P1] Preserve target-head validation during revalidation
  • reviewed 2026-08-08T03:01:36.236Z sha 5ba31b2 :: needs real behavior proof before merge. :: [P1] Preserve target-head validation during cache revalidation

masatohoshino and others added 4 commits August 7, 2026 12:16
Drives the shipped review command against a live issue in a repository the
proof author owns, so the reserved-lease claim and the receipt-persistence
path are exercised rather than inferred from the probe decision alone.

The claim branch emits `structural-cache-start-comment=reserved`, and a
second run persists `review_structural_target_head_sha` where the first run
wrote `unknown` — the production symptom, reproduced and then cleared.

Also records what the run did not reach: the structural cache still misses
with `activity_changed`, because the lease comment `reserve-review-lease`
posts moves the item's `updated_at` past the owned-sync markers recorded in
the prior report. The model-skipping hit that run did produce came from the
content stage, whose coordination the pre-existing post-hydration claim
already satisfies, so it is not attributed to this change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Clearing the coordination gate alone did not restore cache reuse. The
exact-event workflow posts its lease reservation before invoking the
review command, so on that lane the reservation is always the item's
newest activity, and it necessarily lands after the sync markers the
prior review recorded. `activityCoveredByReview` therefore read
ClawSweeper's own write as reporter activity and returned
`activity_changed`, so scheduled deliveries kept hydrating and rerunning
Codex even once they reached the decision.

The reservation is now validated before the cache decision instead of
after it, and its timestamp is passed in as the owned-activity boundary.
Only the reservation this run has already elected as its lease winner
can widen that window, and it widens it to its own timestamp and no
further: activity after the reservation, including a reporter comment,
still forces hydration. Validating first also removes a second GitHub
probe, because the claim below reuses the result.

Proof: a live scheduled delivery on an unchanged item now reports
`cache-hit structural-unchanged skip-hydration-model` with
`structural_cache_hits=1` and `hydrations=0`, where the same item
previously missed with `activity_changed`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… blocker

The reservation lookup was unconditional once the probe passed, so every
structural miss on the reserved-lease lane paid a GitHub read it did not
need. Decide first without the owned boundary; only when the sole reason
is `activity_changed` validate the reservation and re-decide with it.

The cache-hit path still reuses that validation when it ran, and elects
the reservation itself when the decision hit for other reasons, so no
path claims the lease twice and none skips claiming it.

Re-verified end to end after the change: a live scheduled delivery on an
unchanged item reports `cache-hit structural-unchanged skip-hydration-model`
with `structural_cache_hits=1` and `hydrations=0`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@masatohoshino
masatohoshino marked this pull request as ready for review August 7, 2026 03:51
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 7, 2026
masatohoshino and others added 2 commits August 7, 2026 14:17
The structural decision compared the target repository's default branch head
across reviews. That head advances for reasons that have nothing to do with
the item under review, so on a repository whose default branch moves faster
than the review cadence the comparison can never match and the cache reuses
nothing. openclaw/openclaw advanced its default branch 100 times in the 21h11m
ending 2026-08-07 — roughly once every 13 minutes — against a daily cadence
over 5,536 open items, so every scheduled pass re-ran a full review.

Staleness stays bounded by the ceiling the probe already enforces: a recorded
verdict is reused for at most REVIEW_STRUCTURAL_CACHE_MAX_AGE_DAYS before a
full review runs regardless of what main did. No new constant is introduced,
and the record still carries targetHeadSha so a single run can verify main held
still across its own pre- and post-hydration probes.

Proof: one unrelated commit on the target branch — a comment appended to a
README, where the item is about a different file — previously turned a
`cache-hit ... hydrations=0` run (8 s) into `target_changed` with a full
hydration and Codex re-run (103 s). The same item on the same advanced main now
reports `structural_cache_hits=1` and `hydrations=0`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 7, 2026
The pull-request path was only covered indirectly. `sourceRevision` hashes
`snapshot.pull.baseSha`, which invites the reading that an advancing default
branch would invalidate pull requests anyway through `source_changed`.

It does not: `baseRefOid` is pinned at pull-request synchronisation rather than
tracked to the base branch. openclaw/openclaw#118777 still reported base
`d2c8fd2e` (2026-08-03T16:46:14Z) on 2026-08-07 with `main` at `9aa24e8f`
(05:02:50Z) — three and a half days and roughly 450 commits later — and four
open pull requests updated within the same hour reported four different base
oids, which they could not if the field followed the branch.

The regression pins both directions: an advanced target head alone reuses the
verdict, while synchronising the pull request onto a new base still returns
`source_changed`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 7, 2026
The live-GitHub runs executed on the author's host, which does not satisfy the
controlled-environment envelope AGENTS.md asks for on code-bearing changes.
This records a Docker-backed Crabbox `local-container` lease at the current
head with the provider, runtime, image digest, lease id, artifact hash, and
capture time, plus the 271-test focused run and the proof harness executed
inside it.

The envelope limits are recorded with it rather than omitted: the lease is a
local container rather than the organization's AWS capacity, the base image
needs jq/zip/unzip/gh installed before the workflow-shell assertions can run at
all, Actions hydration is skipped because local emulation rejects
pnpm/action-setup, and the live-GitHub runs are not repeated inside the lease
because it is kept free of GitHub credentials.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 7, 2026
Recording a current-head capture in the repository advances the head past the
head the capture names, so the committed envelope always identifies an older
commit than the one under review. Re-running and re-committing reproduces the
same off-by-one, because the recording commit is itself the change.

The document now holds only the method, the commands, and the limits. The
capture — provider, image, lease, artifact hash, head, timestamp — belongs in
the pull request body, which AGENTS.md names as the place to keep proof
current and which can be updated without moving the head.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 7, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Maintainer triage note while this waits on proof: the bug is real and worth fixing — scheduled re-reviews of unchanged items burn Codex spend and API quota every pass. Two asks before this can land:

  1. The review bot still marks the proof insufficient: it needs evidence from the scheduled lane itself (a scheduled delivery hitting the cache and completing as a cache-served no-op), not only the harness in docs/proof. The exact-review queue's own run artifacts are the cleanest source.

  2. Scope question, honestly asked: this restructures review preparation (+837 lines) to make the cache reachable. Could the cache be made reachable on the scheduled lane with a smaller seam — e.g. threading the existing structural-cache lookup into the scheduled delivery path where it diverges — without moving the preparation logic? If you tried that and it genuinely doesn't work, say why in the PR body and the current shape is fine; VISION.md pushes us to prefer the smallest trustworthy change, so the reasoning deserves a sentence.

No urgency from our side — the fix direction is right. 🦞

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Superseded by #1067, now merged — thank you for this one. Your diagnosis was exactly right: scheduled deliveries never reached the structural cache, and the re-review churn was burning real model spend. What changed in the landed shape: instead of relocating review preparation, the cache path claims the scheduled delivery's supplied lease inside the existing flow and re-evaluates staleness against the reservation timestamp, which kept the diff at +463/−64 with your test approach preserved. The merged commit carries your Co-authored-by credit, and the maintainer note about preferring the smallest trustworthy seam is thanks to your PR making the tradeoff concrete. 🦞

@steipete steipete closed this Aug 8, 2026
@masatohoshino

Copy link
Copy Markdown
Contributor Author

'm honored to have been able to help. I learned a lot from seeing how you narrowed the fix down to the smallest trustworthy seam — really elegant. Thank you for the credit, too! 🦞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduled review deliveries cannot reach the structural review cache, so unchanged items are re-reviewed and re-rated every pass

2 participants