Skip to content

improvement(mothership): workflow edits via sockets#3927

Merged
icecrasher321 merged 4 commits intostagingfrom
improvement/mothership-workflow-edit
Apr 4, 2026
Merged

improvement(mothership): workflow edits via sockets#3927
icecrasher321 merged 4 commits intostagingfrom
improvement/mothership-workflow-edit

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Workflow edits persistence via sockets for mothership embedded view.

Type of Change

  • Other: UX Improvement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 4, 2026 1:35am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 4, 2026

PR Summary

Medium Risk
Adds new socket-driven workflow state reload behavior and new server-to-socket notification calls, which can impact collaborative editing consistency and introduce unexpected overwrites if events fire at the wrong time. Changes are scoped but touch real-time sync paths and shared stores.

Overview
Enables embedded workflow views to join/leave workflow socket rooms and report cursor positions using absolute screen coordinates.

Adds a new workflow-updated socket event and handler pipeline so clients can reload workflow state from the API when a workflow is reverted or updated externally (skipping reload during active diffs and pruning invalid undo/redo entries).

Server-side workflow edits (Copilot edit-workflow) now notify the socket server via /api/workflow-updated using INTERNAL_API_SECRET, triggering refreshes for connected clients.

Reviewed by Cursor Bugbot for commit 93197f1. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 4, 2026

Greptile Summary

This PR adds real-time workflow state synchronisation for the mothership embedded view: when a copilot AI tool edits a workflow, the edit-workflow server tool now notifies the socket server, which broadcasts a workflow-updated event. Clients receive the event via SocketProvider and useCollaborativeWorkflow re-fetches and applies the full workflow state, ensuring the embedded view stays in sync without a manual refresh.

Key changes:

  • socket-provider.tsx: Adds onWorkflowUpdated registration following the established pattern for other socket events (clean, no issues).
  • use-collaborative-workflow.ts: Adds handleWorkflowUpdated that re-fetches the workflow and applies it to WorkflowStore and SubBlockStore. It's missing the undo/redo history pruning (pruneInvalidEntries) that the analogous handleWorkflowReverted performs, which can leave stale stack entries referencing deleted blocks.
  • edit-workflow/index.ts: Emits a best-effort socket notification after persisting. The await fetch(...) has no timeout, so a slow or unreachable socket server can delay the tool's response even though the workflow is already saved.

Confidence Score: 4/5

Safe to merge after addressing the missing undo/redo pruning, which can corrupt the undo history after an external workflow update.

One P1 finding: handleWorkflowUpdated skips the pruneInvalidEntries step that handleWorkflowReverted correctly performs, leaving the undo/redo stack with references to blocks/edges that may no longer exist. One P2 finding: no fetch timeout on the socket notification could add latency to the copilot tool. The socket-provider changes are clean and correct.

apps/sim/hooks/use-collaborative-workflow.ts — missing undo/redo pruning after external workflow state replacement.

Important Files Changed

Filename Overview
apps/sim/hooks/use-collaborative-workflow.ts Adds handleWorkflowUpdated handler that re-fetches and applies the full workflow state on socket event; missing undo/redo history pruning that the analogous handleWorkflowReverted performs, risking stale/invalid undo entries.
apps/sim/lib/copilot/tools/server/workflow/edit-workflow/index.ts After persisting the workflow edit, emits a best-effort socket-server notification; no timeout on the fetch could delay tool response when socket server is slow.
apps/sim/app/workspace/providers/socket-provider.tsx Adds onWorkflowUpdated event handler registration following the same pattern as existing handlers; straightforward and correct.

Sequence Diagram

sequenceDiagram
    participant Copilot as Copilot Tool (Server)
    participant DB as Database
    participant Socket as Socket Server
    participant Provider as SocketProvider (Client)
    participant Hook as useCollaborativeWorkflow
    participant Store as WorkflowStore / SubBlockStore

    Copilot->>DB: saveWorkflowToNormalizedTables()
    DB-->>Copilot: success
    Copilot->>Socket: POST /api/workflow-updated { workflowId }
    Socket-->>Copilot: 200 OK
    Socket->>Provider: emit('workflow-updated', { workflowId })
    Provider->>Hook: eventHandlers.workflowUpdated(data)
    Hook->>Hook: check activeWorkflowId & hasActiveDiff
    Hook->>DB: GET /api/workflows/{workflowId}
    DB-->>Hook: { data: { state: { blocks, edges, ... } } }
    Hook->>Store: replaceWorkflowState(...)
    Hook->>Store: useSubBlockStore.setState(subblockValues)
    Note over Hook,Store: pruneInvalidEntries() missing here
Loading

Reviews (1): Last reviewed commit: "improvement(mothership): workflow edits ..." | Re-trigger Greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 79476dd. Configure here.

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 93197f1. Configure here.

@icecrasher321 icecrasher321 merged commit a0796f0 into staging Apr 4, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/mothership-workflow-edit branch April 4, 2026 19:52
waleedlatif1 pushed a commit that referenced this pull request Apr 4, 2026
* improvement(mothership): workflow edits via sockets

* make embedded view join room

* fix cursor positioning bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant