Skip to content

fix: recover Linux stream automations after command-anchor crashes - #203149

Merged
daniel-lxs merged 3 commits into
mainfrom
openclaw/stream-relay-recovery-202900
Nov 26, 2026
Merged

daniel-lxs merged 3 commits into
mainfrom
openclaw/stream-relay-recovery-202900

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #202900

What Problem This Solves

A Linux stream automation can stop permanently when its command anchor crashes: it immediately exhausts its restart budget, and disabling and re-enabling it cannot recover the retained cleanup failure. Simply clearing that failure is unsafe: a detached child can remain alive after both the source and anchor disappear.

User Impact

Stream automations recover through their existing backoff after the command anchor dies, including across shutdown and restart. Old descendants are stopped and reaped before replacement. No configuration or data migration is required.

Strict Linux child scopes retain one additional native relay process. Losing that final custodian remains fail-closed: neither retry nor manual enable overrides unconfirmed extinction. macOS/Windows, owned workers, and intentional root-exit handoffs keep their existing paths.

Why This Change Was Made

The existing relay now retains kernel subreaper custody outside the command anchor for strict, non-handoff Linux child scopes. After anchor loss, it adopts and reaps detached descendants and supplies an independent extinction certificate. The host joins that certificate, output/lineage closure, and relay exit before releasing cleanup. Cron continues using its existing restart owner and backoff; no exhaustion bypass is added.

Certificate observation stays with the retirement owner. Existing startup/private-input settlement moves into preparation to preserve the enforced module-size limit without changing its admission or cleanup behavior.

Evidence

Verified result (2026-11-21 16:51 UTC): The completed exact-head review rates patch quality 4/6 platinum, proof 5/6 diamond, with no actionable findings and ready for maintainer review. The exact-head CI gate is successful on 0c080a7fc16a7f0c341eb400df78e93a0d635b99; the full observed check inventory has no failed or active checks. This PR is open and non-draft; it has not been merged or deployed.

Forced-cancellation review repair

The second hosted review, on f2430a8c0f37f957dbda9dff0a03895fc014e2db, accepted both prior fixes and rated the real terminal proof 5/6, but found a P2 cancellation-result regression. That finding is repaired in 0c080a7fc16a7f0c341eb400df78e93a0d635b99: after independent extinction is certified, an explicitly requested cancellation uses the existing requested-signal result instead of becoming an unexpected-anchor-loss error. Unexpected anchor loss still rejects its missing command result; loss of final custody still rejects cleanup.

The new native regression runs a real child that ignores SIGTERM, then closes its strict scope within a 500ms cleanup budget. On the reviewed head cleanup succeeds but run.wait() rejects; on the repaired head it returns reason: manual-cancel, exitSignal: SIGKILL, and the child is absent. The unexpected-loss regression now explicitly requires the error rather than swallowing it. 88 native/supervisor cases pass (40.9s wrapper), including the failed-custody and deadline controls. Core/services-test types, touched-file lint/format, session-identity and line-cap guards pass; the runtime build and real Gateway matrix were rerun on this repaired tree. The final exact-head review and CI now pass, as recorded above.

Review and CI repairs

The initial review of 3789e953445a identified two P2 defects, both reproduced locally and repaired in f2430a8c0f37f957dbda9dff0a03895fc014e2db:

  • Prepared and overlay matrix runtimes now bind both compiled native owners through the existing sealed-runtime manifest. This restores the intent of d782bc046eba / #181621: source-loader compiler children cannot share exclusive kernel child-wait ownership. The loader prohibition is unchanged; the companion fixture supplies the same complete native closure.
  • Custody receipts now enter through the host's existing generation-validated dispatcher. The retirement owner no longer adds a second filtering listener. The session-identity guard passes without a baseline change or renamed comparison.

Repair proof: the previously failing matrix file now passes all 4 cases; the selected matrix/resolver/native-host group passes 74 tests (45.2s wrapper), sealed-build consumers pass 70 tests, and the real cloud-worker mid-turn-loss composition passes (85.8s wrapper). That last local fixture initially lacked Debian ps; genuine signed-repository procps 4.0.2 and its library were staged only in task scratch, then the same test passed through the real native utility. No application guard or test assertion was relaxed. Core, scripts, tooling-test and E2E-test typechecks, changed-file lint/format, line-cap, session-identity and runtime-process-lifecycle checks pass. The runtime build and full disposable Gateway matrix were rerun after repair. Initial CI run 44920799768 remains failed evidence for the first head; the final head has its own successful CI receipt above; the original failed run is not backdated green.

