feat(copilot): open the table on the view table_views just wrote - #7166
Conversation
Direct main-agent tools for saved table views. create_table_view takes a table id (optional name, config, isDefault) and returns the view id; edit_table_view takes a view id plus a config patch and resolves the owning table from the view. Both results name the table and view, so the resource panel opens the table pinned to that view, and an already-open table switches to it once its views list carries the id (view-pin store). viewId now rides the resource stream descriptor and chat-resource persistence so the pin survives reopening the chat.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
✅ Cross-repo companion checkAll declared companion PRs are merged into
|
Greptile SummaryThe PR connects table-view tool operations to chat resources so affected views open and restore correctly, while serializing related persistence and default-view writes.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts | Propagates table-view selections and clears into both resource state and the one-shot table pin store. |
| apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts | Coordinates chat-resource persistence and resets pending view pins during chat teardown and switching. |
| apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx | Restores a table-view pin when refreshed chat metadata supplies a selected view after mount. |
| apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx | Consumes valid pending pins once the embedded table and its view list are ready. |
| apps/sim/app/api/copilot/chat/resources/route.ts | Serializes authenticated resource mutations and merges explicit view-selection clears transactionally. |
| apps/sim/lib/api/contracts/mothership-chats.ts | Reuses the canonical Copilot resource body schema so clearViewId survives validation without contract drift. |
| apps/sim/lib/table/views/service.ts | Routes every explicit default-state write through the shared per-table advisory lock. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Tool[table_views operation] --> Event[Resource update]
Event --> Persist[Persist chat resource viewId]
Event --> Pin[Pin selected table view]
Persist --> Hydrate[Reopen or refresh chat]
Hydrate --> Pin
Pin --> Table[Embedded table adopts view]
Reviews (15): Last reviewed commit: "fix(copilot): hold a reorder for pending..." | Re-trigger Greptile
There was a problem hiding this comment.
All reported issues were addressed across 38 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
- edit_table_view resolves the view's table under a workspace-only context (no table scope exists yet for the delegated principal), then re-enters the table-scoped read and update with that id - updateTableView takes the per-table views lock when promoting, so it serializes with default-on-create instead of racing the unique index - the View N fallback is chosen inside the locked create - unknown column names are classified as validation errors in the shared translation, so the model sees which column it got wrong - pending view pins are reset when a chat is torn down or switched - add and reorder share one chat-resource item schema; reorder merges incoming entries with stored ones so pins and paths survive - mergeChatResource keeps every field the newcomer defines - the pin merge runs for every pinned upsert, not gated on wasAdded
…e_views Views stay with the table subagent's multiplexed table_views; the orchestrator delegates as before. Its create/update/set-default results now name the table and view they wrote, and resource extraction turns that into the pinned table resource, so the panel opens (or switches) the table on that view. Unknown column names are classified as validation errors, and create_view's isDefault lands in the same locked transaction as the insert. The stream/persistence plumbing for viewId, the pin store, and the lock on default promotion are unchanged.
|
@cubic-dev-ai review this PR |
@j15z I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 28 files
Confidence score: 3/5
- In
apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts, when the table already exists in chat,addResource(resource)returns false without issuing the POST, so this path only updates React state and reopening the chat can restore an old or missingviewId; persist the merged resource server-side.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts">
<violation number="1" location="apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts:129">
P2: When the table already exists in the chat, `addResource(resource)` returns false and performs no POST. This block only changes React state, so reopening the chat restores the old or absent `viewId`. Persist the merged resource for existing tables too.</violation>
</file>
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@j15z I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 37 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Re-trigger cubic
|
@cubic-dev-ai review this PR |
@j15z I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 37 files
Confidence score: 3/5
- In
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts, the pin effect can drop a transition when the URL already contains the pin while a different local view creation is pending, leaving the pending state uncleared and the view transition unapplied; applytransition.pendingCreatedViewIdbefore handlingnextViewId.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts">
<violation number="1" location="apps/sim/app/workspace/[workspaceId]/tables/[tableId]/view-state.ts:69">
P1: When the URL already contains the pin but a different local creation is pending, the pin effect drops this transition before clearing the pending ref. Apply `transition.pendingCreatedViewId` before the `nextViewId` early return so view resolution does not remain blocked on the old creation.</violation>
</file>
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@j15z I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 37 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@j15z I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 40 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Fix all with cubic | Re-trigger cubic
Review follow-ups on the saved-view pinning work. Correctness: - Reorder persistence was parked by ANY pending write. A repeatedly failing update to an already-stored resource (a view pin) blocked tab ordering for the rest of the session; gate on unpersisted writes only, which are the ones the server's identity check can actually reject. - A parked reorder body that the server rejects was re-parked verbatim, so a tab closed after the order was captured poisoned it permanently. Discard on 400; keep retrying everything transient. - adoptScope merged the provisional and chat-scoped updates in the wrong order, letting an older pending write overwrite a newer one. - A view pin that arrived before the table finished its first adoption was dropped for good when the table data resolved after the views list. The stream path self-rescued through query invalidation; the restore path did not. Re-run the effect when adoption becomes possible. - Reordering a chat holding a legacy duplicate row 400'd forever. Compare identity sets so the duplicate collapses on write instead. - mergeChatResource aliased the caller's object into React state, the query cache and the pending-write queue at once. Copy it. Robustness: - The new copilot_chats FOR UPDATE transactions had no lock_timeout, and neither the pool nor the deployment sets one. finalizeAssistantTurn holds that same row across an assistant-message append, so a waiter could park a pool connection indefinitely. Bound all five writers. - mergeChatResource's field list is now one declaration that fails to compile when MothershipResource gains a field, rather than silently dropping it from both the merge and its no-op check. - Extraction can no longer emit viewId and clearViewId together, a pair the wire contract rejects and the merge would resolve to neither. - Restrict the eager view-id URL write to embedded tables, leaving standalone table behaviour identical to staging. - Drop the queue's unreachable unscoped bucket, its uncalled clear(), and its test-only getPendingUpdates(). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FwmaLmAXSK2hsPBGZmkPnT
The reorder gate landed one case short: a delete that has not reached the server leaves the server holding a resource the client's order omits, so the order fails its identity check exactly as an unlanded add does. Gating only on unpersisted adds let that order fire and be discarded as unsatisfiable, losing the tab order until the next reorder or hydration. Name the predicate for what it actually decides — whether a pending write changes WHICH resources the chat holds — and cover both directions. A failing update to an already-stored resource still does not park the order, which is what the gate was narrowed for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FwmaLmAXSK2hsPBGZmkPnT
|
@greptile review |
Summary
table_viewswrite operations to the resource panel so it opens on the view they affectedType of Change
Testing
bun run lintbun run lint:checkbun run apps/sim/scripts/check-block-registry.ts origin/stagingbun run check:audits— 44 audits passingChecklist
Screenshots/Videos
Not included; this changes restored selection behavior without changing the table's visual design.
Companion: simstudioai/mothership#461