Skip to content

fix(review): recover scheduled enqueue from transient queue failures - #1416

Merged
vincentkoc merged 2 commits into
mainfrom
fix/scheduled-enqueue-retry
Sep 4, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/scheduled-enqueue-retry

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Related: #1372

What Problem This Solves

Fixes an issue where scheduled review enqueue could commit in the Worker but lose the HTTP response, causing the producer's retry to receive an ambiguous delivery receipt and abort the plan even though admission had already happened.

Why This Change Was Made

The Worker now fingerprints the exact authenticated scheduled-enqueue bytes and atomically stores a closed queued, scheduled-item-deduped, backpressure-shed, or scheduled-rate-shed disposition with the delivery receipt. A matching delivery ID and fingerprint replays the exact stored response; different authenticated bytes return HTTP 409; legacy receipts without a fingerprint remain ambiguous and fail closed in the producer.

The public queue projection advertises scheduled_feed.enqueue_replay: scheduled_disposition_v1, which the scheduled producer requires before posting. Only scheduled enqueue uses the existing bounded three-attempt transport/5xx retry. Publication and other post-effects remain single-attempt.

No workflow, queue limit, dead-letter, concurrency, or generic delivery-receipt behavior changed. The additive nullable delivery columns do not bump the storage schema version.

User Impact

Maintainers can expect scheduled review plans to recover from a lost response without duplicating queue admission, shed accounting, or logical attempted counts. Rollout fails closed until the Worker advertises the exact replay capability.

OpenClaw Bay Impact

OpenClaw Bay is unaffected. The public queue status gains one bounded scheduler capability field, but Bay activity, lifecycle projections, references, and mutation boundaries are unchanged; the strict projector retains only the rate and capability.

Documentation Impact

Updated docs/scheduler.md with the capability gate, byte-stable retry contract, legacy fail-closed behavior, and the explicit publication post-effect exclusion.

Evidence

  • Signed head: 843078fc9b5ad2cd6b68edb8429e1db92107d0a6
  • Base: 934d526e73e032ece6fcd23f374be9895dffd71b
  • Focused scheduled enqueue/Worker/DO tests: 20 passed, 0 failed.
  • Focused queue/status/privacy/dashboard tests: 131 passed, 0 failed.
  • Shared batch queue client tests: 25 passed, 0 failed.
  • Repair and dashboard TypeScript checks, targeted oxfmt, git diff --check, and privacy scrub: passed.
  • Required precommit and committed-range Codex reviews: no actionable regressions. The committed review independently reported 176 focused tests passing with both typechecks.
  • Production TypeScript delta: +295/-42, net +253. This implements the durable replay ownership boundary, authenticated-byte conflict invariant, additive storage upgrade, and public rollout capability. Tests: +620/-17, net +603.
  • Local pnpm run check could not start because pnpm attempted to purge the shared symlinked node_modules and aborted without a TTY. The shared install was not mutated; exact-head hosted CI is the canonical full pnpm run check gate.
  • Exact-head hosted pnpm check, sparse repair build, Windows launcher, CodeQL, and hosted-target rejection checks: passed.
  • Crabbox run run_8ce36a7d9fcb, lease cbx_8bfc59824297: passed on the pinned local-container image below. Redacted artifact member .artifacts/pr1416-local-container-proof.json; archive SHA-256 cf8b96d5d9d625b313ac2416e4b5d4e77356df8911b24a7124eb5eb15c898418.

Accepted review finding:

  • P1 exact delivery replay: resolved by preserving the exact scheduled disposition with its authenticated-body fingerprint in the same transaction as admission. No generic delivery_receipt scope was added.

Rank-up moves:

  • Added queue-backed response-loss regressions for queued, scheduled-item-deduped, backpressure-shed, and scheduled-rate-shed outcomes.
  • Added the exact Worker replay contract, accepting only a matching authenticated fingerprint and closed persisted disposition.
  • Published a redacted exact-head Crabbox local-container trace with the provider, pinned image, lease, limits, replay identity, logical accounting, and one-attempt conflict evidence.

Real Behavior Proof

Claim: A scheduled enqueue whose response is lost after the Worker/DO commit retries with identical signed bytes and receives the exact original disposition; altered bytes conflict without retry.

Exercised surface: Built scheduled producer and shared queue client over a loopback HTTPS server, forwarding through the actual Worker fetch adapter into the in-memory Durable Object implementation.

Scenario: The fixture destroyed the first TLS connection only after the Worker/DO returned a committed queued response. The producer retried. It then sent one separately signed request with the same delivery ID but one extra byte.

Command/environment: Fresh PR checkout in Crabbox local-container run run_8ce36a7d9fcb, lease cbx_8bfc59824297, with 4 CPUs, 8 GiB memory, Node 24.20.0, and pinned image node:24-bookworm@sha256:be23f54a88d34e8824c741b19b91064094f92c1c97b194144bfc8b50d67258e2. The fixture used a generated one-day loopback certificate; TLS verification was disabled only inside the isolated fixture process.

Observed result:

{
  "source_head": "843078fc9b5ad2cd6b68edb8429e1db92107d0a6",
  "provider": "local-container",
  "image": "node:24-bookworm@sha256:be23f54a88d34e8824c741b19b91064094f92c1c97b194144bfc8b50d67258e2",
  "limits": {
    "cpus": 4,
    "memory": "8g"
  },
  "node": "v24.20.0",
  "https_fixture": true,
  "committed_response_lost": true,
  "retry_attempts": 2,
  "request_body_sha256_count": 1,
  "unique_retry_signatures": 1,
  "replay_response_bytes_equal": true,
  "summary": {
    "lane": "normal_backfill",
    "offered": 1,
    "attempted": 1,
    "queued": 1,
    "deduped": 0,
    "shed": 0,
    "rateLimited": 0,
    "backpressured": 0,
    "rejected": 0,
    "deferred": 0,
    "ageHours": {
      "p50": null,
      "p90": null,
      "max": null
    }
  },
  "conflict_status": 409,
  "conflict_body": {
    "error": "exact_review_delivery_conflict"
  },
  "conflict_attempts": 1
}

Limits: This used the real Worker routing and Durable Object adapter with in-memory storage inside an isolated local-container lease, not the production Cloudflare deployment. It did not mutate GitHub, the production queue, or OpenClaw Bay.

@clawsweeper

clawsweeper Bot commented Sep 4, 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 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. 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 Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 6:46 AM ET / 10:46 UTC.

ClawSweeper review

What this changes

This PR makes scheduled review enqueue retry transient response-loss failures by replaying a durable, authenticated admission result for the identical request.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open for maintainer review: the base/current main does not contain this replay behavior, and the PR supplies a focused, proof-backed implementation, but it is Member-authored and changes a durable queue protocol that needs explicit rollout approval.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong production-path fault proof and focused regression coverage support a good patch, with rollout approval remaining an operational maintainer decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies an exact-head Crabbox local-container terminal trace for the changed Worker-to-Durable-Object enqueue path: a post-commit response loss causes one identical retry that receives the original disposition, while altered signed bytes receive 409 before another retry. The trace uses in-memory durable storage, so it proves the production ownership path under injected transport failure rather than deployed Cloudflare behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies an exact-head Crabbox local-container terminal trace for the changed Worker-to-Durable-Object enqueue path: a post-commit response loss causes one identical retry that receives the original disposition, while altered signed bytes receive 409 before another retry. The trace uses in-memory durable storage, so it proves the production ownership path under injected transport failure rather than deployed Cloudflare behavior.
Evidence reviewed 5 items Current-main comparison: The fetched main/base revision uses one direct signed enqueue request and only checks scheduled-feed rate capability; it has neither the replay-capability gate nor bounded retry client used by this PR.
Durable replay implementation: The PR records a fingerprinted scheduled disposition in the same storage transaction, rejects a mismatched replay, and returns the saved response for a matching retry.
Worker authentication boundary: The Worker verifies the enqueue HMAC before deriving and forwarding the body fingerprint to the queue, so the Durable Object receives a fingerprint of authenticated request content.
Findings None None.
Security None None.

How this fits together

Scheduled-review plans send signed enqueue requests through the Worker to the Exact Review Queue Durable Object. The queue admits or sheds work, stores delivery receipts, and returns a status capability that the scheduler uses before retrying.

flowchart LR
  A[Scheduled review plan] --> B[Signed enqueue request]
  B --> C[Worker authentication]
  C --> D[Exact Review Queue]
  D --> E[Durable admission receipt]
  E --> F[Replay or conflict response]
  D --> G[Queue status capability]
Loading

Decision needed

Question Recommendation
Should this durable scheduled-enqueue replay protocol be approved for a capability-gated rollout? Approve the capability-gated rollout: Land the protocol with Worker-first deployment, accepting temporary scheduled-enqueue fail-closed behavior until the new capability is visible.

Why: The implementation deliberately changes retry and receipt behavior across the scheduler, Worker, and Durable Object, so acceptance of the temporary fail-closed rollout posture is an operational decision.

Before merge

  • Resolve merge risk (P1) - Deploying the Worker and scheduled producer out of order temporarily fail-closes scheduled enqueue until the Worker advertises the v1 replay capability; maintainers should confirm that is acceptable for the rollout.
  • Complete next step (P2) - Obtain maintainer approval of the capability-gated scheduled-enqueue replay rollout before landing this draft.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch scope 11 files, +921/-59 The change spans scheduler, Worker, Durable Object, public status projection, and focused tests.
Runtime versus test delta production +295/-42, tests +620/-17 The substantial test coverage targets replay, conflict, atomicity, legacy receipts, and status projection.

Merge-risk options

Maintainer options:

  1. Approve capability-gated rollout (recommended)
    Accept the Worker-first rollout contract, which prevents an older Worker from receiving replaying scheduled producers.
  2. Pause for deployment confirmation
    Keep the draft open until operators confirm that temporary scheduled-enqueue fail-closed behavior is acceptable during deployment.

Technical review

Best possible solution:

Deploy the capability-gated Worker and scheduled producer together or Worker-first, preserving fail-closed behavior for any older queue deployment.

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

Yes: the supplied exact-head Crabbox trace injects response loss after queue commit through the Worker adapter and records a matching retry replay plus an altered-byte conflict.

Is this the best way to solve the issue?

Yes: storing a closed scheduled-only disposition alongside the authenticated receipt is narrower than broadening generic delivery-receipt retries and preserves legacy fail-closed behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an exact-head Crabbox local-container terminal trace for the changed Worker-to-Durable-Object enqueue path: a post-commit response loss causes one identical retry that receives the original disposition, while altered signed bytes receive 409 before another retry. The trace uses in-memory durable storage, so it proves the production ownership path under injected transport failure rather than deployed Cloudflare behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded scheduled-review reliability improvement rather than an active user-facing outage.
  • merge-risk: 🚨 automation: The PR changes scheduler retry behavior, durable queue admission receipts, and a deployed capability contract.
  • 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 supplies an exact-head Crabbox local-container terminal trace for the changed Worker-to-Durable-Object enqueue path: a post-commit response loss causes one identical retry that receives the original disposition, while altered signed bytes receive 409 before another retry. The trace uses in-memory durable storage, so it proves the production ownership path under injected transport failure rather than deployed Cloudflare behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an exact-head Crabbox local-container terminal trace for the changed Worker-to-Durable-Object enqueue path: a post-commit response loss causes one identical retry that receives the original disposition, while altered signed bytes receive 409 before another retry. The trace uses in-memory durable storage, so it proves the production ownership path under injected transport failure rather than deployed Cloudflare behavior.

Evidence

What I checked:

  • Current-main comparison: The fetched main/base revision uses one direct signed enqueue request and only checks scheduled-feed rate capability; it has neither the replay-capability gate nor bounded retry client used by this PR. (src/repair/scheduled-review-enqueue.ts:56, 934d526e73e0)
  • Durable replay implementation: The PR records a fingerprinted scheduled disposition in the same storage transaction, rejects a mismatched replay, and returns the saved response for a matching retry. (dashboard/exact-review-queue.ts:1414, 843078fc9b5a)
  • Worker authentication boundary: The Worker verifies the enqueue HMAC before deriving and forwarding the body fingerprint to the queue, so the Durable Object receives a fingerprint of authenticated request content. (dashboard/worker.ts:6333, 843078fc9b5a)
  • Real behavior proof: The supplied current-head Crabbox local-container trace records a post-commit TLS response loss, two identical signed attempts, byte-identical replay, one logical queued admission, and a single 409 response for altered bytes. It exercises the Worker adapter and in-memory Durable Object rather than the deployed Cloudflare service. (843078fc9b5a)
  • Relevant current-main history: Recent queue maintenance includes receipt and queue-path work by Peter Steinberger, while Vincent Koc's merged queue-client change is an ancestor of the PR base. (dashboard/exact-review-queue.ts:1414, d32eaf1ba7b6)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-09-04T09:56:36.335Z sha e7dc02d :: blocked before merge. :: [P1] Accept an explicit delivery-receipt replay
  • reviewed 2026-09-04T10:35:16.885Z sha 843078f :: blocked before merge. :: none

@vincentkoc
vincentkoc force-pushed the fix/scheduled-enqueue-retry branch from e7dc02d to 843078f Compare September 4, 2026 10:31
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 4, 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.

@clawsweeper clawsweeper Bot added 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. proof: sufficient Contributor real behavior proof is sufficient. labels Sep 4, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 4, 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.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 4, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer rollout decision: approved.

The temporary fail-closed window is accepted. Merge the capability-gated Worker and scheduled producer together; the automatic main dashboard deployment will publish the Worker, and scheduled enqueue remains intentionally closed until the live Worker advertises scheduled_disposition_v1.

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