Skip to content

Commit 8deb1ef

Browse files
clawsweeper[bot]TurboTheTurtleTakhoffman
authored
Isolate boot-md startup sessions (#85919)
Summary: - The branch updates gateway boot startup handling to use an `agent:<id>:boot` session, suppress prompt persis ... that boot mapping after the run, and adds focused gateway boot regression coverage plus a changelog entry. - Reproducibility: yes. there is a high-confidence source reproduction path: current main passes the generated ... idence of repeated persisted boot prompts. I did not execute the gateway scenario in this read-only review. Automerge notes: - PR branch already contained follow-up commit before automerge: Fix boot-md test lint - PR branch already contained follow-up commit before automerge: Isolate boot-md startup sessions Validation: - ClawSweeper review passed for head 5d5338c. - Required merge gates passed before the squash merge. Prepared head SHA: 5d5338c Review: #85919 (comment) Co-authored-by: Andy Ye <[email protected]> Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com> Co-authored-by: clawsweeper[bot] <274271284+clawsweeper[bot]@users.noreply.github.com> Approved-by: takhoffman Co-authored-by: takhoffman <[email protected]>
1 parent d075111 commit 8deb1ef

4 files changed

Lines changed: 61 additions & 25 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Docs: https://docs.openclaw.ai
6666
### Fixes
6767

6868
- Gateway/restart: honor the configured restart drain budget for embedded runs and avoid spending the deferral timeout twice after forced restart timeouts. (#85708) Thanks @Kaspre.
69+
- Gateway/boot: run `BOOT.md` startup checks in an isolated boot session so gateway restarts do not overwrite the agent's main session mapping. (#85479)
6970
- Meeting Notes: include a speaker-labeled transcript section in generated summaries so Discord group voice captures show who said each captured utterance.
7071
- Discord/voice: recover stale realtime playback state when Discord stream-close/player-idle events do not arrive, and keep generated runtime plugin aliases available after postbuild rewrites.
7172
- Discord/voice: keep realtime playback running when meeting notes attaches to an existing voice session or a realtime consult starts, and route realtime user transcripts into meeting notes.

‎src/gateway/boot.test.ts‎

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ describe("runBootOnce", () => {
3232
const sessionKey = resolveMainSessionKey(cfg);
3333
const agentId = resolveAgentIdFromSessionKey(sessionKey);
3434
const storePath = resolveStorePath(cfg.session?.store, { agentId });
35-
return { sessionKey, storePath };
35+
const bootSessionKey = `agent:${agentId}:boot`;
36+
return { sessionKey, bootSessionKey, storePath };
3637
};
3738

3839
beforeEach(async () => {
@@ -68,8 +69,12 @@ describe("runBootOnce", () => {
6869
}
6970
};
7071

71-
const mockAgentUpdatesMainSession = (storePath: string, sessionKey: string) => {
72-
agentCommand.mockImplementation(async (opts: { sessionId?: string }) => {
72+
const mockAgentUpdatesRequestedSession = (storePath: string) => {
73+
agentCommand.mockImplementation(async (opts: { sessionId?: string; sessionKey?: string }) => {
74+
const sessionKey = opts.sessionKey ?? "";
75+
if (!sessionKey) {
76+
throw new Error("expected sessionKey");
77+
}
7378
const current = loadSessionStore(storePath, { skipCache: true });
7479
current[sessionKey] = {
7580
sessionId: String(opts.sessionId),
@@ -87,7 +92,7 @@ describe("runBootOnce", () => {
8792
return call as Record<string, unknown>;
8893
};
8994

90-
const expectMainSessionRestored = (params: {
95+
const expectSessionMapping = (params: {
9196
storePath: string;
9297
sessionKey: string;
9398
expectedSessionId?: string;
@@ -145,7 +150,8 @@ describe("runBootOnce", () => {
145150
expect(agentCommand).toHaveBeenCalledTimes(1);
146151
const call = requireAgentCall();
147152
expect(call.deliver).toBe(false);
148-
expect(call.sessionKey).toBe(resolveMainSessionKey({}));
153+
expect(call.sessionKey).toBe("agent:main:boot");
154+
expect(call.suppressPromptPersistence).toBe(true);
149155
expect(call.message).toContain("BOOT.md:");
150156
expect(call.message).toContain(content);
151157
expect(call.message).toContain("NO_REPLY");
@@ -173,7 +179,26 @@ describe("runBootOnce", () => {
173179
});
174180

175181
expect(agentCommand).toHaveBeenCalledTimes(1);
176-
expect(requireAgentCall().sessionKey).toBe(resolveAgentMainSessionKey({ cfg, agentId }));
182+
const mainSessionKey = resolveAgentMainSessionKey({ cfg, agentId });
183+
expect(requireAgentCall().sessionKey).toBe(
184+
`agent:${resolveAgentIdFromSessionKey(mainSessionKey)}:boot`,
185+
);
186+
});
187+
});
188+
189+
it("keeps boot session isolation when the main session key is configured", async () => {
190+
await withBootWorkspace({ bootContent: "Check status." }, async (workspaceDir) => {
191+
agentCommand.mockResolvedValue(undefined);
192+
const cfg = { session: { mainKey: "primary" } };
193+
const agentId = "ops";
194+
await expect(runBootOnce({ cfg, deps: makeDeps(), workspaceDir, agentId })).resolves.toEqual({
195+
status: "ran",
196+
});
197+
198+
expect(agentCommand).toHaveBeenCalledTimes(1);
199+
const mainSessionKey = resolveAgentMainSessionKey({ cfg, agentId });
200+
expect(mainSessionKey).toBe("agent:ops:primary");
201+
expect(requireAgentCall().sessionKey).toBe("agent:ops:boot");
177202
});
178203
});
179204

@@ -200,7 +225,7 @@ describe("runBootOnce", () => {
200225
const content = "Say hello when you wake up.";
201226
await withBootWorkspace({ bootContent: content }, async (workspaceDir) => {
202227
const cfg = {};
203-
const { sessionKey, storePath } = resolveMainStore(cfg);
228+
const { bootSessionKey, sessionKey, storePath } = resolveMainStore(cfg);
204229
const existingSessionId = "main-session-abc123";
205230

206231
await saveSessionStore(storePath, {
@@ -222,15 +247,16 @@ describe("runBootOnce", () => {
222247
expect(call.sessionId).toMatch(
223248
/^boot-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-\d{3}-[0-9a-f]{8}$/,
224249
);
225-
expect(call.sessionKey).toBe(sessionKey);
250+
expect(call.sessionKey).toBe(bootSessionKey);
251+
expectSessionMapping({ storePath, sessionKey, expectedSessionId: existingSessionId });
226252
});
227253
});
228254

229-
it("restores the original main session mapping after the boot run", async () => {
255+
it("does not mutate the original main session mapping after the boot run", async () => {
230256
const content = "Check if the system is healthy.";
231257
await withBootWorkspace({ bootContent: content }, async (workspaceDir) => {
232258
const cfg = {};
233-
const { sessionKey, storePath } = resolveMainStore(cfg);
259+
const { bootSessionKey, sessionKey, storePath } = resolveMainStore(cfg);
234260
const existingSessionId = "main-session-xyz789";
235261

236262
await saveSessionStore(storePath, {
@@ -240,27 +266,29 @@ describe("runBootOnce", () => {
240266
},
241267
});
242268

243-
mockAgentUpdatesMainSession(storePath, sessionKey);
269+
mockAgentUpdatesRequestedSession(storePath);
244270
await expect(runBootOnce({ cfg, deps: makeDeps(), workspaceDir })).resolves.toEqual({
245271
status: "ran",
246272
});
247273

248-
expectMainSessionRestored({ storePath, sessionKey, expectedSessionId: existingSessionId });
274+
expectSessionMapping({ storePath, sessionKey, expectedSessionId: existingSessionId });
275+
expectSessionMapping({ storePath, sessionKey: bootSessionKey });
249276
});
250277
});
251278

252-
it("removes a boot-created main-session mapping when none existed before", async () => {
279+
it("removes a boot-created boot-session mapping when none existed before", async () => {
253280
await withBootWorkspace({ bootContent: "health check" }, async (workspaceDir) => {
254281
const cfg = {};
255-
const { sessionKey, storePath } = resolveMainStore(cfg);
282+
const { bootSessionKey, sessionKey, storePath } = resolveMainStore(cfg);
256283

257-
mockAgentUpdatesMainSession(storePath, sessionKey);
284+
mockAgentUpdatesRequestedSession(storePath);
258285

259286
await expect(runBootOnce({ cfg, deps: makeDeps(), workspaceDir })).resolves.toEqual({
260287
status: "ran",
261288
});
262289

263-
expectMainSessionRestored({ storePath, sessionKey });
290+
expectSessionMapping({ storePath, sessionKey });
291+
expectSessionMapping({ storePath, sessionKey: bootSessionKey });
264292
});
265293
});
266294
});

‎src/gateway/boot.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ function buildBootPrompt(content: string) {
5454
].join("\n");
5555
}
5656

57+
function resolveBootSessionKey(sessionKey: string): string {
58+
const agentId = resolveAgentIdFromSessionKey(sessionKey);
59+
return `agent:${agentId}:boot`;
60+
}
61+
5762
async function loadBootFile(
5863
workspaceDir: string,
5964
): Promise<{ content?: string; status: "ok" | "missing" | "empty" }> {
@@ -74,7 +79,7 @@ async function loadBootFile(
7479
}
7580
}
7681

77-
function snapshotMainSessionMapping(params: {
82+
function snapshotSessionMapping(params: {
7883
cfg: OpenClawConfig;
7984
sessionKey: string;
8085
}): SessionMappingSnapshot {
@@ -99,7 +104,7 @@ function snapshotMainSessionMapping(params: {
99104
entry: structuredClone(entry),
100105
};
101106
} catch (err) {
102-
log.debug("boot: could not snapshot main session mapping", {
107+
log.debug("boot: could not snapshot session mapping", {
103108
sessionKey: params.sessionKey,
104109
error: String(err),
105110
});
@@ -112,7 +117,7 @@ function snapshotMainSessionMapping(params: {
112117
}
113118
}
114119

115-
async function restoreMainSessionMapping(
120+
async function restoreSessionMapping(
116121
snapshot: SessionMappingSnapshot,
117122
): Promise<string | undefined> {
118123
if (!snapshot.canRestore) {
@@ -160,12 +165,13 @@ export async function runBootOnce(params: {
160165
return { status: "skipped", reason: result.status };
161166
}
162167

163-
const sessionKey = params.agentId
168+
const mainSessionKey = params.agentId
164169
? resolveAgentMainSessionKey({ cfg: params.cfg, agentId: params.agentId })
165170
: resolveMainSessionKey(params.cfg);
171+
const sessionKey = resolveBootSessionKey(mainSessionKey);
166172
const message = buildBootPrompt(result.content ?? "");
167173
const sessionId = generateBootSessionId();
168-
const mappingSnapshot = snapshotMainSessionMapping({
174+
const mappingSnapshot = snapshotSessionMapping({
169175
cfg: params.cfg,
170176
sessionKey,
171177
});
@@ -178,6 +184,7 @@ export async function runBootOnce(params: {
178184
sessionKey,
179185
sessionId,
180186
deliver: false,
187+
suppressPromptPersistence: true,
181188
},
182189
bootRuntime,
183190
params.deps,
@@ -187,9 +194,9 @@ export async function runBootOnce(params: {
187194
log.error(`boot: agent run failed: ${agentFailure}`);
188195
}
189196

190-
const mappingRestoreFailure = await restoreMainSessionMapping(mappingSnapshot);
197+
const mappingRestoreFailure = await restoreSessionMapping(mappingSnapshot);
191198
if (mappingRestoreFailure) {
192-
log.error(`boot: failed to restore main session mapping: ${mappingRestoreFailure}`);
199+
log.error(`boot: failed to restore session mapping: ${mappingRestoreFailure}`);
193200
}
194201

195202
if (!agentFailure && !mappingRestoreFailure) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ describe("startGatewayPostAttachRuntime", () => {
10031003
async () => {
10041004
let releaseChannels: (() => void) | undefined;
10051005
const events: string[] = [];
1006-
const pluginServices = { stop: vi.fn(async () => {}) };
1006+
const pluginServices: PluginServicesHandle = { stop: vi.fn(async () => {}) };
10071007
const onPluginServices = vi.fn();
10081008
const onSidecarsReady = vi.fn();
10091009
const startChannels = vi.fn(
@@ -1110,7 +1110,7 @@ describe("startGatewayPostAttachRuntime", () => {
11101110
async () => {
11111111
let shouldStartPluginServices = true;
11121112
let releasePluginServices: (() => void) | undefined;
1113-
const pluginServices = { stop: vi.fn(async () => {}) };
1113+
const pluginServices: PluginServicesHandle = { stop: vi.fn(async () => {}) };
11141114
const onPluginServices = vi.fn();
11151115
hoisted.startPluginServices.mockImplementationOnce(
11161116
async () =>

0 commit comments

Comments
 (0)