fix(agents): preserve context engine session ownership (#124376)

* fix(agents): preserve context engine session ownership

Unbound legacy context-engine hooks no longer execute LLM calls under the default agent. Explicit, agent-scoped, main-alias, and persisted session ownership remain supported.

* test(ci): avoid scheduler pid file race
This commit is contained in:
Peter Steinberger
2026-08-15 20:42:26 -07:00
committed by GitHub
parent e8e7598c5b
commit a6cb2fbc9f
21 changed files with 313 additions and 58 deletions
+16 -6
View File
@@ -265,6 +265,14 @@ function isProcessAlive(pid: number): boolean {
}
}
function readCompletePidFile(pidPath: string): number | undefined {
if (!existsSync(pidPath)) {
return undefined;
}
const pid = Number.parseInt(readFileSync(pidPath, "utf8"), 10);
return Number.isInteger(pid) ? pid : undefined;
}
async function waitFor(predicate: () => boolean, timeoutMs = 5_000): Promise<void> {
const started = Date.now();
while (Date.now() - started < timeoutMs) {
@@ -1275,9 +1283,10 @@ setInterval(() => {}, 1000);
timeoutMs: 250,
});
await waitFor(() => existsSync(grandchildPidPath));
grandchildPid = Number.parseInt(readFileSync(grandchildPidPath, "utf8"), 10);
expect(Number.isInteger(grandchildPid)).toBe(true);
await waitFor(() => {
grandchildPid = readCompletePidFile(grandchildPidPath) ?? 0;
return grandchildPid > 0;
});
expect(isProcessAlive(grandchildPid)).toBe(true);
await expect(runPromise).resolves.toMatchObject({ timedOut: true });
@@ -1494,9 +1503,10 @@ await runShellCommand({
cwd: process.cwd(),
stdio: ["ignore", "ignore", "pipe"],
});
await waitFor(() => existsSync(readyPath) && existsSync(grandchildPidPath));
grandchildPid = Number.parseInt(readFileSync(grandchildPidPath, "utf8"), 10);
expect(Number.isInteger(grandchildPid)).toBe(true);
await waitFor(() => {
grandchildPid = readCompletePidFile(grandchildPidPath) ?? 0;
return existsSync(readyPath) && grandchildPid > 0;
});
expect(isProcessAlive(grandchildPid)).toBe(true);
runner.kill("SIGTERM");