Skip to content

fix(files): make embedded resource file view collaborative - #6095

Merged
waleedlatif1 merged 2 commits into
realtime-roomsfrom
fix/embedded-file-collab
Jul 30, 2026
Merged

fix(files): make embedded resource file view collaborative#6095
waleedlatif1 merged 2 commits into
realtime-roomsfrom
fix/embedded-file-collab

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The /chat resource panel rendered saved files through FileViewer without the collaborative opt-in, so the same file open on the Files page and in the embedded panel never joined the same file-doc room — no live text caret and no live content sync between the two surfaces.
  • Pass collaborative on the EmbeddedFile FileViewer. Collaboration self-gates on canEdit + non-streaming + workspace doc, so it engages exactly when the user edits a settled file (the reported case) and stays off during streaming.
  • The dedicated agent token-stream preview path (resource.id === 'streaming-file', canEdit={false}) is untouched — no regression to the streaming preview.

Type of Change

  • Bug fix

Testing

Tested manually (typecheck clean; two-surface live caret + content sync). The synthetic streaming-file preview path is unaffected (canEdit=false, collab never engages).

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)

The /chat resource panel rendered saved files through FileViewer without
the collaborative opt-in, so a file open on the Files page and the same
file open in the embedded panel never joined the same file-doc room —
no live carets and no live content sync between the two surfaces.

Pass collaborative on the EmbeddedFile FileViewer. Collaboration still
self-gates on canEdit + non-streaming + workspace doc, so the agent
token-stream preview (the dedicated streaming-file path, canEdit=false)
is untouched.
@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 30, 2026 6:19pm

Request Review

@cursor

cursor Bot commented Jul 30, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes realtime room join/leave and multi-surface collaboration behavior; refcount logic is covered by new tests but affects live sync and presence.

Overview
The embedded chat resource panel now opts into live collaboration by passing collaborative on FileViewer, so the same file open on the Files page and in that panel can share the file-doc room (live content and carets). Collaboration still self-gates on edit permissions, settled content, and workspace docs—not during agent streaming.

FileDocProvider adds a per-socket, per-file refcount so LEAVE runs only when the last provider for that file tears down. Multiple surfaces in one tab share one Socket.IO connection; the server removes the socket from the room on any leave, so an early destroy used to strand a still-mounted sibling editor.

Tests cover shared-socket refcounting and independent leave per file id.

Reviewed by Cursor Bugbot for commit 60db01b. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR enables collaborative editing for settled files in the embedded resource panel and prevents one same-file provider from prematurely removing a shared socket from the collaboration room.

  • Adds per-socket, per-file provider reference counting so LEAVE is emitted only after the final provider is destroyed.
  • Adds tests for shared same-file membership and independent per-file teardown.
  • Enables the collaborative FileViewer mode in EmbeddedFile.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/collaboration/file-doc-provider.ts Adds socket- and file-scoped provider reference counting so destroying one same-file provider does not terminate collaboration for another.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/collaboration/file-doc-provider.test.ts Covers final-provider room departure and verifies that membership counts remain independently scoped by file.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx Enables collaboration for the embedded saved-file viewer while preserving existing editability and streaming gates.

Sequence Diagram

sequenceDiagram
  participant A as Embedded file viewer
  participant B as Files viewer
  participant P as FileDocProvider
  participant S as Shared socket
  participant R as Realtime room
  A->>P: Create provider for file
  P->>S: Retain file membership (count 1)
  S->>R: JOIN file room
  B->>P: Create provider for same file
  P->>S: Retain file membership (count 2)
  A->>P: Destroy first provider
  P->>S: Release membership (count 1)
  Note over S,R: No LEAVE emitted
  B->>P: Destroy final provider
  P->>S: Release membership (count 0)
  S->>R: LEAVE file room
Loading

Reviews (3): Last reviewed commit: "fix(files): refcount file-doc room membe..." | Re-trigger Greptile

Two collaborative surfaces in one tab (the Files editor and the embedded
chat resource panel) share one Socket.IO connection, so both providers for
the same file JOIN the same room over that socket. The server's LEAVE does
socket.leave(name) with no membership refcount, so the first provider's
destroy() would strand the second still-mounted one — no more live content
or presence.

Count live providers per file per socket (keyed by the stable Socket object,
so it survives reconnects) and emit LEAVE only when the last provider for a
file tears down. The single-provider path is unchanged (0->1->0).
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 60db01b. Configure here.

@waleedlatif1
waleedlatif1 merged commit f9b557b into realtime-rooms Jul 30, 2026
5 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/embedded-file-collab branch July 30, 2026 18:39
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