Skip to content

fix(publication): keep throttled batch publications on the transient retry budget - #1089

Merged
steipete merged 4 commits into
mainfrom
steipete/fix-batch-publication-retry-budget
Aug 10, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/fix-batch-publication-retry-budget

Conversation

@steipete

@steipete steipete commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The exact-review publication lane has been critical in production, dead-lettering finished Codex reviews at roughly 20-30 per hour. Sampling the live queue endpoint over ~21 minutes showed the store growing monotonically, and only in one bucket:

00:08:53Z  dlq 900  {retry_exhausted: 719, tuple_protocol_invalid: 177, workflow_cancelled: 4}
00:15:37Z  dlq 904  {retry_exhausted: 723, tuple_protocol_invalid: 177, workflow_cancelled: 4}
00:29:35Z  dlq 907  {retry_exhausted: 724, tuple_protocol_invalid: 177, workflow_cancelled: 4}

Each row is a review that was computed and then never posted.

Root cause

A publication dead letter is labelled retry_exhausted only when the reason code is unknown_failure, and unknown_failure carries by far the tightest budget in dashboard/exact-review-publication-retry.ts: 14 attempts or one hour, against 48 attempts / 24 hours for every other retryable reason.

The two publication paths disagreed about the same transport failure. postDirectPublicationResult returns only accepted or fallback, so every non-2xx and every network error arrives as fallback with an optional status:

  • Single-item path (src/repair/publish-event-result.ts) already mapped no-status / 429 / 5xx to state_contention, i.e. the generous transient budget.
  • Batch path (src/repair/exact-review-batch-cli.ts) special-cased only fence-ownership and 400/413, funnelled everything else into unknown_failure, and then discarded even that computed reason code by hardcoding unknown_failure in the completion mapper.

Batch is the dominant production path (batching enabled, 8 concurrent, 8 items each). So during a GitHub throttling episode — and the review lane confirms one, with 38 of 41 pending items in throttle_retry backoff — every batch publication landed on the one-hour budget.

The dead-letter inventory confirms the mechanism rather than merely fitting it. Of the 721 retry_exhausted rows:

  • 706 (98%) had spent fewer than 14 attempts, so the attempt cap did not fire.
  • The minimum observed lifespan is exactly 60.0 minutes, with median 91.8 — the UNKNOWN_RETRY_MAX_AGE_MS age cap, evaluated on the first failure after the hour mark.

Change

In src/repair/exact-review-batch-cli.ts only: classify no-status / 429 / 5xx as state_contention, and propagate the computed reason code through publicationCompletion instead of hardcoding unknown_failure. The receipt validator accepts the widened code.

400/413 keep their permanent tuple_protocol_invalid mapping, fence-ownership is untouched, and the genuinely unknown-cause branches (hasPendingPostEffects, non-eligible) keep the tight budget deliberately. No retry constant changed.

state_contention is already in the Worker's allowlist for retryable_failure in dashboard/exact-review-queue.ts, so there is no protocol change and no deployment-ordering constraint between Worker and publisher.

OpenClaw Bay

Not affected. This changes only how the batch publisher classifies its own transport failures before reporting a completion the queue protocol already accepts. No lifecycle state, status field, telemetry shape, or dashboard data contract changes.

pr-behavior-proof

  • Claim: a batch publication that fails with no HTTP status, HTTP 429, or HTTP 5xx completes as retryable_failure / state_contention; the real queue accepts that tuple, returns the publication to pending, increments its attempt count, schedules its next attempt, and creates no open dead letter.
  • Exercised surface: the built dist/repair/exact-review-batch-cli.js commit and complete commands over real localhost TLS sockets, followed by signed enqueue/claim/complete traffic through a pinned local Wrangler Worker and the real ExactReviewQueue Durable Object.
  • Scenario / fixture: a disposable HTTPS listener on 127.0.0.1 returns a connection reset, 429, and 503 in separate CLI runs and captures the HMAC-signed completion envelopes. The captured 429 tuple is then posted unchanged to a real local Worker/DO batch. A second fresh item repeats the Worker/DO sequence with only reason_code: "unknown_failure" as an attempt-one control. No fetch or timer monkeypatch is used, no production endpoint is contacted, and no real secret is loaded.
  • Command and environment: docs/proof/csw-1089/run-proof.sh on macOS with Node 24, npx --yes [email protected] dev --local --persist-to ..., disposable local persistence, and loopback-only listeners.
  • Observable result: all 21 proof assertions pass. Reset, 429, and 503 each take three real publication attempts and write retryable_failure / state_contention. After the captured 429 tuple crosses the real Worker/DO, item status is pending at attempt 1 with backoff_reason: "publication_retry", a scheduled next_attempt_at, and dead_letters: []. The attempt-one unknown_failure control is also pending with no dead letter, as required before its old budget is exhausted.
