Skip to content

feat: use webhook snapshots for non-mutating GitHub reads - #1167

Merged
steipete merged 5 commits into
mainfrom
steipete/webhook-read-model
Aug 14, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/webhook-read-model

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

ClawSweeper still spent thousands of GitHub REST reads per hour on planning, dashboard health, placeholder recovery, and repair-loop routing after the first four quota-saving changes. Those reads repeatedly hydrated state that GitHub App webhooks already describe, but there was no durable, freshness-labelled read model safe for non-mutating consumers.

Measured residual from the post-PRs 1–4 four-hour window:

GitHub egress class Four-hour residual Approximate hourly rate This PR
repository_actions:item_metadata 8,929 2,200/hour Targets planning item reads and dashboard run/job scans
repository_actions:comments 3,012 750/hour Targets placeholder and repair-loop comment hydration
reviews 8 effectively extinct Intentionally leaves the rank-1 review cursor path unchanged

Why This Change Was Made

This adds a signed-webhook materialized read model to the exact-review queue Durable Object. It stores bounded, monotonic item, comment, review, review-comment, workflow-run, workflow-job, and check snapshots; serves publisher-HMAC reads with an explicit watermark and freshness; and moves four measured consumers to snapshot-first reads with live polling on miss, gap, staleness, or missing event-class coverage.

The read model is evidence for planning, discovery, hydration, and dashboards only. Apply mutation guards, the two-sided lease check, final post-mutation verification, and placeholder deletion revalidation remain live GitHub reads.

Review round 1 dispositions

Accepted finding Disposition and evidence
Require complete per-run workflow coverage Resolved. Webhook rows alone are never usable as a complete workflow view. The dashboard requires a fresh persisted bounded run census, reconciles rows only up to the census start watermark, and uses cached jobs only for run IDs with fresh complete job coverage. Missing workflow_job delivery still forces the live poll. The cold/partial and per-run coverage cases are in the refreshed Crabbox proof.
Use authentication available to exact-review workers Resolved. Exact-review planning uses its existing full live lease tuple as a read-only capability for only the tuple's repository/item. The worker receives no CLAWSWEEPER_WEBHOOK_SECRET; forged tuple tests return 409, and the capability exposes no repair/write route.

Both applicable rank-up moves were applied: the proof now includes a cold/partial workflow census scenario and a secret-free exact-review lease-reader scenario.

Required GitHub App event subscriptions

The owner must enable delivery of all of these repository events for the corresponding savings to activate:

App event subscription Required actions/state
Issues Full lifecycle including close/reopen, label/unlabel, lock/unlock, assignment, and milestone changes
Pull requests Lifecycle, head/base, draft, state, labels, and counts
Issue comments Created, edited, and deleted, including ordinary non-command comments
Pull request reviews Submitted, edited, and dismissed
Pull request review comments Created, edited, and deleted
Workflow runs Requested, in-progress, and completed state
Workflow jobs Queued, in-progress, waiting, completed, and step state
Check runs and check suites Current check state

Readiness is tracked per exact event class. A related class cannot unlock a consumer. If a class has never arrived, the consumer keeps polling and emits one structured github_read_model_degraded line; the 30-minute probe window is reported rather than silently assuming App configuration.

Poller migrations and request formulas

Consumer Before Fresh snapshot Repair contract
Exact-item review planning 1 issue GET per selected item 0 GitHub requests One live GET on miss/gap/TTL, then repair
Dashboard workflow health 2 general/completed run scans + 5 active-status scans + J job pages 0 GitHub requests while fresh Bounded complete run census plus fresh per-run job coverage; fixture with one active run is 8 → 0
Placeholder discovery 2 state searches + P per-item comment pages 0 GitHub requests while the index is fresh Slow six-hour search/comment repair sweep; fixture is 3 → 0
Repair-loop router R per-item complete comment-list reads 0 GitHub requests on complete fresh collections 30-minute repair poll; absent comments become tombstones; fixture is 1 → 0

The composed dashboard response cache increases from 20 seconds to 60 seconds. Read-model TTLs are 15 minutes for items, 30 minutes for comment/review collections, 5 minutes for workflow state, and 6 hours for placeholder index repair coverage.

Read-model schema and ordering

  • One normalized issue/PR row per repository and number, including state, labels, head/base, counts, source timestamp, delivery GUID, and object watermark.
  • Numeric-ID ordered issue comments with deletion tombstones, capped at 500 per item and 64 KiB per body.
  • Reviews and inline review comments stored separately with tombstones, counts, and a stable digest, capped at 500 per item.
  • Workflow runs, jobs, check runs, and check suites capped at 1,000 current/recent objects.
  • A persisted run-census coverage row and separate per-run job coverage rows; partial/cold webhook rows cannot bypass polling.
  • Delivery GUID receipts retained for 30 days.
  • One monotonically increasing observation watermark per unique delivery. Older deliveries may advance observation state but cannot replace a newer object row.
  • Complete repair lists detect count gaps, tombstone disappeared comments, and make an empty collection cacheable.

User Impact

Operators get the same planning, recovery, routing, and dashboard decisions with substantially fewer GitHub REST requests once the required App subscriptions have delivered at least one event. Missing webhook configuration, lost deliveries, late events, and stale snapshots degrade to the existing poll path instead of changing decisions or weakening safety.

OpenClaw Bay Impact

OpenClaw Bay is unaffected. This changes internal read transport only; the public observer schema and observer-only/no-action boundary are unchanged. Bay still cannot trigger queue, workflow, GitHub, DLQ, recovery, deployment, or rollback actions.

Documentation Lifecycle

