Skip to content

fix(nodes): keep starting containers out of the exited state - #129102

Merged
steipete merged 1 commit into
mainfrom
fix/node-worker-container-startup-state
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/node-worker-container-startup-state

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators running node-hosted worker sessions with nodeHost.workerRuns.isolation=container would have a healthy worker killed mid-run when anything asked for its status during container startup. The launch ends as failed with node worker failed with exit code 137, and the session dies for no reason the operator can see.

The same defect makes src/node-host/node-worker-supervisor.container.test.ts flaky on CI. It has been failing on loaded Blacksmith shards since #128447 landed, e.g. run 32706072003 and run 32789084018, always as expected 'failed' to be 'completed'.

Why This Change Was Made

inspectNodeWorkerContainer asked the engine for {{.State.Running}}, which is false in two unrelated situations: a container that already exited, and one that was created but has not started yet. NodeWorkerSupervisor.status() treats dead as proof the workload ended, so it force-removes the container and finalizes the launch. Because the launch path returns as soon as the start client is spawned and the journal is written, any status poll in the startup window destroys a live worker.

The fix classifies the engine's {{.State.Status}} instead of a boolean: statuses that still own a workload (created, initialized, running, paused, restarting, stopping) stay live, finished ones (exited, stopped, dead, removing) report dead, and anything else remains unknown. The set members come from Docker's documented container states and Podman's upstream ContainerStatus values, since both engines are supported. As a side effect, killNodeWorkerContainer's post-removal verification no longer accepts a surviving created container as successfully removed.

Non-goal: no retry, timeout bump, or test-side sleep. The startup window is real and the supervisor now reads it correctly.

User Impact

Container-isolated worker sessions no longer die at random during startup. A status call arriving while the container is still starting returns running instead of killing the worker and recording a bogus failed receipt.

Evidence

Real engine, not just the test double. Docker 29.4.0 reports the created state as not-running, and the window persists after the start client is spawned:

$ docker inspect --type container --format '{{.State.Status}}|{{.State.Running}}' "$CID"
created|false

$ docker start --attach --interactive "$CID" &   # then poll
 60ms after spawn: created|false
120ms after spawn: running|true

Pre-fix, that first sample is classified dead and the supervisor kills the container.

Deterministic reproduction. Widening the startup window by 40ms in the fake engine made the existing test fail with the exact CI signature, and a probe on the terminal receipt showed the self-inflicted kill:

[probe] status inspect => dead
[probe] terminal {"state":"failed","errorText":"node worker failed with exit code 137"}
AssertionError: expected 'failed' to be 'completed'

With the fix in place, that same 40ms window passes 3/3.

Regression test. keeps a launch running while its container is still starting holds the container in created until the supervisor's own inspect observes it, then asserts the launch is still running and completes. Against the old classification it is the only failing test in the file (13 passed, 1 failed); with the fix the file is 14/14. The fake engine now models engine status rather than a boolean, matching what a real engine reports.

Diagnosability. The original assertion compared only state, so CI printed expected 'failed' to be 'completed' and discarded the receipt's errorText, which named the cause. It now uses toMatchObject, so the next failure prints it.

Local validation (branch base 49c5bb21c3b):

  • node scripts/run-vitest.mjs src/node-host — 41 files, 561 passed, 2 skipped
  • node scripts/check-changed.mjs — green
  • container suite run 8x consecutively — 8/8 green
  • Codex autoreview (gpt-5.6-sol, xhigh) — clean, no accepted findings

Size. Production LOC: +20/-4 (net +16) | Tests: +49/-11. The production growth is the closed status classification and the comment explaining why .State.Running is not a liveness signal; it encodes an engine contract that cannot be expressed more simply.

Not covered. No live proof against Podman; its status strings were verified from upstream libpod/define/containerstate.go rather than a running daemon.

Prior repair for context: #128788 fixed a different cause of the same assertion (partial JSON reads of the fake engine's state file) on 2026-08-24. Sampling failed vitest shard jobs in three one-hour windows after that landed still found 4 hits of this signature out of 25, so this race is the surviving cause.

`inspectNodeWorkerContainer` read `{{.State.Running}}`, which is false both
before a container starts and after it exits, so the supervisor treated a
container still in `created` as a finished workload. A `status()` poll landing
in the window between spawning `docker start --attach` and the container
entering `running` therefore killed and removed a healthy worker and finalized
its launch as `failed` with exit code 137.

