diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-25 10:21:23 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-25 10:21:23 +0300 |
| commit | 7e7f545112e918451320a87922ab6b34461ed3c5 (patch) | |
| tree | 0a00caa567fc1f09fcd19dfe7217e20566bcf0e3 | |
| parent | 106f3f414802e34f2f58bdc4d9c2c92c845bab15 (diff) | |
fix(loop-scheduler): replace ctx.waitForIdle() with isIdle() polling in agent_end handlermain
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.
| -rw-r--r-- | pi/agent/extensions/loop-scheduler/index.ts | 9 |
1 files changed, 8 insertions, 1 deletions
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(); }); |
