Skip to content

fix(gateway): audit managed service starts - #110497

Merged
steipete merged 3 commits into
mainfrom
fix/gateway-start-audit
Jul 18, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/gateway-start-audit

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #110323. Live verification showed a plain successful gateway start (bootstrap of an installed-but-not-running service) wrote no line to gateway-restart.log — only stop/restart and the darwin recovery branch audited. Managed starts are now first-class: GatewayService gains a real start() (launchd enable+kickstart/bootstrap, systemctl start, schtasks /Run + login-item), so start no longer routes through restart(), and each successful mutation is audited immediately, before fallible validation — same ordering as the stop/restart hardening. The already-running no-op stays silent.

Proof

  • Focused suites green (service, launchd, systemd, schtasks, lifecycle-core): 275 tests.
  • Targeted oxlint clean, max-lines ratchet OK, git diff --check clean.
  • Structured review (Codex gpt-5.6-sol): clean, no actionable findings.

Release-note context: managed gateway starts recorded in the lifecycle audit log across platforms.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes size: M maintainer Maintainer-authored PR labels Jul 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ea6c94866

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/daemon/systemd.ts
Comment on lines +1390 to +1394
await runSystemdServiceAction({
stdout,
env,
action: "start",
label: "Started systemd service",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset failed systemd units before starting

When an installed systemd unit is enabled but stopped after hitting systemd's failed/start-limit state, openclaw gateway start now reaches this new start path and runs only systemctl start. Before this commit the same CLI start path called restartSystemdService, whose adjacent branch runs reset-failed first specifically so crash-looped units recover (src/daemon/systemd.ts:1372-1375); I also checked systemctl --help, which says reset-failed [PATTERN...] resets failed unit state. Without that reset here, a latched failed managed gateway remains unrecoverable via gateway start and reports systemctl start failed instead of clearing the latch.

Useful? React with 👍 / 👎.

Comment thread src/daemon/schtasks.ts
Comment on lines +1959 to +1963
await runScheduledTaskOrThrow({
taskName,
env: effectiveEnv,
scriptPath: resolveTaskScriptPath(effectiveEnv),
onMutation: () => reportMutation("schtasks-start"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove stale Startup launchers after Windows start

When a Windows install has both a registered Scheduled Task and a leftover Startup-folder fallback but no currently running gateway, this new start path runs /Run and immediately returns with the runScheduledTaskOrThrow result discarded. The old gateway start route went through restartRegisteredScheduledTask, which waits for running evidence and removes Startup entries once the Scheduled Task is proven (src/daemon/schtasks.ts:2023-2046); keeping the fallback here leaves the old login item in place, so the next login can launch a duplicate gateway or hit a port conflict.

Useful? React with 👍 / 👎.

@steipete steipete self-assigned this Jul 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de775f6923

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/daemon/launchd.ts
reportMutation("enable");
}

const start = await execLaunchctl(["kickstart", serviceTarget]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reuse port cleanup before LaunchAgent start

When a macOS LaunchAgent is installed but stopped while the gateway port is still held by a stale or unverified process, this new start path goes straight to kickstart without the pre-launch cleanup and busy-port gate that restartLaunchAgent still applies before starting (src/daemon/launchd.ts:1346-1358, with coverage at src/daemon/launchd.test.ts:2302-2347). Before this commit, gateway start routed through that restart path, so the command failed before spawning; now launchd can accept the start, the gateway can immediately exit on the occupied port, and the CLI still reports started after reading only the loaded service state.

Useful? React with 👍 / 👎.

Comment thread src/daemon/schtasks.ts
stdout: NodeJS.WritableStream,
onMutation?: () => void,
): Promise<GatewayServiceRestartResult> {
await launchFallbackTaskScript(env);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Verify Startup fallback before launching it

When Windows has only the Startup-folder fallback installed and the configured gateway port is unknown or busy with a non-owned process, this new start path launches the fallback unconditionally. The previous gateway start route used restartStartupEntry, which first calls resolveControllableFallbackRuntime and the existing tests prove it refuses an unverified busy port (src/daemon/schtasks.startup-fallback.test.ts:1962-1979); skipping that check here can spawn a doomed duplicate and report Started Windows login item even though the fallback cannot own the port.

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing proof for de775f6923f5b446c3be39a92a837056d40b39b5:

  • PNPM_CONFIG_MODULES_DIR=/Users/steipete/Projects/clawdbot/node_modules node scripts/run-vitest.mjs src/cli/daemon-cli.coverage.test.ts — 7 passed.
  • PNPM_CONFIG_MODULES_DIR=/Users/steipete/Projects/clawdbot/node_modules node scripts/run-vitest.mjs src/cli/daemon-cli/lifecycle-core.config-guard.test.ts — 11 passed.
  • Autoreview — clean, no accepted/actionable findings.
  • CI run 29635323985 — success on the exact head. checks-node-compact-small-7, checks-node-compact-small-8, and openclaw/ci-gate all passed; no reruns used.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 110497 — passed at 2026-07-18T07:22:04Z with gate mode hosted_exact_or_recent_parent; remote PR tree matched the local prep head. Hosted exact-head CI satisfied the gate, so no separate Testbox lease/run URL was emitted.

No proof gaps remain.

@steipete
steipete merged commit 6416bae into main Jul 18, 2026
116 checks passed
@steipete
steipete deleted the fix/gateway-start-audit branch July 18, 2026 07:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
* fix(gateway): audit managed service starts

* chore: drop changelog edit (release-only per repo policy)

* test(gateway): align start routing mocks
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
* fix(gateway): audit managed service starts

* chore: drop changelog edit (release-only per repo policy)

* test(gateway): align start routing mocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant