Repository navigation
Commit 8084eab
committed
fix(write-to-file): keep rollback honest when the discard itself fails
CodeRabbit Persistence Integrity on Zoo-Code-Org#1929: "In DiffViewProvider.saveChanges()
(src/integrations/editor/DiffViewProvider.ts:350-358), placeholderPath is cleared before
the awaited document save succeeds. If a new-file save fails, WriteToFileTool.execute()
only calls reset() in its catch ...; reset() clears the ownership fields without unlinking
the placeholder ... The failed operation can therefore leave an empty or partially written
new file. Also, handlePartial() ignores the rollback error returned by
discardUnapprovedStreamBeforeReset() ... so a later user save can persist that content."
Ownership now follows the write: saveChanges() releases placeholderPath only after the
approved save lands, and execute()'s catch runs the discard before reset() - the only
teardown that removes what this edit created - so a rejected save no longer leaves an
empty or half-written new file behind.
The discard failure is reported instead of dropped. Two failures get two channels: the
exception the delta produced stays the primary one (BaseTool.handle() reports it
unchanged - wrapping it would change the failure the caller sees), and the discard failure,
which is about debris still on disk, gets its own report through task.say("error", ...).
Both the streaming catch and the write teardown do this now.
Open thread 4236260447: "Abandoned create leaves the target tab open, so the placeholder
unlink orphans it. closeFileTab() skips tabs where tab.isDirty is true ... Lines 624-631
still unlink the placeholder. The user then sees an open dirty tab for a file that no
longer exists on disk ... If the user presses Ctrl+S, VS Code recreates the file with that
unapproved content." The discard now keeps the placeholder and the directories this edit
created whenever the editor work failed with the buffer still dirty, and says so in the
error it throws; when the buffer ended clean - or there was never an editor at all - the
artifacts are debris and still go.
Carried follow-up (Zoo-Code-Org#41 (comment)):
closeAllDiffViews() moved after the buffer restore inside the discard. A vscode.diff tab is
dirty while its modified side holds the streamed content and closeAllDiffViews() skips
dirty tabs, so closing first left that tab open over the file being unlinked.
Lifecycle Resource Cleanup: "A completed call then awaits createDirectoriesForFile() at
:308-309 before the cleanup boundary at :335; a filesystem error such as EACCES or EROFS
rejects execute() without calling releasePartialStreamBookkeeping()." The setup awaits are
now inside a boundary that releases this task's entry and rethrows, so the error still
travels the path it always took and nothing reports it twice.
Regression Evidence: the abort test now asserts exactly one TaskAborted registration per
task and deregisters that same function reference (expect.any(Function) passed even when a
different callback was removed), and a new liveness test replaces the state under the same
key while a delta is in flight - presence-only liveness would pass the old tests.
Negative controls (Buffer snapshots, sha256 0dbb4148ab1b5011 provider / afee0b37e8ca0ecb
tool, verified after every mutant): clearing placeholderPath before the save -> 1 red;
keepArtifacts always false -> 3 red; keepArtifacts ignoring the buffer state -> 2 red;
execute() catch not discarding -> 2 red; dropping the write-teardown report -> 1 red;
dropping the streaming report -> 1 red; wrapping the primary error instead (the shape the
review suggested) -> 1 red; setup boundary not releasing -> 1 red; liveness by key presence
-> 1 red; re-registering the abort listener per delta -> 1 red.
Local: sweep (core/tools, integrations/editor, core/task, core/webview) 97 files / 1973
passed / 5 skipped; tsc --noEmit 0 with the local @roo-code/types paths override; eslint .
--ext=ts --max-warnings=0 exit 0; prettier --check clean on all four files;
eslint-suppressions.json untouched; it( 48 -> 53 and 86 -> 90, no removals.1 parent 12ec5f8 commit 8084eab
4 files changed
Lines changed: 379 additions & 58 deletions
File tree
- src
- core/tools
- __tests__
- integrations/editor
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
| 297 | + | |
296 | 298 | | |
297 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
298 | 309 | | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
305 | 316 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
311 | 322 | | |
312 | | - | |
313 | | - | |
314 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
315 | 326 | | |
316 | | - | |
317 | | - | |
318 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
319 | 330 | | |
320 | | - | |
321 | | - | |
322 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
323 | 334 | | |
324 | | - | |
325 | | - | |
| 335 | + | |
| 336 | + | |
326 | 337 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
333 | 348 | | |
334 | 349 | | |
335 | 350 | | |
| |||
433 | 448 | | |
434 | 449 | | |
435 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
436 | 465 | | |
437 | 466 | | |
438 | 467 | | |
| |||
579 | 608 | | |
580 | 609 | | |
581 | 610 | | |
582 | | - | |
| 611 | + | |
583 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
584 | 624 | | |
585 | 625 | | |
586 | 626 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
452 | | - | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
453 | 460 | | |
454 | 461 | | |
455 | 462 | | |
| |||
600 | 607 | | |
601 | 608 | | |
602 | 609 | | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
603 | 659 | | |
604 | 660 | | |
605 | 661 | | |
| |||
955 | 1011 | | |
956 | 1012 | | |
957 | 1013 | | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
958 | 1106 | | |
959 | 1107 | | |
960 | 1108 | | |
| |||
0 commit comments