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:
@@ -39,6 +39,35 @@ test("ui_request without a phase keeps the existing currentPhase", () => {
|
||||
expect(useSessionStore.getState().currentPhase).toBe("F2");
|
||||
});
|
||||
|
||||
test("agentActive lifecycle: off by default, on with activity, off on agent_end", () => {
|
||||
const st = useSessionStore.getState();
|
||||
expect(useSessionStore.getState().agentActive).toBe(false);
|
||||
// Any streamed text means the turn is alive (also covers reattaching mid-turn).
|
||||
st.applyEvent({ type: "text_delta", text: "Analisi" });
|
||||
expect(useSessionStore.getState().agentActive).toBe(true);
|
||||
// Pi's end-of-turn signal (mapped by the backend) releases the working state.
|
||||
st.applyEvent({ type: "system_event", event: "agent_end" });
|
||||
expect(useSessionStore.getState().agentActive).toBe(false);
|
||||
});
|
||||
|
||||
test("setLastUserEntry hands the ball back to the harness (agentActive on)", () => {
|
||||
useSessionStore.getState().setLastUserEntry({ kind: "choice", text: "approve" });
|
||||
expect(useSessionStore.getState().agentActive).toBe(true);
|
||||
});
|
||||
|
||||
test("setAgentActive drives the flag directly (resume optimistic spin)", () => {
|
||||
useSessionStore.getState().setAgentActive(true);
|
||||
expect(useSessionStore.getState().agentActive).toBe(true);
|
||||
useSessionStore.getState().resetSession();
|
||||
expect(useSessionStore.getState().agentActive).toBe(false);
|
||||
});
|
||||
|
||||
test("a ui_request keeps agentActive on (turn blocked on the gate, not ended)", () => {
|
||||
const st = useSessionStore.getState();
|
||||
st.applyEvent({ type: "ui_request", ui_request: { id: "u1", widget: "select" } });
|
||||
expect(useSessionStore.getState().agentActive).toBe(true);
|
||||
});
|
||||
|
||||
test("pushToast appends an error toast", () => {
|
||||
useSessionStore.getState().pushToast({ level: "error", text: "boom" });
|
||||
expect(useSessionStore.getState().toasts.at(-1)).toEqual({ level: "error", text: "boom" });
|
||||
|
||||
Reference in New Issue
Block a user