fix(bridge): forward Pi agent_end so the spinner stops at workflow completion

The FE derived 'working' purely as activeSession && !pendingWidget, so the
final workflow turn — the only one that ends without a follow-up gate —
left the spinner on forever (observed live: 21592s after F8 approve).

- SessionBridge maps Pi's agent_end -> SSE system_event {event: agent_end}
- PiProcessManager notifies the client (info error + synthetic agent_end)
  when the child dies unexpectedly; expected teardowns stay silent
- sessionStore tracks agentActive (on: user entry/text_delta/ui_request,
  off: agent_end); AppShell working now requires it; resume sets it
  optimistically

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 10:14:43 +02:00
co-authored by Claude Fable 5
parent b59b57c4e6
commit 2410f01b34
7 changed files with 115 additions and 7 deletions
+27
View File
@@ -80,6 +80,33 @@ function recordingChild() {
return ch;
}
test("un exit INATTESO del child notifica il client (info error + agent_end)", async () => {
const cfg = loadConfig({});
const child = recordingChild();
const mgr = new PiProcessManager(cfg, { spawnFn: () => child as any });
const rt = await mgr.spawnFor("crash-id", {});
const seen: any[] = [];
rt.bridge.onClientEvent((e) => seen.push(e));
child.emit("exit", 137);
expect(seen).toEqual([
{ type: "info", level: "error", text: expect.stringContaining("137") },
{ type: "system_event", event: "agent_end" },
]);
expect(mgr.count()).toBe(0);
});
test("l'exit dopo teardown NON emette eventi al client (uscita attesa)", async () => {
const cfg = loadConfig({});
const child = recordingChild();
const mgr = new PiProcessManager(cfg, { spawnFn: () => child as any });
const rt = await mgr.spawnFor("stop-id", {});
const seen: any[] = [];
rt.bridge.onClientEvent((e) => seen.push(e));
mgr.teardown("stop-id");
child.emit("exit", 0);
expect(seen).toEqual([]);
});
test("spawnFor resume mode sends /riprendi-sessione <id>", async () => {
const cfg = loadConfig({}); // no provider/model/thinking -> no rpc.request handshakes
const child = recordingChild();