Repository navigation
Commit 2b5ccf7
committed
Merge upstream main 73931fe into fws/u9-task-history-delete
Four paths conflicted. The fork is real, not textual, so each one was resolved by
deciding which behaviour survives rather than by picking a side wholesale.
src/utils/safeWriteJson.ts and its test: main carries the Zoo-Code-Org#1309 replacement protocol
inside this module - the interrupted-write recovery pass, the trace stage stream that
persistenceTrace and taskMessages consume, createTempFilePath, the best-effort flush,
the single-rename commit with its EPERM two-step fallback, and a rollback that keeps the
backup so a later writer can recover. Our side replaced that body with a delegation to
services/file-safety/safeWriteText, a module main does not have. Resolving to our side
would have deleted behaviour main shipped and mains own tests assert, so the protocol
stays and our path-safety layer is grafted onto it: resolvePublishTarget under the lock,
resolveLockKey for the advisory lock key, and confineTo with ConfinedPathEscapeError
checked before any mkdir side effect, again on the lock key, and again under the lock.
Staging and all four rename sites - commit, fallback backup, fallback commit, rollback -
name the same resolved publish target, so no half-graft can leave the staged file on one
canonicalisation and the commit on another. Mains recovery, trace, flush and fallback
tests are kept verbatim, and our confinement, publish-target and lock-key tests are kept
alongside them. The mode-parity assertion our chain added is preserved by copying the
targets mode onto the staged file before the rename, which is what the commit needs
because the rename publishes the staged inode.
Two of our test variants were dropped rather than ported, and the reason is that the
mechanism they describe no longer exists: both assumed a backup copy taken before the
commit, which the single-rename protocol never does. Their observable claims - target
content intact, no leftovers, original error surfaced - are covered by the kept test
"a failed commit keeps the previous content at the target and leaves no backup behind".
TaskHistoryStore: our delete semantics (removeTaskFile reports whether the file is really
gone, and delete and deleteMany throw TaskHistoryDeleteError otherwise) stay. Main's
resurrection guarantee was then moved inside them rather than left beside them: the sweep
of a task file's .bak_/.new_ siblings now runs under the same per-file lock as the unlink,
before it, in the order jsonFileRecovery.deleteJsonFile already used, and a sibling this
store cannot collect blocks the canonical unlink instead of leaving a backup next to a file
the delete claimed to remove - a later reader's recovery pass would resurrect content this
delete was meant to destroy. isReplacementLeftover is exported from jsonFileRecovery so the
two callers share one naming rule instead of duplicating it. Main's shared helper still runs
once more after our lock releases, to collect anything a peer created in that window. When
the guard fires, the canonical file and the backup both survive, which is main's guarantee,
and the delete is reported as failed, which is this branch's contract: an item whose file is
still on disk stays in the cache rather than being contradicted by the next reconciliation.
Main's two "preserves the canonical file if backup cleanup fails" cases therefore keep both
file assertions unchanged and gain the rejection the merged contract requires; that is the
only main case whose expectation moved, and it moved because this branch exists to make
delete report per-file verdicts instead of swallowing the failure.
DiffViewProvider.spec: mains makeTaskDouble helper stays and gains the two members our
guarded save reads - task.cwd and a real in-memory observation registry - so the
suites keep using the shared double instead of three divergent inline literals.
Flagged for the maintainer thread: whichever of these branches lands first puts a fourth
implementation of services/file-safety/safeWriteText.ts into main (main has none; Zoo-Code-Org#1408
carries 1de2e57, Zoo-Code-Org#1405 7a59e9a, Zoo-Code-Org#1911 3846158, this branch 0ed4a19).
The naming and recovery contract between that module and jsonFileRecovery is open in Zoo-Code-Org#2350.
safeWriteJson also gained two things the merged protocol needed to keep its own promises:
the committed directory is fsynced best-effort after the commit rename (POSIX only, failures
logged and never fatal), and the cleanup of a staging file that the failed commit already
consumed no longer logs an ENOENT that says nothing. The post-commit durability spec was
rewritten against the mechanism that survived - failure injected on the staged write stream,
not on an open the merged protocol no longer performs - and the lock-key spec's expected call
order was corrected to the six calls this module actually issues now that no writer is
delegated to. One test mechanism moved for a reason that is worth recording: the injected cleanup failure in
"preserves the canonical file if backup cleanup fails" is pinned to the leftover's basename
rather than to the whole path, because the store re-derives the sibling path from its own
resolved and realpath'd directory, and on a Windows runner that spelling need not be
string-equal to the spelling the test created the file under. The basename of a leftover is
unique to the task file, so the injection still lands on exactly one unlink. That is what the
windows-latest leg needed: with the path-equality pin the injected EACCES never fired there,
the sweep succeeded, and delete resolved instead of reporting the blocked verdict.
The windows-latest leg failed a second time, in a different harness and for the same
underlying reason: safeWriteJson.interruption.test.ts ran 12 failures, every one "expected
WRITE_COMPLETED to contain EXIT_AT_REPLACEMENT_RENAME", because the child identifies the
commit rename by comparing the rename destination to the target as text, and that
comparison does not agree with this graft on Windows.
Measured here on the pinned runtime: fs.realpath (the async call the writer uses) expands an
NTFS 8.3 short name - C:\work\ZOO-CO~1\TMP-AL~1 resolves to
C:\work\Zoo-Code-fork\.tmp-alias-repro, one inode 673102249:1125899919173473 - while
fs.realpathSync leaves the alias alone, and only fs.realpathSync.native expands it in the
synchronous family. On a runner whose temp directory is reported as an alias the writer
publishes under the long spelling while the parent process still holds the alias spelling, so
text equality misses the commit rename; on a developer box the two spellings agree and the
suite passes. The hook now identifies the commit rename the way Zoo-Code-Org#1911 already identifies its
interception point: equal dev+ino is the same file, and when the destination is not on disk
yet (the commit of a first write) it falls back to the identity of the containing directory
plus the basename. The claim is unchanged - kill the child at the commit rename, whatever
protocol the writer uses - and the injection is no longer spelling-dependent.
Reproduced rather than inferred: with TEMP pointed at the 8.3 alias the suite runs 12 failed
before this change and 12 passed after it; with TEMP at the long spelling it runs 12 passed
both times. Full misc shard after the change on pinned v22.23.4: 119 files passed and 1
skipped (120), 2184 passed | 17 skipped. tsc 0 errors, eslint 0 at --max-warnings=0, prettier
clean, suppressions unchanged at 265 files / 2868 entries.
The consequence is recorded rather than buried: a publish target whose spelling differs from
the path the caller handed in is a contract question, not a test question. This is the third
site in the series where spelling equality turned out to be the wrong comparison - TaskHistory
Store backup cleanup, this hook, and the Zoo-Code-Org#1911 commit matcher - and Zoo-Code-Org#2356 carries the
measurement and the routing.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Review-driven repairs landed on this round (threads at head e991674):
- guardedWrite.createIfAbsent: create the directory that would hold the lock before
acquiring it. proper-lockfile builds "<key>.lock" with a non-recursive mkdir, so a
create into a directory that does not exist failed with ENOENT at lock acquisition,
before the writer reached its own mkdir -p. Measured on the pinned runtime (22.23.4):
acquireFileLock on <tmp>/missing-a/missing-b/target.json -> ENOENT; resolveLockKey of
the same path returns a key inside the missing directory and fails the same way;
after mkdir -p of that directory the identical call acquires and releases.
- guardedWrite.replaceIfVersion: hoist the lock key and re-derive it from the bound
target under the lock, as createIfAbsent already did. A key computed before the lock
does not cover a target that was repointed while the call waited, so the version
comparison could pass against the new target and the rename overwrite a writer that
held the other lock.
- guardedWrite: verify the target inside the enqueued FIFO link, so ordering between
two writes to one path is submission order, not the order in which two verifications
happened to complete. The publish helpers verify again under the lock, so only the
timing of a refusal moves, never whether it is reported.
- guardedWrite: the dangling-link refusal no longer embeds an absolute ancestor path in
a model-visible message.
- safeWriteJson: run the interrupted-replacement recovery pass against the resolved
publish target instead of the lexical spelling. Leftover names are derived from the
publish target, so for a symlink whose referent lives elsewhere the backup sat beside
the referent while the scan searched the link directory, found nothing, and the write
published over orphaned newer content. Best-effort: a link with no referent falls back
to the named path (what was always scanned) and the strict resolution still decides.
- safeWriteText._copyTargetMode: fail closed when the staged file cannot reproduce the
target mode instead of logging and publishing a wider mode over a 0o600 file. A staged
mode that already matches is still allowed, so filesystems that ignore POSIX modes do
not lose the write.
- jsonFileRecovery.deleteJsonFile / recoverMissingJsonFile: lock on resolveLockKey, the
key safeWriteJson and TaskHistoryStore lock, while still operating on the named path.
Three writers of one file were taking three different locks.
Tests: three new cases in guardedWrite.spec.ts, each shown to fail without its
implementation change (control run against the pre-edit blob: 3 failed, 68 pre-existing
cases still green; with the changes 71 passed). Two resolution-order fixtures in
safeWriteJson.lockKey.spec.ts record the extra in-lock resolution the recovery target
now needs; their claims (lock key is the referent, the strict rejection happens inside
the protected block so the lock is released) are unchanged, and both cases fail again
when the recovery-target hunk is folded back. One alias containment case now pins the
lock-key double to the canonical referent, the same line the other alias cases set.
Gates at this commit: misc 2184 passed | 17 skipped (120 files, 0 failures), core 4411
passed | 9 skipped (200 files, 0 failures), interruption harness 12 passed with TEMP at
the NTFS 8.3 alias and 12 passed with TEMP at the long spelling, tsc --noEmit 0 errors,
eslint --max-warnings=0 clean, prettier --check clean, knip reports nothing but scratch
files removed before this commit, eslint-suppressions.json unchanged at 265 files / 2868
entries (no count rose on any touched file). No Stryker directive added; no local
Stryker preflight run for this push, and mutation-diff on this PR is advisory cap-class,
not a new directive.216 files changed
Lines changed: 13129 additions & 1957 deletions
File tree
- .github/workflows
- apps/vscode-e2e
- src
- restart
- suite
- visual
- __screenshots__
- docs
- architecture
- locales
- ca
- de
- es
- fr
- hi
- id
- it
- ja
- ko
- nl
- pl
- pt-BR
- ru
- tr
- vi
- zh-CN
- zh-TW
- packages
- config-eslint
- types/src
- scripts
- src
- api/providers
- __tests__
- utils
- __tests__
- assets/marketplace
- core
- config
- __tests__
- message-manager
- task-persistence
- __tests__
- task
- __tests__
- tools
- __tests__
- webview
- __tests__
- extension
- __tests__
- integrations
- editor
- __tests__
- kimi-code/__tests__
- misc/__tests__
- performance
- terminal/__tests__
- streamUtils
- theme
- __tests__
- services/tools
- __tests__
- test-utils
- utils
- __tests__
- webview-ui
- playwright/gallery
- src
- __tests__
- components
- chat
- __tests__
- __screenshots__
- history
- __tests__
- settings
- __tests__
- __screenshots__
- context
- i18n/locales
- ca
- de
- en
- es
- fr
- hi
- id
- it
- ja
- ko
- nl
- pl
- pt-BR
- ru
- tr
- vi
- zh-CN
- zh-TW
- utils
- __tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
| |||
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
159 | 177 | | |
160 | 178 | | |
161 | 179 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 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 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
3 | 77 | | |
4 | 78 | | |
5 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
0 commit comments