Skip to content

Commit bd5bf48

Browse files
anyechvincentkoc
andauthored
fix(cli): retry logs.tail after journal fallback in logs follow (#88159)
* fix(cli): retry logs.tail after journal fallback in logs follow Rebase #88159 onto current main and keep systemd journal fallback temporary in follow mode. Preserve the journal cursor across repeated fallback outages, but retry logs.tail on the next loop so recovered Gateway RPC returns to normal log output. This refresh also replaces the stale red checks-node-core-fast result from the old head with a current-head CI run. * Keep log source metadata explicit * ci: retrigger checks for PR #88159 * docs: clarify logs follow JSON source transitions * fix(cli): keep journal logs responsive during recovery --------- Co-authored-by: Vincent Koc <[email protected]>
1 parent b6ad306 commit bd5bf48

6 files changed

Lines changed: 613 additions & 66 deletions

File tree

‎docs/cli/logs.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ openclaw logs --url ws://127.0.0.1:18789 --token "$OPENCLAW_GATEWAY_TOKEN"
6161
- If the implicit local loopback Gateway asks for pairing, closes during connect, or times out before `logs.tail` answers, `openclaw logs` falls back to the configured Gateway file log automatically. Explicit `--url` targets do not use this fallback.
6262
- `openclaw logs --follow` does not follow configured-file fallbacks after implicit local Gateway RPC failures. On Linux, it uses the active user-systemd Gateway journal by PID when available and prints the selected log source; otherwise it keeps retrying the live Gateway instead of tailing a potentially stale side-by-side file.
6363
- When using `--follow`, transient gateway disconnects (WebSocket close, timeout, connection drop) trigger automatic reconnection with exponential backoff (up to 8 retries, capped at 30 s between attempts). A warning is printed to stderr on each retry, and a `[logs] gateway reconnected` notice is printed once a poll succeeds. In `--json` mode both the retry warning and the reconnect transition are emitted as `{"type":"notice"}` records on stderr. Non-recoverable errors (auth failure, bad configuration) still exit immediately.
64+
- In `--follow --json` mode, log source transitions are emitted as `{"type":"meta"}` records. Consumers should track cursors per `sourceKind`: a stream can move from Gateway file output (`sourceKind: "file"`) to local journal fallback (`sourceKind: "journal"`, `localFallback: true`, with `service.pid`/`service.unit`) and back to Gateway file output after recovery. Do not assume one stable source or cursor for the whole follow session, and tolerate overlapping lines when recovery replays the Gateway file cursor.
6465

6566
## Related
6667

‎src/cli/gateway-rpc.runtime.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,19 @@ describe("callGatewayFromCliRuntime", () => {
7373
}),
7474
);
7575
});
76+
77+
it("forwards caller cancellation to the gateway call", async () => {
78+
const controller = new AbortController();
79+
80+
await callGatewayFromCliRuntime("logs.tail", {}, undefined, {
81+
signal: controller.signal,
82+
});
83+
84+
expect(callGatewayMock).toHaveBeenCalledWith(
85+
expect.objectContaining({
86+
method: "logs.tail",
87+
signal: controller.signal,
88+
}),
89+
);
90+
});
7691
});

‎src/cli/gateway-rpc.runtime.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type CallGatewayFromCliRuntimeExtra = {
1212
clientName?: Parameters<typeof callGateway>[0]["clientName"];
1313
mode?: Parameters<typeof callGateway>[0]["mode"];
1414
deviceIdentity?: Parameters<typeof callGateway>[0]["deviceIdentity"];
15+
signal?: Parameters<typeof callGateway>[0]["signal"];
1516
expectFinal?: boolean;
1617
progress?: boolean;
1718
scopes?: Parameters<typeof callGateway>[0]["scopes"];
@@ -45,6 +46,7 @@ export async function callGatewayFromCliRuntime(
4546
deviceIdentity: extra?.deviceIdentity,
4647
expectFinal: extra?.expectFinal ?? Boolean(opts.expectFinal),
4748
scopes: extra?.scopes,
49+
signal: extra?.signal,
4850
timeoutMs,
4951
clientName: extra?.clientName ?? GATEWAY_CLIENT_NAMES.CLI,
5052
mode: extra?.mode ?? GATEWAY_CLIENT_MODES.CLI,

‎src/cli/gateway-rpc.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function callGatewayFromCli(
3737
clientName?: GatewayClientName;
3838
mode?: GatewayClientMode;
3939
deviceIdentity?: DeviceIdentity | null;
40+
signal?: AbortSignal;
4041
expectFinal?: boolean;
4142
progress?: boolean;
4243
scopes?: OperatorScope[];

0 commit comments

Comments
 (0)