Skip to content

Commit dbb14df

Browse files
committed
fix(context-engine): forward abortSignal through delegation bridge to runtime compaction
delegateCompactionToRuntime built the CompactEmbeddedAgentSessionDirect params object without forwarding params.abortSignal. The ContextEngine compact() public API and CompactEmbeddedAgentSessionParams both carry an optional abortSignal, but the delegate bridge silently dropped it. When the user pressed stop during auto-compaction, the host aborted the wait via the signal, but the in-flight compaction LLM call continued to completion and wrote its summary to the session file. The next turn then saw a compacted session (e.g. 239→4 messages) the user had not consented to, causing model confusion about ongoing work and instructions. Fixes #89868
1 parent e0ab71d commit dbb14df

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/context-engine/context-engine.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,32 @@ describe("Engine contract tests", () => {
447447
});
448448
});
449449

450+
it("delegateCompactionToRuntime forwards the caller abortSignal to the runtime (#89868)", async () => {
451+
installCompactRuntimeSpy();
452+
const controller = new AbortController();
453+
await delegateCompactionToRuntime({
454+
sessionId: "s-abort",
455+
sessionFile: "/tmp/session-abort.json",
456+
tokenBudget: 4096,
457+
abortSignal: controller.signal,
458+
});
459+
460+
const compactRuntimeParams = requireCompactRuntimeParams(0);
461+
expect(compactRuntimeParams.abortSignal).toBe(controller.signal);
462+
});
463+
464+
it("delegateCompactionToRuntime passes undefined abortSignal when none supplied", async () => {
465+
installCompactRuntimeSpy();
466+
await delegateCompactionToRuntime({
467+
sessionId: "s-no-abort",
468+
sessionFile: "/tmp/session-no-abort.json",
469+
tokenBudget: 4096,
470+
});
471+
472+
const compactRuntimeParams = requireCompactRuntimeParams(0);
473+
expect(compactRuntimeParams.abortSignal).toBeUndefined();
474+
});
475+
450476
it("builds a normalized memory system prompt addition from the active memory prompt path", () => {
451477
registerMemoryPromptSection(({ citationsMode }) => [
452478
"## Memory Recall",

src/context-engine/delegate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export async function delegateCompactionToRuntime(
5959
...(currentTokenCount !== undefined ? { currentTokenCount } : {}),
6060
force: params.force,
6161
customInstructions: params.customInstructions,
62+
abortSignal: params.abortSignal,
6263
workspaceDir:
6364
typeof runtimeContext.workspaceDir === "string" ? runtimeContext.workspaceDir : process.cwd(),
6465
});

0 commit comments

Comments
 (0)