Redacted terminal receipts from the repaired real Gateway run

The following is the terminal receipt projection from the same public CLI/Gateway reproduction, completed 2026-11-21 16:28 UTC on the repaired tree. Addresses, paths, process/job identifiers and credentials are omitted; statuses and observed cleanup results are retained. The published file blobs were compared with that tested tree. The before-state and source regression are described above; this is not an in-process mocked Gateway.

{"case":"midrun-recovered","at":"2026-11-21T16:27:57.933Z","streamStatus":"running","failures":1,"restartExhausted":false,"oldExtinct":true}
{"case":"same-gateway-disable-enable","at":"2026-11-21T16:28:02.756Z","streamStatus":"running","failures":0,"restartExhausted":false}
{"case":"gateway-stop","at":"2026-11-21T16:28:03.168Z","exitCode":0}
{"case":"shutdown-reopen-recovered","at":"2026-11-21T16:28:10.774Z","streamStatus":"running","failures":1,"restartExhausted":false}
{"case":"detached-descendant-reclaimed","at":"2026-11-21T16:28:47.538Z","streamStatus":"running","failures":1,"restartExhausted":false,"oldExtinct":true,"noOverlap":true}
{"case":"custodian-loss-fail-closed","at":"2026-11-21T16:28:52.256Z","streamStatus":"error","failures":1,"restartExhausted":true,"noReplacement":true}
{"case":"gateway-stop","at":"2026-11-21T16:28:52.644Z","exitCode":0}
{"case":"cleanup","at":"2026-11-21T16:28:52.648Z","allRecordedProcessesAbsent":true,"portRebound":true}

The source emitted {} periodically with a deliberately nonmatching predicate, so these cases made no model turn. Faults targeted only fixture processes after checking their birth identity and ancestry. The real custodian-loss control remained in error and could not admit a replacement.

The real disposable Gateway reproduced the original failure before the change. The repaired source passed the same production CLI/Gateway flows:

Scenario Before After
Command anchor killed mid-run Error/exhausted with zero restart attempts Old processes extinct, restart after normal 30-second backoff
Disable/enable in the same Gateway Remained exhausted Running again, restart counter reset
Anchor killed immediately before shutdown; same state reopened Persisted cleanup error/exhaustion Clean stop and running source after reopen
Detached descendant outlives root and anchor Descendant remained alive Adopted and reaped before replacement; no overlap
Final custodian killed No equivalent additional custodian on base Cleanup remains unconfirmed; manual enable does not start a replacement

The final proof used a nonmatching stream predicate: no channel or model execution was needed. Every recorded fixture process disappeared, both Gateway stops exited 0, and the fixture port rebound successfully. This is Linux source proof with the normal pinned OpenClaw Bun runtime and a Node 24.20 feeder, not packaged-release or Node-26 parity.

  • Native regression fails on base 0c475b963b585012a180030bdabbfb0016027505 with the missing closing receipt, and passes on the candidate. The existing deadline test now stalls the final custodian rather than the recoverable inner anchor; it still requires a failed cleanup result.
  • Initial published-head focused run: 122 passed, 1 platform-specific skip, across 12 files, 64.8 seconds wrapper wall. The changed native file also ran independently; baseline wrapper 38.6 seconds, initial candidate 37.2 seconds. Per-file CI seconds were not collected.
  • pnpm build:runtime, core and selected services-test typechecks, touched-file typed lint/format, line-cap/assertion-safety guards, import-cycle check, and git diff --check passed.
  • Review history: Auto Review was attempted on the full local candidate against the pinned base, P0–P2, with relevant unchanged owner context. The same managed route timed out after 1,200 seconds without a report. That attempt supplies no clean-review verdict. All three findings across the two subsequent hosted review cycles were repaired. The final exact-head review is linked above and reports no actionable findings, patch quality 4/6 and proof confidence 5/6.
  • No failure-alert destination was configured in the reported reproduction. The existing alert path is unchanged; configured external terminal-source notification delivery is not claimed as live-tested.
Focused commands and scope

