Skip to content

Commit a8ab778

Browse files
committed
test(gateway): lock recovery marking failure order
1 parent 420ac47 commit a8ab778

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎src/gateway/server-startup-post-attach.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,43 @@ describe("startGatewayPostAttachRuntime", () => {
18761876
expect(hoisted.scheduleRestartAbortedMainSessionRecovery).not.toHaveBeenCalled();
18771877
});
18781878

1879+
it("marks startup main-session orphans before propagating model runtime failure", async () => {
1880+
const modelRuntimeError = new Error("model runtime unavailable");
1881+
const startChannels = vi.fn(async () => {});
1882+
const prewarmPrimaryModel = vi.fn(async () => {
1883+
throw modelRuntimeError;
1884+
});
1885+
hoisted.markStartupOrphanedMainSessionsForRecovery.mockResolvedValueOnce({
1886+
marked: 1,
1887+
skipped: 0,
1888+
});
1889+
1890+
await expect(
1891+
startGatewaySidecars({
1892+
cfg: { hooks: { internal: { enabled: false } } } as never,
1893+
pluginRegistry: createPostAttachParams().pluginRegistry,
1894+
defaultWorkspaceDir: "/tmp/openclaw-workspace",
1895+
deps: {} as never,
1896+
startChannels,
1897+
prewarmPrimaryModel,
1898+
log: { warn: vi.fn() },
1899+
logHooks: {
1900+
info: vi.fn(),
1901+
warn: vi.fn(),
1902+
error: vi.fn(),
1903+
},
1904+
logChannels: {
1905+
info: vi.fn(),
1906+
error: vi.fn(),
1907+
},
1908+
}),
1909+
).rejects.toBe(modelRuntimeError);
1910+
1911+
expect(hoisted.markStartupOrphanedMainSessionsForRecovery).toHaveBeenCalledTimes(1);
1912+
expect(prewarmPrimaryModel).toHaveBeenCalledTimes(1);
1913+
expect(startChannels).not.toHaveBeenCalled();
1914+
});
1915+
18791916
it("logs startup main-session marker failures and still starts channels", async () => {
18801917
const log = { warn: vi.fn() };
18811918
const startChannels = vi.fn(async () => {});

‎src/gateway/server-startup-post-attach.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ export async function startGatewaySidecars(params: {
662662
const skipChannels =
663663
isTruthyEnvValue(process.env.OPENCLAW_SKIP_CHANNELS) ||
664664
isTruthyEnvValue(process.env.OPENCLAW_SKIP_PROVIDERS);
665+
// These runs were orphaned by the previous Gateway lifecycle. Record that fact
666+
// even if this process later fails model preparation and never starts channels.
665667
await measureStartup(params.startupTrace, "sidecars.main-session-recovery", async () => {
666668
try {
667669
const { markStartupOrphanedMainSessionsForRecovery } = await measureStartup(

0 commit comments

Comments
 (0)