Skip to content

perf(apply): memoize per-item guard reads; stabilize coalescing race test - #1060

Merged
steipete merged 3 commits into
mainfrom
steipete/apply-guard-read-memo
Aug 7, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/apply-guard-read-memo

Conversation

@steipete

@steipete steipete commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Apply guards re-fetched identical GitHub endpoints up to seven times per item during one apply decision, amplifying pressure on the shared GitHub App installation rate limit that has been returning production 403s. A shared memo cache now deduplicates those reads per item, resets at item boundaries, and clears after every observed mutation.
  • The dashboard coalescing test hard-coded which enqueue won a legitimate race. It now asserts the same invariants for either winner.

Proof

  • Claim: one apply decision reuses identical guard reads without carrying stale data across items or observed mutations, while dashboard coalescing remains correct under either enqueue ordering.
  • Exercised surface: apply-guard read caching and invalidation plus the dashboard worker's coalescing race fixture.
  • Scenario: full unit suite, including both race interleavings and the per-item/mutation cache boundaries, plus a Docker-contained controlled apply run through the production apply-decisions entrypoint.
  • Unit command and environment: pnpm test:unit on Node 24. Observable result: 1950 of 1952 tests passed; 2 skipped. Both race interleavings were verified.
  • Controlled apply command and environment: exact head a17e2aa651d361708209da46da04493b08f3d951 on Crabbox provider=aws, lease cbx_fca17c765f6d, run run_46dc6edd2324, with node:24-bookworm. The container built the branch and invoked node dist/clawsweeper.js apply-decisions --skip-dashboard --item-number 321 --closed-dir <temp> against a controlled GitHub fixture.
  • Controlled apply result: two guard consumers produced one comments read before reset; resetting forced a second read. After one observed label mutation, the real apply workflow fetched changed review state and stopped the next mutation with skipped_changed_since_review (APPLY_CACHE_PROOF=PASS).
  • Limits: the GitHub endpoint was a controlled fixture, not production GitHub; no live issue, PR, comment, label, or close mutation was performed.

Review disposition

  • Removed the release-owned CHANGELOG.md entry; release context remains in this PR body and commit history.
  • Added current-head Docker-backed apply-boundary proof for read coalescing and post-mutation invalidation.

OpenClaw Bay is unaffected: this changes internal apply-decision read reuse and a test race assertion, without changing lifecycle publication, queue controls, status/telemetry, or dashboard data contracts.

@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. 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 Aug 7, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 7, 2026, 7:02 PM ET / 23:02 UTC.

ClawSweeper review

What this changes

The PR memoizes repeated GitHub guard reads within each apply item, clears that cache at item and mutation boundaries, and makes the dashboard coalescing-race test accept either valid enqueue winner.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This remains a current, useful PR: the cache and reset wiring are not on current main, the earlier changelog finding is resolved, and the updated PR body supplies controlled apply-boundary proof. No blocking patch defect was found.

Priority: P2
Reviewed head: a17e2aa651d361708209da46da04493b08f3d951

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, has dedicated boundary coverage, and includes controlled production-entrypoint proof for its central cache-invalidation claim.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body records a current-head Docker-backed controlled run through the production apply entrypoint, demonstrating cache reuse, reset behavior, and post-mutation fresh-state blocking.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body records a current-head Docker-backed controlled run through the production apply entrypoint, demonstrating cache reuse, reset behavior, and post-mutation fresh-state blocking.
Evidence reviewed 5 items Current-main gap: The cache and reset wiring are unique to the PR head; current main does not contain the guard-read cache implementation.
Cache scope and invalidation: The PR keys JSON and paged guard reads separately, resets before each item, and resets again through the observed-mutation path.
Focused coverage: Dedicated tests cover shared paged and JSON reads, request-key distinction, and explicit cache reset boundaries; the queue test now checks invariants for either legitimate race winner.
Findings None None.
Security None None.

How this fits together

ClawSweeper’s apply lane reads GitHub state to validate a reviewed item before mutating GitHub. Apply guards supply those checks, while the dashboard worker coalesces incoming exact-review work into a stored queue item.

flowchart LR
  A[Apply report] --> B[Per-item apply workflow]
  B --> C[Apply guard reads]
  C --> D[GitHub state]
  C --> E[Per-item guard cache]
  B --> F[Observed mutation]
  F --> E
  B --> G[Apply decision]
  H[Queue deliveries] --> I[Dashboard coalescing]
  I --> J[Stored queue item]
Loading

