Commit f2c305f
committed
fix(folders): row-lock restore reads, map conflict errorCode to 409
Three more review findings this round:
1. statusForOrchestrationError never mapped errorCode: 'conflict' to a
status, so it silently fell to 500. The folders PUT route (rename
conflicts) and the restore route (file-folder name conflicts) both used
this default, turning a legitimate 409 into a misleading 500. Added the
conflict -> 409 case, matching the sibling workspaceFilesOrchestrationStatus
mapper that already had it.
2. Switched the folders [id] PUT/DELETE routes and the restore route from
their bespoke inline errorCode->status ternaries to the shared
statusForOrchestrationError helper, now that every orchestration failure
branch they consume sets an explicit errorCode (verified branch by
branch) -- this was deliberately deferred in an earlier commit until that
was true. Also closed two errorCode gaps this surfaced: the
archived-workspace check in performRestoreFolder (workflow) had no
errorCode, and performRestoreFileFolder's catch-all didn't recognize the
'Cannot restore folder into an archived workspace' message, so it was
being mapped to a generic 500 by the previous commit's internal-error
fallback.
3. Greptile: performRestoreFolder's (workflow) and performRestoreResourceFolder's
(kb/table) restore-transaction reads of the folder's own locked/deletedAt
columns were plain SELECTs, not SELECT ... FOR UPDATE -- being inside the
same transaction as the write closes the round-trip race but not this one,
since a plain read doesn't block a concurrent UPDATE from another
transaction. Added FOR UPDATE to both, matching the existing
restoreKnowledgeBase precedent. The file-folder restore path doesn't need
this: it already takes a workspace-scoped pg_advisory_xact_lock that the
lock-toggle path also acquires, so it was already race-free.1 parent 9df6dff commit f2c305f
5 files changed
Lines changed: 33 additions & 13 deletions
File tree
- apps/sim
- app/api/folders/[id]
- restore
- lib
- folders
- workflows/orchestration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
| |||
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
167 | 170 | | |
168 | 171 | | |
169 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
324 | 327 | | |
325 | 328 | | |
326 | 329 | | |
| |||
529 | 532 | | |
530 | 533 | | |
531 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
532 | 539 | | |
533 | 540 | | |
534 | 541 | | |
| |||
539 | 546 | | |
540 | 547 | | |
541 | 548 | | |
| 549 | + | |
542 | 550 | | |
543 | 551 | | |
544 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
481 | 485 | | |
482 | 486 | | |
483 | 487 | | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
484 | 492 | | |
485 | 493 | | |
486 | 494 | | |
487 | 495 | | |
| 496 | + | |
488 | 497 | | |
489 | 498 | | |
490 | 499 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
0 commit comments