From 7e7f545112e918451320a87922ab6b34461ed3c5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 25 May 2026 10:21:23 +0300 Subject: fix(loop-scheduler): replace ctx.waitForIdle() with isIdle() polling in agent_end handler The agent_end event handler receives ExtensionContext, not ExtensionCommandContext, so ctx.waitForIdle() is not available. Replace with a polling loop using ctx.isIdle() to wait for the run to finish before draining pending jobs, preventing stuck follow-up messages. --- pi/agent/extensions/loop-scheduler/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pi') diff --git a/pi/agent/extensions/loop-scheduler/index.ts b/pi/agent/extensions/loop-scheduler/index.ts index 67247b8..cdd30a4 100644 --- a/pi/agent/extensions/loop-scheduler/index.ts +++ b/pi/agent/extensions/loop-scheduler/index.ts @@ -1210,7 +1210,14 @@ export default function loopSchedulerExtension(pi: ExtensionAPI): void { // stuck "Follow-up: ..." in pi's UI. We'd also leak agentBusy=true and // block every subsequent pending job because no further agent_end fires. // Wait for the run to actually finish before draining. - await ctx.waitForIdle(); + // ctx.waitForIdle() is only available on ExtensionCommandContext, not + // ExtensionContext, so we poll isIdle() instead. + let attempts = 0; + const maxAttempts = 600; // ~30s at 50ms each + while (!ctx.isIdle() && attempts < maxAttempts) { + await new Promise((r) => setTimeout(r, 50)); + attempts++; + } agentBusy = false; drainPendingJobs(); }); -- cgit v1.2.3