Classify the engine's `{{.State.Status}}` instead: statuses that still own a
workload stay `live`, only finished ones report `dead`. This also tightens
removal verification, which previously accepted a surviving `created` container
as successfully removed.

Verified against Docker 29.4.0: a container reports `created|false` for roughly
the first 100ms after its start client is spawned. The fake engine now models
engine status like a real one, and a regression test holds a container in
`created` until the supervisor inspects it, then asserts the launch stays
running and completes.
@clawsweeper

clawsweeper Bot commented Aug 25, 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 size: S maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete
steipete marked this pull request as ready for review August 25, 2026 07:24
@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: 🐚 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. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 3:36 AM ET / 07:36 UTC.

ClawSweeper review

What this changes

The PR classifies Docker-compatible container lifecycle status instead of a running boolean so a newly created worker container remains live during startup status polling.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: this focused repair corrects a source-visible lifecycle race, and no patch correctness defect was found. The PR is member-authored and maintainer-labeled, so it should follow the normal maintainer landing path rather than automated cleanup.

Priority: P1
Reviewed head: 1a789b34be720c8b84d7cb0dcf118b788589991d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is small and owner-bound with strong Docker and regression evidence; a Podman smoke would remove the remaining engine-specific uncertainty.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This member-authored PR is outside the external-contributor proof gate; its body nevertheless includes a real Docker created-to-running observation and an after-fix regression run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is outside the external-contributor proof gate; its body nevertheless includes a real Docker created-to-running observation and an after-fix regression run.
Evidence reviewed 6 items Changed lifecycle classification: Container inspection now reads State.Status and treats created, initialized, running, paused, restarting, and stopping as live; only explicit ended states become dead.
Caller proves the prior failure mode: A dead inspection makes status clean up the active container and wait for its terminal outcome, while a live inspection preserves the running receipt.
Focused regression coverage: The new test holds the fake engine in created until the supervisor inspects it, then asserts the receipt remains running and reaches completed.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/node-host/node-worker-supervisor.container.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/node-host/node-worker-supervisor.container.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129102-00JpgL/target$ node scripts/run-vitest.mjs src/node-host/node-worker-supervisor.container.test.ts
node scripts/run-vitest.mjs src/node-host/node-worker-supervisor.container.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129102-00JpgL/target

 ✓  unit  src/node-host/node-worker-supervisor.container.test.ts (14 tests) 5922ms
     ✓ mounts only the admitted bundle and workspace and round-trips the stdio result  758ms
     ✓ keeps a launch running while its container is still starting  548ms
     ✓ uses the documented Node 22 image when no override is configured  536ms
     ✓ keeps a pending cancelled container slot occupied until the fake engine confirms removal  497ms
     ✓ cancel kills and removes the container before terminal persistence  514ms
     ✓ close kills and removes the container before terminal persistence  523ms
     ✓ sweeps owned orphan containers before finalizing stale pending launches  330ms
     ✓ interrupts a stale running journal after verifying its dead container identity  358ms
     ✓ keeps the launch and capacity occupied when removal fails until cancellation can retry  636ms
     ✓ never executes a container worker when its durable identity cannot be recorded  552ms

 Test Files  1 passed (1)
      Tests  14 passed (14)
   Start at  07:37:08
   Duration  8.87s (transform 2.08s, setup 986ms, import 1.61s, tests 5.92s, environment 0ms)

[test] passed 1 Vitest shard in 20.41s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129102-00JpgL/target$ node scripts/run-vitest.mjs src/node-host/node-worker-supervisor.container.test.ts

























Assertions:

  • PASS expect_output: keeps a launch running while its container is still starting

How this fits together

Node-hosted worker sessions may run in Docker- or Podman-compatible containers. The node-worker supervisor uses container inspection to decide whether a journaled worker remains active or should be finalized and cleaned up.

flowchart LR
  A[Worker launch request] --> B[Container created and journaled]
  B --> C[Engine start request]
  C --> D[Supervisor status check]
  D --> E[Container lifecycle status]
  E --> F[Keep active launch live]
  E --> G[Clean up ended launch]
Loading

Before merge

  • Resolve merge risk (P1) - Podman is a supported engine, but the supplied real-engine evidence covers Docker only; an unexpected Podman status safely becomes unknown but could retain a completed worker slot until reconciliation.
Agent review details

Security

None.

PR surface

Source +16, Tests +38. Total +54 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 20 4 +16
Tests 1 49 11 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 69 15 +54

