-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(terminal): reconnect to running executions after page refresh #3200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, 3 comments
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, 2 comments
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, 2 comments
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, 1 comment
|
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
12 files reviewed, 2 comments
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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