Skip to content

fix(gateway): prevent hosted lifecycle crashes and self-waits - #137456

Merged
steipete merged 8 commits into
mainfrom
steipete/hosted-lifecycle-landing
Sep 4, 2026
Merged

steipete merged 8 commits into
mainfrom
steipete/hosted-lifecycle-landing

Conversation

@steipete

@steipete steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #137386 — hosted Gateway lifecycle crashes and self-wait.

Also repairs the reproduced Windows checkout-fixture startup failure encountered in the landing gates. Separate from the received-work state-lifetime repair; this does not import that PR or its unpublished follow-up candidate. Maintainer edits remain available on this repository-owned branch.

What Problem This Solves

Users asking a running Gateway's SystemAgent to start or stop the Gateway could lose their response when a native service error exited the hosting process. Hosted stop also awaited native termination from the same SystemAgent work lane that shutdown was waiting to drain.

Both paths predate the received-work lifetime PR. The Linux baseline reproduced abrupt exit and the legacy process-only systemd self-wait; native macOS reproduced the existing self-stop refusal reaching the CLI's process-exit handler.

Why This Change Was Made

Lifecycle requests now go through a capability bound to the exact serving host, kernel, and caller. Stop prepares its native resource, returns and audits scheduling acceptance, drains existing work, closes the kernel, and only then executes from the private host continuation. Retirement joins preparation, executor close, and in-flight native inspection; retained public handles cannot act on a successor.

Start reports that this Gateway is already running. Restart retains the existing safe scheduler. Linux selects its manager from the actual process cgroup and validates the native generation; its stop client runs outside the Gateway service cgroup. macOS uses ordinary bootout and canonical native probe status plus exact PID. Windows exits only the exclusively owned process, preserving the task supervisor and failure-restart contract.

The old hosted-to-CLI route and separate hosted-restart branch are removed. Standalone CLI semantics, shutdown budgets and joins, native service definitions/policy, configuration/environment surface, SQLite schemas, and wire protocol remain unchanged. Main's delegated approval-completion flow and awaited update-check shutdown ordering are preserved.

User Impact

Hosted lifecycle errors return as operation failures rather than abruptly exiting the Gateway. A successful stop request reports Scheduled Gateway stop, not unverified process extinction, and lets its requesting work settle before native termination. An offline Gateway still needs the standalone CLI or owning service manager to start.

Definitive same-generation systemd refusal after successful kernel close can reopen a fresh kernel; uncertain native outcomes do not claim success or revive a successor. External supervisors and hosts without exclusive process ownership receive actionable guidance. See the Gateway CLI docs and Gateway runbook.

Evidence

Current candidate

Head e2de7fc4c194c02160f45862df7030db4de9b3a6, tree 03a81ee126d7c200dee9842d2354fcfd62ca0109, based on 8b553470f091a77a222621cb8a6166f884d99010.

The required rebase preserved both hosted-capability revocation and main's awaited update-check/Bonjour teardown. At parent cc1027ce7ba74460c86fc55d267b6de46d4e5ab9, 618 lifecycle/update-owner tests and 675 fixture/planner/runner tests passed, followed by the full 50-path changed-gate plan and pnpm build with no ineffective dynamic-import warning. The real dist-backed CLI/authenticated protocol-4 WebSocket rescue flow returned terminal Gateway already running and Scheduled Gateway stop results, then independently joined exit 0 and cleanup.

The final follow-ups change only CI routing and test support. Three deterministic split-stderr cases failed before the census owner repair; all three then passed, followed by all 59 checkout-fixture tests, root-test types, script/root-test lint, formatting, and applicable guards. A separate workflow-only routing regression failed with runWindows: false; the existing matcher now includes the Windows probe workflow, and all 237 classifier tests plus changed types/lint/export guards pass. Fresh Codex autoreview is scoped-clean at P0 for the parent branch and each follow-up. Product source and build inputs are unchanged by these follow-ups.

The last CI repair is test-only: fixed artifact dates caused two release-candidate CLI fixtures to become ineligible at September 3, 22:00 UTC. Both failed with the real clock before repair; all 83 candidate contract/reuse tests, changed gates and fresh P0 review pass after assigning coherent relative dates before archive/digest construction. Pure fixed-clock expiry tests and production's 14-hour rule remain unchanged.

Required exact-head CI succeeded: run 33815057999, attempt 6, with 117 successful jobs and 14 planned skips. The dependency audit and aggregate gate both passed. The native Windows job at parent 65ab7d4 passed five tests. Inspected final artifacts confirm audit/response before zero-work close, Gateway/descendant/supervisor exit 0, unchanged enabled task, 66,253 ms without restart, exact cached DB closure, and successful cleanup. The sole subsequent change is the release-test fixture; all Gateway/native/workflow/dependency inputs are unchanged. The same manual run also succeeded in its headless Windows job. A superseded run at 03cbef4 was intentionally cancelled after its native job succeeded.

The dependency audit previously blocked attempts 1–5 on 60-second npm bulk-advisory timeouts. Independent secretless VM checks reproduced the endpoint failure with curl and Node while registry ping succeeded; the VM was resealed and stopped. Attempt 6 completed the audit at 01:05:29 UTC on September 4, with no matching high-or-higher advisories returned by npm bulk. That is the audit's stated scope, not comprehensive upstream vulnerability clearance. No audit exemption, timeout increase, or branch patch was introduced to obtain the pass. Fresh complete-branch Codex review is scoped-clean at P0, and the live required-check rollup is green. The branch is ready for the native prepare/merge gates.

Native before/after and sibling proof

  • Original fail-first regressions: three intended failures reached the real CLI handler's defaultRuntime.exit(1).
  • Linux baseline: manual-stop refusal and current control-group policy dropped the response and exited 1. A legacy process-only unit without TimeoutStopSec waited until this VM's 90-second manager timeout and SIGKILL. This models the old policy, not the entire old release; 90 seconds is an observation, not a universal default.
  • Linux repair: real user/system scopes, refusal, current/legacy kill policies, and foreground stop passed. Native scope/literal-argument proof verifies the prepared executor, whose source hash remains unchanged. Direct upstream systemd v259.5/v249 source confirms scope registration uses the same PID and execs the command; the exact-PID guard remains. These are earlier-base native runs, not newly relabeled exact-head proof.
  • Native macOS 26.6.2 / Node 24.19.0: baseline self-stop disconnected/exited 1; repaired flow delivered the response before zero-work close, bootout and exit 0. No respawn across the generated throttle window; definition/disable policy unchanged; audit inspected and jobs/processes cleaned. A redundant raw launchctl-state check failed its regression before removal: nested coalition active is not the canonical job's running state.
  • Windows run 33809169680 succeeded in both native and headless jobs at parent cc1027ce7ba74460c86fc55d267b6de46d4e5ab9. All five native tests passed. Inspected qualification/proof/cleanup artifacts show zero forwarded credentials/Tailnet surfaces/operator mounts, explicit managed-identity absence, audit/response before zero-work close, Gateway/descendant/supervisor exit 0, unchanged enabled task definition, 66,866 ms without restart, and successful cleanup. The log confirms exact cached state-handle closure. This precedes the two-file diagnostic fix; the new-head run above is separate.

CI failures repaired, not waived

The earlier native Windows run passed lifecycle assertions but failed EBUSY during cleanup: its premature pass artifact is invalid. The fixture now closes only its captured parent-process database handle after service/config observation and publishes proof only after cleanup. Effective task enablement comes from COM, not an omitted default XML field. Canonical test-support naming/module-relative URLs fix discovery without ignores. Workflow assertions retain isolation/cleanup gates; cache membership comes from the canonical shard rather than a fixed count.

Retained Windows diagnostics proved the checkout failure was spawnSync python ETIMEDOUT before sentinel registration in the original overlapping cases. One supervisor-owned sampler now separates interpreter startup from the unchanged one-second query deadline, preserving exact PID/creation-time identity, lease fencing and concurrency. Retirement joins actual process/stdio/socket closure. RED/GREEN cleanup regressions also prevent expired waits or late truthful census results from publishing completed reports; Windows reserves the last second of the existing four-second success budget for retirement, never abandons its raw join, and retains the existing outer termination fallback.

CI 33809069251 then exposed a diagnostic race: killing Python on its first stderr chunk discarded the actual error and native exit code. The final fix retains bounded stderr through child/stdio close and rejects any later complete readiness/query frame after observed stderr. Deterministic prefix → owner-observed acknowledgment → tail tests fail before the fix and pass after it. No retry, timeout extension, Python protocol rewrite, platform skip, service-policy or product configuration was added.