Review metrics

Metric Value Why it matters
Production versus test LOC production +20/-4 (net +16); tests +49/-11 (net +38) The added production code is the explicit engine-status contract and classification needed to distinguish startup from exit; the larger test delta models and exercises that boundary.

Merge-risk options

Maintainer options:

  1. Confirm Podman lifecycle states (recommended)
    Run a short Podman create/start/inspect smoke that observes the pre-start and terminal status strings before merge.
  2. Accept the documented source contract
    Proceed with the existing Docker live evidence and upstream Podman-status verification, accepting that no Podman daemon proof accompanies this PR.

Technical review

Best possible solution:

Land the status-based lifecycle classification after exact-head validation and a short Podman created-to-running smoke if a Podman daemon is available.

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

Yes—source-reproducible: the prior boolean maps a created container to dead, and the added deterministic regression test holds that state until the supervisor polls it.

Is this the best way to solve the issue?

Yes: interpreting the engine lifecycle state at the inspection owner fixes the ambiguity without retries, sleeps, or downstream compensation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8c5a12c112e6.

Labels

Label changes:

  • add P1: A status poll can terminate an otherwise healthy container-isolated worker session during startup.
  • add merge-risk: 🚨 availability: The patch changes Docker- and Podman-compatible lifecycle interpretation, which can affect whether a worker is retained or finalized.
  • 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. Not applicable: This member-authored PR is outside the external-contributor proof gate; its body nevertheless includes a real Docker created-to-running observation and an after-fix regression run.

Label justifications:

  • P1: A status poll can terminate an otherwise healthy container-isolated worker session during startup.
  • merge-risk: 🚨 availability: The patch changes Docker- and Podman-compatible lifecycle interpretation, which can affect whether a worker is retained or finalized.
  • 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. Not applicable: This member-authored PR is outside the external-contributor proof gate; its body nevertheless includes a real Docker created-to-running observation and an after-fix regression run.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the merged container-isolation feature and the current lifecycle repair. (role: introduced the container-isolation implementation and recent area contributor; confidence: high; commits: 3fa3276381dc, 1a789b34be72; files: src/node-host/node-worker-container-engine.ts, src/node-host/node-worker-supervisor.container.test.ts)

Rank-up moves

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

  • Capture a redacted Podman created-to-running lifecycle smoke when that daemon is available.

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 876f2de into main Aug 25, 2026
241 of 242 checks passed
@steipete
steipete deleted the fix/node-worker-container-startup-state branch August 25, 2026 08:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor Author

Rank-up move from the ClawSweeper review — "capture a redacted Podman created-to-running lifecycle smoke" — skipped, with the reason recorded here.

The Podman machine on this host has never been started (podman machine list → podman-machine-default false Never), and connecting fails before any container work:

Error: unable to connect to Podman socket: knownhosts: /Users/steipete/.ssh/known_hosts:198: knownhosts: missing key type pattern

Booting a Podman VM and repairing that host's SSH known_hosts is outside the scope of this fix, so the Podman states remain verified from upstream source (libpod/define/containerstate.go) rather than a live daemon. The Docker 29.4.0 live observation in the PR body stands and covers the code path that regressed.

Worth noting the Podman risk is bounded in one direction: the new classification only ever moves a state from dead toward live, and live means "do not finalize or fence this launch". A Podman status string we mapped incorrectly would leave a launch running slightly longer until its attach client reports the real terminal outcome; it cannot reintroduce the kill-a-healthy-worker behavior this PR removes. Any status we do not recognize still falls through to unknown, which is the pre-existing fail-safe.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…w#129102)

`inspectNodeWorkerContainer` read `{{.State.Running}}`, which is false both
before a container starts and after it exits, so the supervisor treated a
container still in `created` as a finished workload. A `status()` poll landing
in the window between spawning `docker start --attach` and the container
entering `running` therefore killed and removed a healthy worker and finalized
its launch as `failed` with exit code 137.

Classify the engine's `{{.State.Status}}` instead: statuses that still own a
workload stay `live`, only finished ones report `dead`. This also tightens
removal verification, which previously accepted a surviving `created` container
as successfully removed.

Verified against Docker 29.4.0: a container reports `created|false` for roughly
the first 100ms after its start client is spawned. The fake engine now models
engine status like a real one, and a regression test holds a container in
`created` until the supervisor inspects it, then asserts the launch stays
running and completes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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