Repository navigation
feat: implement real-time file change notifications for project and w… - #794
Conversation
…orkspace scopes - Added `useWorkspaceFilesRealtime` hook to manage real-time updates for workspace-wide file changes. - Integrated real-time file change handling in the `FilesPage` component. - Enhanced the `applyFileChange` function to refetch affected file listings based on changes. - Updated the file service to announce changes via a new `realtime` interface, allowing clients to receive updates for file operations (create, move, trash, etc.). - Implemented authorization checks for file changes, ensuring users have the necessary permissions to view updates. - Created tests for file change application logic and real-time event routing. - Updated documentation to reflect new file change events and permissions.
There was a problem hiding this comment.
ℹ️ No critical issues — a few rough edges worth a look, with details inline.
Approach: sound — one realtime-only, ids-only event per file-manager mutation, routed through the existing namespace/room machinery, with the general scope split into its own room because it has no project. The client refetches only the listings the event names, which keeps the fan-out cheap.
Reviewed changes
- API announcer —
filesvcpublishesfile.changedafter each mutation; new topic, authz rule and registry entry. - Realtime routing — new
filesnamespace/room, aworkspace:filesroom joined at handshake and refreshed on IAM changes, and special routing for general-scope events. - Web invalidation —
applyFileChangerefetches the named folders, searches, sections and breadcrumbs; a project event rule and a workspace-scope hook feed it. - Global-page wiring —
FilesPagefollows the general scope and joins the browsed project's rooms. - Global permissions fix — the realtime client now reads
actions, the key the API actually returns.
ℹ️ Files the manager shows that come from other services stay stale
The announcer lives only in filesvc, but the file manager also lists files written by the attachment, doc and annotation services into the project's system folders ("Task attachments", "Document files", "Annotation screenshots"). Those rows get a folder_id in those folders via trigger and are included by file_items, so adding or removing a task attachment changes a listing another user may be looking at without publishing file.changed.
Technical details
# System-folder listings are not announced
## Affected sites
- `services/api/migrations/000093_file_management.sql:194-207` — `files_before_insert` assigns `project_id`/`folder_id` for non-upload sources.
- `services/api/migrations/000093_file_management.sql:261-266` — `file_items` includes every uploaded file that has a folder.
- `services/api/internal/repository/postgres/file_repository_pg_test.go:61-95` — proves task/doc attachments are listed inside those folders, and a detached attachment lands in the trash.
- `services/api/internal/service/attachment/service.go`, `doc_service.go` and `annotation_service.go` — insert/delete `files` rows without publishing anything.
## Required outcome
- Decide whether those listings are in scope. If they are, the attachment/doc/annotation flows need to announce too (or the announcer has to move to a shared layer). If not, add it to the PR's known limitations so the claim "other users browsing the same folder see it without reloading" is qualified.ℹ️ A reconnect that cannot resume leaves project file listings stale
refetchProject invalidates the project, tasks and conversations after a reconnect, but not the file manager's ["files", projectId, ...] queries. The sync feed is opt-in, so the legacy join path is the default: a file change made while the socket was away is neither replayed nor covered by that refetch, and the listing stays stale until some later file.changed arrives.
Technical details
# Project file queries are missing from the reconnect refetch
## Affected sites
- `apps/web/src/hooks/use-project-realtime.ts:191-201` — `refetchProject` only touches `conversation-event-window`, `["projects", id]` and `["users","me","tasks"]`.
- `apps/web/src/hooks/use-project-realtime.ts:237-244` — it runs when a rejoin did not resume the feed.
- `apps/web/src/hooks/use-workspace-files-realtime.ts:44-52` — the general scope does invalidate on reconnect, showing the intended behavior.
- `apps/web/src/lib/files-api.ts:446-447` — `invalidateFiles` is the helper to reuse.
## Required outcome
- A project reconnect that cannot replay missed changes should refresh the project's file listings along with its other data.deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior review at d1de3d6d):
- Workspace files room covered by the periodic resync —
resyncWorkspaceFiles()now runs on every pass, so the 60-second backstop and connection-state-recovery sockets correctworkspace:filesmembership; the README states the periodic correction. - Project
filesrule scoped correctly — it ignores events whosescopeis notprojector whoseproject_idis another project, so general-scope events no longer invalidate a project's file queries. New tests cover both cases. filesnamespace now participates in cache resets —holdsDataOfmatches["files", projectId, ...], so losingfiles:readresets the cached listings and gaining it invalidates the errored queries.- Reconnect refetch includes file listings —
refetchProjectnow invalidates["files", currentProjectId], covering a rejoin that could not replay missed changes.
All three prior review threads are addressed and resolved. Verified with npx vitest run src/lib/project-event-rules.test.ts src/lib/files-api.test.ts (40 tests pass).
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
…gic for workspace files
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior review at 6c403118):
- Burst coalescing for
file.changed—applyFileChangenow applies the first change of a burst at once and merges the rest into a single pass 250 ms later, keyed perQueryClientand per scope, so moving many files no longer refetches every active search and section once per event. New tests cover the first-event/trailing-merge behavior. - Restored folders refresh their contents — the API names the restored folder's own listing on
Restore, and the client invalidates it forrestoredfolder events; a test asserts the extra listing is refetched. - Duplicate folder ids are removed on the API —
announcededuplicatesfolder_ids, which makesUpdatepassing the same parent twice for a rename-only change a single entry. - Workspace files resync grouped per account —
resyncWorkspaceFilesnow issues one verification request per account instead of one per token, tries each token until one is accepted, and ends only the sockets whose own token the API rejected; the newresync.test.tscase drives revocation and re-grant.
The files-api and project-event-rules suites pass here (42 tests) along with go test for internal/service/file and internal/events; the services/realtime bun suite could not run in this sandbox.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
…ect and general scope
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior pullfrog review at 85ee894e):
- End-to-end coverage for the feature — a new
tests/realtime/file-changes.spec.tsdrives the real app in a browser for project create, rename, trash/restore and move, plus the general scope, and adds four socket probes that assert ids-only payloads andfiles:readgating for both scopes. - Feature file —
features/realtime/file-changes.featurerecords the nine scenarios; the spec has a matching test per scenario. - Platform role fixture —
PLATFORM_RESOURCESintests/helpers/e2e-api.tsgainsfile/*, mirroring the server's platform root (iam.PlatformRootFor→file/*) so a workspace role can actually grant platform-levelfiles:read.
The spec matches the implementation's contracts: change values, scope: "project" | "general", project_id, kind: "folder", and root: true for root-level mutations (the announcer maps a nil parent to root). The UI assertions cannot pass without the event, since file listings have a 15 s staleTime and the page is not refocused. The specs were not executed here — the Playwright stack and browsers are not available in this environment — so this is a read-through cross-checked against the existing files/file-manager.spec.ts and the realtime specs.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Summary
When someone creates, renames, moves, trashes or restores a file or folder in the file manager, other users browsing the same folder now see it without reloading. This works for project files and for the general (workspace-wide) scope.
Design
file.changedevent (create, update, move, trash, restore, delete; upload completion counts as a create). It is not written to the activity log or sent to plugins.folder_ids,root), no file names. A move names both the old and the new folder.files:readon the project and delivered to a newfilesroom.workspace:filesroom joined at connect by sockets whose account has platform-levelfiles:read, and re-synced on every IAM change.applyFileChangerefetches only the listing of a folder the event names (or the top level), plus searches, Recent/Starred/Trash and breadcrumbs. Folders nobody is viewing are only marked stale.Changes
filesvcannounces changes through a new realtime sink (service/file/realtime.go, wired inbootstrap/app.go); newTopicFileChangedand its authz rule;registry.jsonregenerated.filesnamespace,workspace:filesroom, routing insubscriber.ts, room join inserver.ts, resync inresync.ts; README updated.applyFileChangeinfiles-api.ts, afilesrule inproject-event-rules.ts, newuseWorkspaceFilesRealtimehook, andFilesPageuses it (and joins the browsed project's rooms on the global page).permissionsfrom/users/me/global-permissions, but the API returnsactions, so its global permission list was always empty. It now accepts both.Known limitations
file.changed; those listings update on the next refetch.workspace:filesroom is re-synced on IAM changes and every 60 seconds, so a revoked account can receive id-only events for up to one interval.Testing
realtime_test.go(announcements, authz, general scope without authz);eventstests and registry pass.file.changed, workspace room resync; all tests pass.applyFileChangecache invalidation cases; related suites pass;tsc -bclean.apps/e2especs were not run.