Skip to content

improve(apply): reduce duplicate live GitHub reads - #1161

Merged
steipete merged 5 commits into
mainfrom
steipete/apply-read-generations
Aug 14, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/apply-read-generations

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Publication apply repeatedly reads the same issue, pull request, comments, timeline, policy, and lease state inside one item decision. The 2026-08-13 GitHub API savings analysis ranked this as opportunity 2, specifically its “Publication apply” and “Lease and mutation barriers” findings: duplicate reads are reducible, but the final mutation guards must remain authoritative and live.

Why This Change Was Made

Apply now creates one explicit LiveReadGeneration per item. Identical reads share one generation-owned result, every observed GitHub mutation advances the generation, and generation-bound context cannot cross that boundary without a runtime assertion. The two-sided lease checks and final proof/comment/close guards use an explicit cache-bypass option.

Apply also consumes the persisted PR hydration snapshot. Existing v2 snapshots immediately reuse commits and inline comments after live validation; v3 snapshots additionally carry the bounded pull-file window. A v3 hit therefore removes all three REST list reads. Any head, updated_at, count, or just-in-time activity-revision mismatch takes the normal full-read path.

Generation semantics:

Boundary Generation action Freshness rule
Start one apply item Create generation 1 fetchItem, context hydration, and policy reads may share identical keys
Successful/ambiguous GitHub mutation attempt Invalidate and advance Cached entries are cleared; generation-bound context is discarded
Durable comment, label, lease, placeholder, or close mutation Same observed mutation runner No mutation site can retain the preceding generation
Two-sided lease check Bypass Head/source, comments, then head/source all hit live transport
Final proof / comment / close guard Bypass Warm generation state cannot satisfy the mutation barrier

User Impact

Operators should see fewer GitHub REST reads during apply without any reduction in race protection. There is no end-user UI change.

OpenClaw Bay Impact

OpenClaw Bay is unaffected. This changes internal publication-apply reads and persisted cache metadata only; Bay’s observer-only data contract and action boundary do not change.

Documentation Lifecycle

The proof package under docs/proof/apply-read-generations/ is historical validation evidence owned by ClawSweeper publication maintainers. No active runbook or public product documentation changes.

Evidence

  • pnpm run check: 3,444 tests, 3,435 passed, 9 platform skips, 0 failures; dashboard-strict, builds, lint, docs, formatting, and coverage thresholds passed. Coverage: 81.57% lines, 74.01% branches, 87.39% functions.
  • Focused current-head integration after rebasing onto fix(apply): comment-only sync defers on GitHub rate limit instead of failing the run #1160: 79/79 passed.
  • Pre-commit and committed-branch autoreview: clean, no accepted/actionable findings.
  • Docker-backed Crabbox local-container receipt: cbx_0241049e673e (golden-barnacle-01a8), Ubuntu 26.04/arm64, fresh PR checkout, exit 0, automatically stopped. Static receipt: docs/proof/apply-read-generations/receipt.json.

Real Behavior Proof

Claim: Apply shares identical reads only within an explicit generation, invalidates on every observed GitHub mutation, and still blocks concurrent head/comment changes at its live barriers. A validated v3 hydration snapshot performs zero pull-file, commit, or inline-comment REST list reads.

Exercised surface: Production LiveReadGeneration, apply guard memoization, two-sided lease guard, mutation-boundary wiring, and hydratePrLists, backed by real loopback HTTP endpoints.

Scenario: Warm pull/comment reads; run pre-comment and pre-close lease barriers; advance the generation after a concurrent head change or new durable comment; validate a persisted v3 snapshot against live pull and activity watermarks.

Command/environment: Node 24.19.0 and pnpm 11.10.0, locally and through Crabbox Docker provider=local-container on Ubuntu 26.04/arm64.

Observable result: Each warm-cache barrier still issued two live pull reads and one live comment read. Both concurrent changes blocked apply. The representative formula changed from F(1)+C(4)+P(6)+L(3)=14 requests to U(6)+L_live(3)=9; the irreducible L(3) stayed live. Validated snapshot list counts were files=0, commits=0, inline-comments=0.

Artifact/trace: scripts/e2e/apply-read-generations-loopback.mjs, its Node test, and the static receipt in docs/proof/apply-read-generations/. The receipt binds tested source 82d9a3b14961793d13f3d0b113078eb84e4caf00, tree feb92bdcd220ed054fe9a73e1615bb327802d0d5, provider, lease, image, timings, formulas, assertions, and full-gate totals.

Limits: The controlled transport is deterministic loopback HTTP, not a live target mutation. Old v2 snapshots lack files, so they reuse validated commits/comments while performing one normal file-list read; new v3 snapshots reach zero for all three lists. The successful Crabbox run covers toolchain/build/source/proof. The exact-source complete gate is recorded on the Node 24 host because Linux cursor-trace workflow fixtures reject Linux filesystem metadata. No latency claim is made.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 12:53 AM ET / 04:53 UTC.

ClawSweeper review

What this changes

This PR reuses identical GitHub reads within a mutation-bounded apply generation and extends validated PR hydration snapshots to reuse pull-file data.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: this is a coherent, unmerged apply-lane optimization with supplied controlled transport proof and no concrete patch defect identified. Independent checkout and history inspection could not run because the read-only executor failed before commands began.

Priority: P2
Reviewed head: 321fdad45b3e8f42a049933d8c0db6a4ddf3032f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong controlled behavior proof and focused regression coverage support a good automation change, with normal maintainer scrutiny warranted for the broad apply safety surface.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR supplies a Crabbox local-container receipt and loopback HTTP trace exercising production read and guard code, with recorded after-fix concurrent-change blocking and snapshot-read results.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR supplies a Crabbox local-container receipt and loopback HTTP trace exercising production read and guard code, with recorded after-fix concurrent-change blocking and snapshot-read results.
Evidence reviewed 5 items Generation-bounded read implementation: The supplied diff adds a generation-owned cache with explicit bypass, invalidation, and generation-bound value assertions; the apply workflow creates one generation per item.
Live-barrier preservation: The supplied diff changes lease and proof-freshness reads to bypass the generation cache, preserving direct GitHub reads at mutation barriers.
Real behavior proof: The PR includes a Crabbox local-container receipt for a loopback HTTP exercise that records concurrent head/comment blocking, two live pull reads plus one comment read at barriers, and zero validated v3 snapshot list reads. The receipt records tested functional source 82d9a3b; the supplied final commit is docs-only proof recording.
Findings None None.
Security None None.

How this fits together

The publication apply lane reads GitHub item state, checks safety and review evidence, then publishes a review comment or closes an eligible item. This change adds bounded read reuse before those live mutation barriers while retaining direct reads for final guards.

flowchart LR
  A[Stored review record] --> B[Apply item processing]
  B --> C[Generation scoped GitHub reads]
  C --> D[Hydrated PR snapshot]
  C --> E[Live lease and proof barriers]
  D --> E
  E --> F[Comment or close mutation]
  F --> G[Generation invalidation]
Loading

Before merge

  • Resolve merge risk (P1) - This broad apply cache and guard refactor could weaken automation safety if a future mutation path omits generation invalidation; the supplied loopback proof covers named mutation and lease barriers but is not a live GitHub mutation.
  • Resolve merge risk (P1) - The proof receipt binds functional source 82d9a3b rather than the final docs-only head; rerun the proof if any functional code changes after that source.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Changed surface 22 files, +1,459 / -126 lines The change spans apply reads, safety guards, hydration data, tests, and a controlled proof package, so the mutation boundary deserves focused maintainer review.

Merge-risk options

Maintainer options:

  1. Land with the bounded-read proof (recommended)
    Accept the controlled transport evidence because it exercises generation invalidation, concurrent-change blocking, live barriers, and snapshot fallback without changing the final mutation guards.
  2. Rerun after functional changes
    If functional code changes beyond the receipt's tested source, regenerate the Crabbox proof against that exact head before merge.

Technical review

Best possible solution:

Retain mutation-bounded invalidation and live final barriers, then land only with the recorded proof still matching the functional head and normal maintainer review of the apply safety boundary.

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

Not applicable as a user bug report; the supplied PR includes a controlled loopback HTTP exercise of the changed internal apply path.

Is this the best way to solve the issue?

Yes, based on the supplied diff and proof: a per-item, mutation-bounded cache with explicit bypasses is a narrow way to reduce duplicate reads without making final guards stale.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies a Crabbox local-container receipt and loopback HTTP trace exercising production read and guard code, with recorded after-fix concurrent-change blocking and snapshot-read results.
  • 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 (linked_artifact): The PR supplies a Crabbox local-container receipt and loopback HTTP trace exercising production read and guard code, with recorded after-fix concurrent-change blocking and snapshot-read results.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded internal automation improvement with limited direct user impact.
  • merge-risk: 🚨 automation: The diff changes publication apply caching, live guard reads, and mutation-boundary behavior.
  • 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 (linked_artifact): The PR supplies a Crabbox local-container receipt and loopback HTTP trace exercising production read and guard code, with recorded after-fix concurrent-change blocking and snapshot-read results.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies a Crabbox local-container receipt and loopback HTTP trace exercising production read and guard code, with recorded after-fix concurrent-change blocking and snapshot-read results.

Evidence

What I checked:

Likely related people:

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rerun the recorded proof if functional code changes after 82d9a3b.

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-14T04:41:04.448Z sha 82d9a3b :: needs real behavior proof before merge. :: none

@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@steipete
steipete merged commit c9eda83 into main Aug 14, 2026
22 of 24 checks passed
@steipete
steipete deleted the steipete/apply-read-generations branch August 14, 2026 04:57
steipete added a commit that referenced this pull request Aug 14, 2026
…arges (#1164)

Quota campaign PR 4/5: durable ETag read broker - unchanged GitHub responses stop costing quota.

No wrapper sent If-None-Match before this; every repeat read paid a full quota charge (measured repeat floors: item_metadata 21.5%, comments 17.6%, reviews 19.5%). The broker persists ETag + body + digest in the queue DO (publisher-HMAC endpoints per the #1163 pattern; 30-day TTL; 2048-entry/512KiB bounds), keyed by credential pool, sorted route/query, media type, and page - a page-1 304 can never validate page 2. Cached bodies are released only after a live 304 plus digest confirmation; final pre/post-mutation guards always revalidate (a 304 is a live authoritative answer, but no guard ever consumes an unrevalidated cache). Composes with #1161: generations cover within-run reuse, the broker covers cross-run revalidation.

Integrated at the highest-repeat sites first: apply issue/pull metadata, paged comment/review collections, dashboard run/job health reads. Telemetry counts 200-with-store, 304-from-cache, miss, and skip as distinct units - this PR reduces QUOTA CHARGES, not wire requests (5 wire calls / 3 charged 200s in the counted fixture).

Proof: loopback ETag semantics with byte-identical 304 replay (digest asserted), page isolation, final-guard revalidation; full gate 3446/0 + dashboard-strict; Crabbox local-container receipt at this exact head, machine-verified provenance. Verdict clean (no actionable findings, proof sufficient) on bd2ef95.
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