Earlier integrated proof included 839 lifecycle/sibling tests; routing passed 475 tests. A broader fixture sweep had 970 passes, 64 platform skips and one offline pnpm bootstrap failure. Seeding the existing pinned environment document into both fixture projects fixed that producer without relaxing network isolation or assertions; its focused rerun passed. These historical runs are not presented as a fresh all-green full-suite run.

All product execution used newly owned synthetic state behind enforced physical isolation. The Mac VM had no host filesystem sharing or credential hydration, VSock-only control, packet filtering and a disconnected NIC during runtime proof; it is now stopped. No operator Gateway/state, peer candidate/lease, or outbox repair work was used. The native owner harness uses a labeled HTTP envelope; separate WebSocket proof covers real CLI/protocol/chat plumbing, not model-driven inference or live messaging-provider ingress.

Scope and size

Against base 8b553470f091a77a222621cb8a6166f884d99010: production +765 / −47 = +718; tests/support +3902 / −1002 = +2900; docs +43 / −2 = +41; CI tooling +89 / −4 = +85. Moves contribute no net growth. The final diagnostic commit adds no product code.

Production growth supplies the missing post-kernel host/native ownership boundary and joined two-phase executor. Three operations share one dispatcher; redundant manager-process discovery and hosted CLI paths are removed. Existing standalone CLI behavior is retained as an explicit public contract. No changelog was edited; this body retains behavior, surfaces, references and proof for release-note generation.

@steipete steipete self-assigned this Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 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 cli CLI command changes size: XL maintainer Maintainer-authored PR labels Sep 3, 2026
@steipete
steipete marked this pull request as ready for review September 3, 2026 17:45
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 9:12 PM ET / September 4, 2026, 01:12 UTC.

ClawSweeper review

What this changes

This PR routes hosted Gateway lifecycle requests through a serving-host capability so requests can settle before Gateway drain and native service or process termination.

Regression provenance

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

Merge readiness

⛔ Blocked before merge - 3 items remain

The host-bound lifecycle path replaces the current hosted start/stop route that can exit or self-wait, with targeted authority and shutdown-order coverage. Keep the PR open until the required exact-head dependency audit succeeds.

Priority: P1
Reviewed head: e2de7fc4c194c02160f45862df7030db4de9b3a6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair is well-targeted and substantially evidenced, with merge readiness held only by the required exact-head dependency audit.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The changed production owner is exercised by targeted authority and shutdown-order tests, and the PR supplies linked native after-fix evidence for the real Gateway lifecycle path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The changed production owner is exercised by targeted authority and shutdown-order tests, and the PR supplies linked native after-fix evidence for the real Gateway lifecycle path.
Evidence reviewed 6 items Hosted lifecycle owner boundary: Hosted start and stop now require the serving Gateway host capability, return an explicit scheduled result, and leave standalone CLI lifecycle handling on its existing path.
Shutdown ordering: The run loop performs the accepted native-stop continuation only after server close, while refusal and uncertain native outcomes take separate paths.
Authority revocation coverage: Tests cover loss of request, tool, Gateway, worker, and session authority after preparation, asserting no acceptance, native effect, or audit record follows.
Findings None None.
Security None None.

How this fits together

SystemAgent lifecycle requests enter through the Gateway and can ultimately stop the process hosting that Gateway. The new host-lifecycle owner separates request acceptance from later native termination after the Gateway has drained and closed.

flowchart LR
  A[Approved SystemAgent request] --> B[Gateway host lifecycle owner]
  B --> C[Prepare native stop]
  B --> D[Scheduled response]
  C --> E[Gateway drain and close]
  E --> F[Host continuation]
  F --> G[Native service or process stop]
Loading

Before merge

  • Resolve merge risk (P1) - The required exact-head dependency audit has repeatedly timed out, leaving its vulnerability result unestablished; do not merge until it succeeds.
  • Complete next step (P2) - Obtain a successful exact-head dependency-audit result before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +718, Tests +2900, Docs +41, Config +85, Other 0. Total +3744 across 52 files.

View PR surface stats
Area Files Added Removed Net
Source 14 765 47 +718
Tests 33 3903 1003 +2900
Docs 3 43 2 +41
Config 1 86 1 +85
Generated 0 0 0 0
Other 1 2 2 0
Total 52 4799 1055 +3744

Review metrics

Metric Value Why it matters
Production vs test delta production +718 net; non-production coverage and supporting changes +3,026 net The production growth establishes the explicit host-owner boundary, with extensive coverage for revocation, drain ordering, native cleanup, and Windows fixture behavior.

