Commit 411570a
committed
fix(folders): close parent-delete race in restore, fix file-folder errorCodes
Two more findings this round:
1. Greptile P1: performRestoreFolder (workflow) and performRestoreResourceFolder
(kb/table) both resolve the target parent by reading its deletedAt inside the
transaction, but that read was a plain SELECT, not SELECT ... FOR UPDATE. A
parent could still be soft-deleted by a concurrent transaction between that
read and the restore write below it, leaving the restored folder pointing at
a now-deleted parent. Added FOR UPDATE to both reads.
Also closed the same class of gap in performReorderFolders: the target-parent
active check ran as a separate, unlocked pre-check before the closure-based
lock query introduced last round. Folded it into the closure-lock query
instead of adding a second incremental lock -- the closure query now also
selects deletedAt and re-validates every target parent resolved to an active
row only after FOR UPDATE is held on it, which is the only point where the
check is actually race-free (a row's deletedAt can't change while the lock is
held). A second, separately-ordered lock acquisition here would have
reintroduced the exact deadlock class fixed last round.
2. Cursor: performUpdateFileFolder only recognized 'Folder not found' from
updateWorkspaceFileFolder's thrown errors; the other three messages it can
throw ('Folder cannot be its own parent', 'Target folder not found',
'Cannot move a folder into one of its descendants') fell through to the
generic errorCode: 'internal' bucket, so the folder PUT route (now using
statusForOrchestrationError) returned 500 for what are actually validation
failures. Mapped all three to errorCode: 'validation'. Found and fixed the
same gap in performCreateFileFolder, which had an identical unhandled
'Target folder not found' case from createWorkspaceFileFolder.
Added a regression test for the reorder parent-delete race. Full local
verification passed (typecheck, full vitest suite 11432 tests,
check:api-validation, lint all clean).1 parent b4a55a2 commit 411570a
3 files changed
Lines changed: 91 additions & 18 deletions
File tree
- apps/sim
- app/api/folders/reorder
- lib
- folders
- workflows/orchestration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
386 | 429 | | |
387 | 430 | | |
388 | 431 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
| |||
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
233 | | - | |
234 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
235 | 246 | | |
236 | 247 | | |
237 | 248 | | |
| |||
603 | 614 | | |
604 | 615 | | |
605 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
606 | 622 | | |
607 | 623 | | |
608 | 624 | | |
609 | 625 | | |
| 626 | + | |
610 | 627 | | |
611 | 628 | | |
612 | 629 | | |
| |||
855 | 872 | | |
856 | 873 | | |
857 | 874 | | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | 875 | | |
873 | 876 | | |
874 | 877 | | |
| |||
909 | 912 | | |
910 | 913 | | |
911 | 914 | | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
912 | 921 | | |
913 | | - | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
914 | 927 | | |
915 | 928 | | |
916 | 929 | | |
| |||
921 | 934 | | |
922 | 935 | | |
923 | 936 | | |
924 | | - | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
925 | 949 | | |
926 | 950 | | |
927 | 951 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
512 | 517 | | |
513 | 518 | | |
514 | 519 | | |
515 | 520 | | |
| 521 | + | |
516 | 522 | | |
517 | 523 | | |
518 | 524 | | |
| |||
0 commit comments