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
This commit is contained in:
openperf
2026-06-03 23:06:57 +08:00
committed by Vincent Koc
parent 3e84836b01
commit ff5a439d76
2 changed files with 27 additions and 0 deletions

View File

@@ -603,6 +603,32 @@ describe("Engine contract tests", () => {
});
});
it("delegateCompactionToRuntime forwards the caller abortSignal to the runtime (#89868)", async () => {
installCompactRuntimeSpy();
const controller = new AbortController();
await delegateCompactionToRuntime({
sessionId: "s-abort",
sessionFile: "/tmp/session-abort.json",
tokenBudget: 4096,
abortSignal: controller.signal,
});
const compactRuntimeParams = requireCompactRuntimeParams(0);
expect(compactRuntimeParams.abortSignal).toBe(controller.signal);
});
it("delegateCompactionToRuntime passes undefined abortSignal when none supplied", async () => {
installCompactRuntimeSpy();
await delegateCompactionToRuntime({
sessionId: "s-no-abort",
sessionFile: "/tmp/session-no-abort.json",
tokenBudget: 4096,
});
const compactRuntimeParams = requireCompactRuntimeParams(0);
expect(compactRuntimeParams.abortSignal).toBeUndefined();
});
it("builds a normalized memory system prompt addition from the active memory prompt path", () => {
registerMemoryPromptSection(({ citationsMode }) => [
"## Memory Recall",

View File

@@ -60,6 +60,7 @@ export async function delegateCompactionToRuntime(
...(currentTokenCount !== undefined ? { currentTokenCount } : {}),
force: params.force,
customInstructions: params.customInstructions,
abortSignal: params.abortSignal,
workspaceDir:
typeof runtimeContext.workspaceDir === "string" ? runtimeContext.workspaceDir : process.cwd(),
});