Stored data model

Persistent data-model change detected: serialized state: src/daemon/hosted-stop.ts, unknown-data-model-change: src/daemon/hosted-stop.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #137386
Summary: This PR is the candidate repair for the hosted Gateway lifecycle crash and self-wait issue; its Windows fixture work is related but distinct.

Members:

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

Merge-risk options

Maintainer options:

  1. Complete the required dependency audit (recommended)
    Run the required audit on the exact PR head and retain a successful result before merge.

Technical review

Best possible solution:

Retain the single host-lifecycle owner path and merge only after a successful exact-head dependency audit confirms the required security gate.

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

Yes: current main retains the hosted daemon-lifecycle route, and the introduced tests exercise the response, drain, native-stop, and caller-revocation ordering; the PR also supplies linked native baseline evidence.

Is this the best way to solve the issue?

Yes: binding the request to the serving host lets the request settle before teardown and prevents stale callers or replacement Gateways from reaching native stop.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3d30b3accb23.

Labels

Label justifications:

  • P1: Hosted lifecycle failures can terminate or hang a running Gateway and lose the requesting operation's response.
  • merge-risk: 🚨 availability: The PR changes live Gateway shutdown and native service/process termination ordering.
  • merge-risk: 🚨 automation: The branch changes Windows CI qualification, changed-scope routing, and process-census fixture behavior.
  • 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 (linked_artifact): The changed production owner is exercised by targeted authority and shutdown-order tests, and the PR supplies linked native after-fix evidence for the real Gateway lifecycle path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is exercised by targeted authority and shutdown-order tests, and the PR supplies linked native after-fix evidence for the real Gateway lifecycle path.

Evidence

Acceptance criteria:

  • [P1] Run the required dependency audit against e2de7fc and retain its successful result.

What I checked:

  • Hosted lifecycle owner boundary: Hosted start and stop now require the serving Gateway host capability, return an explicit scheduled result, and leave standalone CLI lifecycle handling on its existing path. (src/system-agent/operations-execute.ts:481, e2de7fc4c194)
  • Shutdown ordering: The run loop performs the accepted native-stop continuation only after server close, while refusal and uncertain native outcomes take separate paths. (src/cli/gateway-cli/run-loop.ts:555, e2de7fc4c194)
  • Authority revocation coverage: Tests cover loss of request, tool, Gateway, worker, and session authority after preparation, asserting no acceptance, native effect, or audit record follows. (src/gateway/server-methods/system-agent.host-lifecycle.test.ts:49, e2de7fc4c194)
  • Current main still needs the repair: Current main still sends hosted start and stop through the daemon lifecycle route and only handles hosted restart specially; it has no serving-host lifecycle capability. (src/system-agent/operations-execute.ts:481, 3d30b3accb23)
  • Feature history: The branch's lifecycle repair history includes the original fix commit, recorded September 3, 2026. (a43012ca299e)
  • Required audit remains unproven: The PR discussion and prior ClawSweeper review record repeated timeouts of the required exact-head dependency audit; successful result evidence is still absent.

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)

Rank-up moves

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

  • Obtain and retain a successful exact-head dependency-audit result.

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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-03T19:01:37.686Z sha 3a8131cb0985e96a5d7082b99ad224eef4a9cd77 :: blocked before merge. :: none
  • reviewed 2026-09-03T20:59:35.742Z sha aeefd28ff1ddd351b49c3d2358fd5306ac5832b5 :: blocked before merge. :: none
  • reviewed 2026-09-03T21:19:25.388Z sha aeefd28ff1ddd351b49c3d2358fd5306ac5832b5 :: blocked before merge. :: none
  • reviewed 2026-09-03T21:51:53.341Z sha cc1027c :: blocked before merge. :: [P2] Route Windows probe workflow edits to the Windows lane
  • reviewed 2026-09-03T22:34:24.640Z sha 65ab7d4 :: blocked before merge. :: none
  • reviewed 2026-09-03T23:21:21.888Z sha e2de7fc :: blocked before merge. :: none
  • reviewed 2026-09-04T00:25:18.963Z sha e2de7fc :: blocked before merge. :: none
  • reviewed 2026-09-04T00:47:00.538Z sha e2de7fc :: blocked before merge. :: none

@steipete

steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready evidence

