Commit 390e1b3
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_01FwmaLmAXSK2hsPBGZmkPnT1 parent 6c6da57 commit 390e1b3
9 files changed
Lines changed: 217 additions & 64 deletions
File tree
- apps/sim
- app
- api/copilot/chat/resources
- workspace/[workspaceId]
- home/hooks
- tables/[tableId]
- lib/copilot/resources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| 64 | + | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| |||
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
| 133 | + | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
| |||
191 | 197 | | |
192 | 198 | | |
193 | 199 | | |
| 200 | + | |
194 | 201 | | |
195 | 202 | | |
196 | 203 | | |
| |||
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
1706 | 1707 | | |
1707 | 1708 | | |
1708 | 1709 | | |
1709 | | - | |
| 1710 | + | |
1710 | 1711 | | |
1711 | 1712 | | |
1712 | 1713 | | |
| |||
1721 | 1722 | | |
1722 | 1723 | | |
1723 | 1724 | | |
1724 | | - | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
1725 | 1732 | | |
1726 | 1733 | | |
1727 | | - | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
1728 | 1740 | | |
1729 | 1741 | | |
1730 | 1742 | | |
| |||
1891 | 1903 | | |
1892 | 1904 | | |
1893 | 1905 | | |
1894 | | - | |
| 1906 | + | |
1895 | 1907 | | |
1896 | 1908 | | |
1897 | 1909 | | |
| |||
Lines changed: 21 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
669 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
670 | 674 | | |
671 | 675 | | |
672 | 676 | | |
| |||
685 | 689 | | |
686 | 690 | | |
687 | 691 | | |
688 | | - | |
| 692 | + | |
689 | 693 | | |
690 | 694 | | |
691 | 695 | | |
| |||
737 | 741 | | |
738 | 742 | | |
739 | 743 | | |
740 | | - | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
741 | 759 | | |
742 | 760 | | |
743 | 761 | | |
| |||
Lines changed: 63 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
| |||
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
| 83 | + | |
85 | 84 | | |
86 | 85 | | |
87 | | - | |
| 86 | + | |
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
| |||
106 | 105 | | |
107 | 106 | | |
108 | 107 | | |
109 | | - | |
| 108 | + | |
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
| |||
125 | 124 | | |
126 | 125 | | |
127 | 126 | | |
128 | | - | |
| 127 | + | |
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
| |||
142 | 141 | | |
143 | 142 | | |
144 | 143 | | |
145 | | - | |
| 144 | + | |
146 | 145 | | |
147 | 146 | | |
148 | 147 | | |
149 | 148 | | |
150 | 149 | | |
151 | | - | |
| 150 | + | |
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
| |||
188 | 187 | | |
189 | 188 | | |
190 | 189 | | |
191 | | - | |
| 190 | + | |
192 | 191 | | |
193 | 192 | | |
194 | | - | |
| 193 | + | |
195 | 194 | | |
196 | 195 | | |
197 | 196 | | |
| |||
210 | 209 | | |
211 | 210 | | |
212 | 211 | | |
213 | | - | |
| 212 | + | |
214 | 213 | | |
215 | 214 | | |
216 | 215 | | |
| |||
220 | 219 | | |
221 | 220 | | |
222 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
223 | 270 | | |
224 | 271 | | |
225 | 272 | | |
| |||
228 | 275 | | |
229 | 276 | | |
230 | 277 | | |
231 | | - | |
| 278 | + | |
232 | 279 | | |
233 | 280 | | |
234 | 281 | | |
235 | 282 | | |
236 | 283 | | |
237 | 284 | | |
238 | | - | |
| 285 | + | |
239 | 286 | | |
240 | 287 | | |
241 | 288 | | |
| |||
0 commit comments