no-status -> retryable_failure / state_contention (3 real socket attempts)
HTTP 429  -> retryable_failure / state_contention (3 real socket attempts)
HTTP 503  -> retryable_failure / state_contention (3 real socket attempts)
Worker/DO state_contention -> pending, attempts=1, next_attempt_at scheduled, dead_letters=[]
Worker/DO unknown_failure  -> pending, attempts=1, next_attempt_at scheduled, dead_letters=[]
  • Artifacts: contract and reproduction harness in docs/proof/csw-1089/; raw completion envelopes in docs/proof/csw-1089/artifacts/completion-{no-status,429,503}.json; socket/HMAC trace in transport-requests.json; Worker/DO status before and after in queue-state-*.json; consolidated observations in runtime-transcript.md and proof-summary.json.
  • Validation: pnpm run lint:repair, pnpm run format:check, source-blind behavior validation, and the full pnpm run check all pass.
  • Limits: reaching attempt 14 through the real DO requires roughly 51 minutes of authentic backoff (1, 2, 4, then 5+ minutes). This bounded run therefore proves the real classification and attempt-one queue transition but does not claim the final unknown_failure retry_exhausted dead letter or the same-attempt terminal contrast. It does not fake time, edit DO storage, or change a retry constant.

Crabbox provenance

The proof re-ran unchanged on reviewed head d54d60abf5de708713e0fbedce496cd5a21dd251 inside Docker-backed Crabbox local-container lease cbx_9797931e8d4d, using image node:24-bookworm and Crabbox CLI 0.39.0, from a clean --fresh-pr checkout. It exited 0 with all 21 assertions passing. See the machine-readable provenance and captured stdout.

Also included

docs/pr-674-observation-runbook.md records that the per-item telemetry producer this contract was written for never landed — PR #674 was closed unmerged on 2026-07-21 — which is why /api/review-observability reports 0 terminal attempts against 6194 expected and a 100% abnormal rate. Those numbers describe a missing producer, not failing reviews. Documentation only; no behavior change.

…retry budget

Batch publication classified every non-2xx and every transport error as
`unknown_failure`, which carries a 14-attempt / 1-hour budget, while the
single-item path in publish-event-result.ts already mapped network errors,
429s, and 5xx to `state_contention` (48 attempts / 24 hours).

Batch is the dominant production path, so a GitHub throttling episode
dead-lettered finished reviews about an hour in. Of 721 `retry_exhausted`
dead letters sampled from the live queue, 706 (98%) had spent fewer than 14
attempts and the minimum lifespan was exactly 60.0 minutes -- the age cap,
not attempt exhaustion.

`state_contention` is already in the Worker's allowlist for
`retryable_failure`, so this needs no protocol or deployment-ordering change.

Also records in the PR 674 observation runbook that its per-item telemetry
producer never landed (PR closed unmerged 2026-07-21), which is why
/api/review-observability reports 0 terminal attempts against 6194 expected.
@clawsweeper

clawsweeper Bot commented Aug 10, 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: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. 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 10, 2026
@clawsweeper

clawsweeper Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 10:36 PM ET / August 10, 2026, 02:36 UTC.

ClawSweeper review

What this changes

The PR classifies transient batch publication failures as state_contention and carries that reason into the durable queue completion.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR remains necessary: current main sends batch no-status, 429, and 5xx publication failures to the short unknown_failure budget while the single-item path uses state_contention. The patch preserves the intended transient classification through completion, with sufficient Docker-backed queue proof and no actionable review finding. Likely related people: steipete (high confidence).

Priority: P1
Reviewed head: b1d12c0cc20539b741b76c6ee7c949d8be8a8991

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow, source-consistent repair with strong real-boundary proof and focused regression coverage.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The committed Crabbox artifact shows 21 successful assertions of the built CLI over real loopback TLS and a real local Worker/Durable Object; it records the corrected retryable queue transition and its stated boundary limits.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The committed Crabbox artifact shows 21 successful assertions of the built CLI over real loopback TLS and a real local Worker/Durable Object; it records the corrected retryable queue transition and its stated boundary limits.
Evidence reviewed 6 items Current batch mismatch: Current main maps every batch fallback other than fence ownership and HTTP 400/413 to unknown_failure, including no-status, 429, and 5xx failures.
Established comparison path: The single-item publisher already classifies no-status, 429, and 5xx publication fallbacks as state_contention.
Queue contract and retry consequence: The queue accepts state_contention for retryable failures, while unknown_failure alone uses the 14-attempt/one-hour exhaustion budget rather than the transient 48-attempt/24-hour budget.
Findings None None.
Security None None.

How this fits together

Finished reviews are published in batches to the exact-review Durable Object queue. The publisher’s completion reason determines whether the queue schedules another attempt or eventually moves the publication to the dead-letter store.

flowchart LR
  Reviews[Finished reviews] --> Publisher[Batch publisher]
  Publisher --> Transport[Signed publication request]
  Transport --> Classifier[Failure classification]
  Classifier --> Queue[Durable review queue]
  Queue --> Outcome[Retry schedule or dead letter]
Loading

Before merge

  • Resolve merge risk (P0) - During a prolonged publication outage, affected batch items will now use the established 24-hour transient retry window instead of dead-lettering after the one-hour unknown-failure window; this matches the single-item path.
  • Complete next step (P2) - No repair-lane work is needed; this is a correct contributor PR with sufficient proof, pending normal maintainer landing and required-check completion.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Runtime and proof scope production +20, tests +163, proof/docs +2,607 across 29 files The runtime repair is narrow; most of the branch is retained real-boundary proof and captured evidence.

Merge-risk options

Maintainer options:

  1. Adopt the established transient retry policy (recommended)
    Merge the mapping so batch publication failures use the same 48-attempt/24-hour transient budget already used by the single-item publisher.

Technical review

Best possible solution:

Land the narrow reason-code mapping with its focused regression cases and retain the Worker/Durable Object proof as the publication-retry regression evidence.

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

Yes. Current-main source shows the batch path emits unknown_failure for the specified transport failures, and the committed local Worker/Durable Object proof exercises the corrected classification through the production queue boundary.

Is this the best way to solve the issue?

Yes. Aligning the batch path with the established single-item classification and preserving that reason through completion is the narrowest compatible repair.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The committed Crabbox artifact shows 21 successful assertions of the built CLI over real loopback TLS and a real local Worker/Durable Object; it records the corrected retryable queue transition and its stated boundary limits.
  • 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 committed Crabbox artifact shows 21 successful assertions of the built CLI over real loopback TLS and a real local Worker/Durable Object; it records the corrected retryable queue transition and its stated boundary limits.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The defect can dead-letter completed reviews during transient publication throttling, preventing their results from being published.
  • merge-risk: 🚨 availability: This changes the retry lifetime for failed batch publications, directly affecting whether completed reviews remain recoverable during an outage.
  • 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 committed Crabbox artifact shows 21 successful assertions of the built CLI over real loopback TLS and a real local Worker/Durable Object; it records the corrected retryable queue transition and its stated boundary limits.
  • proof: sufficient: Contributor real behavior proof is sufficient. The committed Crabbox artifact shows 21 successful assertions of the built CLI over real loopback TLS and a real local Worker/Durable Object; it records the corrected retryable queue transition and its stated boundary limits.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger is attributed by blame to the existing batch behavior and authored the adjacent retry-policy refactor and this repair. (role: batch-publication and retry-policy contributor; confidence: high; commits: fd7c6919fa5b, 8558de58384a; files: src/repair/exact-review-batch-cli.ts, dashboard/exact-review-publication-retry.ts, src/repair/publish-event-result.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 (2 earlier review cycles)
  • reviewed 2026-08-10T00:51:55.564Z sha ee609d3 :: needs real behavior proof before merge. :: [P2] Remove the release-owned changelog entry | [P2] Prove recovery through the production transport boundary
  • reviewed 2026-08-10T01:36:45.101Z sha d54d60a :: needs real behavior proof before merge. :: [P2] Run the proof through the required Crabbox environment

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 10, 2026
@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 status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 10, 2026
@steipete
steipete merged commit 1370914 into main Aug 10, 2026
19 checks passed
@steipete
steipete deleted the steipete/fix-batch-publication-retry-budget branch August 10, 2026 02:39
steipete added a commit that referenced this pull request Aug 12, 2026
Ports the durable command-intake pipeline for the "@clawsweeper re-review" command from the abandoned Aug-8 WIP (snapshot 4cad8de on codex/fix-command-review-publication) onto current main.

Commands are now durably recorded pre-acknowledgement (intake/watermark/receipt/revision tables, 16-item intake, 15s-15m bounded retries, 30-day receipts), verified against the live comment and head, fenced through verify/enqueue/effects stages, and superseded by full version identity - including equal-timestamp edits (review-caught P1). Acknowledgement and reaction effects are idempotent; router runs that throttle mid-command now recover instead of stranding the command (live instance: openclaw/openclaw#116562 was acked then lost when both router runs throttled).

Superseded snapshot pieces were dropped, not ported: retry jitter (#1076/#1077), quota headroom (#1086), retry budgets (#1089), parked reconciliation (#1111), branch guard (#962); dashboard-monolith diffs were reworked around the #1116/#1124/#1132 splits.

Proof: committed receipt at this exact head (docs/proof/durable-command-intake/), real Wrangler Worker + DO comparison with durable throttled recovery, GitHub confined to loopback API; full gate 7056 passed / 0 failed; strict check green. Verdict clean (Findings: None) on 9eb957e.
steipete added a commit that referenced this pull request Aug 14, 2026
…ications (#1168)

Fixes a real regression the "automerge quota-fixture" check caught on main: throttled publications (403 rate-limit / 429) were classified permanent_failure instead of retryable_failure, routing throttle victims toward the permanent dead-letter path instead of the transient retry budget - the exact failure class #1089 fixed at the start of this effort. The check was red on main because it was RIGHT.

The publisher now preserves quota metadata through the publication path and restores retryable classification: 403/429 cases assert [1,1] requests with retryable_failure; delete paths [0,0]. Introduced during the quota campaign refactors; the fixture (asserting classification, not just counts) was the only gate that saw it.

Proof: red/green on the exact fixture, full gates green including the previously-red automerge check, Crabbox local-container receipt at this head, machine-verified provenance. Verdict clean (no findings, proof sufficient) on 0014afe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. 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