Reviewed head: e2de7fc4c194c02160f45862df7030db4de9b3a6 (tree 03a81ee126d7c200dee9842d2354fcfd62ca0109). Exact-head CI is now green: run 33815057999, attempt 6, 117 successful jobs and 14 planned skips. Security-fast 100873530589 completed the npm audit at September 4, 01:05:29 UTC; aggregate gate 100873825338 succeeded. A fresh live rollup confirms no failed or pending checks; older cached failures were not treated as current state.

The latest ClawSweeper review's actionable request—successful exact-head dependency audit—is satisfied. Attempts 1–5 had real 60-second endpoint timeouts, corroborated with independent curl/Node probes in a secretless VM. No audit waiver, timeout increase, or new branch patch was used. The successful result is npm bulk's stated high-severity production-dependency coverage, not comprehensive upstream vulnerability clearance. Fresh complete-branch Codex P0 autoreview is scoped-clean, with no accepted findings.

Behavior and native evidence

The host owns the deferred native stop, not the SystemAgent request being drained. Acceptance and its response/audit settle before zero-work kernel close and native termination; exact host/kernel/caller authority is rechecked, and raw preparation, execution and resource closure are joined. Standalone CLI behavior, shutdown budgets, native service policy, configuration, protocol and SQLite schema remain unchanged.

The Windows native and headless run 33812903031 succeeded at parent 65ab7d4. Its five-test native job and inspected artifacts prove audit/response before zero-work close; Gateway, descendant and supervisor exit 0; unchanged enabled task; 66,253 ms without restart; exact cached DB closure; and successful cleanup. The only subsequent change is a release-test fixture: all Gateway/native/workflow/dependency inputs are byte-identical. Required Windows CI also passed the original concurrent cold-start, native PID-reuse, stderr, lease and joined-retirement cases. The earlier EBUSY run's premature pass artifact remains invalid.

Linux before/after and native scope/literal-argument proof retain their earlier-base labels. macOS before/after observed baseline disconnect/exit 1, then response-before-close/bootout/exit 0 with no respawn and unchanged definition. The real dist-backed CLI/authenticated protocol-4 WebSocket rescue flow independently verified terminal already-running/scheduled results, exit 0 and cleanup. The native HTTP owner harness and real WebSocket plumbing are separate evidence; no model-inference or live messaging-provider proof is claimed.

Exact focused commands

These ran in task-owned physically isolated synthetic environments, not against the operator's Gateway. The parent code/build inputs remain unchanged after the CI/test-only follow-ups.

618 lifecycle/update-owner tests passed:

node scripts/run-vitest.mjs src/cli/gateway-cli/host-lifecycle.test.ts src/cli/gateway-cli/run-loop.test.ts src/gateway/server-kernel.test.ts src/gateway/server-close.test.ts src/gateway/server-startup-post-attach.test.ts src/infra/update-startup.test.ts src/daemon/hosted-stop.test.ts src/daemon/hosted-stop-executor.test.ts src/daemon/hosted-stop-executor.lifecycle.test.ts src/daemon/systemd.test.ts src/system-agent/operations.gateway-lifecycle.test.ts src/gateway/server-methods/system-agent.host-lifecycle.test.ts

675 fixture/planner/runner tests passed:

node scripts/run-vitest.mjs test/scripts/ci-platform-checkout.test.ts test/scripts/ci-node-test-plan.test.ts test/scripts/build-all.test.ts test/scripts/vitest-process-cache.test.ts src/scripts/ci-changed-scope.git-owner.test.ts test/scripts/test-projects.test.ts

Final focused suites passed 59, 237 and 83 tests respectively; their regressions failed before repair:

node scripts/run-vitest.mjs test/scripts/ci-platform-checkout.test.ts
node scripts/run-vitest.mjs src/scripts/ci-changed-scope
node scripts/run-vitest.mjs test/scripts/full-release-candidate-reuse.test.ts test/scripts/full-release-candidate-contract.test.ts

Applicable changed gates passed, including core/root test types, formatting, lint and export/ownership guards. The final fixture-only check was:

OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs -- test/scripts/full-release-candidate-reuse.test.ts

The earlier complete 50-path changed plan and build passed without an ineffective dynamic-import warning:

pnpm build

