Skip to content

Commit 6b02b00

Browse files
authored
fix(gateway): scope crash loop channel recovery hints (#129697)
1 parent 422d681 commit 6b02b00

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎src/infra/gateway-boot-lifecycle.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from "node:fs";
33
import os from "node:os";
44
import path from "node:path";
55
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
6-
import { afterEach, describe, expect, it } from "vitest";
6+
import { afterEach, describe, expect, it, vi } from "vitest";
77
import {
88
formatLegacyAgentMediaMigrationRequiredMessage,
99
GATEWAY_AGENT_MEDIA_MIGRATION_REQUIRED_REASON,
@@ -35,6 +35,7 @@ const GATEWAY_BOOT_LIFECYCLE_RETENTION_MS = 24 * 60 * 60_000;
3535

3636
afterEach(() => {
3737
closeOpenClawStateDatabaseForTest();
38+
vi.unstubAllEnvs();
3839
});
3940

4041
function createLifecycleDb() {
@@ -386,4 +387,25 @@ describe("formatGatewayCrashLoopManualChannelStartHint", () => {
386387
formatGatewayCrashLoopManualChannelStartHint({ channelId: "telegram", accountId: "work" }),
387388
).toContain(`--params '{"channel":"telegram","accountId":"work"}'`);
388389
});
390+
391+
it.each([
392+
{ name: "default", profile: "", container: "", command: "openclaw" },
393+
{ name: "named profile", profile: "work", container: "", command: "openclaw --profile work" },
394+
{ name: "container", profile: "", container: "demo", command: "openclaw --container demo" },
395+
{
396+
name: "container and profile",
397+
profile: "work",
398+
container: "demo",
399+
command: "openclaw --container demo",
400+
},
401+
])("targets the active gateway for $name", ({ profile, container, command }) => {
402+
vi.stubEnv("OPENCLAW_PROFILE", profile);
403+
vi.stubEnv("OPENCLAW_CONTAINER_HINT", container);
404+
405+
expect(
406+
formatGatewayCrashLoopManualChannelStartHint({ channelId: "telegram", accountId: "work" }),
407+
).toBe(
408+
`Start a channel manually with: ${command} gateway call channels.start --params '{"channel":"telegram","accountId":"work"}'`,
409+
);
410+
});
389411
});

‎src/infra/gateway-boot-lifecycle.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Persists gateway boot outcomes for supervisor crash-loop decisions.
22
import { randomUUID } from "node:crypto";
33
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
4+
import { formatCliCommand } from "../cli/command-format.js";
45
import { createSubsystemLogger } from "../logging/subsystem.js";
56
import { OPENCLAW_AGENT_SCHEMA_VERSION } from "../state/openclaw-agent-db-contract.js";
67
import {
@@ -38,13 +39,12 @@ export function formatGatewayCrashLoopManualChannelStartHint(target?: {
3839
channelId: string;
3940
accountId?: string;
4041
}): string {
41-
const params = target
42-
? JSON.stringify({
43-
channel: target.channelId,
44-
...(target.accountId ? { accountId: target.accountId } : {}),
45-
})
46-
: `{"channel":"<id>"}`;
47-
return `Start a channel manually with: openclaw gateway call channels.start --params '${params}'`;
42+
const params = JSON.stringify({
43+
channel: target?.channelId ?? "<id>",
44+
...(target?.accountId ? { accountId: target.accountId } : {}),
45+
});
46+
const command = formatCliCommand("openclaw gateway call channels.start");
47+
return `Start a channel manually with: ${command} --params '${params}'`;
4848
}
4949

5050
const gatewayLifecycleLog = createSubsystemLogger("gateway/lifecycle");

0 commit comments

Comments
 (0)