Commit 7395a37
feat(copilot): open the table on the view table_views just wrote (#7166)
* feat(copilot): add create_table_view and edit_table_view
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.
* fix(copilot): address review findings on table view tools
- 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
* refactor(copilot): drop the direct view tools, pin views through table_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.
* chore(copilot): sync table view update semantics
* fix(copilot): sync table view sort item schema
* fix(copilot): persist table view pin updates
* fix(tables): reconcile agent view pins
* fix(copilot): type resource update directives
* fix(tables): serialize default view demotions
* fix(copilot): preserve view pin clear requests
* fix(copilot): serialize resource view updates
* fix(copilot): close resource persistence races
* fix(copilot): retain resource removal intent
* fix: isolate copilot resource persistence by chat
* fix(tables): restore view when returning to chat
* fix(copilot): bound resource-write locks and repair reorder persistence
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
* fix(copilot): hold a reorder for pending deletes too
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
---------
Co-authored-by: Waleed Latif <walif6@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 39307bd commit 7395a37
40 files changed
Lines changed: 2575 additions & 415 deletions
File tree
- apps/sim
- app
- api/copilot/chat/resources
- workspace/[workspaceId]
- home
- components/mothership-view/components
- resource-content
- resource-registry
- hooks
- stream
- tables/[tableId]
- hooks/queries
- lib
- api/contracts
- copilot
- generated
- request
- session
- tools
- resources
- tool-executor
- tools/server/table
- table
- application
- views
- stores/table/view-pin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | | - | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
| |||
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
46 | | - | |
| 52 | + | |
47 | 53 | | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
59 | 66 | | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
63 | | - | |
64 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
65 | 76 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 77 | + | |
69 | 78 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 79 | + | |
| 80 | + | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
88 | 98 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| |||
125 | 128 | | |
126 | 129 | | |
127 | 130 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
137 | | - | |
138 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
139 | 145 | | |
140 | | - | |
141 | | - | |
142 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
143 | 158 | | |
144 | | - | |
145 | | - | |
| 159 | + | |
| 160 | + | |
146 | 161 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 162 | | |
151 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
152 | 167 | | |
153 | 168 | | |
154 | 169 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | 170 | | |
167 | 171 | | |
168 | 172 | | |
| |||
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
214 | 202 | | |
215 | 203 | | |
216 | 204 | | |
217 | 205 | | |
218 | | - | |
219 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
220 | 212 | | |
221 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
222 | 234 | | |
223 | 235 | | |
224 | 236 | | |
225 | | - | |
226 | | - | |
227 | 237 | | |
228 | 238 | | |
229 | 239 | | |
| |||
Lines changed: 70 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
181 | 201 | | |
182 | 202 | | |
183 | 203 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
303 | 306 | | |
304 | 307 | | |
305 | 308 | | |
| |||
0 commit comments