Other review items

  • Systemd PID guard retained: direct upstream v259.5 self-PID registration and scope exec path, corroborated by v249 and real scope proof, refute service-mode forking assumptions. Executor SHA-256 remains 3b6cc9b412cf8b0e2a0d56ecff7bc85eff2fc892736e4eb220b7631ac760cdcd. A read-only review runner's DNS limitation does not invalidate that retained source/native evidence.
  • Workflow routing fixed: the workflow-only Windows selection regression is RED/GREEN; one matcher entry and existing-table case select Windows without unrelated app builds.
  • No data-model migration: native identity is read-only/closure-bound, and scheduling uses the existing SystemAgent audit owner/schema. No new persistent store or migration is present.
  • Production growth: +765/−47 = +718 for the missing exact-instance host/native owner and prepared executor. Tests/support +3902/−1002 = +2900; docs +41; CI tooling +85. Old hosted CLI/restart branches and redundant manager discovery were removed; standalone CLI is retained as a public contract.
  • Docs: Gateway CLI and runbook distinguish scheduling from native completion. The Linux manual-unit example now matches the existing 330-second policy; runtime budgets were not extended.
  • Main composition: source review and read-only three-tree comparison through cd8c748 found no conflict or runtime blocker; no combined-main execution is claimed. Main independently added a test child-clock preload. Follow-up: consolidate the redundant fixture clock strategies/stale merged test comment after integration; do not discard newer main. The canonical audit retry repair is already on main and was not copied into this branch to obtain its green run.

Native prepare/merge is the remaining operation. No operator state/service, peer lease/candidate, or separate received-work lifetime patch was touched. Changelog remains release-owned and unchanged.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. labels Sep 3, 2026
@steipete
steipete force-pushed the steipete/hosted-lifecycle-landing branch from 00c0ca6 to 3a8131c Compare September 3, 2026 18:44
@clawsweeper clawsweeper Bot added 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 3, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 3, 2026
Route Gateway-hosted SystemAgent lifecycle operations through the exact
run-loop owner instead of the exiting daemon CLI. Accept and audit stop
before draining its requesting work, then execute native termination only
after kernel teardown. Join preparation, executor close, and late native
inspection before retiring ownership.

Preserve standalone CLI behavior, shutdown budgets, native service policy,
and current delegated-approval completion. Validate Linux service scopes,
macOS bootout, caller/kernel fencing, and real CLI/WebSocket rescue replies.
Native Windows exact-head proof is included for CI verification before merge.

Fixes #137386 (hosted Gateway lifecycle crashes and self-wait).
#137386
Preserve sentinel and descendant startup failures in the existing fixture report, including native census signal/cause details. Keep the original deadlines, concurrency, process identity checks, and cleanup joins unchanged. Add fail-first startup diagnostic coverage.

Refs #136317; this adds evidence and does not claim to fix the intermittent Windows census startup failure.
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Sep 3, 2026
Do not SIGKILL the persistent Windows census sampler after its first
stderr chunk: that discards Python's actual error and native exit code.
Retain the bounded traceback until the existing child/stdio close join,
while rejecting readiness and query replies after observed stderr.

Deterministic startup/query regressions synchronize the diagnostic tail
after the owner has observed its prefix; a mixed-output case proves a
real valid reply remains rejected. All three fail before the owner fix.
Query, startup, cleanup and outer watchdog budgets are unchanged.

Context: #136317; hosted lifecycle landing #137456.
Include windows-testbox-probe.yml in the existing Windows workflow scope.
An edit to this workflow alone previously selected generic Node coverage
without Windows validation. Extend the existing exact-scope table; its
new case fails before the matcher repair. Other platform scopes stay off.

Addresses the CI-selection finding on #137456. No product or native
workflow behavior changes.
@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. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 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 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

The subprocess discovery tests use the real clock, but their synthetic
artifacts expired on a fixed date. Once the remaining lifetime fell below
14 hours, selection correctly returned a miss before either intended
unavailable branch was exercised.

Give CLI fixtures one fresh creation time and a coherent seven-day expiry
across evidence metadata and all manifest constituents before ZIP/digest
construction. Keep fixed NOW for pure expiry tests and retain all trust,
ordering, bounded-evaluation, and missing-constituent assertions.

Both original failures reproduced on unchanged code after the deadline.
No production policy, timeout, release workflow, or clock override changes.

CI follow-up for #137456.
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 3, 2026
@steipete
steipete merged commit da7d113 into main Sep 4, 2026
871 of 882 checks passed
@steipete
steipete deleted the steipete/hosted-lifecycle-landing branch September 4, 2026 01:20
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Chulixx162Chulixx1622624/openclaw that referenced this pull request Sep 4, 2026
* fix(gateway): prevent hosted lifecycle crashes and self-waits

