fix(platform): let an interaction detach from its owner signal on completion (Q-6.9-7)

createExecutionContext forwarded an owner signal's abort and removed
that listener only when the interaction itself aborted. An interaction
that finished normally under a long-lived owner signal left its listener
and AbortController on the owner. ExecutionContext gains complete():
idempotent, detaches from the owner without aborting the interaction.
No caller passes an owner signal today, so this closes a latent leak.

Verified: new test in tests/platform/execution/execution-context.test.ts
(RED before: complete is not a function); all gates pass except the
known tests/unit/removal-fixture.test.ts (artifacts/ absent).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 13:58:35 +09:00
co-authored by Claude Opus 5.5
parent b7c4e380e2
commit 911561985b
2 changed files with 39 additions and 6 deletions
+18 -5
View File
@@ -49,6 +49,13 @@ export interface ExecutionContext {
readonly clock: () => number;
/** Time left before the absolute interaction deadline; never negative. */
remainingMs(): number;
/**
* Q-6.9-7. Ends the interaction normally: it detaches from the owner
* `signal` without aborting its own. Idempotent. Without it, every
* interaction under a long-lived owner signal left one abort listener (and
* its controller) on that owner until the owner itself aborted.
*/
complete(): void;
}
export type ExecutionContextOptions = Readonly<{
@@ -95,17 +102,20 @@ export function createExecutionContext(
const controller = new AbortController();
const parent = options.signal;
let detachFromParent = () => {};
if (parent) {
if (parent.aborted) controller.abort();
else {
const forward = () => controller.abort();
parent.addEventListener("abort", forward, { once: true });
detachFromParent = () => {
detachFromParent = () => {};
parent.removeEventListener("abort", forward);
};
// The interaction must not keep the parent's listener alive after it ends.
controller.signal.addEventListener(
"abort",
() => parent.removeEventListener("abort", forward),
{ once: true },
);
controller.signal.addEventListener("abort", () => detachFromParent(), {
once: true,
});
}
}
@@ -127,5 +137,8 @@ export function createExecutionContext(
return 0;
}
},
complete() {
detachFromParent();
},
});
}