Skip to content

Commit ec059ec

Browse files
author
xin
committed
fix(compaction): forward abortSignal through delegateCompactionToRuntime bridge
When a user presses the stop button during auto-compaction, the abort signal cancels the wait but the compaction LLM call continues in-flight and writes its result to the session transcript. This causes model confusion as the model receives only a compaction summary instead of the full context. The bridge gap: delegateCompactionToRuntime forwarded sessionId, sessionFile, tokenBudget, and other params, but not abortSignal. The runtime already accepts this field in CompactEmbeddedAgentSessionParams, but it was never populated by the delegate. Fix: forward params.abortSignal so the runtime can properly abort compaction when the stop button or safety timeout fires. Closes #89868
1 parent 0314819 commit ec059ec

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ describe("Engine contract tests", () => {
434434
expect(compactRuntimeParams.tokenBudget).toBe(4096);
435435
expect(compactRuntimeParams.currentTokenCount).toBe(12345);
436436
expect(compactRuntimeParams.workspaceDir).toBe("/tmp/workspace");
437+
// abortSignal should be undefined when not passed
438+
expect(compactRuntimeParams.abortSignal).toBeUndefined();
437439
expect(result).toEqual({
438440
ok: true,
439441
compacted: false,
@@ -448,6 +450,25 @@ describe("Engine contract tests", () => {
448450
});
449451
});
450452

453+
it("forwards abortSignal to the compaction runtime bridge", async () => {
454+
const compactRuntimeSpy = installCompactRuntimeSpy();
455+
const controller = new AbortController();
456+
const abortSignal = controller.signal;
457+
458+
await delegateCompactionToRuntime({
459+
sessionId: "s3",
460+
sessionFile: "/tmp/session.json",
461+
tokenBudget: 4096,
462+
abortSignal,
463+
runtimeContext: { workspaceDir: "/tmp/workspace" },
464+
});
465+
466+
const compactRuntimeParams = requireCompactRuntimeParams(0);
467+
// abortSignal must be forwarded so the runtime can abort compaction
468+
// when the stop button is pressed during overflow auto-compaction
469+
expect(compactRuntimeParams.abortSignal).toBe(abortSignal);
470+
});
471+
451472
it("builds a normalized memory system prompt addition from the active memory prompt path", () => {
452473
registerMemoryPromptSection(({ citationsMode }) => [
453474
"## Memory Recall",

src/context-engine/delegate.ts

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

0 commit comments

Comments
 (0)