Repository navigation
fix(gateway): audit managed service starts - #110497
Conversation
There was a problem hiding this comment.
💡 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".
| await runSystemdServiceAction({ | ||
| stdout, | ||
| env, | ||
| action: "start", | ||
| label: "Started systemd service", |
There was a problem hiding this comment.
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 👍 / 👎.
| await runScheduledTaskOrThrow({ | ||
| taskName, | ||
| env: effectiveEnv, | ||
| scriptPath: resolveTaskScriptPath(effectiveEnv), | ||
| onMutation: () => reportMutation("schtasks-start"), |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| reportMutation("enable"); | ||
| } | ||
|
|
||
| const start = await execLaunchctl(["kickstart", serviceTarget]); |
There was a problem hiding this comment.
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 👍 / 👎.
| stdout: NodeJS.WritableStream, | ||
| onMutation?: () => void, | ||
| ): Promise<GatewayServiceRestartResult> { | ||
| await launchFallbackTaskScript(env); |
There was a problem hiding this comment.
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 👍 / 👎.
|
Landing proof for
No proof gaps remain. |
|
Merged via squash.
|
* fix(gateway): audit managed service starts * chore: drop changelog edit (release-only per repo policy) * test(gateway): align start routing mocks
* fix(gateway): audit managed service starts * chore: drop changelog edit (release-only per repo policy) * test(gateway): align start routing mocks
Summary
Follow-up to #110323. Live verification showed a plain successful
gateway start(bootstrap of an installed-but-not-running service) wrote no line togateway-restart.log— only stop/restart and the darwin recovery branch audited. Managed starts are now first-class:GatewayServicegains a realstart()(launchd enable+kickstart/bootstrap,systemctl start, schtasks/Run+ login-item), so start no longer routes throughrestart(), 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
git diff --checkclean.Release-note context: managed gateway starts recorded in the lifecycle audit log across platforms.