Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(chatRuntime): reset streaming state when a run is cancelled

Steven Enamakelfeb3f292af11
diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.ts
index c6e1919fee..d5fd171583 100644
--- a/app/src/store/chatRuntimeSlice.ts
+++ b/app/src/store/chatRuntimeSlice.ts
@@ -2397,6 +2397,29 @@ const chatRuntimeSlice = createSlice({
clearPendingApprovalForThread: (state, action: PayloadAction<{ threadId: string }>) => {
delete state.pendingApprovalByThread[action.payload.threadId];
},
+ /**
+ * Turn-end clear (`chat_done` / `chat_error`): a park bound to the turn
+ * cannot outlive it, but a detached one (an async sub-agent's) is still
+ * waiting on the user and stays until `approval_decided` clears it.
+ */
+ clearTurnApprovalForThread: (state, action: PayloadAction<{ threadId: string }>) => {
+ dropTurnBoundApproval(state, action.payload.threadId);
+ },
+ /**
+ * Clear the thread's parked approval when it is `requestId` — for an
+ * `approval_decided` that resolves a detached card on a client that did
+ * not answer it (no turn end follows to clear it). A no-op when the store
+ * holds a different request.
+ */
+ clearPendingApprovalIfRequest: (
+ state,
+ action: PayloadAction<{ threadId: string; requestId: string }>
+ ) => {
+ const current = state.pendingApprovalByThread[action.payload.threadId];
+ if (current?.requestId === action.payload.requestId) {
+ delete state.pendingApprovalByThread[action.payload.threadId];
+ }
+ },
/**
* Record a server-decided terminal resolution (`approval_decided` socket
* event carrying `resolution: 'expired' | 'cancelled'`) on the thread's
@@ -2694,7 +2717,7 @@ const chatRuntimeSlice = createSlice({
turnStateLog('turn settled thread=%s request=%s', threadId, requestId ?? 'none');
delete state.streamingAssistantByThread[threadId];
delete state.inferenceStatusByThread[threadId];
- delete state.pendingApprovalByThread[threadId];
+ dropTurnBoundApproval(state, threadId);
delete state.pendingPlanReviewByThread[threadId];
delete state.liveRequestIdByThread[threadId];
delete state.inferenceTurnLifecycleByThread[threadId];
@@ -2730,7 +2753,7 @@ const chatRuntimeSlice = createSlice({
// failed send, the silence timeout) would remount every settled turn.
delete state.liveRequestIdByThread[action.payload.threadId];
delete state.inferenceTurnLifecycleByThread[action.payload.threadId];
- delete state.pendingApprovalByThread[action.payload.threadId];
+ dropTurnBoundApproval(state, action.payload.threadId);
delete state.pendingPlanReviewByThread[action.payload.threadId];
delete state.pendingWorkflowProposalsByThread[action.payload.threadId];
delete state.queueStatusByThread[action.payload.threadId];
@@ -2875,7 +2898,7 @@ const chatRuntimeSlice = createSlice({
}
// Snapshots don't carry pending-approval payloads; drop any stale in-memory
// approval so the card reflects the rehydrated core truth, not pre-drift state.
- delete state.pendingApprovalByThread[threadId];
+ dropTurnBoundApproval(state, threadId);
// Likewise drop any stale parked plan review — its gate future cannot
// survive a rehydrate, so the card must not linger.
delete state.pendingPlanReviewByThread[threadId];
@@ -3088,6 +3111,8 @@ export const {
resolveSubagentTranscriptTool,
setPendingApprovalForThread,
clearPendingApprovalForThread,
+ clearPendingApprovalIfRequest,
+ clearTurnApprovalForThread,
resolvePendingApprovalForThread,
setPendingPlanReviewForThread,
clearPendingPlanReviewForThread,