fix(terminal): reconnect to running executions after page refresh#3200
fix(terminal): reconnect to running executions after page refresh#3200waleedlatif1 merged 16 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryAdds Redis-backed event buffering and SSE reconnection to restore running executions after page refresh. The implementation dual-writes execution events to Redis alongside SSE streaming, allowing clients to detect running console entries on mount and reconnect to replay missed events. Key changes:
Issues addressed:
Minor style concerns:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Browser
participant ExecuteAPI as /api/workflows/[id]/execute
participant EventBuffer as Redis Event Buffer
participant StreamAPI as /api/workflows/[id]/executions/[executionId]/stream
participant Console as Terminal Console Store
Note over User,Console: Initial Execution
User->>Browser: Start workflow execution
Browser->>ExecuteAPI: POST with workflow input
ExecuteAPI->>EventBuffer: createExecutionEventWriter(executionId)
ExecuteAPI->>EventBuffer: setExecutionMeta(status: active)
ExecuteAPI-->>Browser: SSE stream + X-Execution-Id header
loop Execution Events
ExecuteAPI->>EventBuffer: writer.write(event)
ExecuteAPI->>Browser: SSE event
Browser->>Console: addConsole(entry with isRunning: true)
end
ExecuteAPI->>EventBuffer: setExecutionMeta(status: complete)
ExecuteAPI->>EventBuffer: writer.close()
ExecuteAPI->>Browser: [DONE]
Browser->>Console: Update entries (isRunning: false)
Note over User,Console: Page Refresh / Navigation
User->>Browser: Refresh page
Browser->>Browser: Zustand rehydrates from IndexedDB
Browser->>Console: Load persisted entries
alt Running entries found
Browser->>Browser: Detect isRunning entries in console
Browser->>Console: Sort by startedAt, pick most recent
Browser->>Console: cancelRunningEntries (mark old zombies as cancelled)
Browser->>StreamAPI: GET /stream?from=0
StreamAPI->>StreamAPI: authorizeWorkflowByWorkspacePermission
StreamAPI->>EventBuffer: getExecutionMeta(executionId)
alt Buffer exists
StreamAPI->>EventBuffer: readExecutionEvents(executionId, fromEventId)
EventBuffer-->>StreamAPI: Buffered events
StreamAPI-->>Browser: SSE replay of events
Browser->>Console: clearOnce() - clear old entries
Browser->>Console: Add/update entries from replayed events
loop Poll for new events (until terminal status)
StreamAPI->>EventBuffer: readExecutionEvents(lastEventId)
StreamAPI->>EventBuffer: getExecutionMeta()
alt New events available
StreamAPI-->>Browser: SSE new events
Browser->>Console: Update console entries
end
end
StreamAPI->>Browser: [DONE]
Browser->>Console: Mark execution complete
else Buffer expired (404)
StreamAPI-->>Browser: 404 error
Browser->>Console: Mark entries with warning (unavailable)
end
end
|
apps/sim/app/api/workflows/[id]/executions/[executionId]/stream/route.ts
Outdated
Show resolved
Hide resolved
Additional Comments (1)
|
…rd<string, unknown> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@greptile |
apps/sim/app/api/workflows/[id]/executions/[executionId]/stream/route.ts
Show resolved
Hide resolved
…oint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@cursor review |
apps/sim/app/api/workflows/[id]/executions/[executionId]/stream/route.ts
Show resolved
Hide resolved
Additional Comments (1)
|
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ock re-entry Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ted by navigation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@greptile |
|
@cursor review |
|
@cursor review |
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Outdated
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
|
@cursor review |
|
@greptile |
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
) * fix(terminal): reconnect to running executions after page refresh * fix(terminal): use ExecutionEvent type instead of any in reconnection stream * fix(execution): type event buffer with ExecutionEvent instead of Record<string, unknown> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(execution): validate fromEventId query param in reconnection endpoint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix some bugs * fix(variables): fix tag dropdown and cursor alignment in variables block (#3199) * feat(confluence): added list space labels, delete label, delete page prop (#3201) * updated route * ack comments * fix(execution): reset execution state in reconnection cleanup to unblock re-entry Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(execution): restore running entries when reconnection is interrupted by navigation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * done * remove cast in ioredis types * ack PR comments --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Siddharth Ganesan <siddharthganesan@gmail.com>
Summary
GET /api/workflows/[id]/executions/[executionId]/stream)X-Execution-IdheaderType of Change
Testing
Tested manually
Checklist