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
+8
View File
@@ -34,6 +34,11 @@ export class SessionBridge {
this.fan({ type: "text_delta", text: m.text ?? "" });
} else if (m.type === "system_event") {
this.fan(m as ClientEvent);
} else if (m.type === "agent_end") {
// Fine turno di Pi (pi-agent-core agent-loop): e' l'unico segnale che il turno e'
// concluso. Senza inoltrarlo, il FE resta "working" per sempre quando il turno
// finisce senza un gate successivo (ultimo step del workflow).
this.fan({ type: "system_event", event: "agent_end" });
}
// altri method nativi (setStatus/setWidget) e altri eventi Pi ignorati in MVP
});
@@ -43,6 +48,9 @@ export class SessionBridge {
onClientEvent(cb: (e: ClientEvent) => void): void { this.cbs.add(cb); }
/** Eventi generati dal backend stesso (es. exit inatteso del child Pi), non da Pi. */
emitClientEvent(e: ClientEvent): void { this.fan(e); }
respond(uiResponse: object & { id: string }): void {
// Correla sull'id RPC di Pi; `value` porta l'uiResponse (con l'id del descriptor) cosi'
// il check interno del gate (resp.id === descriptor.id) regge.
+14 -1
View File
@@ -70,7 +70,20 @@ export class PiProcessManager {
const rt: SessionRuntime = { rpc, bridge, child };
this.runtimes.set(sessionId, rt);
// Identity-checked: a stale child's exit must not evict a newer runtime.
child.on("exit", () => { if (this.runtimes.get(sessionId) === rt) this.runtimes.delete(sessionId); });
// Expected teardowns (teardown()/respawn) delete the runtime from the map BEFORE the
// exit event fires, so reaching this branch with `rt` still mapped means the child
// died on its own: tell the client, or the UI spins forever waiting for a turn end.
child.on("exit", (code) => {
if (this.runtimes.get(sessionId) === rt) {
this.runtimes.delete(sessionId);
rt.bridge.emitClientEvent({
type: "info",
level: "error",
text: `Pi process exited unexpectedly (code ${code ?? "?"})`,
});
rt.bridge.emitClientEvent({ type: "system_event", event: "agent_end" });
}
});
const provider = o.provider ?? this.cfg.defaults.provider;
const model = o.model ?? this.cfg.defaults.model;