From e5ffd6219917e13177d32c2e401a12297da35b31 Mon Sep 17 00:00:00 2001 From: Amos Date: Sun, 28 Jun 2026 16:35:30 +0300 Subject: [PATCH] fixed abort trigger persisting across sessions --- agents/researcher.md | 2 +- agents/worker.md | 1 + pi-extension/subagents/index.ts | 8 ++++++++ test/test.ts | 12 ++---------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/agents/researcher.md b/agents/researcher.md index e40d4a0..32b5105 100644 --- a/agents/researcher.md +++ b/agents/researcher.md @@ -1,7 +1,7 @@ --- name: researcher description: Web researcher — searches the web and synthesizes findings -tools: web_search, web_fetch +tools: web_search, web_fetch, safe_bash model: openrouter/z-ai/glm-5.2 thinking: medium system-prompt: append diff --git a/agents/worker.md b/agents/worker.md index de8e321..7e70d9f 100644 --- a/agents/worker.md +++ b/agents/worker.md @@ -6,6 +6,7 @@ subagent_agents: scout, researcher model: openrouter/z-ai/glm-5.2 thinking: medium system-prompt: append +auto-exit: true --- You are a worker agent. You operate in an isolated context — you have no knowledge of any prior conversation. All necessary context will be provided in the task description. diff --git a/pi-extension/subagents/index.ts b/pi-extension/subagents/index.ts index 8e06f69..8c80264 100644 --- a/pi-extension/subagents/index.ts +++ b/pi-extension/subagents/index.ts @@ -1500,6 +1500,14 @@ export default function subagentsExtension(pi: ExtensionAPI) { // Capture the UI context for widget updates pi.on("session_start", (_event, ctx) => { latestCtx = ctx; + // pi runs multiple sessions in one process. A prior session's shutdown + // aborts the shared module poll-abort controller; install a fresh one so + // subagents spawned in this session aren't watched against a dead signal. + // See https://github.com/HazAT/pi-interactive-subagents/issues/5 + const prevAbort = (globalThis as any)[POLL_ABORT_KEY] as AbortController | undefined; + if (!prevAbort || prevAbort.signal.aborted) { + (globalThis as any)[POLL_ABORT_KEY] = new AbortController(); + } }); // Clean up on session shutdown diff --git a/test/test.ts b/test/test.ts index 038c435..dae8336 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1076,8 +1076,8 @@ describe("subagent discovery", () => { ); }); - it("bundled scout/researcher resolve as non-interactive; worker resolves as interactive", () => { - for (const name of ["scout", "researcher"]) { + it("bundled scout/researcher/worker all resolve as non-interactive (auto-exit)", () => { + for (const name of ["scout", "researcher", "worker"]) { const defs = testApi.loadAgentDefaults(name); assert.ok(defs, `expected bundled agent ${name} to be discoverable`); assert.equal( @@ -1086,14 +1086,6 @@ describe("subagent discovery", () => { `${name} should resolve as non-interactive (autonomous, auto-exit)`, ); } - - const worker = testApi.loadAgentDefaults("worker"); - assert.ok(worker, "expected bundled worker to be discoverable"); - assert.equal( - testApi.resolveEffectiveInteractive({ name: "worker", task: "" }, worker), - true, - "worker should resolve as interactive (no auto-exit)", - ); }); it("worker is granted the spawning toolset restricted to scout and researcher", () => {