Skip to content

fix(workers): re-arm admission-deadline launches, terminalize dead-worker turns, defer debris cleanup - #130446

Merged
steipete merged 3 commits into
mainfrom
steipete/fu-lifecycle
Aug 27, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/fu-lifecycle

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Three lifecycle defects proven live in the 50-worker farm campaign (#129979):

  1. Worker mortality asymmetry: on a transient network flap the node host retries its own gateway WS forever and recovers, but each worker child dies at one fixed 120s admission deadline — the launch adapter's replacement dies the same way, so a brief partition killed every in-flight turn while the node looked healthy.
  2. Stuck turns never terminalize: gateway diagnostics logged stuck session recovery: status=skipped action=keep_lane every cycle for 25+ minutes over provably dead workers; turns only ended via caller timeouts.
  3. Startup over placement debris: a gateway restart above ~50 failed placements hung startup recovery for many minutes doing per-placement git cleanup before readiness.

Why This Change Was Made

  • Bounded admission re-arm at the launch owner: when the node's launch journal proves the child died on the admission deadline specifically (parsed result, not string matching), the gateway launch adapter re-arms the launch — up to five attempts (~10 minutes of 120s windows), exponential backoff with jitter, always capped by the caller's deadline. Deterministic derived launch/turn ids mean an adapter replay finds the same journal rows and never spawns a duplicate child for a completed retry. Credential/build rejections and post-start failures remain immediately terminal; every attempt's reason is journaled.
  • Terminalization with a grace: once a worker is journal-terminal with no live claim past a 30s cleanup grace, stuck-turn recovery records a terminal turn failure (drain + recorded reason) instead of keep_lane forever. Genuinely live slow turns are untouched — the predicate requires journal-terminal + claim-free + grace elapsed, revalidated against the exact drain generation.
  • Debris off the readiness path: orphan git cleanup for already-terminal placements moves into the first tracked background sweep; pending-result recovery and ownership fences stay ahead of readiness. Fixture with 50 failed placements: startup git scans 50 → 0, ~556ms → ~5ms.

User Impact

A farm node surviving a network blip finishes its turns instead of burying them; dead-worker turns fail visibly within seconds, not after 25-minute waits; gateways restart promptly even after a bad night of failed placements.

Evidence

All regressions verified failing pre-fix (re-arm on admission-deadline with journaled attempts and terminal-rejection immediacy; grace-gated terminalization vs. live-turn preservation; deferred-cleanup ordering with fences ahead of readiness). Focused suites green: launcher (67), supervisor child processes, journal replay, runtime admission, diagnostics; pnpm check:changed green; Codex autoreview clean (0.94). Two failing tests in unchanged files (config.test.ts subprocess startup, workspace-sync-scripts.test.ts quiescence fixtures) reproduce on clean origin/main — pre-existing, not introduced here. Production +229, tests/support +544; no schema/config changes. A combined live rig run with the reconciliation lane follows before the campaign closes.

Context: #129979

@clawsweeper

clawsweeper Bot commented Aug 26, 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 agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 22:02
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 26, 2026, 7:36 PM ET / 23:36 UTC.

ClawSweeper review

What this changes

The PR retries worker launches that expire before admission, terminalizes proven-dead worker turns after a grace period, and defers orphan workspace cleanup until after Gateway readiness.

Merge readiness

⛔ Blocked by patch quality or review findings - 4 items remain

The prior P1 credential-expiry blocker remains: re-arms reuse the descriptor minted before the first admission attempt, so the final advertised retry can be rejected as credential-expired instead of recovering the outage.

Priority: P1
Reviewed head: 7157deb49d2c8019455127c7be1d58f5c43a553a

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The retry design has focused coverage, but the credential-lifetime defect blocks reliable recovery.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored worker lifecycle PR is exempt from the external-contributor proof gate; its stated live campaign result remains supplemental evidence.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored worker lifecycle PR is exempt from the external-contributor proof gate; its stated live campaign result remains supplemental evidence.
Evidence reviewed 6 items Retry reuses the original credential: The re-arm branch creates a new launch and turn ID but spreads originalInput, retaining descriptor.admission.credential for every attempt.
Credential lifetime is shorter than the retry envelope: Worker credentials expire after 600,000 ms; five 120-second admission windows plus backoff can begin the fifth attempt around 495 seconds and expire before its deadline completes.
Admission rejects stale credentials: The admission owner rejects a credential at or past its expiry, so the late retry cannot recover the outage.
Findings 1 actionable finding [P1] Refresh the credential for each admission re-arm
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/worker-environments/node-launch-adapter.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs src/gateway/worker-environments/node-launch-adapter.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs src/gateway/worker-environments/node-launch-adapter.test.ts"

[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130446-2FxHcn/target

 ✓  gateway-core  ../../src/gateway/worker-environments/node-launch-adapter.test.ts (28 tests) 221ms

 Test Files  1 passed (1)
      Tests  28 passed (28)
   Start at  23:37:39
   Duration  2.03s (transform 1.31s, setup 1.01s, import 430ms, tests 221ms, environment 0ms)

[test] passed 1 Vitest shard in 8.68s

Assertions:

  • FAIL expect_output: node worker launch adapter

How this fits together

Gateway workers run session turns on paired node hosts. A credential-bound launch descriptor goes through the node supervisor journal, then placement recovery records the final session outcome.

flowchart LR
  A[Session turn] --> B[Worker turn owner]
  B --> C[Credential-bound descriptor]
  C --> D[Node supervisor journal]
  D --> E{Admission result}
  E -->|Deadline before start| F[Re-arm launch]
  E -->|Started or terminal| G[Placement recovery]
  G --> H[Visible session outcome]
Loading

Before merge

  • Refresh the credential for each admission re-arm (P1) - The new launch ID is built by spreading originalInput, so every re-arm carries the credential minted before the first 120-second attempt. With five windows and backoff, the last child can reach the gateway after the 10-minute credential expiry and be rejected as credential-expired, defeating the recovery path. Rebuild the descriptor through the credential owner per attempt, or cap the envelope within the original credential lifetime.
  • Resolve merge risk (P0) - Merging would advertise five admission re-arms, but a prolonged outage can make the last attempt fail closed on the original expired credential.
  • Improve patch quality - Refresh the credential and full launch descriptor for every admission re-arm.
  • Improve patch quality - Add an expiry-boundary test that advances through the full five-attempt envelope and proves final admission is authorized.

Findings

  • [P1] Refresh the credential for each admission re-arm — src/gateway/worker-environments/node-launch-adapter.ts:493-500
Agent review details

Security

None.

PR surface

Source +232, Tests +541, Docs +4. Total +777 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 14 317 85 +232
Tests 6 543 2 +541
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 864 87 +777

Review metrics

Metric Value Why it matters
Production versus test delta production +229, tests/support +544 The lifecycle repair materially grows production behavior; the remaining blocker is in the production retry path.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/node-launch-adapter.test.ts, durable storage schema: src/gateway/worker-environments/node-launch-adapter.ts, durable storage schema: src/gateway/worker-environments/placement-dispatch-pending-results.ts, durable storage schema: src/gateway/worker-environments/worker-turn-admission.ts, durable storage schema: src/gateway/worker-environments/worker-turn-failure.ts, durable storage schema: src/gateway/worker-environments/worker-turn-launcher-failure-recovery.test.ts, and 19 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Renew at the credential owner before re-arm (recommended)
    Rebuild each retry descriptor with a newly minted, claim-bound credential and prove the final retry remains admissible after the earlier deadline windows.
  2. Limit retries below credential expiry
    Reduce the maximum retry envelope so every admission window completes before the original credential expires, accepting less outage recovery.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Renew and rebind the worker credential for every admission re-arm, then add an expiry-boundary regression covering five 120-second attempts plus backoff.

Technical review

Best possible solution:

Mint and atomically bind a fresh claim-bound credential and launch descriptor for every eligible re-arm, then prove the fifth attempt remains admissible after the earlier deadline windows.

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

Yes, from source: advance a credential-bound launch through four 120-second admission deadlines and backoffs, then observe the fifth attempt use the original credential past its ten-minute expiry.

Is this the best way to solve the issue?

No: bounded re-arms are the right shape, but they must obtain a current authoritative credential at the retry owner or be capped within the credential lifetime.

Full review comments:

  • [P1] Refresh the credential for each admission re-arm — src/gateway/worker-environments/node-launch-adapter.ts:493-500
    The new launch ID is built by spreading originalInput, so every re-arm carries the credential minted before the first 120-second attempt. With five windows and backoff, the last child can reach the gateway after the 10-minute credential expiry and be rejected as credential-expired, defeating the recovery path. Rebuild the descriptor through the credential owner per attempt, or cap the envelope within the original credential lifetime.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P1: A transient node-to-Gateway outage can still leave in-flight worker turns unable to recover on the final advertised retry.
  • merge-risk: 🚨 auth-provider: The retry path reuses an expiring credential across new admission attempts.
  • merge-risk: 🚨 availability: Credential expiry defeats the intended worker-turn recovery path during a prolonged transient outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored worker lifecycle PR is exempt from the external-contributor proof gate; its stated live campaign result remains supplemental evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Current blame attributes the re-arm implementation to this author, who also has substantial history in the worker lifecycle paths. (role: introduced the current retry behavior; confidence: high; commits: 7157deb49d2c; files: src/gateway/worker-environments/node-launch-adapter.ts, src/gateway/worker-environments/worker-turn-launcher.ts)
  • joshavant: Feature-history shortlog shows repeated work in the credential, launcher, and adapter area. (role: historical area contributor; confidence: medium; files: src/gateway/worker-environments/credential-broker.ts, src/gateway/worker-environments/worker-turn-launcher.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-26T22:09:15.398Z sha ed71ef4944fb28c48eb6608400c2264df86dcf39 :: found issues before merge. :: [P1] Keep re-arms within the credential lifetime
  • reviewed 2026-08-26T22:28:07.179Z sha 8d55190daf7cdbcb5944ceb68da34376667bc20e :: needs changes before merge. :: [P1] Refresh the credential for each admission re-arm

@steipete
steipete force-pushed the steipete/fu-lifecycle branch 2 times, most recently from 88b22c9 to d8bd5a5 Compare August 26, 2026 23:19
…rker turns, defer debris cleanup

Three lifecycle repairs from the 50-worker campaign (#129979): the gateway
launch adapter re-arms a launch up to five times (exponential backoff with
jitter, caller-deadline capped, deterministic derived launch/turn ids so
adapter replays find the same journal rows) when the node journal proves the
child died on the admission deadline — credential/build rejections and
post-start failures stay terminal; stuck-turn recovery records a terminal
failure once a journal-terminal worker has no claim past a 30s cleanup grace
instead of skipping keep_lane forever; and startup recovery defers orphan
git cleanup for terminal placements into the first tracked background sweep
(50-placement fixture: 50 startup git scans to zero, ~556ms to ~5ms) while
pending-result recovery and ownership fences stay ahead of readiness.
 rebase

WorkerConnection now formats the redacted last-failure diagnosis into the
deadline error itself, so the runtime's re-format (and its
lastConnectionFailure tracking) is redundant; errorText uses error.message.
@steipete
steipete force-pushed the steipete/fu-lifecycle branch from d8bd5a5 to 7157deb Compare August 26, 2026 23:30
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 26, 2026
…time

Re-arms reused the credential minted before the first admission attempt,
so with five 120s windows plus backoff the final advertised retry could
start after the credential expiry and fail closed as credential-expired.
The launcher now threads credential.expiresAtMs through the tunnel launch
request, and the adapter re-arms only while the retried child still gets a
full admission window (WORKER_ADMISSION_DEADLINE_MS, now shared from the
connection contract) on the original credential; otherwise it returns the
terminal admission result. Expiry-boundary tests walk both sides.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the P1 (re-arms reusing the pre-expiry credential) is addressed at head 940780d: the launcher threads credential.expiresAtMs through the tunnel launch request and the adapter re-arms only while the retried child still gets a full admission window on the original credential, with expiry-boundary tests walking both sides of the envelope.

@clawsweeper

clawsweeper Bot commented Aug 27, 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:

@steipete
steipete merged commit 0b60846 into main Aug 27, 2026
201 checks passed
@steipete
steipete deleted the steipete/fu-lifecycle branch August 27, 2026 00:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…rker turns, defer debris cleanup (openclaw#130446)

* fix(workers): re-arm admission-deadline launches, terminalize dead-worker turns, defer debris cleanup

Three lifecycle repairs from the 50-worker campaign (openclaw#129979): the gateway
launch adapter re-arms a launch up to five times (exponential backoff with
jitter, caller-deadline capped, deterministic derived launch/turn ids so
adapter replays find the same journal rows) when the node journal proves the
child died on the admission deadline — credential/build rejections and
post-start failures stay terminal; stuck-turn recovery records a terminal
failure once a journal-terminal worker has no claim past a 30s cleanup grace
instead of skipping keep_lane forever; and startup recovery defers orphan
git cleanup for terminal placements into the first tracked background sweep
(50-placement fixture: 50 startup git scans to zero, ~556ms to ~5ms) while
pending-result recovery and ownership fences stay ahead of readiness.

* fix(workers): use the diagnosed admission-deadline message after openclaw#130435 rebase

WorkerConnection now formats the redacted last-failure diagnosis into the
deadline error itself, so the runtime's re-format (and its
lastConnectionFailure tracking) is redundant; errorText uses error.message.

* fix(workers): cap admission re-arms within the minted credential lifetime

Re-arms reused the credential minted before the first admission attempt,
so with five 120s windows plus backoff the final advertised retry could
start after the credential expiry and fail closed as credential-expired.
The launcher now threads credential.expiresAtMs through the tunnel launch
request, and the adapter re-arms only while the retried child still gets a
full admission window (WORKER_ADMISSION_DEADLINE_MS, now shared from the
connection contract) on the original credential; otherwise it returns the
terminal admission result. Expiry-boundary tests walk both sides.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL 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.

1 participant