Skip to content

fix(cloud-workers): retry timed-out dispatches without reprovisioning - #121616

Merged
steipete merged 2 commits into
mainfrom
fix/cloud-dispatch-retry-singleflight
Aug 10, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/cloud-dispatch-retry-singleflight

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #121612

AI-assisted: yes. The implementation and tests were inspected and validated before publication.

What Problem This Solves

Fixes an issue where users retrying cloud-session dispatch after an RPC or CLI timeout would receive session cannot dispatch from placement provisioning even though the original dispatch was still running server-side.

Why This Change Was Made

Identical same-Gateway retries now join the one in-flight dispatch at the reconciliation coordinator, before any queued reconciliation barrier can delay the retry into a fresh operation. Requests with a different session identity, agent, or profile still reject, and active/draining/reconciling placements remain non-dispatchable.

The single-flight entry is identity-guarded and cleared after both success and failure. This location is important: coalescing inside the leaf dispatcher alone races with the outer reconciliation barrier and can still produce a fresh dispatch after failure.

The cloud-worker guide now documents request-time AWS SSH CIDR discovery, the read-only scope of crabbox doctor, retry behavior, and the currently supported profile fields.

Production LOC: +33/-5 (net +28) | Tests: +100/-15 | Docs: +9/-7. The production growth owns one process-local operation registry at the existing dispatch/reconciliation boundary; no second dispatch path or compatibility shim is added.

Provenance: the blanket nonlocal-placement gate was introduced by #107677 on 2026-07-14; code author and merger were @steipete. The surrounding cloud-worker dispatch coordinator originated in #106332.

User Impact

Operators can safely retry an identical cloud-session dispatch after a client timeout without allocating another worker or losing the original terminal result. Conflicting retries fail explicitly.

Evidence

  • Exact-head focused suite:
    node scripts/run-vitest.mjs src/gateway/server-worker-placement-startup.test.ts src/gateway/server-methods/sessions.dispatch.test.ts --reporter=dot
    • 2 files, 22 tests passed.
  • Exact-head formatting check passed for all five changed files.
  • Patch-identical changed-scope gate passed before the final conflict-free rebase, including core/test typechecks, oxlint, dead exports, import cycles, and repository guards. The configured remote provider was unavailable and the repository reported its local fallback.
  • Fresh structured Codex autoreview on the rebased branch: clean, patch is correct (0.97), no accepted/actionable findings.
  • Real OpenAI Responses API inference completed with openai/gpt-5.6-luna.
  • Live Gateway + Crabbox/AWS reached profile advertisement, managed-worktree session creation, and the real dispatch/retry path. AWS then denied its first required mutation, ec2:ImportKeyPair; no instance was launched. Final authoritative AWS lease inventory was empty. VM bootstrap, remote tool execution, and workspace reconciliation remain blocked by that external IAM policy and are not claimed as passing.

@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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 10, 2026
@steipete steipete self-assigned this Aug 10, 2026
@steipete
steipete marked this pull request as ready for review August 10, 2026 14:13
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. 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 10, 2026
@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 10, 2026, 10:54 AM ET / 14:54 UTC.

ClawSweeper review

What this changes

This PR lets identical cloud-session dispatch retries share the in-flight Gateway operation during provisioning, while rejecting conflicting session, agent, or profile requests.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open: the coordinator-level single-flight is the right repair for the provisioning retry race, but the new Cloud Workers guide contradicts the unchanged configuration reference on whether AWS SSH CIDRs are required.

Priority: P1
Reviewed head: 872eb7d494c650fd224161ecb2c5d7df57fdc619

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The runtime repair and focused regression tests are coherent, but contradictory operator documentation leaves the patch incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the reported live Crabbox run is supplementary rather than a merge-gate proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the reported live Crabbox run is supplementary rather than a merge-gate proof.
Evidence reviewed 7 items Current main retains the reported rejection: Current main rejects every placement state except local, reclaimed, and failed before dispatch reaches the coordinator; provisioning is therefore rejected today.
Coordinator owns the correct repair boundary: The branch records a request identity and promise before a retry can wait behind reconciliation, joins identical requests, rejects mismatches, and removes only its own completed entry.
Leaf lifecycle confirms why coordinator coalescing is needed: Dispatch owns the durable requested-to-provisioning-to-syncing-to-starting-to-active sequence, while the placement store rejects a second leaf dispatch from every transitional state.
Findings 1 actionable finding [P2] Align the configuration reference with request-time CIDRs
Security None None.

How this fits together

Cloud-session dispatch moves a Gateway session onto a managed worker. The Gateway validates the placement, coordinates reconciliation and provisioning, then returns the active placement to the requesting RPC or CLI client.

flowchart LR
  A[RPC or CLI dispatch request] --> B[Placement-state validation]
  B --> C[Dispatch coordinator]
  C --> D{Matching operation in flight?}
  D -->|Yes| E[Share existing promise]
  D -->|No| F[Reconcile and provision worker]
  E --> G[Terminal placement result]
  F --> G