node scripts/run-vitest.mjs src/process/supervisor/service-child-relay-host*.test.ts src/process/supervisor/service-child-relay.native-owner.test.ts src/process/supervisor/supervisor.cleanup-history.real.test.ts src/process/supervisor/supervisor.test.ts src/process/supervisor/supervisor.root-exit.real.test.ts src/gateway/cron-stream-watchers.extinction.test.ts src/gateway/server-cron.stream-lifecycle.test.ts --maxWorkers=1

node scripts/run-tsgo-core-test-shards.mjs --changed-paths-json '["src/process/supervisor/service-child-relay-host.test.ts","src/process/supervisor/supervisor.cleanup-history.real.test.ts"]'

The repair changes 14 existing files. No production cleanup path was replaced with a PID census or a fabricated receipt. Necessary growth is the independent native custody join and its regression coverage; the input-startup movement is behavior-preserving. Broader platform/CI proof remains with normal PR CI.

Requested by Donniefi. Original report and reproduction details by @warm-cloth.

Work sessions

Linked for team reference; these sessions aren’t public.

🦞 Made with OpenClaw

Worked on by

Worked on by:
- @DonnieFi

Co-authored-by: DonnieFi <[email protected]>
OpenClaw-Publication: f661748b-286f-4b2e-9a63-08c463e19eb5
@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Nov 21, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 21, 2026 15:44
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Retain an outer Linux subreaper so stream automations can restart after command-anchor crashes once descendant cleanup is confirmed.

Example: A Linux stream emitting {} every two seconds loses its command anchor to SIGKILL.

  • Before: The stream immediately becomes restart-exhausted, and disable/enable repeats the retained cleanup failure.
  • After: The outer custodian reaps surviving descendants and permits restart through the existing 30-second backoff.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused recovery repair with production-entry-point evidence, distinct native regressions, and no remaining finding; broad exact-head CI is unfinished.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Public repaired-tree terminal receipts exercise the real Linux CLI/Gateway stream owner through crash recovery, manual re-enable, shutdown/reopen, detached-descendant cleanup without overlap, and final-custodian loss remaining terminal; packaged-release and Node-26 parity are expressly unclaimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A stream automation stops permanently after its command anchor crashes, even when the user disables and re-enables it.
Reason: The maintainer-authored direction restores documented recovery while retaining confirmed descendant cleanup and the existing restart owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a confirmed Linux automation recovery failure, and all three prior findings are addressed; no remaining actionable defect was found, while exact-head CI is still pending.

Priority: P2
Reviewed head: 0c080a7fc16a7f0c341eb400df78e93a0d635b99

Before merge

None.

Findings

None.

Agent review details

How this fits together

The process supervisor launches stream commands and owns their cleanup; the cron owner consumes command results and extinction confirmation before scheduling replacements.

flowchart TD
  A[Cron stream owner] --> B[Process supervisor]
  B --> C[Outer Linux custodian]
  C --> D[Command anchor]
  D --> E[Source and descendants]
  E --> C
  C --> F[Kernel extinction certificate]
  F --> B
  B --> A
Loading

Technical review

Best possible solution:

Merge the existing-owner custody repair once the normal exact-head gates pass.

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

Current source establishes the missing-receipt cleanup rejection and terminal restart path, supported by the reporter's released-version reproduction and the PR's before/after Gateway evidence.

Is this the best way to solve the issue?

The patch repairs cleanup at the shared process owner rather than clearing cron failures, reuses kernel subreaper custody, and preserves the existing restart and intentional-handoff contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f4ef065b92f1.

Provenance checked

  • Cleanup confirmation and relay retirement keeps the original intent (220578b: Merged cleanup work requires reliable descendant extinction before releasing ownership; later retirement fixes preserve that requirement through forced cleanup.)
  • Linux kernel subreaper custody keeps the original intent (2aed866: Merged work uses retained kernel child-wait ownership for cleanup without relying on process-group signals; this patch reuses that mechanism outside the fallible anchor.)
  • Intentional root-exit handoff keeps the original intent (237111e: Normal exec completion must preserve deliberately detached services; retained custody is restricted to strict non-handoff child scopes.)
  • Startup and private-input settlement keeps the original intent (69ff526: Startup failure must retain precedence over consequential secret-pipe failure and join cleanup; the moved preparation code preserves those operations and checks.)
  • Prepared and sealed runtime entrypoints keeps the original intent (57f6d20: Runtime manifests own packaged helper resolution; the patch adds the newly required relay sibling to that same manifest and existing prepared-runtime bindings.)
  • Historical cleanup diagnostics keeps the original intent (22b29a7: Historical cleanup failures remain diagnostic without blocking later shutdown; the deadline control still verifies retained failure and successful later shutdown.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit d782bc0 adds scripts/lib/code-mode-matrix-process-owner.ts:7 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d782bc046eba; files: scripts/lib/code-mode-matrix-process-owner.ts)

PR surface

Source +187, Tests +121, Docs +2, Other +4. Total +314 across 14 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 268 81 +187
Tests 4 129 8 +121
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 4 0 +4
Total 14 403 89 +314

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Command-anchor loss can permanently interrupt configured unattended Linux streams, while the rest of the Gateway remains usable.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-21T16:01:24.550Z sha 3789e95 :: needs changes before merge. :: [P2] Resolve the outer custodian from the compiled prepared runtime | [P2] Route custody certificates through the validated host dispatcher
  • reviewed 2026-11-21T16:17:33.873Z sha f2430a8 :: needs changes before merge. :: [P2] Preserve cancellation results when deliberately killing the inner anchor

Reviewed November 21, 2026, 11:34 AM ET / 16:34 UTC (Revision 3).

Worked on by:
- @DonnieFi

Co-authored-by: DonnieFi <[email protected]>
OpenClaw-Publication: 804ae956-6252-4826-b6c8-1cf779c86539
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 21, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Nov 21, 2026
Worked on by:
- @DonnieFi

Co-authored-by: DonnieFi <[email protected]>
OpenClaw-Publication: 4c82b555-2bdd-4796-81a6-b5bf44c45d18
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 21, 2026
@daniel-lxs
daniel-lxs merged commit fad575b into main Nov 26, 2026
155 checks passed
@daniel-lxs
daniel-lxs deleted the openclaw/stream-relay-recovery-202900 branch November 26, 2026 02:20
vincentkoc added a commit that referenced this pull request Nov 26, 2026
…irement-rule

* origin/main: (172 commits)
  test(gateway): expect a revoked person's Goal retry to be hidden as not found (#205698)
  fix: keep browser disabled when only hardening relay authentication (#203137)
  fix: recover Linux stream automations after command-anchor crashes (#203149)
  fix(whatsapp): identify voice-note captions as text in delivery receipts (#205381)
  fix(test): unblock restart-auth plugin and worker publication qualification (#205679)
  chore(ui): refresh control ui locales (#205691)
  fix: reduce memory during SQLite usage refresh (#201064)
  fix(plugins): readmit native captures with a dangling host link
  chore(i18n): refresh native locales (#205680)
  fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification (#205668)
  fix(skill-workshop): skip the skill diet for skills with Markdown outside support directories (#204881)
  fix(plugins): clarify dated SDK migration notices (#200932)
  fix: keep the resident launcher when reinstalling Gateway (#205655)
  fix: show the whole reply when you reopen a TUI session (#200455)
  test(ui): wait for restored speech player authorization (#199502)
  feat: let agents post approved GitHub comments (#204301)
  fix(agents): honor imageMaxDimensionPx at the provider and CLI image handoffs (#205663)
  chore(ui): refresh control ui locales (#205664)
  fix(google): preserve playback when Google Live splits audio into parts (#205364)
  fix: show named characters in exported session messages (#205362)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…penclaw#203149)

Keep a separate Linux process owner alive when the command anchor crashes. Retire its descendants before restarting the stream, and leave cleanup unconfirmed if that process owner is lost.

Closes openclaw#202900.
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…203149)

Keep a separate Linux process owner alive when the command anchor crashes. Retire its descendants before restarting the stream, and leave cleanup unconfirmed if that process owner is lost.

Closes #202900.

(cherry picked from commit fad575b)
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…203149)

Keep a separate Linux process owner alive when the command anchor crashes. Retire its descendants before restarting the stream, and leave cleanup unconfirmed if that process owner is lost.

Closes #202900.

(cherry picked from commit fad575b)

Release adaptation: None; source applies intact to current stable owner.

Companion audit: PR #203149 is the source; keep the protocol, runtime-worker manifest, and cleanup refusal together. No native package bump.

Co-authored-by: RomneyDa <[email protected]>
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M 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.

[Bug]: A stream automation whose relay dies is marked restart-exhausted at once, and re-enabling it fails until a Gateway restart

2 participants