Skip to content

perf(review): reuse prior verdict when reviewable content is unchanged - #410

Merged
steipete merged 14 commits into
openclaw:mainfrom
yetval:feat/review-content-cache
Jul 4, 2026
Merged

steipete merged 14 commits into
openclaw:mainfrom
yetval:feat/review-content-cache

Conversation

@yetval

@yetval yetval commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Scheduled reviews currently start a fresh high-reasoning Codex process even when the reviewable content is unchanged. This adds a conservative content cache for planned background reviews without reducing the 128-worker pool.

An automatic review can reuse a prior report only when all of these are true:

  • the prior review completed successfully and decided keep_open;
  • the review policy and reviewable-content digest still match;
  • the last full model review is less than 14 days old; and
  • the run is a planned background review, not an exact dispatch or maintainer-requested review.

Close verdicts are never cached. They always receive a fresh model review.

Reviewable content

The digest covers the issue or PR source, human timeline activity, closing and related items, the latest release, PR head/base state, diff, commits, and inline review comments. ClawSweeper-owned churn and advisory-label churn are ignored.

Issue cache keys also include the target main SHA because a main-branch fix can change an issue verdict without changing its discussion. PR keys already include their live base SHA.

Prompts remain bounded, but cache freshness does not depend on those bounds: long human timelines and PRs with more than 40 inline comments get full-set revision hashes. A changed middle comment therefore invalidates the cache even when that comment is omitted from the model prompt window.

The cache is self-migrating. Existing reports without the new digest fields take one full review before they can become eligible.

Safety boundaries

  • First reviews, failed reviews, policy changes, content changes, exact dispatches, maintainer prompts, missing decisions, and reports older than 14 days always run Codex.
  • Only non-destructive keep_open verdicts can be reused. A stale close can never be carried into apply.
  • Cache eligibility uses the immutable verdict from the last full model run, so an apply-time close-to-keep-open rewrite cannot enter the cache.
  • Cache-carried reports cannot be promoted to close by no-diff, supersession, pause/close, or stale-rating apply rules. A fresh full review must run first.
  • Related-item discovery still receives the full available review-comment context, including outside the cache path.
  • Workflow-generated planned item lists are cache eligible; manual exact-item workflow dispatches remain fresh.

Proof

  • Focused cache and close-promotion suite: 41/41 passed.
  • Full repository pnpm run check: 651 unit, 617 repair, and 1,268 coverage tests passed, plus builds, lint, coverage thresholds, active-surface/limits checks, and formatting.
  • Independent AutoReview: no accepted or actionable findings on exact head 63c5a7d1bd2672c12c198a3f5598d2e1e7db63f8.
  • No dependency, release, version, or worker-count changes.

The original subprocess smoke remains representative: among first review, unchanged keep-open, changed diff, new maintainer comment, and unchanged close, only the unchanged keep-open review skips the model process.

The review lane re-runs the full model (codex exec, high reasoning effort) for
every due item on a fixed cadence, gated only on time and the review-policy
hash. It never checks whether the reviewable content changed, so most
re-reviews across the open backlog re-derive an identical verdict from
identical input, spending tokens and a worker slot for tens of minutes each.

Add a content-addressed skip. On an automatic re-review, compute a content
digest of the review-relevant surface (item source revision plus, for PRs, the
head sha, base sha, diff, and inline review comments) and skip the model when a
prior completed review has a matching digest under an unchanged policy within a
14-day ceiling, carrying the prior verdict forward. Explicit re-review requests,
policy changes, content changes, failed priors, and the 14-day ceiling all
still run a full review.

