Skip to content

fix(ui) Live update resources in resource main view - #3617

Merged
TheodoreSpeaks merged 2 commits into
stagingfrom
fix/live-resource
Mar 17, 2026
Merged

fix(ui) Live update resources in resource main view#3617
TheodoreSpeaks merged 2 commits into
stagingfrom
fix/live-resource

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

Mothership changes to resources should live update those resources.
Fixes #(issue)

Type of Change

  • Bug fix
  • [] New feature
  • [] Breaking change
  • Documentation
  • Other: ___________

Testing

Validated files, kbs, tables all live update when changes are made

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)

Screenshots/Videos

@vercel

vercelBot commented Mar 17, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedMar 17, 2026 1:38am

Request Review

@cursor

cursorBot commented Mar 17, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes how the chat UI detects tool-driven resource mutations and invalidates React Query caches; incorrect extraction or query-key invalidation could cause stale data or extra refetching across workspaces.

Overview
Ensures the workspace resource main view live-updates after copilot tool executions (not just resource_added SSE events) by extracting affected resources from successful tool results and invalidating the corresponding React Query caches.

Refactors resource parsing into a new resource-extraction.ts, adds read-only-operation filtering to avoid unnecessary invalidations, and updates resource-registry invalidators to target the broader *.lists() query keys (plus file storageInfo) so list views refresh reliably.

Written by Cursor Bugbot for commit d828160. This will update automatically on new commits. Configure here.

@greptile-apps

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes live-update behavior for resources (files, tables, knowledge bases, workflows) displayed in the resource main view after Mothership chat tool calls modify them. The core fix is hooking into the existing tool_result SSE handler in useChat to call invalidateResourceQueries whenever a resource-modifying tool completes successfully, so React Query re-fetches the updated data without requiring a manual refresh.

Key changes:

  • resource-extraction.ts (new): Extracts the extractResourcesFromToolResult, isResourceToolName, and related utilities from resources.ts into a dedicated client-safe module, enabling import in the browser-side use-chat.ts hook.
  • resources.ts: Refactored to re-export from the new module, keeping server-side consumers unchanged.
  • use-chat.ts: Extended the tool_result event handler to detect resource tool completions and trigger targeted query invalidation; also stores tool args for resource tools (as already done for read) to support ID extraction from params.
  • resource-registry.tsx: Switched from workspace-scoped list keys (.list(wId)) to the broader prefix keys (.lists()), ensuring all list variants — including different scopes — are invalidated when a resource changes.

Minor concerns found: the knowledge read-only tool is included in RESOURCE_TOOL_NAMES causing unnecessary cache invalidation on list reads; and when a tool result is followed by a resource_added SSE event, invalidateResourceQueries is called twice for the same resource. Direct import from resource-extraction in use-chat.ts also bypasses the established resources barrel.

Confidence Score: 4/5

  • This PR is safe to merge — changes are additive, well-scoped, and validated against all three resource types.
  • The logic is sound and the query-key changes (.list(wId).lists()) are correct. The two noted concerns (redundant double-invalidation and the read-only knowledge tool triggering refetches) are performance/style issues that don't affect correctness or data integrity. The refactoring of resources.ts is backward-compatible.
  • apps/sim/lib/copilot/resource-extraction.ts — verify the knowledge tool classification; apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts — double-invalidation path and import source.

Important Files Changed

FilenameOverview
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.tsWires live cache invalidation into the tool_result SSE handler so resource views refresh immediately; minor double-invalidation risk when resource_added also fires, and direct import bypasses the re-export barrel in resources.ts.
apps/sim/lib/copilot/resource-extraction.tsNew file extracting resource descriptor logic from resources.ts; the knowledge tool is classified as a write tool causing unnecessary cache invalidation on read-only list calls.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-registry/resource-registry.tsxSwitches query invalidation from workspace-scoped list keys (.list(wId)) to the broader prefix keys (.lists()), correctly ensuring all cached list variants are invalidated across all workspaces/scopes.
apps/sim/lib/copilot/resources.tsRefactored to re-export resource extraction utilities from the new resource-extraction.ts module; backward-compatible with no behavior change to the DB persistence logic.

Sequence Diagram

sequenceDiagram
participant User
participant useChat
participant SSEStream
participant extractResourcesFromToolResult
participant invalidateResourceQueries
participant ReactQueryCache
User->>useChat: sendMessage()
useChat->>SSEStream: POST /api/copilot/chat
SSEStream-->>useChat: tool_call event (tool_name, id, args)
Note over useChat: isResourceToolName(name)?<br/>Store args in toolArgsMap
SSEStream-->>useChat: tool_result event (id, output, success)
useChat->>useChat: Update tc.status = 'success'
useChat->>extractResourcesFromToolResult: (toolName, params, output)
extractResourcesFromToolResult-->>useChat: [{ type, id, title }, ...]
loop For each resource
useChat->>invalidateResourceQueries: (qc, workspaceId, type, id)
invalidateResourceQueries->>ReactQueryCache: invalidateQueries(lists())
invalidateResourceQueries->>ReactQueryCache: invalidateQueries(detail(id))
end
ReactQueryCache-->>User: UI re-renders with fresh data
SSEStream-->>useChat: resource_added event (optional)
useChat->>invalidateResourceQueries: (second call, same resource)
invalidateResourceQueries->>ReactQueryCache: invalidateQueries again (redundant)
Loading

Last reviewed commit: 90650be

Comment threadapps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
Comment threadapps/sim/lib/copilot/resource-extraction.ts
Comment threadapps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
@TheodoreSpeaksTheodoreSpeaks changed the title fix(ui0 Live update resources in resource main viewfix(ui) Live update resources in resource main viewMar 17, 2026
@TheodoreSpeaks
TheodoreSpeaks merged commit c867801 into stagingMar 17, 2026
12 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the fix/live-resource branch March 17, 2026 01:47
emir-karabeg pushed a commit that referenced this pull request Mar 17, 2026
* Live update resources in resource main view
* Stop updating on read tool calls
---------
Co-authored-by: Theodore Li <theo@sim.ai>
adithyaakrishna pushed a commit to adithyaakrishna/sim that referenced this pull request Mar 20, 2026
* Live update resources in resource main view
* Stop updating on read tool calls
---------
Co-authored-by: Theodore Li <theo@sim.ai>
Sign up for freeto 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

@TheodoreSpeaks