Loading

Before merge

  • Align the configuration reference with request-time CIDRs (P2) - The changed guide says an empty aws.sshCIDRs list is valid when Crabbox discovers the caller address per request, but docs/gateway/configuration-reference.md still tells operators to configure and verify a /32 before provisioning. Update the sibling reference so linked setup guidance does not prescribe contradictory AWS ingress requirements.
  • Resolve merge risk (P1) - The runtime fix adds 28 net production lines for a per-session promise registry; no net-neutral owner-boundary refactor is apparent because active-dispatch counts and reconciliation barriers do not retain request identity or a shareable operation.
  • Complete next step (P2) - A narrow, mechanical documentation repair can resolve the only blocking finding without changing the coordinator fix.

Findings

  • [P2] Align the configuration reference with request-time CIDRs — docs/gateway/cloud-workers.md:41
Agent review details

Security

None.

PR surface

Source +28, Tests +85, Docs +2, Other 0. Total +115 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 33 5 +28
Tests 2 100 15 +85
Docs 1 9 7 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 6 143 28 +115

Review metrics

Metric Value Why it matters
Production versus test delta production +28, tests +85, docs +2, generated baseline 0 The new coordinator registry is justified by the identity-preserving retry boundary, while the added regression coverage exercises success, failure, and reconciliation ordering.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server-methods/sessions-dispatch.ts, serialized state: src/gateway/server-methods/sessions.dispatch.test.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #121612
Summary: This PR is the proposed fix for the linked provisioning-retry defect and current main does not yet implement it.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Align the AWS setup guidance (recommended)
    Update the configuration reference so it distinguishes optional fixed CIDRs from request-time CIDR discovery before merging the changed Cloud Workers guide.
  2. Hold unverified external-CLI claims
    If the request-time Crabbox behavior cannot be confirmed, remove or narrow the new external-CLI assertions rather than publishing contradictory setup guidance.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Update docs/gateway/configuration-reference.md to state that an explicitly pinned aws.sshCIDRs /32 is optional when request-time discovery is available, then run the documentation checks.

Technical review

Best possible solution:

Keep the coordinator-owned single-flight registry, then align the configuration reference with the guide’s optional fixed-CIDR guidance; the registry cannot be absorbed into the existing aggregate barrier state without losing identity-safe retry sharing.

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

Yes, source-reproducible: current main rejects provisioning before the coordinator, and the branch’s focused ordering test encodes the same retry sequence. No live reproduction was run in this read-only review.

Is this the best way to solve the issue?

Yes for the runtime defect: coalescing at the coordinator, before reconciliation can queue a retry, is safer than a leaf-dispatch workaround and preserves the existing state-machine owner.

Full review comments:

  • [P2] Align the configuration reference with request-time CIDRs — docs/gateway/cloud-workers.md:41
    The changed guide says an empty aws.sshCIDRs list is valid when Crabbox discovers the caller address per request, but docs/gateway/configuration-reference.md still tells operators to configure and verify a /32 before provisioning. Update the sibling reference so linked setup guidance does not prescribe contradictory AWS ingress requirements.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: A deterministic retry during cloud-worker provisioning currently fails for operators whose RPC or CLI timeout expires before provisioning completes.
  • add merge-risk: 🚨 availability: The PR changes concurrency and lifecycle admission at the Gateway dispatch coordinator, so an error in coalescing or cleanup could stall or reject cloud-session dispatches.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the reported live Crabbox run is supplementary rather than a merge-gate proof.

Label justifications:

  • P1: A deterministic retry during cloud-worker provisioning currently fails for operators whose RPC or CLI timeout expires before provisioning completes.
  • merge-risk: 🚨 availability: The PR changes concurrency and lifecycle admission at the Gateway dispatch coordinator, so an error in coalescing or cleanup could stall or reject cloud-session dispatches.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; the reported live Crabbox run is supplementary rather than a merge-gate proof.

Evidence

Acceptance criteria:

  • [P1] pnpm docs:list.
  • [P1] pnpm check:docs.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • steipete: Authored the merged cloud-worker placement feature and the session-handler refactor that define this dispatch boundary. (role: feature owner; confidence: high; commits: e98c7dfbcb9f, 0b409a0348c6; files: src/gateway/server-worker-placement-startup.ts, src/gateway/server-methods/sessions-dispatch.ts)
  • Jesse Merhi: The current-main lines containing the blanket placement gate were most recently materialized by this recent gateway-area commit. (role: recent area contributor; confidence: medium; commits: 66196b7bf70c; files: src/gateway/server-methods/sessions-dispatch.ts, src/gateway/server-worker-placement-startup.ts)

Rank-up moves

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

  • Update docs/gateway/configuration-reference.md to match the revised Cloud Workers CIDR guidance.

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 8747575 into main Aug 10, 2026
131 checks passed
@steipete
steipete deleted the fix/cloud-dispatch-retry-singleflight branch August 10, 2026 16:17

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud session dispatch retry is rejected during provisioning

2 participants