The digest excludes volatile inputs (item updated_at, live main sha, and
ClawSweeper's own comments) so the bot's own writes do not bust the cache. The
carry-forward refreshes only liveness fields (reviewed_at, item_updated_at,
item_snapshot_hash) and preserves the verdict, last_full_review_at, and
review-comment metadata, so the apply lane's changed-since-review protection is
unchanged.
@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 4, 2026, 12:03 PM ET / 16:03 UTC.

Summary
Adds a review-content digest/cache gate that carries forward completed reports for unchanged automatic re-reviews, persists cache metadata, and adds focused scheduler/digest tests.

Reproducibility: not applicable. as a performance PR rather than a bug report. The PR body provides live-output proof and the added tests exercise the skip-versus-spawn decisions.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 3 files, +380/-2. The diff is small but touches the central review loop, scheduler policy, and durable report tests.
  • Cache horizon: 14 days. A carried verdict is bounded by a fixed maximum age before a full model review is forced.
  • Close-verdict guard: 1 main_sha match check added. The current head addresses the prior stale-close concern by refusing to reuse close reports after main moves.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Wait for exact-head pnpm check and CodeQL action checks to finish before merge.

Risk before merge

  • [P1] This changes automatic review scheduling and durable report reuse, so a cache regression could suppress a needed model review until the 14-day ceiling.
  • [P1] Keep-open verdicts are intentionally cacheable across target-branch movement; maintainers should accept that delayed-close trade-off before merge.
  • [P1] Exact-head CI was still pending at inspection time, so merge should wait for required checks to finish.

Maintainer options:

  1. Land with bounded cache semantics (recommended)
    If maintainers accept that keep-open verdicts may delay closes for up to 14 days while close verdicts re-review after main moves, this can proceed once exact-head checks pass.
  2. Tighten freshness before merge
    Maintainers can require all carried reports to refresh or match current main state if state-display freshness matters more than cache-hit rate.
  3. Pause the cache rollout
    If the durable report semantics need a broader design pass, keep this draft open or close it in favor of a narrower follow-up.

Next step before merge

  • [P2] Human review is appropriate because this draft changes central automation semantics and requires maintainer acceptance, not a code repair.

Security
Cleared: The diff adds deterministic hashing, report metadata, scheduler logic, and tests without changing dependencies, workflows, permissions, secrets, or third-party execution paths.

Review details

Best possible solution:

Land the cache only after required checks pass and maintainers accept the bounded keep-open staleness, preserving the current close-verdict main-sha guard.

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

Not applicable as a performance PR rather than a bug report. The PR body provides live-output proof and the added tests exercise the skip-versus-spawn decisions.

Is this the best way to solve the issue?

Yes. The current approach is a narrow cache around completed reviews, and the current head now forces close verdicts through a full re-review when the recorded main SHA no longer matches.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output from the compiled gate with a fake codex showing unchanged re-reviews skip while first, changed-diff, and review-comment cases still spawn.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a normal-priority review-lane performance improvement with limited blast radius but real automation semantics to review.
  • merge-risk: 🚨 automation: The diff changes review scheduling and report reuse, so a mistake could skip needed model reviews or carry stale verdict state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output from the compiled gate with a fake codex showing unchanged re-reviews skip while first, changed-diff, and review-comment cases still spawn.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied live output from the compiled gate with a fake codex showing unchanged re-reviews skip while first, changed-diff, and review-comment cases still spawn.
Evidence reviewed

What I checked:

  • Repository policy read: AGENTS.md was read fully; its conservative automation and durable-state guidance is relevant to reviewing this review-lane cache change. (AGENTS.md:1, cdcb851924a7)
  • Digest construction: The PR-head digest hashes item kind, source revision, and for pull requests the head sha, base sha, diff, and non-bot review comments. (src/clawsweeper.ts:2322, 9f76d13358cd)
  • Cache gate: The current head requires a complete prior review, matching policy and digest, no explicit/maintainer request, a fresh last full review, and a matching main_sha before reusing close verdicts. (src/scheduler-policy.ts:148, 9f76d13358cd)
  • Review-loop integration: The review loop passes the current git main SHA into the cache gate before carrying a prior report forward and skipping the model call. (src/clawsweeper.ts:16789, 9f76d13358cd)
  • Regression coverage: The added tests cover digest busting, cache eligibility, the 14-day ceiling, explicit/maintainer misses, pre-digest reports, and close-verdict main movement. (test/review-content-cache.test.ts:179, 9f76d13358cd)
  • Prior finding addressed: Comparing the previously reviewed head to the current head shows the added decision/mainSha fields and close-verdict main-sha cache miss guard. (src/scheduler-policy.ts:162, 9f76d13358cd)

Likely related people:

  • brokemac79: Extracted the central scheduler policy and has multiple recent review/apply automation changes adjacent to this cache gate. (role: recent area contributor; confidence: high; commits: e95da707d494, 84796f0c9b0c, 44f0d7ac1222; files: src/scheduler-policy.ts, src/clawsweeper.ts)
  • Vincent Koc: Current reviewCommand and itemSnapshotHash history traces back through blame to the apply/checkpoint work that established snapshot-based freshness behavior. (role: introduced behavior; confidence: medium; commits: f94588d89c2f; files: src/clawsweeper.ts)
  • Peter Steinberger: Recently changed the same reviewCommand/apply paths for local-range review and deleted-target handling, making this a strong routing signal for review-lane safety questions. (role: recent area contributor; confidence: medium; commits: 55652622c484, cdcb851924a7; files: src/clawsweeper.ts)
  • yetval: Also appears in merged current-main review-lane history for re-review continuity, separate from authoring this PR. (role: recent adjacent contributor; confidence: medium; commits: 4db0631ce933; files: src/clawsweeper.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-04T15:44:56.955Z sha 08928d4 :: needs changes before merge. :: [P1] Re-review issue close verdicts after main changes

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. labels Jul 4, 2026
steipete and others added 2 commits July 4, 2026 16:59
A close verdict (for example implemented_on_main) depends on target-branch
code that is not in the content digest, because the live main sha advances on
every merge and would collapse the cache. Gate cache hits for close verdicts on
the stored main_sha matching the current one, so a main-branch change forces a
full re-review before any close and a close is never carried across
target-branch state it was not verified against. keep_open verdicts still cache
on content alone.
@yetval

yetval commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the [P1] on target-branch state in 9f76d13.

A close verdict can depend on main-branch code (implemented_on_main and similar), which the content digest omits on purpose: the live main sha advances on every merge, so digesting it would collapse the cache. Instead, a cache hit for a close verdict now additionally requires the stored main_sha to equal the current one. If main moved since the review that produced the close, the item takes a full re-review before any close, so a close is never carried across target-branch state it was not verified against. keep_open verdicts still cache on content alone (a stale keep-open only delays a close and is bounded by the 14-day ceiling).

Added regression tests: a prior close report cache-misses when main_sha changed, misses when it has no stored main_sha, hits when main is unchanged, and keep_open still hits across main movement.

@clawsweeper clawsweeper Bot added 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 4, 2026
steipete and others added 5 commits July 4, 2026 17:05
…-cache

# Conflicts:
#	src/scheduler-policy.ts
#	test/review-content-cache.test.ts
Supersede the close/main_sha gate with a structural invariant: the review cache
only carries keep_open verdicts, and a close verdict always takes a full
re-review. The apply lane only ever closes via a live re-check of current item
state and never turns a report's stored verdict into a close, so the sole
destructive risk is carrying a stale close forward. Restricting the cache to
keep_open removes that surface regardless of what the content digest covers; a
carried keep_open is non-destructive (at worst a delayed close, bounded by the
14-day ceiling).
@yetval

yetval commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the [P1] on prompt-changing context in bcbab37, and I stepped back on the approach.

This is the third finding of the same shape: a stale close carried forward because the content digest omits part of the prompt (first PR review comments, then main state, now closingPullRequests/referencingMergedPullRequests/relatedItems). Chasing digest completeness against the full nested, evolving context is a losing game, so I moved the boundary rather than adding another field.

The only destructive automated action is a close, and the apply lane only ever closes via a live re-check of current state (livePullRequestHasNoDiff, pullRequestClosePromotion on currentItemContext()); it never turns a report's stored verdict into a close on its own. So the whole risk is carrying a stale close forward. The cache now only carries keep_open verdicts; a close verdict always takes a full re-review. That removes the destructive surface structurally, independent of what the digest covers, and supersedes the earlier main_sha gate (which only covered main state). A carried keep_open is non-destructive (at worst a delayed close, bounded by the 14-day ceiling and by any content change), so digest coverage is now a freshness concern for keep-open items, not a safety one.

Proof (real gate plus a fake codex counting spawns) over [first-ever, unchanged keep-open, changed diff, new review comment, unchanged close]: base spawns 5, patched spawns 4. Only the unchanged keep-open skips; the unchanged close still runs the model.

@steipete
steipete marked this pull request as ready for review July 4, 2026 16:32
@steipete
steipete requested a review from a team as a code owner July 4, 2026 16:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7030d564ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/scheduler-policy.ts Resolved
@yetval

yetval commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

^^^Codex review is giving me the same review comment seems like
Review comment:

  • [P2] Prevent cached keep-open reports from being auto-closed — /
    root/cw-review-cache/src/clawsweeper.ts:17077-17077
    When a planned cache hit reuses a keep_open PR report that has since
    crossed an age-based stale threshold, this writes the carried
    markdown as a normal complete kept_open report. The apply path can
    then run pullRequestClosePromotion on that cached report and turn it
    into a close without a fresh Codex review, so destructive closes can
    still be produced from cached review output despite the intended
    safety boundary that only non-destructive verdicts are reused.

@steipete
steipete merged commit eca6fbf into openclaw:main Jul 4, 2026
11 checks passed
azaj01 pushed a commit to azaj01/clawsweeper that referenced this pull request Sep 21, 2026
openclaw#410)

* perf(review): reuse prior verdict when reviewable content is unchanged

The review lane re-runs the full model (codex exec, high reasoning effort) for
every due item on a fixed cadence, gated only on time and the review-policy
hash. It never checks whether the reviewable content changed, so most
re-reviews across the open backlog re-derive an identical verdict from
identical input, spending tokens and a worker slot for tens of minutes each.

Add a content-addressed skip. On an automatic re-review, compute a content
digest of the review-relevant surface (item source revision plus, for PRs, the
head sha, base sha, diff, and inline review comments) and skip the model when a
prior completed review has a matching digest under an unchanged policy within a
14-day ceiling, carrying the prior verdict forward. Explicit re-review requests,
policy changes, content changes, failed priors, and the 14-day ceiling all
still run a full review.

The digest excludes volatile inputs (item updated_at, live main sha, and
ClawSweeper's own comments) so the bot's own writes do not bust the cache. The
carry-forward refreshes only liveness fields (reviewed_at, item_updated_at,
item_snapshot_hash) and preserves the verdict, last_full_review_at, and
review-comment metadata, so the apply lane's changed-since-review protection is
unchanged.

* fix(review): harden content cache safety

* harden close-verdict cache against target-branch drift

A close verdict (for example implemented_on_main) depends on target-branch
code that is not in the content digest, because the live main sha advances on
every merge and would collapse the cache. Gate cache hits for close verdicts on
the stored main_sha matching the current one, so a main-branch change forces a
full re-review before any close and a close is never carried across
target-branch state it was not verified against. keep_open verdicts still cache
on content alone.

* fix(review): invalidate cache on human timeline events

* fix(review): bind cache reuse to target head

* fix(review): preserve exact dispatch freshness

* fix(review): hash full dynamic review context

* restrict content cache to keep-open verdicts

Supersede the close/main_sha gate with a structural invariant: the review cache
only carries keep_open verdicts, and a close verdict always takes a full
re-review. The apply lane only ever closes via a live re-check of current item
state and never turns a report's stored verdict into a close, so the sole
destructive risk is carrying a stale close forward. Restricting the cache to
keep_open removes that surface regardless of what the content digest covers; a
carried keep_open is non-destructive (at worst a delayed close, bounded by the
14-day ceiling).

* fix(review): preserve related review comments

* fix(review): refresh issue cache on main changes

* fix(review): preserve cache verdict provenance

---------

Co-authored-by: Peter Steinberger <[email protected]>
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. P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants