fix: harden resume and SSE replay

This commit is contained in:
User
2026-07-15 00:06:00 +02:00
parent e5366d14a6
commit 2b4797f133
18 changed files with 871 additions and 102 deletions
+4
View File
@@ -16,6 +16,7 @@ interface SessionState {
lastSystemEvent: StreamEvent | null;
currentPhase: string | null;
phaseError: string | null;
seenGateIds: Set<string>;
// True while a Pi turn is in flight. Turned off by the backend-forwarded `agent_end`
// system event — the only end-of-turn signal on the final workflow step, where no
// follow-up gate arrives to release the spinner.
@@ -62,6 +63,7 @@ const empty = {
lastSystemEvent: null,
currentPhase: null as string | null,
phaseError: null as string | null,
seenGateIds: new Set<string>(),
agentActive: false,
};
@@ -70,9 +72,11 @@ export const useSessionStore = create<SessionState>((set) => ({
applyEvent: (e) =>
set((st) => {
if (e.type === "ui_request") {
if (st.seenGateIds.has(e.ui_request.id)) return {};
const currentPhase = phaseOf(e.ui_request.phase, st.currentPhase);
return {
pendingWidget: e.ui_request,
seenGateIds: new Set([...st.seenGateIds, e.ui_request.id]),
// The turn is blocked on the gate, not ended: keep the agent marked active.
agentActive: true,
currentPhase,