Skip to content

Commit a54caf0

Browse files
authored
fix(setup): preserve configured channel when status refresh fails (#124383)
* fix(setup): preserve channel config on status failure * fix(setup): limit status recovery to configure results
1 parent 62deb87 commit a54caf0

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

‎src/flows/channel-setup.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,61 @@ describe("setupChannels workspace shadow exclusion", () => {
971971
});
972972
});
973973

974+
it("keeps completed setup when the follow-up status refresh fails", async () => {
975+
const getStatus = vi
976+
.fn()
977+
.mockResolvedValueOnce({
978+
channel: "external-chat",
979+
configured: false,
980+
statusLines: [],
981+
})
982+
.mockRejectedValueOnce(new Error("controlled status failure"));
983+
const externalChatPlugin = makeSetupPlugin({
984+
id: "external-chat",
985+
label: "External Chat",
986+
setupWizard: {
987+
channel: "external-chat",
988+
getStatus,
989+
configure: vi.fn(async ({ cfg }) => ({
990+
cfg: {
991+
...cfg,
992+
channels: { ...cfg.channels, "external-chat": { token: "configured" } },
993+
},
994+
accountId: "external-account",
995+
})),
996+
} as ChannelSetupPlugin["setupWizard"],
997+
});
998+
resolveChannelSetupEntries.mockReturnValue(externalChatSetupEntries());
999+
listActiveChannelSetupPlugins.mockReturnValue([externalChatPlugin]);
1000+
const note = vi.fn(async () => undefined);
1001+
1002+
const result = await setupChannels(
1003+
{} as OpenClawConfig,
1004+
{} as never,
1005+
{
1006+
confirm: vi.fn(async () => true),
1007+
note,
1008+
select: vi.fn(async () => "__done__"),
1009+
} as never,
1010+
{
1011+
initialSelection: ["external-chat"],
1012+
finishAfterInitialSelection: true,
1013+
deferStatusUntilSelection: true,
1014+
skipDmPolicyPrompt: true,
1015+
},
1016+
);
1017+
1018+
expect(result).toMatchObject({
1019+
channels: { "external-chat": { token: "configured" } },
1020+
});
1021+
expect(getStatus).toHaveBeenCalledTimes(2);
1022+
expect(note).toHaveBeenCalledWith(
1023+
"Status unavailable (controlled status failure).\n" +
1024+
"Retry: openclaw channels status --channel external-chat",
1025+
"Channel status",
1026+
);
1027+
});
1028+
9741029
it("returns targeted channel setup Back navigation to the channel picker", async () => {
9751030
const promptOrder: string[] = [];
9761031
const configureInteractive = vi.fn(async ({ prompter }) => {

‎src/flows/channel-setup.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Channel setup flow configures channels, auth, and workspace bindings.
2+
import { sanitizeTerminalText } from "../../packages/terminal-core/src/safe-text.js";
23
import { getBundledChannelSetupPlugin } from "../channels/plugins/bundled.js";
34
import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
45
import { listActiveChannelSetupPlugins } from "../channels/plugins/setup-registry.js";
@@ -458,7 +459,21 @@ export async function setupChannels(
458459
if (channel === targetedChannel) {
459460
finishSetupRequested = true;
460461
}
461-
await refreshStatus(channel);
462+
try {
463+
await refreshStatus(channel);
464+
} catch (error) {
465+
const detail = sanitizeTerminalText(formatErrorMessage(error));
466+
statusByChannel.set(channel, {
467+
channel,
468+
configured: isChannelConfigured(next, channel),
469+
statusLines: [],
470+
selectionHint: "status unavailable",
471+
});
472+
await prompter.note(
473+
`Status unavailable (${detail}).\nRetry: ${formatCliCommand(`openclaw channels status --channel ${channel}`)}`,
474+
t("wizard.channels.statusTitle"),
475+
);
476+
}
462477
};
463478

464479
const applyCustomSetupResult = async (

0 commit comments

Comments
 (0)