Skip to content

perf(review): cache exact-review bundles in R2 - #1163

Merged
steipete merged 6 commits into
mainfrom
steipete/r2-bundle-cache
Aug 14, 2026
Merged

steipete merged 6 commits into
mainfrom
steipete/r2-bundle-cache

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

Cache validated exact-review artifact bundles in R2 by content digest so unchanged publication retries can avoid another GitHub artifact download. GitHub Artifacts remains authoritative: every cache miss, missing/corrupt object, receipt mismatch, or validation failure falls back to the existing GitHub path, subject to the existing open-circuit skip.

This is phase A of the two-phase design: GitHub download first, then populate R2. Producer-side R2 upload remains a later change after this path is proven.

Analysis citation

Implements rank 3, repository_actions:artifact_download, from the 2026-08-13 ClawSweeper GitHub API savings analysis: 12,784 observed artifact-download operations plus roughly 6,000 circuit skips, with a conservative 36% successful-repeat floor. The analysis recommended an immutable digest key plus a receipt binding producer run/attempt, canonical item key, lease revision, and protocol version.

Protocol and ownership

  • Object key: artifacts/exact-review/v1/<lowercase-sha256>.
  • The state-blob Worker requires the key suffix to equal the declared SHA-256 for direct PUT and multipart start/complete; exact-review objects are immutable.
  • Receipt primary key: (producer_run_id, producer_run_attempt, artifact_name, canonical_item_key, lease_revision, protocol_version).
  • Receipt value: digest, bytes, derived object_key, created_at, and expires_at.
  • Cache lookup happens before the GitHub rate-limit circuit. A hit consumes no GitHub artifact request; a fallback under an open circuit preserves the existing skip outcome.
  • Both receipt endpoints and state-blob transfer use CLAWSWEEPER_WEBHOOK_SECRET. These are automated publisher data-plane operations, and that secret already enters the batch job. EXACT_REVIEW_OPERATOR_SECRET remains confined to human recovery/admin endpoints.

Retention

Receipts expire after 30 days, matching existing terminal-receipt conventions. Each cache lookup/store performs bounded incremental cleanup: at most 128 expired receipts and one 128-object R2 page. A digest-leading (digest, expires_at) index supports live-reference checks. Old unreferenced objects, including upload orphans, are deleted; active receipts retain shared objects.

Counted behavior proof

Docker-backed Crabbox provider=local-container, lease cbx_27fd45c696a1, image node:24-bookworm; lease stopped automatically. The committed receipt is docs/proof/r2-bundle-cache/receipt.json.

Scenario GitHub artifact requests Result
First tuple acquisition 1 Validated bundle populated R2 + receipt
Identical tuple retry 0 Served byte-identical R2 content
Receipt present, R2 object missing 1 Failed closed to GitHub
Same producer tuple, different lease revision 1 Receipt not reused; GitHub fallback

All four paths produced SHA-256 3133665a6449f68c78754dfdca7548fa3b450474dd97cd54f4bb79b2a86d8eb3. Counted repeat result: 1 → 0 GitHub artifact requests (100% avoided for the exercised repeat).

Behavior-tested code head: 0e9ca08dea526b536e6818176228a09409a3c6a9; tree: d06aa801c6ee434707f15d9724e237bb8cec8181. Both were resolved with git rev-parse and cross-checked with git cat-file -e before the container run. PR tip 8be2e61d6cb4aca6feb1685be695727e37ca11d6 differs only by the refreshed committed receipt.

The same lease ran pnpm run check: dashboard-strict, docs, formatting, builds, all lint lanes, 260-file full tests, and coverage passed (81.58% lines / 74.00% branches / 87.41% functions).

Limits: Wrangler local R2/Durable Object semantics rather than deployed Cloudflare networking; counted loopback artifact server rather than GitHub's hosted artifact service. Production bundle input remains bounded at 64 MiB, with a 66 MiB archive bound.

Review disposition

  • Round 1: added digest-leading receipt indexing and rejected malformed/nested/uppercase immutable artifact keys.
  • Round 2: bound artifact object-key suffixes to declared digests for direct and multipart writes.
  • Final local ClawSweeper review at current tip: patch correct, no findings, proof sufficient, A/A/A.
  • Final committed-branch autoreview: clean, no accepted/actionable findings.
  • Rank-up moves: none.

OpenClaw Bay

Not affected. This changes internal publication data-plane acquisition and adds no observer or control contract; Bay remains observer-only.

@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. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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, 1:37 AM ET / 05:37 UTC.

ClawSweeper review

What this changes

The PR adds an R2-backed, digest-addressed cache for validated exact-review artifact bundles so unchanged publication retries can avoid GitHub artifact downloads.

Merge readiness

⚠️ Needs maintainer review before merge - 1 item remains

Keep open for normal maintainer review: the supplied PR evidence shows a real local cache/fallback exercise, but local source and history inspection could not run because the read-only sandbox failed before executing commands.

Priority: P2
Reviewed head: 8be2e61d6cb4aca6feb1685be695727e37ca11d6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The supplied behavior proof is strong, but the patch quality rating is limited by the failed independent source and history inspection.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body and committed receipt document an after-fix Docker-backed Crabbox run with real local Durable Object/R2 bindings, counted fallback behavior, and explicit proof limits.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body and committed receipt document an after-fix Docker-backed Crabbox run with real local Durable Object/R2 bindings, counted fallback behavior, and explicit proof limits.
Evidence reviewed 3 items Provided behavior proof: The PR body records a Docker-backed Crabbox run exercising first acquisition, an identical retry, a missing-object fallback, and lease-revision mismatch; the retry reduced counted artifact requests from 1 to 0 while fallback cases returned to GitHub.
PR scope: The supplied PR metadata reports 18 changed files and changes both the Durable Object receipt protocol and R2 state-blob access, so current-source review is required before a landing verdict.
Inspection infrastructure failure: Read-only inspection commands could not start: the sandbox returned bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted. No local files, git history, or matching maintainer notes were inspected.
Findings None None.
Security None None.

How this fits together

Exact-review publication prepares review bundles from GitHub artifacts before publishing review results. This cache sits between that preparation step and GitHub Artifacts, using Durable Object receipts and R2 objects to reuse a validated bundle while preserving GitHub fallback behavior.

flowchart LR
  A[Exact review publication] --> B[Receipt lookup]
  B --> C{Valid R2 cache entry?}
  C -->|Yes| D[Restore validated bundle]
  C -->|No| E[Download GitHub artifact]
  E --> F[Validate and cache bundle]
  D --> G[Publish review result]
  F --> G
Loading

Before merge

  • Resolve merge risk (P2) - This changes the review-publication data plane, authenticated receipt endpoints, Durable Object storage, and R2 fallback path; a source-level review is still needed to confirm failure handling and compatibility on the current base.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Changed surface 18 files, +1,773 / -136 lines The PR spans queue orchestration, R2 storage, scripts, tests, and proof documentation rather than a localized cache helper.

Merge-risk options

Maintainer options:

  1. Complete current-base reliability review (recommended)
    Review the merged diff’s receipt authentication, R2 error paths, and rate-limit fallback before landing because this path prepares and publishes automated reviews.
  2. Pause pending inspectable review environment
    Defer landing if a reviewer cannot inspect the exact current-base implementation and its storage boundary.

Technical review

Best possible solution:

Land only after a reviewer can inspect the current-base merge result and confirm that malformed, missing, and expired receipt paths preserve the established GitHub fallback and circuit behavior.

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

Not applicable as a defect report; the PR supplies a high-confidence controlled behavior exercise of the new cache protocol, but local independent execution was unavailable.

Is this the best way to solve the issue?

Unclear; the cache-first design and explicit GitHub fallback are plausible, but the sandbox failure prevented verification against current main and the complete merged implementation.

AGENTS.md: unclear because the file could not be read completely.

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

Labels

Label changes:

  • add P2: This is a bounded performance and reliability change to automated exact-review publication, with no demonstrated current user outage.
  • add merge-risk: 🚨 availability: A cache or fallback defect could prevent review bundles from being prepared when publication retries occur.
  • add merge-risk: 🚨 automation: The diff changes exact-review batch preparation and publication retry behavior.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body and committed receipt document an after-fix Docker-backed Crabbox run with real local Durable Object/R2 bindings, counted fallback behavior, and explicit proof limits.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body and committed receipt document an after-fix Docker-backed Crabbox run with real local Durable Object/R2 bindings, counted fallback behavior, and explicit proof limits.

Label justifications:

  • P2: This is a bounded performance and reliability change to automated exact-review publication, with no demonstrated current user outage.
  • merge-risk: 🚨 automation: The diff changes exact-review batch preparation and publication retry behavior.
  • merge-risk: 🚨 availability: A cache or fallback defect could prevent review bundles from being prepared when publication retries occur.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body and committed receipt document an after-fix Docker-backed Crabbox run with real local Durable Object/R2 bindings, counted fallback behavior, and explicit proof limits.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and committed receipt document an after-fix Docker-backed Crabbox run with real local Durable Object/R2 bindings, counted fallback behavior, and explicit proof limits.

Evidence

What I checked:

  • Provided behavior proof: The PR body records a Docker-backed Crabbox run exercising first acquisition, an identical retry, a missing-object fallback, and lease-revision mismatch; the retry reduced counted artifact requests from 1 to 0 while fallback cases returned to GitHub. (docs/proof/r2-bundle-cache/receipt.json, 8be2e61d6cb4)
  • PR scope: The supplied PR metadata reports 18 changed files and changes both the Durable Object receipt protocol and R2 state-blob access, so current-source review is required before a landing verdict. (dashboard/exact-review-artifact-cache.ts, 8be2e61d6cb4)
  • Inspection infrastructure failure: Read-only inspection commands could not start: the sandbox returned bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted. No local files, git history, or matching maintainer notes were inspected.

Likely related people:

  • unresolved-current-main-owner: The required current-main history and blame pass could not run in the read-only sandbox; the PR author is not listed solely for proposing this branch. (role: current-main area owner unresolved; confidence: low; files: dashboard/exact-review-queue.ts, dashboard/state-blobs.ts, scripts/prepare-exact-review-batch.mjs)

Rank-up moves

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

  • Obtain a current-base source review of the authenticated receipt, R2 cleanup, and GitHub-fallback paths.

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.

@steipete
steipete merged commit 6a358d2 into main Aug 14, 2026
20 checks passed
@steipete
steipete deleted the steipete/r2-bundle-cache branch August 14, 2026 05:44
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. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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