Route Gateway-hosted SystemAgent lifecycle operations through the exact
run-loop owner instead of the exiting daemon CLI. Accept and audit stop
before draining its requesting work, then execute native termination only
after kernel teardown. Join preparation, executor close, and late native
inspection before retiring ownership.

Preserve standalone CLI behavior, shutdown budgets, native service policy,
and current delegated-approval completion. Validate Linux service scopes,
macOS bootout, caller/kernel fencing, and real CLI/WebSocket rescue replies.
Native Windows exact-head proof is included for CI verification before merge.

Fixes #137386 (hosted Gateway lifecycle crashes and self-wait).
openclaw/openclaw#137386

* ci(windows): qualify hosted runner independently of image label

* docs(linux): align manual Gateway stop budget

* test(ci): retain checkout actor startup diagnostics

Preserve sentinel and descendant startup failures in the existing fixture report, including native census signal/cause details. Keep the original deadlines, concurrency, process identity checks, and cleanup joins unchanged. Add fail-first startup diagnostic coverage.

Refs #136317; this adds evidence and does not claim to fix the intermittent Windows census startup failure.

* fix(ci): join census helpers and close native proof fixtures

Own one Windows process-census sampler per checkout supervisor rather than
charging every actor's one-second query deadline for interpreter startup.
Preserve exact process birth identity, concurrent cases, and lease fences.
Reserve helper retirement within the existing cleanup-success budget and
always join actual process, stdio, and broker closure before supervisor exit.

Close only the native hosted-stop fixture's cached state database before
removing its directory, and publish its pass proof after cleanup succeeds.
Keep native fixtures discoverable through canonical test-support names and
real module-relative import URLs. Update workflow and cache-plan assertions
without weakening their isolation or membership contracts.

Seed the existing pinned pnpm environment in both offline-test projects
before bootstrap, avoiding an unnecessary registry lookup. Preserve fresh
homes, hardlink identity, release-age enforcement, and importer checks.

Isolated proof: cleanup false-completion regressions failed before repair;
475 routing tests passed; shared-owner sweep had 970 passes and exposed the
pnpm fixture defect; its repair and census boundaries passed 13 focused
tests, followed by changed types/lint/format and full discovery/export gates.
Fresh Codex autoreview is scoped-clean at P0. Native Windows rerun pending.

Related: openclaw/openclaw#136317
Hosted lifecycle repair: openclaw/openclaw#137456

* fix(ci): retain census diagnostics through process closure

Do not SIGKILL the persistent Windows census sampler after its first
stderr chunk: that discards Python's actual error and native exit code.
Retain the bounded traceback until the existing child/stdio close join,
while rejecting readiness and query replies after observed stderr.

Deterministic startup/query regressions synchronize the diagnostic tail
after the owner has observed its prefix; a mixed-output case proves a
real valid reply remains rejected. All three fail before the owner fix.
Query, startup, cleanup and outer watchdog budgets are unchanged.

Context: #136317; hosted lifecycle landing #137456.

* fix(ci): route Windows probe workflow edits to native checks

Include windows-testbox-probe.yml in the existing Windows workflow scope.
An edit to this workflow alone previously selected generic Node coverage
without Windows validation. Extend the existing exact-scope table; its
new case fails before the matcher repair. Other platform scopes stay off.

Addresses the CI-selection finding on #137456. No product or native
workflow behavior changes.

* test(ci): derive CLI candidate fixture expiry from creation time

The subprocess discovery tests use the real clock, but their synthetic
artifacts expired on a fixed date. Once the remaining lifetime fell below
14 hours, selection correctly returned a miss before either intended
unavailable branch was exercised.

Give CLI fixtures one fresh creation time and a coherent seven-day expiry
across evidence metadata and all manifest constituents before ZIP/digest
construction. Keep fixed NOW for pure expiry tests and retain all trust,
ordering, bounded-evaluation, and missing-constituent assertions.

Both original failures reproduced on unchanged code after the deadline.
No production policy, timeout, release workflow, or clock override changes.

