fix(daemon): warn on token drift during restart (#18018)

When the gateway token in config differs from the token embedded in the
service plist/unit file, restart will not apply the new token. This can
cause silent auth failures after OAuth token switches.

Changes:
- Add checkTokenDrift() to service-audit.ts
- Call it in runServiceRestart() before restarting
- Warn user with suggestion to run 'openclaw gateway install --force'

Closes #18018
This commit is contained in:
Operative-001
2026-02-16 14:03:28 +01:00
committed by Peter Steinberger
parent 8af4712c40
commit d6e85aa6ba
3 changed files with 90 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ export const SERVICE_AUDIT_CODES = {
gatewayRuntimeBun: "gateway-runtime-bun",
gatewayRuntimeNodeVersionManager: "gateway-runtime-node-version-manager",
gatewayRuntimeNodeSystemMissing: "gateway-runtime-node-system-missing",
gatewayTokenDrift: "gateway-token-drift",
launchdKeepAlive: "launchd-keep-alive",
launchdRunAtLoad: "launchd-run-at-load",
systemdAfterNetworkOnline: "systemd-after-network-online",
@@ -360,6 +361,35 @@ async function auditGatewayRuntime(
}
}
/**
* Check if the service's embedded token differs from the config file token.
* Returns an issue if drift is detected (service will use old token after restart).
*/
export function checkTokenDrift(params: {
serviceToken: string | undefined;
configToken: string | undefined;
}): ServiceConfigIssue | null {
const { serviceToken, configToken } = params;
// No drift if both are undefined/empty
if (!serviceToken && !configToken) {
return null;
}
// Drift: config has token, service has different or no token
if (configToken && serviceToken !== configToken) {
return {
code: SERVICE_AUDIT_CODES.gatewayTokenDrift,
message:
"Config token differs from service token. The daemon will use the old token after restart.",
detail: "Run `openclaw gateway install --force` to sync the token.",
level: "recommended",
};
}
return null;
}
export async function auditGatewayServiceConfig(params: {
env: Record<string, string | undefined>;
command: GatewayServiceCommand;