docs/github-webhook-read-model.md is active architecture/operator documentation. It names the dashboard/queue maintainer role, owning source files, update triggers, required App subscriptions, TTLs, schema bounds, and safety boundary. docs/proof/webhook-read-model/** is historical proof under the existing proof lifecycle classification.

Evidence

Real Behavior Proof

  • Claim: signed webhook deliveries can replace the four non-mutating pollers without changing their decisions, while duplicate, late, missing, and deleted-event cases stay conservative and mutation guards remain live.
  • Exercised surface: Worker webhook classifier and signature verification, exact-review queue Durable Object SQLite store, publisher-HMAC reads, planning item reads, dashboard run/job health, placeholder recovery, repair-loop routing, apply LiveReadGeneration, and final bypass reads.
  • Scenario: realistic issue, ordinary comment, comment delete, PR review, inline review comment, workflow run, workflow job, and check deliveries; duplicate GUID; late item update; deleted comment followed by late edit; count gap followed by complete repair; missing event-class degradation.
  • Command/environment: Docker-backed Crabbox provider=local-container, image node:24-bookworm, lease cbx_7451f463bac8; docs/proof/webhook-read-model/run-proof.sh d563120f3b7be59b3e6df6bb928c8a1933dec4f3 386730fc41ae0b1b63a7dbbd648404be6bd65c66.
  • Observed result: 59/59 focused tests passed; static jq accepted the behavior report; dashboard-strict passed with the new module enrolled; full pnpm run check passed 3,455 tests with 0 failures and 8 skips. Poller fixtures produced identical decisions at 1 → 0, 8 → 0, 3 → 0, and 1 → 0 GitHub requests. Cold/partial workflow rows remained unusable until census coverage; missing job subscription retained live polling; the scoped exact-review lease reader succeeded without the webhook secret and rejected a forged tuple. Apply-generation and final-bypass counters each observed one live hit and zero read-model guard hits.
  • Artifact: docs/proof/webhook-read-model/receipt.json, behavior-report.json, and container-transcript-summary.txt. Crabbox reports leaseStopped: true.
  • Revision: code/proof ran at d563120f3b7be59b3e6df6bb928c8a1933dec4f3; final head df35ef612f adds only the refreshed receipt/report/summary files.
  • Limits: deterministic loopback fixtures; no production GitHub, App settings, Worker deployment, queue, comment, label, close, merge, or workflow state was mutated.

Additional validation:

  • Pre-commit autoreview: clean, no accepted/actionable findings.
  • Committed branch autoreview against origin/main: clean, no accepted/actionable findings.
  • Proof artifacts passed TruffleHog with 0 verified and 0 unknown secrets.
  • OpenClaw Bay impact: none, for the contract reason above.

CI note: production automerge flow currently fails its hermetic GitHub-quota expectation (retryable_failure expected, permanent_failure observed). The exact targeted Docker scenario fails identically on this PR and on archived origin/main@386730fc41, so this is an inherited base failure outside this PR's changed surface. The PR's pnpm check and refreshed Docker proof are green.

@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: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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, 6:22 AM ET / 10:22 UTC.

ClawSweeper review

What this changes

Adds a signed webhook-backed snapshot store for non-mutating GitHub reads, with freshness checks and live-poll repair fallbacks for planning, dashboard, placeholder recovery, and comment routing.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for normal merge review: both prior blockers are resolved, and the branch has strong current behavior proof; production webhook-subscription activation remains a maintainer operational choice.

Priority: P2
Reviewed head: df35ef612f839905d4824e2f2409936adf50b8f2
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong focused and full-gate evidence supports a coherent implementation with both prior review blockers addressed.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Recorded Docker-backed Crabbox proof exercises the signed webhook, Durable Object, poller equivalence, fallback, and mutation-bypass paths with passing results.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): Recorded Docker-backed Crabbox proof exercises the signed webhook, Durable Object, poller equivalence, fallback, and mutation-bypass paths with passing results.
Evidence reviewed 5 items Prior workflow-coverage blocker resolved: The workflow reader requires a persisted run census before its snapshot is usable and exposes per-run job coverage; dashboard job readers use cached jobs only for covered run IDs.
Prior exact-review authentication blocker resolved: The public Worker routes the secret-free exact-review item request to the lease-capability endpoint, and the queue verifies the complete live lease tuple before returning a snapshot.
Lease capability coverage: The focused test exercises a secret-free lease reader and rejects a forged claim generation.
Findings None None.
Security None None.

How this fits together

GitHub App webhooks enter the dashboard Worker and are materialized in the exact-review queue’s Durable Object. Planning and observability consumers use fresh complete snapshots, while incomplete or stale state falls back to live GitHub reads and repairs the cache.

flowchart LR
  A[GitHub App deliveries] --> B[Signed webhook ingress]
  B --> C[Durable snapshot store]
  C --> D{Fresh and complete?}
  D -->|yes| E[Planning and dashboard readers]
  D -->|no| F[Live GitHub poll and repair]
  F --> C
  E --> G[Review and health views]
Loading

Decision needed

Question Recommendation
Should the production GitHub App enable the complete event-subscription set required to activate this read model’s savings? Enable and verify subscriptions: Enable the documented event classes and confirm the Worker stops reporting missing-class degradation for the migrated consumers.

Why: The PR cannot configure the deployed GitHub App itself; its safe fallback preserves current behavior, but only a maintainer can choose the production subscription scope.

Before merge

  • Resolve merge risk (P1) - The expected GitHub-read savings require the documented GitHub App event subscriptions; without them, consumers safely retain live polling but the feature’s central operational benefit remains inactive.
  • Complete next step (P2) - No concrete repair is needed; the remaining action is maintainer confirmation of the external GitHub App subscription rollout.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Code and test growth production +2,496/-67; tests +741/-11; docs +519/-0 This is a broad new persistence and transport surface with substantial focused regression coverage.
Behavior proof 59 focused passed; full check 3,455 passed, 0 failed, 8 skipped The recorded Docker-backed proof directly exercises ingress, fallback, coverage, and live-read boundaries.

Merge-risk options

Maintainer options:

  1. Verify production webhook readiness (recommended)
    Enable the required GitHub App subscriptions and confirm degraded-read telemetry clears for each migrated event class before relying on the promised savings.
  2. Land with conservative fallback
    Merge while retaining live polling until the subscription configuration is intentionally completed.

Technical review

Best possible solution:

Enable and verify the documented GitHub App subscriptions, then monitor the degraded-read telemetry while preserving the live-read mutation boundary.

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

Not applicable — this is a feature PR; its Docker-backed proof exercises signed deliveries, snapshot misses, gaps, stale state, and live fallback behavior.

Is this the best way to solve the issue?

Yes — a bounded, freshness-labelled snapshot cache with explicit live fallbacks is an appropriate way to reduce non-mutating GitHub reads without weakening mutation guards.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 automation: The PR changes webhook ingestion and queue/dashboard automation, whose intended savings depend on production App event subscriptions.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): Recorded Docker-backed Crabbox proof exercises the signed webhook, Durable Object, poller equivalence, fallback, and mutation-bypass paths with passing results.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 other: Current PR review merge-risk labels are merge-risk: 🚨 automation.

Label justifications:

  • P2: This is a bounded operational improvement to GitHub-read efficiency with conservative fallbacks, not an urgent user-facing regression.
  • merge-risk: 🚨 automation: The PR changes webhook ingestion and queue/dashboard automation, whose intended savings depend on production App event subscriptions.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): Recorded Docker-backed Crabbox proof exercises the signed webhook, Durable Object, poller equivalence, fallback, and mutation-bypass paths with passing results.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Docker-backed Crabbox proof exercises the signed webhook, Durable Object, poller equivalence, fallback, and mutation-bypass paths with passing results.

Evidence

What I checked:

  • Prior workflow-coverage blocker resolved: The workflow reader requires a persisted run census before its snapshot is usable and exposes per-run job coverage; dashboard job readers use cached jobs only for covered run IDs. (dashboard/github-webhook-read-model.ts:794, df35ef612f83)
  • Prior exact-review authentication blocker resolved: The public Worker routes the secret-free exact-review item request to the lease-capability endpoint, and the queue verifies the complete live lease tuple before returning a snapshot. (dashboard/worker.ts:933, df35ef612f83)
  • Lease capability coverage: The focused test exercises a secret-free lease reader and rejects a forged claim generation. (test/github-webhook-read-model.test.ts:370, df35ef612f83)
  • Current real-behavior proof: Docker-backed Crabbox evidence for code head d563120 reports 59 focused tests passing and a full check with 3,455 passes, 0 failures, and 8 skips; the final head changes only three proof artifacts. (docs/proof/webhook-read-model/receipt.json:10, df35ef612f83)
  • Feature-history provenance: The current queue and Worker read-broker boundary was introduced by the durable ETag broker work, with adjacent live-read and hydration-snapshot safety work also on current main. (dashboard/exact-review-queue.ts:3024, dc6762092a50)

Likely related people:

  • steipete: Current-main history attributes the adjacent durable ETag broker, live-read generation, and hydration-snapshot work to Peter Steinberger. (role: recent area contributor; confidence: high; commits: dc6762092a50, c9eda83c29d2, 96b8703e4c0b; files: dashboard/exact-review-queue.ts, dashboard/worker.ts, src/clawsweeper-review-planning-inventory.ts)
  • Martin Cleary: Recent queue recovery and dashboard work provides adjacent ownership context for the Durable Object and operational fallback surfaces. (role: adjacent queue contributor; confidence: medium; commits: 56cb78d60734, ac340908bf69; files: dashboard/exact-review-queue.ts, dashboard/worker.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-14T10:03:04.889Z sha fd5c871 :: needs changes before merge. :: [P2] Require complete per-run coverage before using workflow snapshots | [P2] Use an authentication path available to exact-review workers

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 14, 2026
@steipete
steipete merged commit bf762f3 into main Aug 14, 2026
22 of 23 checks passed
@steipete
steipete deleted the steipete/webhook-read-model branch August 14, 2026 10:28
steipete added a commit that referenced this pull request Aug 14, 2026
…ntom queued runs (#1169)

Fixes the phantom queued run that put operational health into a false "degraded" state after #1167 (production evidence: queued_over_threshold=1 aging 54->58->61min across probes while zero queued runs older than 30min existed in any of the nine involved repos - the App's Workflow runs/jobs subscriptions are not yet enabled, so a run whose terminal transition fell between repair polls stuck in the snapshot forever).

Root cause: repository-wide census freshness let unconfirmed queued rows reach health calculation with no per-run confirmation age. Fix, hardened across three review rounds: per-run confirmation timestamps; bounded exact rechecks (batch of 10 per refresh, oldest-stale first, two five-way waves under the 20s cadence - a 200-stale-row snapshot now issues exactly 10 reads instead of 205 and stays fast); race-safe terminal/404 eviction with telemetry; verification failures report unknown, never a phantom alert; omitted unconfirmed rows are unknown and never count toward thresholds; live polling remains authoritative without subscriptions; no rechecks beyond the 24h zombie boundary. Genuine stuck runs still alert.

Proof: red reproduced the phantom-degraded state and the 205-read stall; green 22/22 focused, backlog drains in 21 refreshes; full gate 3466/0 host and container; Crabbox local-container receipt at this exact head, machine-verified provenance. Verdict clean (no actionable correctness finding) on 26d446e.
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: 🦞 diamond lobster Very strong PR readiness with only minor 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