CI follow-up for #137456.
vincentkoc added a commit that referenced this pull request Sep 4, 2026
* origin/main:
  fix(git-hooks): keep unstaged bytes out of pre-commit formatting (#137723)
  test(gateway): drain session tool fixture cleanup (#137743)
  fix: avoid duplicate errors when a desktop disconnects (#137724)
  refactor: streamline temporary mention retention (#137714)
  fix(gateway): prevent hosted lifecycle crashes and self-waits (#137456)
  test(daemon): make managerless port fixture hermetic (#137692)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
…aw#137456)

* fix(gateway): prevent hosted lifecycle crashes and self-waits

Route Gateway-hosted SystemAgent lifecycle operations through the exact
run-loop owner instead of the exiting daemon CLI. Accept and audit stop
before draining its requesting work, then execute native termination only
after kernel teardown. Join preparation, executor close, and late native
inspection before retiring ownership.

Preserve standalone CLI behavior, shutdown budgets, native service policy,
and current delegated-approval completion. Validate Linux service scopes,
macOS bootout, caller/kernel fencing, and real CLI/WebSocket rescue replies.
Native Windows exact-head proof is included for CI verification before merge.

Fixes openclaw#137386 (hosted Gateway lifecycle crashes and self-wait).
openclaw#137386

* ci(windows): qualify hosted runner independently of image label

* docs(linux): align manual Gateway stop budget

* test(ci): retain checkout actor startup diagnostics

Preserve sentinel and descendant startup failures in the existing fixture report, including native census signal/cause details. Keep the original deadlines, concurrency, process identity checks, and cleanup joins unchanged. Add fail-first startup diagnostic coverage.

Refs openclaw#136317; this adds evidence and does not claim to fix the intermittent Windows census startup failure.

* fix(ci): join census helpers and close native proof fixtures

Own one Windows process-census sampler per checkout supervisor rather than
charging every actor's one-second query deadline for interpreter startup.
Preserve exact process birth identity, concurrent cases, and lease fences.
Reserve helper retirement within the existing cleanup-success budget and
always join actual process, stdio, and broker closure before supervisor exit.

Close only the native hosted-stop fixture's cached state database before
removing its directory, and publish its pass proof after cleanup succeeds.
Keep native fixtures discoverable through canonical test-support names and
real module-relative import URLs. Update workflow and cache-plan assertions
without weakening their isolation or membership contracts.

Seed the existing pinned pnpm environment in both offline-test projects
before bootstrap, avoiding an unnecessary registry lookup. Preserve fresh
homes, hardlink identity, release-age enforcement, and importer checks.

Isolated proof: cleanup false-completion regressions failed before repair;
475 routing tests passed; shared-owner sweep had 970 passes and exposed the
pnpm fixture defect; its repair and census boundaries passed 13 focused
tests, followed by changed types/lint/format and full discovery/export gates.
Fresh Codex autoreview is scoped-clean at P0. Native Windows rerun pending.

Related: openclaw#136317
Hosted lifecycle repair: openclaw#137456

* fix(ci): retain census diagnostics through process closure

Do not SIGKILL the persistent Windows census sampler after its first
stderr chunk: that discards Python's actual error and native exit code.
Retain the bounded traceback until the existing child/stdio close join,
while rejecting readiness and query replies after observed stderr.

Deterministic startup/query regressions synchronize the diagnostic tail
after the owner has observed its prefix; a mixed-output case proves a
real valid reply remains rejected. All three fail before the owner fix.
Query, startup, cleanup and outer watchdog budgets are unchanged.

Context: openclaw#136317; hosted lifecycle landing openclaw#137456.

* fix(ci): route Windows probe workflow edits to native checks

Include windows-testbox-probe.yml in the existing Windows workflow scope.
An edit to this workflow alone previously selected generic Node coverage
without Windows validation. Extend the existing exact-scope table; its
new case fails before the matcher repair. Other platform scopes stay off.

Addresses the CI-selection finding on openclaw#137456. No product or native
workflow behavior changes.

* test(ci): derive CLI candidate fixture expiry from creation time

The subprocess discovery tests use the real clock, but their synthetic
artifacts expired on a fixed date. Once the remaining lifetime fell below
14 hours, selection correctly returned a miss before either intended
unavailable branch was exercised.

Give CLI fixtures one fresh creation time and a coherent seven-day expiry
across evidence metadata and all manifest constituents before ZIP/digest
construction. Keep fixed NOW for pure expiry tests and retain all trust,
ordering, bounded-evaluation, and missing-constituent assertions.

Both original failures reproduced on unchanged code after the deadline.
No production policy, timeout, release workflow, or clock override changes.

CI follow-up for openclaw#137456.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: linux cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. plugin: linux-node 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: XL 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]: Hosted Gateway start/stop errors can exit the Gateway or self-wait during shutdown

1 participant