Before merge

  • Resolve merge risk (P1) - Merging changes guard-read behavior in the apply automation path; future mutation calls must continue to use the observed-mutation boundary so later guards do not reuse stale state.
  • Complete next step (P2) - No repair dispatch is needed because the current patch has no actionable review finding.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Runtime and test delta production +53/-5; tests +189/-3 Most added code is focused regression coverage around a comparatively small apply-path behavior change.
Changed surface 6 files affected The patch wires the cache through apply workflow boundaries and updates the related dashboard race assertion.

Merge-risk options

Maintainer options:

  1. Retain cache-boundary coverage (recommended)
    Merge with the per-item and post-mutation reset tests plus the recorded controlled apply trace, which directly cover the stale-state failure mode.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Retain the focused cache-reset tests and current-head controlled apply-boundary proof.

Technical review

Best possible solution:

Land the scoped cache with its reset contract intact, retaining focused coverage and the controlled apply-boundary proof for the final head.

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

Not applicable: this PR improves internal apply efficiency and a test’s race assertion rather than addressing a user-reported runtime reproduction.

Is this the best way to solve the issue?

Yes: exact-request memoization scoped to one apply item, with resets before the next item and after observed mutation, is the narrowest maintainable solution.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records a current-head Docker-backed controlled run through the production apply entrypoint, demonstrating cache reuse, reset behavior, and post-mutation fresh-state blocking.
  • 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 (terminal): The PR body records a current-head Docker-backed controlled run through the production apply entrypoint, demonstrating cache reuse, reset behavior, and post-mutation fresh-state blocking.
  • remove status: 📣 needs proof: 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 bounded reliability and rate-limit-pressure improvement in internal apply automation.
  • merge-risk: 🚨 automation: A missed cache invalidation boundary could make apply automation decide from stale GitHub guard 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 (terminal): The PR body records a current-head Docker-backed controlled run through the production apply entrypoint, demonstrating cache reuse, reset behavior, and post-mutation fresh-state blocking.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records a current-head Docker-backed controlled run through the production apply entrypoint, demonstrating cache reuse, reset behavior, and post-mutation fresh-state blocking.

Evidence

What I checked:

  • Current-main gap: The cache and reset wiring are unique to the PR head; current main does not contain the guard-read cache implementation. (src/clawsweeper-apply-guards.ts:10, f6f6bfca7d65)
  • Cache scope and invalidation: The PR keys JSON and paged guard reads separately, resets before each item, and resets again through the observed-mutation path. (src/clawsweeper-apply-decision-workflow.ts:454, a17e2aa651d3)
  • Focused coverage: Dedicated tests cover shared paged and JSON reads, request-key distinction, and explicit cache reset boundaries; the queue test now checks invariants for either legitimate race winner. (test/apply-guard-read-cache.test.ts:65, a17e2aa651d3)
  • Area provenance: The current apply-guard split was introduced by Peter Steinberger, establishing a direct history connection to this guard surface. (src/clawsweeper-apply-guards.ts:1, 0036015e1dd0)
  • Real behavior proof: The PR body records an exact-head Docker-contained run through apply-decisions, including one coalesced read, a reset-induced reread, and post-label-mutation changed-state blocking. (a17e2aa651d3)

Likely related people:

  • steipete: Peter Steinberger introduced the current apply-guards split and authored the PR’s guard-cache and queue-race changes. (role: original apply-guards refactor author and recent area contributor; confidence: high; commits: 0036015e1dd0, a63cfc4df278, 1a226605ad26; files: src/clawsweeper-apply-guards.ts, src/clawsweeper-apply-decision-workflow.ts, test/dashboard-worker.test.ts)
  • Vincent Koc: Recent dashboard and queue history includes durable exact-review queue work relevant to the race-test surface. (role: recent adjacent queue contributor; confidence: medium; commits: 49e8c7de6cfe, 2a61adcc1f06; files: test/dashboard-worker.test.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 (1 earlier review cycle)
  • reviewed 2026-08-07T22:23:18.681Z sha 1a22660 :: needs real behavior proof before merge. :: [P2] Remove the release-owned changelog entry

@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: 🦪 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. labels Aug 7, 2026
@steipete
steipete merged commit 5bfa2d9 into main Aug 7, 2026
21 checks passed
@steipete
steipete deleted the steipete/apply-guard-read-memo branch August 7, 2026 23:03
steipete added a commit that referenced this pull request Aug 8, 2026
The 450/h trim ducked App installation 403s at ~30 API calls per review.
Apply-guard memoization (#1060) cut that per-item cost and the read-pool
split (#1062/#1064) moved router and public reads onto the Actions token
pool, so the App bucket now carries only memoized hydration and writes.
Post-#1064 telemetry shows ~336 ok reviews/h with near-empty throttle
backoff at the 450 cap; restoring the historical 600/h uses the
recovered headroom.
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.

1 participant