@vzn/vx 0.0.640 → 0.0.642

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/launcher.sh +9 -2
  2. package/package.json +5 -12
  3. package/skills/vx/SKILL.md +4 -4
  4. package/src/bin.ts +8 -6
  5. package/src/cache/archive.ts +735 -107
  6. package/src/cache/cache.ts +133 -29
  7. package/src/cache/fold-memo.ts +58 -0
  8. package/src/cache/git-inputs.ts +213 -31
  9. package/src/cache/index.ts +9 -2
  10. package/src/cache/inputs.ts +244 -108
  11. package/src/cache/key-fold.ts +90 -69
  12. package/src/cache/layer.ts +9 -7
  13. package/src/cache/layered-cache.ts +74 -9
  14. package/src/cache/output-index.ts +25 -4
  15. package/src/cache/remote-lane.ts +27 -10
  16. package/src/cache/schema.ts +13 -3
  17. package/src/cache/scoped-cache.ts +11 -3
  18. package/src/cache/umask.ts +29 -0
  19. package/src/cli/docs.ts +71 -7
  20. package/src/cli/help.ts +11 -5
  21. package/src/cli/plan-format.ts +4 -1
  22. package/src/cli/run.ts +10 -3
  23. package/src/cli/select.ts +2 -0
  24. package/src/cli/upgrade.ts +37 -2
  25. package/src/cli/watch-filter.ts +1 -6
  26. package/src/cli/watch-fs.ts +2 -1
  27. package/src/exec/runner.ts +5 -0
  28. package/src/exec/sandbox-runtime.ts +81 -1
  29. package/src/graph/priorities.ts +14 -1
  30. package/src/handoff.ts +5 -0
  31. package/src/history/history.ts +43 -33
  32. package/src/index.ts +11 -1
  33. package/src/orchestrator/deferred-outputs.ts +3 -2
  34. package/src/orchestrator/execute-task.ts +20 -14
  35. package/src/orchestrator/hit-restore.ts +111 -29
  36. package/src/orchestrator/index.ts +1 -0
  37. package/src/orchestrator/local-shortcircuit.ts +8 -0
  38. package/src/orchestrator/lockfile-claim.ts +54 -8
  39. package/src/orchestrator/miss-save.ts +27 -17
  40. package/src/orchestrator/output-host.ts +9 -1
  41. package/src/orchestrator/plan.ts +4 -0
  42. package/src/orchestrator/plugin-host.ts +35 -5
  43. package/src/orchestrator/plugin.ts +29 -3
  44. package/src/orchestrator/prepare.ts +74 -5
  45. package/src/orchestrator/projects.ts +6 -1
  46. package/src/orchestrator/run-report.ts +30 -9
  47. package/src/orchestrator/run.ts +62 -38
  48. package/src/orchestrator/sandbox-request.ts +1 -48
  49. package/src/orchestrator/save-lane.ts +17 -10
  50. package/src/orchestrator/signals.ts +7 -10
  51. package/src/orchestrator/stable-keys.ts +83 -25
  52. package/src/orchestrator/task-hash.ts +46 -12
  53. package/src/report/events.ts +12 -0
  54. package/src/report/framed-output.ts +2 -1
  55. package/src/report/logger.ts +58 -15
  56. package/src/report/status-line.ts +45 -4
  57. package/src/report/summary.ts +11 -6
  58. package/src/util/errors.ts +1 -1
  59. package/src/util/hidden-prompt.ts +74 -0
  60. package/src/util/index.ts +13 -0
  61. package/src/util/paths.ts +58 -5
  62. package/src/util/secrets.ts +150 -0
  63. package/src/workspace/affected.ts +63 -13
  64. package/src/workspace/config-eval.ts +2 -2
  65. package/src/workspace/config-schema.ts +37 -3
  66. package/src/workspace/project-loader.ts +6 -4
  67. package/src/workspace/workspace.ts +17 -11
  68. package/docs/caching.md +0 -2352
  69. package/docs/cli.md +0 -3280
  70. package/docs/execution.md +0 -675
  71. package/docs/features.md +0 -178
  72. package/docs/patterns.md +0 -219
  73. package/docs/schema.md +0 -2461
  74. package/docs/security.md +0 -252
  75. package/src/cli/docs-corpus.ts +0 -21
  76. package/src/cli/docs-text.d.ts +0 -5
package/docs/caching.md DELETED
@@ -1,2352 +0,0 @@
1
- # Caching
2
-
3
- `@vzn/vx`'s cache is content-addressed, opt-in per task, and shaped to
4
- cascade through the dependency graph the same way Turborepo's does.
5
- This page explains _what's in the cache key_, _what triggers
6
- invalidation_, _what's actually stored_, and _why_.
7
-
8
- ## Why caching is opt-in
9
-
10
- A task is cached iff its `TaskConfig` provides a `cache` block, with
11
- `cache.outputs.files` and the task's `inputs.files`. Omit `cache` and
12
- the task always runs; no read, no write. `inputs` stands alone: a task
13
- is keyed on it whether it caches or not, and its dependents fold that
14
- key.
15
-
16
- The reasoning:
17
-
18
- - **Defaulting caching ON with implicit globs leads to silently stale
19
- builds.** The first time a user forgets to revisit their config to
20
- add an input, the cache returns a hit for an out-of-date snapshot.
21
- Stale hits are the worst failure mode of a task runner — they erode
22
- trust in the cache itself.
23
- - **Forcing declaration makes "what does this task read?" and "what
24
- does it produce?" conscious choices.** The user pays a one-time
25
- cost (write the globs) for a permanent gain (the cache key actually
26
- reflects reality).
27
- - **The cost of a forgotten cache miss is small.** A task re-runs.
28
- The cost of a stale cache hit is large. Asymmetric risk justifies
29
- asymmetric defaults.
30
-
31
- Turbo defaults caching ON for `outputs: []` tasks; Nx requires you to
32
- opt _out_ via `cache: false`. We chose the strictest of the three.
33
-
34
- ## Cache key derivation
35
-
36
- Core keys no package file: no `package.json`, lockfile or install
37
- setting is a part of its own. A `package.json` keys a task as an input
38
- it lists (step 10), a lockfile or install setting as a plugin's key
39
- material (step 9); `@vzn/vx-lockfile`'s `pnpm()`, `bun()`, `npm()` and
40
- `yarn()` add both. Without a lockfile plugin an install moves no key, so
41
- a JS workspace declares one (`vx init` and `@vzn/vx-migrate` write it).
42
-
43
- The cache key for one task is a **16-hex xxHash3 digest**, seed-chained
44
- over (in order):
45
-
46
- 1. **`CACHE_VERSION`** — the key-derivation sentinel
47
- (currently `'vx-cache-v43'`, in `src/cache/key-fold.ts`). Bumped when
48
- the key derivation or the artifact container changes, or stored bytes
49
- are wrong under an unchanged key. See
50
- [§ Bumping CACHE_VERSION](#bumping-cache_version).
51
- 2. **`taskId`** — `${projectName}#${taskName}`. Two tasks with
52
- identical everything else still produce distinct keys — protects
53
- against e.g. `pkg-a#build` accidentally cache-hitting on a
54
- `pkg-b#build` entry.
55
- 3. **Task config hash** — `xxh3(JSON.stringify(hashableConfig(node.config)))`
56
- of the _evaluated_ task config. The projection is one field wide:
57
- `exec.remote` is dropped, because it says WHERE a task runs and not
58
- what it does (§ What's NOT in the key). Captures:
59
- - `exec` block (command, env declarations, timeout, persistent).
60
- - `dependsOn` and `inputs.tasks` declarations.
61
- - `cache.outputs.files`, `inputs.files`, `inputs.env`,
62
- `inputs.runtime` / `workspaceRuntime` declarations (the
63
- strings themselves; their resolved file content / env values /
64
- command output contribute separately).
65
- - `description` (because it's part of the resolved object — even
66
- though it has no behavioural effect; a description change isn't a
67
- correctness change but the cost of a re-run is low).
68
- - **Imported / computed values** — anything a preset or
69
- `process.env`-read at config-load time injected. Bun's native
70
- `await import()` evaluates the module and bakes those values into
71
- the object before we serialize.
72
- 4. **`forwardArgs`** — CLI args passed after `--`. Folded into the
73
- key so `vx run test -- --watch` doesn't cache-hit a previous
74
- `vx run test`. Scoped to the user-requested tasks only — dependsOn-
75
- pulled deps don't see them (their cache identity stays clean) — and
76
- to a command: a requested default `build` runs none and folds none
77
- (X-119).
78
- 5. **`inputs.env` resolved values** — `[name, value]` pairs
79
- read from host `process.env` at hash time (delimited `name\0value`
80
- so boundaries are unambiguous). Listed names get their current
81
- values; an unset name folds its bare name, with no `\0`, so unset
82
- and set-to-empty are two keys (the child tells them apart:
83
- `passThrough` leaves an unset name out). A name holding a NUL is
84
- refused at load.
85
- 6. **`inputs.runtime` resolved output** — `[command, output]`
86
- pairs, where `output` is the trimmed stdout of each command run via
87
- `sh -c` in the **project dir** at hash time; a command with stderr
88
- (or a NUL in stdout) folds `\0<stdout length>\0<stdout><stderr>`,
89
- so bytes moved between the streams move the key.
90
- The runtime-output analog of step 5: the command _strings_ are in
91
- the resolved config (step 3), their _output_ is resolved live every
92
- run. Folded with the command count + each `command\0output` pair.
93
- 7. **`inputs.workspaceRuntime` resolved output** — same as step
94
- 8 but commands run at the **workspace root**, and the pairs fold
95
- into a **distinct namespace** (`ws-runtime-values:`) so an identical
96
- `(command, output)` never aliases the project-cwd `runtime` values.
97
- 8. **Filtered upstream task cache hashes** — every upstream task's
98
- own cache key, filtered by `inputs.tasks` (default: all of
99
- them). Sorted by hash before folding so the ordering of `dependsOn`
100
- doesn't change the key. This is the cascade mechanism: if anything
101
- beneath you changes, your hash changes too. The set is `dependsOn`'s,
102
- never the run's selection: a dependency `--exclude-dependencies`
103
- keeps from running is still folded, with the key a full run would
104
- derive for it (nx#35234), so the flag moves no key. Its outputs are
105
- whatever is on disk, which nothing proves current, so a task whose
106
- key folds one, and everything built on it, may hit but does not
107
- save (`orchestrator/excluded-keys.ts`); a task with
108
- `inputs.tasks: []` folds none and saves as usual.
109
- 9. **Plugin key material** — the `{ name: value }` pairs a plugin's
110
- `key(task, ctx)` stage returned for this task, stored on the node as
111
- sorted `plugin/name` pairs and folded after the upstream keys and BEFORE the input files,
112
- ONLY when non-empty — so a workspace with no `key` plugin derives
113
- byte-identical keys to one before the stage existed (no
114
- `CACHE_VERSION` bump when it shipped). `vx why` names a changed pair
115
- as `plugin <plugin>/<name>`. Two plugins of one package (a plugin's
116
- name is its package's) that return one name are told apart as
117
- `<name>`, `<name>#2`, … in value order, so declaration order still
118
- keys nothing (item 1028).
119
-
120
- A plugin that reads a root file claims it (`VxPlugin.fingerprint`).
121
- `@vzn/vx-lockfile`'s `pnpm()` folds the project's own resolved
122
- dependency closure from `pnpm-lock.yaml` and the root package's, so
123
- `pnpm update foo` re-keys only the projects that depend on `foo` —
124
- every project when the root does, since the root's tools run from the
125
- root `node_modules/.bin` on every task's PATH; `bun()`, `npm()` and
126
- `yarn()` are the same for their lockfiles (`npm()` reads
127
- `npm-shrinkwrap.json` over `package-lock.json`, as npm does; `bun()`
128
- refuses a `bun.lockb` with no `bun.lock`, which it cannot read), and
129
- this repo declares `bun()`. Each also claims its manager's install
130
- settings (`pnpm()`: `pnpm-workspace.yaml`, `.npmrc`; `bun()`:
131
- `bunfig.toml`, `.npmrc`; `npm()`: `.npmrc`; `yarn()`: `.yarnrc.yml`)
132
- and folds each whole into every task.
133
-
134
- The run reads each claimed root file once, before any task. A task
135
- in the root project may rewrite one — `pnpm install` without
136
- `--frozen-lockfile` updates the lockfile and the installed tree — and
137
- every key taken before it names the old one. So a task that may
138
- (unsandboxed in the root project, or granted a write over one) tells
139
- the run when its command ran, the run re-checks the claimed files
140
- then (one `stat` each, following a symlink as both reads do — an
141
- `lstat` missed a lockfile rewritten through a link, item 760 — the
142
- bytes compared for any written since the read), and once one moved
143
- nothing keyed on the old bytes is probed or saved for the rest of the
144
- run, with one status line naming the file. Every reader after such a
145
- task is keyed late, not up front. Without it the run after a lockfile
146
- rewrite restored a build made against the old install, and a save
147
- filed a build against the new install under the old lockfile's key,
148
- replayed whenever the tree went back (item 750,
149
- [`modules/fingerprint-watch.md`](./modules/fingerprint-watch.md)).
150
- With nothing claimed, no root file is read or watched.
151
-
152
- 10. **Input files' content hashes** — `inputs.files` resolved to
153
- a concrete list of project-relative paths (gitignore-aware,
154
- declared-outputs-excluded, nested-projects-excluded), each file
155
- contributing its **git blob OID** (v20). On a clean tree the OID
156
- comes straight from the index — the run's up-front enumeration is
157
- three concurrent spawns, `git ls-files -s -v -z` (every tracked
158
- path, its OID and its cache-state flag),
159
- `git status --porcelain -z -uall --ignored=matching --no-renames`
160
- (dirty tracked paths, the untracked files and the ignored ones) and
161
- `git var -l` (the clean-filter gate's config) — so deriving these hashes
162
- costs zero file reads and zero per-file stats. Each trusted OID's
163
- blob must be the size the index recorded for the file (A-60): `git
164
- add` under a clean filter (`core.autocrlf=true`, a `text` rule)
165
- stores the LF blob of a CRLF file, and once the filter is gone git
166
- holds that stat-clean entry clean without re-reading it, so status
167
- and the filter gate (today's config) both let the LF blob key the
168
- CRLF bytes. Which paths an index distrusts is a function of its
169
- entries, so the verdict is kept in `blob_verdicts` by a hash of
170
- the index file and the pathspecs: a warm run reads the file and
171
- one row (the `--debug` listing and a lookup per entry cost 550 ms
172
- at 100,000 files). The key stands only for an index written before
173
- the run began and still in place after its listing, so a `git add`
174
- between the two cannot pair one index's verdict with the other's
175
- entries; any other run checks every blob. A changed index spawns
176
- `git ls-files -s -v -z --debug` for the recorded sizes, takes each
177
- blob's size from `blob_sizes` (fixed for its OID), and asks one
178
- `git cat-file --batch-check` for the ones not yet known (65 ms
179
- over 3,000 loose objects, 10 ms packed). The check is by size,
180
- so a filter that keeps the size (a `filter` driver such as
181
- `tr a-z A-Z`), removed after an add, still leaves a blob that
182
- stands for other bytes: probed, the run hit the build of the
183
- filtered bytes. Only a read of every trusted file would catch it,
184
- the cost the index OIDs exist to avoid. After changing a filter,
185
- `git add --renormalize .` makes the index describe the worktree
186
- again. A
187
- re-listing mid-run, or a nested repository's project, spawns
188
- `git ls-files -s --others --exclude-standard -z .` in the project
189
- dir instead, and its OIDs are not trusted: those files hash by
190
- content. `--no-renames`, because status pairs a deleted file with a
191
- similar unmerged path (a conflict mid-resolve) as its rename source
192
- and prints only `UU <path>`: the deletion went unsaid, the file kept
193
- its index OID, and the run hit the output built with it (A-59).
194
-
195
- Ref storage is not a key input: every ref vx reads comes from a git
196
- command, so a repository in reftable storage (git 2.45) keys every
197
- task as its files-backend twin. A sha256 repository keys from its
198
- 64-hex index OIDs, and a dirty file is hashed in-process as sha256,
199
- so Git 3's defaults (reftable and sha256 together) run, hit and
200
- select `--affected` as a sha1 repository does
201
- (`tests/git-reftable.unsafe.test.ts`).
202
-
203
- A **submodule or an embedded repository** is enumerated by its own
204
- git: the workspace repository lists the nested one as a single entry
205
- (a gitlink, or `dir/` when untracked) and none of its files, so vx
206
- replaces that entry with the files `git ls-files` lists inside it
207
- (one spawn per nested repository per run, nested ones recursively),
208
- and those files hash by content rather than by index OID. That holds
209
- for a nested repository inside a project (`vendor/lib` under a
210
- `**` glob — until 2026-09-27 its files never reached the key, and an
211
- edit there was a hit on the old output), for a project inside one,
212
- and for a `workspaceFiles` glob. A gitlink whose directory has no
213
- `.git` (a submodule never initialised, or one whose `.git` was
214
- removed to vendor its files, the gitlink left in the index) has no
215
- repository to ask and `git status` says nothing of it: its files
216
- are listed by a walk and hash by content (A-61), so an empty one
217
- folds nothing. `--affected` follows the
218
- same shape — git reports the nested repository as one changed path,
219
- and every project under it is selected.
220
-
221
- A task with **no `cache` block** derives a key too, from its
222
- `inputs` — its dependents fold it (step 8), as Turbo and Nx hash
223
- every task. That key is for its dependents only: the task always
224
- runs, and no cache, local or remote, is asked about or handed
225
- anything under it; its log goes to the run's own store
226
- (`run/<id>/<task>/log`). A lookup follows `cache`, never a key
227
- (`tests/uncached-no-lookup.test.ts`). One that also declares no
228
- `inputs` is **keyless**: no
229
- key can stand for what it read, so a key that folds it is this
230
- run's alone, and every task behind it misses and saves nothing.
231
- A task reading `**` with no `cache` folds its own outputs too,
232
- since it declared none: its key moves whenever it writes a file
233
- git does not ignore, so a cached dependent misses once more after
234
- the upstream's first run. Ignore the outputs in git, narrow its
235
- `inputs`, or declare the block (`tests/uncached-upstream-key.test.ts`).
236
-
237
- Declaring no outputs, such a task may also have **written** anywhere
238
- in its project, so what the run learned about that project at its
239
- start — the git listing and the index OIDs — is dropped once its command exits, pass or fail, and a later key
240
- re-lists and hashes by content. For the same reason a task after it
241
- in the same project (`dependsOn`, even with `tasks: []`) is never
242
- keyed up front by the local short-circuit or the remote prefetch.
243
- Without both, an uncached `gen` that copies a seed into a `build`'s
244
- declared `config.json` replayed seed B's build under seed A
245
- (turborepo#13788, item 743). A sandbox narrows the reach to its
246
- write grants: none reaches nothing, and a grant elsewhere in the
247
- workspace reaches every project. An unsandboxed write into another
248
- project crosses a project boundary and is not tracked, as for a
249
- cached task's undeclared write (`tests/undeclared-writes.test.ts`).
250
-
251
- A task **with** a `cache` block may still rewrite its own inputs in
252
- place — a formatter declaring `outputs: []` — and a same-project
253
- reader after it whose key does not fold its key (`tasks: []`, or a
254
- filter that leaves it out, on every path) is not keyed up front
255
- either: its key would be taken over the bytes before the rewrite, and
256
- seeds A,B,B,A replayed B on the fourth run (item 750). A reader that
257
- folds the rewriter's key keeps its up-front probe — that key names
258
- the rewriter's inputs, which are what it may rewrite. A cached task
259
- writing a file that is neither a declared output nor its own input
260
- is out of contract: a hit restores only what it declared.
261
-
262
- A file whose name is **not valid UTF-8** (Linux allows any byte
263
- but `/` and NUL) cannot be opened from a string, so it cannot be
264
- hashed: a task whose globs select one is refused by name, and so
265
- is a task whose declared outputs hold one, rather than the file
266
- dropping out of the key or the artifact without a word
267
- (turborepo#9345). Rename it, or exclude it with a negated glob.
268
-
269
- Your globs are a **filter over the set git reports**, so a broad
270
- glob never reaches a gitignored file. An entry that names one
271
- outright does: a literal (`.env.local`, `gen`), or a glob whose fixed
272
- prefix git ignores (`dist/**`), walked on disk under that prefix
273
- only (owner, 2026-10-16). Such a file is hashed from disk with the
274
- blob formula an untracked file gets, and is never stored or
275
- restored. `--affected` reflects only what git sees, so an edit to
276
- one never selects a task on its own (as in Nx); `vx watch` re-runs
277
- it on an edit there.
278
- A **glob** matching nothing stays silent, and so does a literal
279
- naming a path that does not exist, until it does. An ignored
280
- directory named outright folds every file under it; an empty one
281
- folds nothing.
282
-
283
- A **bracket is literal** in a task glob, and there are no character
284
- classes (item 667): `app/[id]/**` folds the route directory
285
- `app/[id]`, and `app/\[id\]/**` is the same path. Read as a class
286
- — what `Bun.Glob`, Turbo and Nx do — it matched `app/i/…` and never
287
- the route, so the route's files keyed nothing (an edit replayed the
288
- old output, green) and an output declared under it cleaned an
289
- unrelated `app/i/page.js` before every run while the artifact
290
- saved nothing.
291
-
292
- An index OID is only trusted where git stores the worktree bytes
293
- **verbatim**, so the enumeration prunes it three ways:
294
- `git status --porcelain` drops paths whose working tree diverges;
295
- the `-v` flag on the same `ls-files` spawn drops `skip-worktree` /
296
- `assume-unchanged` entries, whose OID says nothing about what is
297
- (or isn't) on disk; and, once those spawns return, a clean-filter
298
- gate (a `git check-attr` spawn only when the gate needs one) drops paths where `text` / `eol` / `ident`,
299
- a `filter` driver, `working-tree-encoding`
300
- or `core.autocrlf` can rewrite bytes between index and worktree
301
- (the blob would be the LF-normalized form while the task reads the
302
- CRLF file). The gate costs nothing in a repo with no attributes
303
- and no `core.autocrlf` — see "Clean filters" below. And when the
304
- repository's config weakens the stat `git status` judges by —
305
- `core.trustctime=false`, or `core.checkStat=minimal` (whole-second
306
- mtime and size) — no index OID is trusted at all: a same-size
307
- rewrite that keeps its mtime (`cp -p`, `tar -x`) reads clean to
308
- git, and until 2026-09-27 (A-6) kept the old bytes' key. Every file
309
- is then hashed through the memo below, which keys on ctime and
310
- inode.
311
-
312
- Every pruned path, plus untracked files, falls back to an
313
- in-process `HASH("blob " + len + "\0" + content)` over the
314
- **worktree bytes** (sha1, or sha256 in `--object-format=sha256`
315
- repos), memoized in `file_hashes` on `(mtime, size, ctime, ino)`.
316
- A file changed within `FILE_HASH_RACY_MS` (50 ms) of its stat is
317
- hashed but not memoised; a ctime with no sub-second part, as a
318
- file system that keeps whole seconds writes it (ext3, HFS+,
319
- FAT/exFAT, some NFS), widens that window by a second, and an even
320
- second by two, since FAT32 keeps even seconds; a rewrite later in
321
- the same stamp keeps it (`racyWindowMs`; until 2026-09-27, A-2 and
322
- A-38, such a rewrite of the same size was a hit on the first bytes'
323
- output). Every such window compares a file's stamp, on its file
324
- system's clock, with a moment vx read from its own, so a run first
325
- measures how far the file system runs behind (one file written and
326
- removed in the cache dir) and widens every window by a lag past the
327
- kernel's tick (20 ms): a WSL2 VM drifted from the Windows host that
328
- stamps `/mnt/c`, a Docker Desktop bind mount or an NFS server dated an
329
- edit made while a command ran before the command, and the entry
330
- filed the edit's output under the old bytes' key (until 2026-10-16).
331
- That is the same value the index holds whenever no filter applies,
332
- so a file's contribution doesn't flip across dirty↔clean
333
- transitions. Folded as `(relPath, identity)` pairs, sorted for
334
- stability across OSes and walk orders. The identity is the OID
335
- prefixed by the file's git mode unless that mode is a plain
336
- file's: `100755:<oid>` for an executable, `120000:<oid>` for a
337
- symlink, the bare OID for 100644. The index gives the mode for a
338
- clean file, and the stat gives it for any other file (owner
339
- execute bit). A blob OID holds no mode, so until item 887 a
340
- `chmod +x`, or a symlink swapped for a file holding its target
341
- string, kept the key that `git status` and `--affected` saw move.
342
- Under `core.fileMode=false` (WSL's DrvFs) git reports no chmod, so
343
- there a clean file's mode comes from an lstat too, and its OID
344
- from the index (item 1076).
345
-
346
- A **symlink** folds as git folds it, the blob of its target
347
- _string_ (its mode-120000 index OID), and then the content behind
348
- it, as Nx reads a linked file where it points: a file's identity, or
349
- for a directory every file beneath it at any depth, tracked or not
350
- (`.git`, `node_modules`, `.vx/cache` and `.yarn/cache` aside, as Nx's walker skips them), a link
351
- among them followed in turn. The target may be anywhere: in the
352
- project, elsewhere in the workspace, outside it. Retargeting a link
353
- changes the key, to equal bytes too; an edit behind it changes the
354
- key. A dangling link, or a loop of links, keys its target string
355
- alone. `--affected` selects a link whose target changed (a file
356
- the diff names, or one under a linked directory) as a changed path of
357
- its project, and a target git cannot diff (outside the workspace,
358
- git-ignored) on every run; `vx watch` arms each link's target and
359
- names the link when it changes (`linked-inputs.ts`). Nx does not
360
- enter a linked directory; vx does, since the task reads it.
361
-
362
- The composition is seed-chained (`xxh3(part, prevDigest)`) with a
363
- label prefix per field, so two different field layouts can't collide.
364
- Bun's xxHash3 reads only the low 32 bits of a seed, so `xxh3` feeds the
365
- seed forward (`xxHash3(part, seed) ^ seed`) and the chain carries all 64
366
- bits of state from step to step (item 682; `tests/hash-chain.test.ts`).
367
- xxHash3 is non-cryptographic by design — cache keys need uniqueness
368
- across honest inputs, not adversarial collision resistance.
369
-
370
- ## Cache lookup → restore
371
-
372
- On a hit:
373
-
374
- 1. `cache.get(hash)` is **pure SQL**: the `entries` row carries the
375
- metadata and the captured stdout; the `output_files` rows carry the
376
- output fingerprints. The tar artifact is not touched by the probe
377
- (its existence is verified with one stat), so hit cost doesn't
378
- scale with artifact size.
379
- 2. If the on-disk output tree already matches the cached snapshot
380
- (size + mode + **millisecond**-mtime check against `output_files`),
381
- extraction is skipped entirely — the outcome reports **up-to-date**
382
- (`restored: false`). Mode and millisecond mtime ride the artifact's
383
- own `.vx-meta.json` sidecar — recorded from a stat while packing —
384
- so the index rows and the restored tree carry the identical values
385
- whether the entry was saved locally or ingested from a remote, and
386
- the comparison is exact in steady state. The check also requires the
387
- file's inode and ctime to equal the ones this machine recorded after
388
- the save or restore that last wrote it (`recordOutputStamps`). Size,
389
- mode and mtime alone cannot tell two entries apart when their
390
- outputs carry one fixed mtime (`tar -x`, `cp -p`, `SOURCE_DATE_EPOCH`)
391
- and one size: a v1 → v2 → v1 round trip reported up-to-date with v2's
392
- bytes on disk (item 886). No task can set a ctime, and a forged mtime
393
- (`touch -r`) moves the ctime too. The inode proves less than it
394
- seems: a restore unlinks the file and renames a new one in, and ext4
395
- hands the new one the freed inode (measured, item 941), so ctime is
396
- the guard. A row with no stamp (an ingest from a remote, or a file
397
- that had changed when the stamp was taken) is never current: the hit
398
- restores and stamps. The residual: ctime ticks on the kernel's coarse
399
- clock (4 ms at HZ=250), so a same-size rewrite inside the tick of
400
- vx's own write, in place or as a new file that took the same inode,
401
- with its mtime forged back, still matches.
402
- 3. Otherwise the task's declared outputs are wiped from the project
403
- dir (`cleanOutputs`) — see
404
- [§ Strict output ownership](#strict-output-ownership) — and the
405
- `outputs/<rel>` (+ `workspace-outputs/<rel>`) entries are extracted
406
- from the artifact into place: its bytes inline in the index, read in
407
- one read transaction with the entry's rows, or `<cacheDir>/<hash>.tar.zst`.
408
- 4. Captured stdout is replayed to the live terminal via the logger —
409
- the framed block looks like a fresh run. (stderr is not cached —
410
- only successful runs are cached and their stderr is near-always
411
- empty; live runs still stream stderr normally.)
412
- 5. The task is marked `cache-hit` (or `cache-hit-remote` when the
413
- `LayeredCache` hydrated from the remote layer this run);
414
- `durationMs` is the wallclock for the restore op, not the original
415
- exec time.
416
-
417
- The cached `exitCode` is preserved. A cached non-zero exit is
418
- impossible by construction — see [§ Cache write](#cache-write) — and
419
- "by construction" is literal: neither `save` nor `ingest` accepts an
420
- `exitCode` at all, so the stored value is pinned to `0` rather than
421
- supplied. The restore path still checks it, because the column outlives
422
- this process: a row from a hand-edited or foreign `cache.db` with a
423
- non-zero exit classifies the hit `failed` instead of restoring a broken
424
- build's outputs under a green run.
425
-
426
- ### Local restore tier (two-tier scheduler)
427
-
428
- `dependsOn` is an ordering gate, so a dependent normally can't even
429
- probe the cache until its upstream finishes running. But a
430
- **stable-key** task's key is provably independent of any upstream's
431
- _outputs_ — its hit/miss status is knowable up front, and restoring
432
- it needs none of its deps' output. So on local-only runs, `run()`
433
- performs an up-front CLASSIFY (`orchestrator/local-shortcircuit.ts`):
434
-
435
- 1. Derive every stable, cacheable, local-read task's key (reusing the
436
- run's `hashCache` memo) and probe local `cache.get` **once**,
437
- building a `preProbed` map covering stable hits AND stable misses.
438
- 2. Confirmed hits become the **restore tier**: the scheduler makes
439
- them ready immediately (no dep gate, and no failed-dep→skip check —
440
- their key is dep-success-independent) but at LOW priority, so cache
441
- **misses own the worker pool and restores only backfill idle
442
- capacity**.
443
- 3. `execute-task` consumes `preProbed`, so the up-front probes ARE the
444
- probes it would have done, hoisted — no double work, and every task
445
- still flows through `execute()` so output is unchanged.
446
-
447
- Stability gate (shared with remote prefetch via
448
- `stable-keys.ts:deriveStableKeys`): a task whose input globs could
449
- match a same-project upstream's declared `outputs.files` (compared by
450
- literal prefix, less what its own `!` inputs take back whole; one with
451
- undeclared writes reaches every input), whose
452
- own `outputs.files` meet another same-project task's (it would restore
453
- into that tree beside the producer's restore), or whose
454
- `inputs.workspaceFiles` could reach any upstream's outputs, has a
455
- _preliminary_ key and stays exec-tier / dep-gated. **Any**
456
- `outputs.workspaceFiles` producer upstream also makes a dependent's key
457
- preliminary, whatever that dependent reads: a root-anchored output is
458
- boundary-ignoring by design, so it can land inside the dependent's own
459
- project dir, where an ordinary project-relative glob reads it. Such a
460
- dependent is therefore in NEITHER tier — it is excluded from probe
461
- reuse as well as from the restore tier, because `execute-task` reuses a
462
- `preProbed` hash verbatim, so probe reuse is itself a stale-hit path
463
- when the key is preliminary. On top of that, an `outputs.workspaceFiles`
464
- declaration keeps every task whose project directory its static prefix
465
- can reach out of the restore tier — edge or no edge, because a
466
- root-anchored output can land in any project's directory — and every
467
- transitive dependant of one with it (their up-front keys fold a
468
- preliminary key); a glob with no literal prefix reaches every project.
469
- Before item 584 one such declaration emptied the tier graph-wide.
470
- `vx lock` refuses a task whose input globs can match another task's
471
- declared outputs (X-54, no opt-out), unless git ignores those outputs
472
- whole (and the entry does not start inside them) or the producer is a
473
- dependency its key does not fold, whose bytes it then hashes after the
474
- producer ran, so the clauses on declared outputs fire only for such a
475
- dependency read or a pair the check cannot decide. An output git ignores whole is no reach either:
476
- a key reads only what git lists, so a `**/*` reader beside a gitignored
477
- `**/dist/**` producer keys up front, the same key before and after the
478
- build. The run asks git once, beside its walk and only when a reader
479
- reaches a same-project output: one `git check-ignore` over each such
480
- output's directory (`dist/`, and a fresh `__vx_probe__/dist/` for a
481
- glob that starts with `**`), and the walk's listing must hold no file
482
- the glob matches (a tracked output, a directory a `!` rule takes back);
483
- anything git cannot answer keeps the key late. Undeclared writes, an
484
- `outputs.workspaceFiles` producer upstream, a rewriter the key does not
485
- fold, and runtime probes after a writer still leave a key preliminary.
486
- The
487
- short-circuit never runs under a `LayeredCache` (remote prefetch owns
488
- those runs — an up-front `get` there would put remote GETs on the
489
- critical path), never fires with local reads off or on a local cache
490
- that holds no artifact (`Cache.holdsNothing`: every probe would miss,
491
- and a cold 1,090-package run started its first task ~90 ms sooner
492
- without it), and never throws —
493
- any error degrades to the normal lazy schedule. Measured: −6.6% on a
494
- mixed slow-upstream/warm-downstream workload; parity on all-hit warm
495
- runs.
496
-
497
- ### Remote prefetch (async, remote-only)
498
-
499
- When a run is backed by a remote cache — a plugin's `cache` capability
500
- or an injected `RunOptions.remoteCache` layer — the network latency of
501
- every remote GET
502
- would otherwise sit on the critical path of the task that needs it.
503
- So before execution starts, `run()` kicks off **background prefetches**:
504
-
505
- 1. Every cacheable task's key is derived once, up front, in
506
- topological order (reusing the run's `hashCache` memo, so
507
- `execute-task`'s later `computeTaskHash` for the same task hits the
508
- memo — no double hashing). This derivation touches **no cache layer**
509
- — keys only.
510
- 2. Each **stable-key** task's remote GET is fired concurrently under a
511
- bounded pool (the run's concurrency). The prefetch ingests a hit
512
- into the _local_ cache; misses/errors degrade to `false`.
513
- 3. Execution starts immediately — the prefetches race alongside it, so
514
- remote latency overlaps real work instead of blocking it.
515
- 4. When `execute-task` later calls `cache.get(hash)`, the `LayeredCache`
516
- **awaits the already-in-flight (resolved-or-pending) prefetch** for
517
- that key rather than starting a fresh round-trip: **at most ONE
518
- remote GET per key**, whether it was served by the prefetch, the
519
- lazy read-through, or both.
520
-
521
- ## A current tree: when a warm hit restores nothing
522
-
523
- A hit whose outputs are already on disk should cost a few stats, not an
524
- extraction. Two checks decide, both against rows the cache recorded when
525
- the tree last matched the entry (`output_files`, and since 2026-09-03
526
- `output_dirs`):
527
-
528
- 1. **The set.** The files under the declared output globs must be exactly
529
- the entry's files — no strays, nothing missing — because a restore
530
- wipes and rewrites the declared outputs, and a stray left in place
531
- would be a stale file the hit silently kept. Until Wave 6 this was a
532
- glob walk on every hit (0.36 ms each; 365 ms of CPU on a warm
533
- 1000-project run). Now, for globs of the shape `<dir>/**` or a bare
534
- literal `<dir>` (a whole subtree — `wholeSubtreePrefixes`; a literal
535
- that names a file is recorded as a file, `mtime_ms` -2, and holds while
536
- a regular file stands there, its bytes being the per-file check's),
537
- the cache records every directory
538
- under `<dir>` with its mtime after each save and restore; on the next
539
- hit, unchanged mtimes on all of them prove the set unchanged, since a
540
- file added or removed anywhere the glob could see bumps its parent
541
- directory, and a new directory bumps the recorded directory that
542
- contains it. The rows are taken per task and written together — one
543
- transaction at the first read, at prune, at stats or at close, since
544
- item 622; a thousand commits at run end were the whole snapshot stage
545
- before — and a reader in the same process flushes them first. A
546
- save's or restore's snapshot is taken at run end, once the directories
547
- are past the racy window, and by then a later task or another process
548
- may have written into them: the walk collects the files it passes and
549
- records nothing unless they are the entry's rows (item 1087). Any other glob shape (`**/*.js`, `dist/*`), a missing
550
- row set (a remote ingest records none), a moved directory, or more
551
- than 8,192 directories (`OUTPUT_DIRS_CAP`) keeps the walk — and a walk that proves the tree
552
- current records the directories so the following hit can skip it.
553
- 2. **The files.** Every recorded file's `(size, mode, mtime-ms)` must
554
- match. This never left: the directory rule only replaces the
555
- enumeration, not the fingerprint.
556
-
557
- The trade is the one every mtime-based skip accepts, already documented
558
- for files: a deliberately forged directory mtime (`touch -r`) hides a
559
- stray. Both directions are pinned in `tests/output-dirs.test.ts`.
560
-
561
- Hard invariants of the remote prefetch:
562
-
563
- - **Remote-only.** This entire path is gated on a `LayeredCache` being
564
- configured. A local-only run never prefetches; its up-front keys and
565
- local probes are the short-circuit's (§ Local restore tier). The
566
- prefetch never adds an upfront _local_ `get` / `isOutputsCurrent` /
567
- stat pass.
568
- - **Stable keys only.** A task with a _preliminary_ key (§ Local
569
- restore tier's stability gate: undeclared writes, an
570
- `outputs.workspaceFiles` producer upstream, or input globs that match
571
- the outputs of a dependency the key does not fold) is not prefetched: its key would name the wrong
572
- artifact, and it resolves via the lazy read-through in `execute-task`. Instability propagates: a task that folds an
573
- unstable upstream is itself unstable. When in doubt, skip.
574
- - **At most once.** The `LayeredCache` keeps an in-flight map keyed by
575
- hash; `prefetch` and `get` share it, and a settled `false` (remote
576
- miss) prevents a second lazy probe of the same dead key.
577
- - **Provenance preserved.** A hash pulled from remote — even when a
578
- later `get` finds it as a now-local hit — still reports
579
- `source: 'remote'`, so the outcome is `cache-hit-remote`.
580
- - **A remote-read-off policy** (`--no-cache`, `--force`, or
581
- `--cache-policy=remote:`) fires no prefetch. With remote writes on
582
- (`--force`), the same up-front keys go to one `hasMany` per remote
583
- the run writes but does not read and that can batch, in the
584
- background: no task waits for it, only each upload does. An upload
585
- of a key that remote holds is skipped (an entry is immutable) and is
586
- counted nowhere. A key the probe did not cover, or a remote with no
587
- `hasMany`, asks `has` for that key inside its upload job; a probe
588
- that fails uploads, as before.
589
- - **No `has` before a `put`.** An entry is immutable: a remote's `put`
590
- of a key it holds keeps the stored bytes, and a wire that would
591
- overwrite checks inside (`turboCache()` asks HEAD unless a 404 or a
592
- batch answer this run said the key is absent; `reapi()` looks the
593
- action up beside its upload and keeps a stored result; Nx servers
594
- answer 409). `ctx.cache.put` and a run's own entries send the `put`
595
- alone.
596
- - **`--dry` batches too.** The plan derives every key first, then asks
597
- each remote with `hasMany` once; a remote without it is asked `has`
598
- per key.
599
- - **Never fail.** Every remote path (get / put / ingest / prefetch)
600
- catches all errors and degrades to a cache miss. A remote 500, a
601
- network drop, a corrupt artifact, or a failed integrity check can
602
- never fail a run.
603
- - **Said once, and said whole.** The warning names the operation
604
- (`probe`, `download`, `upload`), the artifact and the layer's
605
- `endpoint`, with a URL's credentials, query and fragment dropped:
606
- `upload <hash> to <endpoint> failed: HTTP 413`. One failure class
607
- (the error's `code` when it has one, else its message with the hash
608
- taken out) is said once per run, and the repeats are counted at
609
- close: `2 more requests failed the same way: <cause>`.
610
-
611
- ### Remote uploads (background, drained at run end)
612
-
613
- Writes go to the local cache synchronously; the **remote PUT is a
614
- fire-and-forget background upload**. The task's outcome (and its
615
- dependents) never wait on upload latency — the uploads race alongside
616
- the rest of the run and are drained before `cache.close()`, so a
617
- short run still ships every artifact before the process exits. Upload
618
- failures are warned once per failure class and are otherwise ignored (the task
619
- already succeeded; the only loss is the remote entry).
620
-
621
- An upload is the outputs as the task wrote them; secret masking does
622
- not reach file contents, so a task whose outputs embed a secret is one
623
- to leave uncached ([security](./security.md)).
624
-
625
- ### Planning probes (`--dry`)
626
-
627
- The planning path (`vx run --dry`) predicts hits without
628
- side effects: against a remote cache they use a **lightweight
629
- existence probe** — no artifact download, no local ingest. A predicted
630
- `hit-remote` means the artifact exists remotely; the bytes move only
631
- when a real run needs them. Locally the probe reads whether the entry's
632
- row is there and stats the artifact, never the row itself: the whole
633
- row, its stored stdout included, made a 200-task plan over 1 MB outputs
634
- 230 ms against 28 (min of 11, 2026-10-02).
635
-
636
- ## Cache policy (read/write axes)
637
-
638
- Caching is controlled by a four-axis `CachePolicy` — **localRead**,
639
- **localWrite**, **remoteRead**, **remoteWrite** — independent toggles,
640
- each enforced inside the matching cache layer at construction time. The
641
- local `Cache` gets a `{ read, write }` slice gating its task artifact
642
- get/save and the file-hash memo's writes (never `recordRun` / `stats` / `prune` / ingest
643
- / key derivation); the `LayeredCache` additionally gates its own remote
644
- read-through (`remoteRead`), upload (`remoteWrite`), and prefetch
645
- (`remoteRead`). The orchestrator derives two booleans per task:
646
-
647
- - `willRead = task has a cache block AND it is not remote-only AND it folds no keyless task AND (localRead || remoteRead)`
648
- - `willWrite = task has a cache block AND it is not remote-only AND (localWrite || remoteWrite)`
649
-
650
- A task reads the cache only when `willRead`, saves only when
651
- `willWrite` and it folds no keyless task, and cleans its declared outputs
652
- before exec only when `willWrite`. A keyless task runs a command and
653
- declares no `inputs`: its key is unknown, so a task that folds it
654
- (through `dependsOn`, directly or through a group) always misses. Remote-only is an `exec.remote: 'only'` task placed on a
655
- remote executor: it never touches this machine's disk (no probe, no
656
- restore, no output clean, no local save), and its result lives in the
657
- remote executor's own store.
658
-
659
- The CLI maps three flags to a policy (precedence: start all-on → apply
660
- `--cache-policy` → `--no-cache` forces all off → `--force` forces both reads
661
- off): `--no-cache` = everything off (no read, no write, no output
662
- clean); `--force` = reads off / writes on (re-execute, outputs cleaned;
663
- a key already stored, locally or in a remote, is kept as it is); `--cache-policy=<spec>` = explicit per-layer control.
664
- Off CI, unless a spec names the remote, `remoteWrite` starts off: a key
665
- holds only declared inputs, so a laptop's undeclared tool or file could
666
- replay on CI. See `docs/cli.md` § Cache control.
667
-
668
- The setup we recommend for a shared remote: the write token only in the
669
- default branch's CI (a protected environment), a read-only token on
670
- laptops and in pull request jobs, and `cache.scope` (`github()` sets it)
671
- so a PR's own writes, when its token allows them, land apart. The token
672
- is the boundary; the policy and the scope are the client's half
673
- (`docs/security.md` § Cache poisoning).
674
-
675
- One subtlety: when `localWrite` is off but `remoteWrite` is on
676
- (`--cache-policy=local:,remote:rw`), there's no on-disk artifact for the
677
- `LayeredCache` to read before uploading — so it packs the tar.zst bytes
678
- in memory (`Cache.packArtifactBytes`) and uploads those.
679
-
680
- ## Cache write
681
-
682
- A miss runs the task. If the final exit code is `0` and the task's
683
- `willWrite` is true (it has a `cache` block AND at least one write axis
684
- is on):
685
-
686
- 1. `cache.outputs.files` (and `outputs.workspaceFiles`) are resolved
687
- against the project dir / workspace root.
688
- 2. The per-component input fingerprint is the one captured before the
689
- command ran: on a miss `describeTaskInputs` fills `captureInto` once
690
- (the same call yields the key re-checked below), so no second
691
- `computeTaskHash` runs.
692
- 3. The artifact — one `stdout` entry (bounded: the first and last 8 Mi
693
- characters of the task's output, the dropped middle named where it was), the `outputs/<rel>` (+
694
- `workspace-outputs/<rel>`) entries, the `.vx-meta.json` sidecar and
695
- the `.vx-sum` checksum — is packed in-process (no staging dir, no subprocess) into a
696
- single `<hash>.tar.zst` and validated. One of at most 32 KiB
697
- compressed (`INLINE_MAX`, almost every artifact: a one-file `dist/`
698
- is a few hundred bytes) stays in memory; a larger one is written to a
699
- temp name.
700
- 4. One `BEGIN IMMEDIATE` SQLite transaction upserts a small artifact's
701
- bytes into `artifacts` (v33), or renames a large one into place and
702
- deletes the key's inline bytes, and upserts the `entries` row (taskId, command, exit code,
703
- duration, size, stdout, timestamps), the `output_files` fingerprint
704
- rows, and the entry's one `entry_inputs` row (`INSERT OR IGNORE`).
705
- Concurrent readers see either no entry or a complete entry — never a
706
- partial one — and bytes and rows go live together: the rename waits
707
- for the write lock, so no other writer's rows land beside it, and a
708
- commit that fails takes the artifact back out (the key then misses).
709
- Until 2026-09-27 (A-3) the rename came first, and a commit refused
710
- past the busy timeout left the new bytes beside the old rows: every
711
- later hit on the key failed the task as a corrupt artifact.
712
- A `--force` save of a key the index already holds is skipped, so
713
- `--force` rewrites nothing. A re-save (a key dropped as corrupt, or
714
- two writers that both found it absent) first moves the previous
715
- artifact aside under
716
- a temp name and unlinks it after the commit: ext4 flushes the
717
- incoming file when a rename replaces one, 0.55 ms a save on the main
718
- thread against 0.04 (a forced 1,000-task run 4.01 s → 3.46 s,
719
- 2026-10-02). A reader probing between the two renames misses.
720
- An inline save moves aside whatever file its key has, the same way
721
- (a rename that finds nothing on a first save, in place of a statement
722
- asking the index). As of every commit a key's bytes are in one place,
723
- and a reader takes the inline bytes first, so a file an older vx
724
- wrote beside them is never read and the sweep takes it. An inline save writes no file at all: no temp, no rename,
725
- and a crash leaves nothing behind (the bytes and the rows are one
726
- transaction in one database file).
727
-
728
- **The key is re-checked before the save** (item 743). It was taken
729
- before the command ran — at the task's start, or up front by the local
730
- short-circuit — and the save files the outputs under it, so the inputs
731
- must still be what it describes. Two checks, in order. The key
732
- re-derived just before the command (`describeTaskInputs`, which the
733
- executor seam needs anyway) must equal it. Then each input file is
734
- `lstat`ed once: a file whose ctime falls
735
- after, or within `FILE_HASH_RACY_MS` before, the moment its digest was
736
- learned — the enumeration's start for an index OID, the describe for a
737
- hashed file — is hashed again and compared, and a file that is gone has
738
- moved. A file written at or after the describe (just before the command)
739
- has moved whatever it holds (a whole-second stamp counts as any moment
740
- of its second, an even one of two, in both checks): an input changed and changed BACK while the
741
- command ran matched its digest again, and its output, built from the
742
- edit, was filed under the key and restored over the original (item
743
- 1015). When one moved, the task's result stands but no entry is saved,
744
- one status line names the file (``[vx] app#format: `packages/app/a.ts`
745
- changed after its key was taken — …``), and the run forgets what it
746
- knew about the project, as after an uncached task (§ Cache key
747
- derivation, step 10). This covers a formatter rewriting its own input
748
- (turborepo#10111) and a user's edit mid-run (turborepo#1146). A task
749
- left remote (`--cache-download=none`) is held to the same checks: a moved
750
- key still lets a local consumer fetch its outputs, but the fetch saves
751
- no entry; until X-123 it saved them under the old key. A task
752
- that rewrites its own input to the SAME bytes (`sed -i` always writes)
753
- is not saved either: its write cannot be told from an edit reverted
754
- mid-run, so it pays a re-run each time rather than risk a stale entry;
755
- declare what it writes as an output, which the status line says when it
756
- names a file other than `package.json` (TanStack Router's committed
757
- `routeTree.gen.ts`, rewritten by every build). That holds on CI too: a
758
- task of the same project running alongside can change an input and put
759
- it back. A task that rewrites its own input to identical bytes (tsdown's
760
- `package.json`) sets `cache.inputStability: { strategy: 'mutable' }`, and a write
761
- during its command is then judged by its bytes, as an earlier write is;
762
- different bytes still withhold the entry, and so does a write made while
763
- another command that may write the file ran (`command-windows.ts`: one
764
- in the same project, or one with a write grant elsewhere in the
765
- workspace), named on the line as `while <task> ran`. `VX_CACHE_INPUT_STABILITY_STRATEGY=mutable`
766
- makes that the default (owner, 2026-10-12); `'unchecked'` skips the
767
- check, and `severity: 'error'` fails the task instead of warning
768
- (`docs/schema.md`). A file ADDED under an
769
- input glob since the listing the key filtered (`addedInput`) withholds
770
- the save the same way, named on the same line: the listing's
771
- directories a glob reaches are `lstat`ed, one whose ctime moved since
772
- the listing is read, and a new name the declaration matches (or an
773
- unlisted directory) is asked of git, which alone knows what is ignored;
774
- a literal input absent then and present now is asked too. Not seen: a
775
- file added inside a directory that held no listed file before (only
776
- ignored ones, or none) and was not itself created mid-run. Cost: one
777
- `lstat` per input and per reached directory on a miss that saves, a
778
- `readdir` per directory that changed, and a `git ls-files` only when a
779
- candidate turned up; a hit runs no command and checks nothing.
780
- A file listed but gone before the key hashes it (an upstream that
781
- deletes a file its dependant's globs match) is keyed as absent, not
782
- read: the dependant failed as `internal error … ENOENT` on every run
783
- until A-55. Absent stays unmoved while it stays gone.
784
- Its dependants whose keys fold its key save nothing either,
785
- transitively: that key does not name the bytes they built from (`[vx] app#use: ran
786
- over app#gen's outputs, which its key no longer describes — …`). Until
787
- 2026-09-27 (A-12) they saved, and once the input was put back they hit
788
- the edit's output.
789
- A claimed root file a task rewrote since the run read it (§ Cache key
790
- derivation, step 9) withholds the save the same way, and no key
791
- taken before it is probed or restored: a hit the up-front probe found
792
- goes back to the scheduler and runs once its deps are done. Until X-124
793
- that hit restored the old install's bytes.
794
-
795
- A miss that ran here and saves **nothing** — it failed, the cache
796
- policy writes nothing (`--cache-policy=local:r,remote:r`), an upstream failed
797
- under `--continue` — runs the same input re-check and, when an input
798
- moved, forgets the project as above; otherwise its declared outputs are
799
- resolved and marked in the git snapshot exactly as a save marks them.
800
- Before item 750 only a save marked them, so a same-run reader keyed
801
- from the snapshot's index OID for an output (or for an input the task
802
- rewrote) restored the bytes from before the command.
803
-
804
- A declared set that resolves to **nothing** is said on the run's
805
- status line. `inputs matched no files (lib/**)` — the key would
806
- not change when the source does — is said on every miss of a cacheable
807
- task, right after `describeTaskInputs` and before the command, whether
808
- or not it saves. `cache.outputs matched no files (build/**)` — an empty
809
- artifact was saved and a later hit restores nothing — is said on the
810
- save path. Both are almost always a glob
811
- against the wrong directory; the output line names one other cause when
812
- it applies: a sandboxed task with no `exec.sandbox.allow.write`, whose
813
- writes never reached disk, or a `workspaceFiles` directory that is a
814
- symlink out of the workspace, whose files vx drops as outside (a project
815
- output directory linked out of the project refuses the task instead, X-88). `outputs.files: []` is a deliberate cached
816
- no-op and says nothing; a task with no `cache` block is never checked.
817
-
818
- **The outputs are what exists when the task's command exits.** The run
819
- waits for the command's own process, not for everything it started — a
820
- backgrounded grandchild that still holds the output pipe does not hold
821
- the run (`tests/runner.test.ts`) — and the save resolves the output
822
- globs at once. A descendant the command detached (`setsid … &`, a
823
- daemon) that writes after that is not in the artifact: the entry saves
824
- what was there, often nothing (with the `cache.outputs matched no
825
- files` line), and the next hit's clean-before-restore removes what the
826
- descendant wrote and restores the saved entry in its place (upstream
827
- survey, turborepo#12786). vx does not wait for it and cannot see it: a
828
- process that left the task's session is outside the process group vx
829
- tracks and signals ([kill-tree](./modules/kill-tree.md)). So a command
830
- finishes writing its outputs before it exits — `wait` for what it
831
- backgrounds, or do not detach it.
832
-
833
- If the task exits non-zero, **nothing is cached.** This is deliberate:
834
-
835
- - Caching a failure prevents retry flows. The next run gets the same
836
- failure even after the user fixes the underlying cause (the inputs
837
- haven't changed, so the cache key matches).
838
- - Failures should be transient by default — flaky tests, network
839
- blips, transient resource exhaustion shouldn't bake into the cache.
840
-
841
- Failed-task stdout / stderr still reach the user via the live stream
842
- and the framed failure block replayed at run end. The `runs` table
843
- records the failure (status + exit code) for analytics.
844
-
845
- ## Strict output ownership
846
-
847
- Declared `cache.outputs.files` are wiped in two distinct places:
848
-
849
- - **Before exec on a cache miss.** A leftover `dist/old.js` from a
850
- prior build can't survive into a fresh build that doesn't rewrite
851
- it.
852
- - **Before restore on a cache hit.** The post-restore tree is the
853
- cached snapshot byte-for-byte. Hand-edits to output files don't
854
- persist through a cache replay. When the hit's own check walked the
855
- output globs to find the tree stale, the clean deletes from that walk's
856
- list instead of walking again: nothing is awaited between them (X-161).
857
-
858
- Both branches use the same `cleanOutputs` helper (`src/cache/inputs.ts`)
859
- with the same boundary rules, and vx's own paths stay off the wipe
860
- whatever the glob: `.git`, `.vx` and each `vx.lock.json` (`OUTPUT_NEVER`;
861
- `.vx` holds the workspace config and the lock, which a clean deleted and a
862
- hit restored stale while `.vx/cache` alone was listed). `node_modules` is
863
- off it too unless a glob names it (`node_modules/**`, an install task's
864
- legitimate output); until 2026-09-27 (A-13) `**/*.js` cleaned every
865
- installed `.js`, and a `workspaceFiles` output glob reached even `.git`.
866
- No clean deletes a file git tracks (owner, 2026-10-14). Under an output
867
- glob it is still an output: the task may rewrite it (TanStack Router's
868
- committed `routeTree.gen.ts`), the artifact saves the bytes the run left,
869
- and a restore writes them. It also stays in the task's key, even under its
870
- own output glob, so an edit moves the key and the saved bytes follow from
871
- it; the task's rewrite is no input that moved mid-run. Until then the
872
- clean deleted a committed file under an output, and a reader with no edge
873
- to its producer failed naming only the file (A-48, vueuse's
874
- `metadata/index.json`). Untracked files under the glob are cleaned as
875
- before. Paths compare as
876
- git compares them: case-folded under `core.ignorecase` (macOS), and a
877
- file inside a submodule counts as committed.
878
- Workspace outputs take the same rules, and a path an output `!` entry
879
- takes back (A-44) is off the wipe, the artifact and the restore alike.
880
- Skipped when:
881
-
882
- - `cache.outputs.files` is empty (nothing declared as output).
883
- - The task's `willWrite` is false — no write axis is enabled (e.g.
884
- `--no-cache`, or a read-only `--cache-policy=local:r`). The user is debugging
885
- and managing the tree, so vx leaves it alone. `--force` keeps writes
886
- on, so it DOES clean (the saved snapshot must be clean).
887
- - `cache.outputs.clean` is `false` (on the task, else the workspace's
888
- `cache.outputs.clean`): the command sees last run's outputs (tsc's
889
- `.tsbuildinfo`). You opt out of the clean-tree guarantee: the save
890
- stores every file the outputs match after the run, so a leftover from
891
- an older build is cached and restored everywhere. A retry cleans as
892
- usual; a hit still cleans before its restore.
893
-
894
- A declared output the process cannot remove (a `dist/` another user
895
- wrote, a read-only checkout) fails the task with `cannot remove declared
896
- output <path>: EACCES — …`, and a restore that cannot write into such a
897
- directory with `restore of <hash> into <dir> could not write its outputs
898
- (EACCES: …)`: the environment's failure, reported plainly, never as an
899
- internal error or a corrupt artifact.
900
-
901
- Why so strict? Turbo and Nx restore additively — files from a prior
902
- state can survive. We've seen this cause:
903
-
904
- - Wrong test runs (a deleted-but-resurrected snapshot file from a
905
- cache miss survives a hit and now your test passes against the
906
- wrong baseline).
907
- - Wrong shipped artifacts (a deleted source-mapped file from a prior
908
- build sits in `dist/` alongside the new bundle).
909
-
910
- The strict-ownership behavior makes the project dir post-run a pure
911
- function of the cache key.
912
-
913
- ### Additive outputs: two tasks, one tree, an edge between them
914
-
915
- Two cached tasks whose declared outputs overlap are refused at graph
916
- build. By default that holds even when one depends on the other: the
917
- workspace rule `rules.exclusiveOutputs` (on unless set to `false` in
918
- `.vx/workspace.ts`, X-53) keeps one path to one task, and its refusal says
919
- how to turn it off. The shape below is correct, only slower: a stamp
920
- before every run, a diff after, and a clean by rows. Give each task its
921
- own output path where you can (`dist-individual` beside `dist`).
922
-
923
- With the rule off, an edge fixes the order, and the dependant is
924
- **additive** (item 588): twenty's
925
- `build` fills `dist` and `build:individual` depends on it and writes
926
- `dist/individual`; strapi's `build:types` runs `tsc` into the same
927
- `dist` as `build`. For the dependant:
928
-
929
- - its **own output set** is what its run added or changed under its
930
- declared outputs — the outputs are stamped (size, mtime, inode, ctime) before the
931
- run and diffed after, the same proof a hit's "already current" check
932
- trusts — and only that set is saved; `outputs.workspaceFiles` are
933
- stamped the same way (until A-43 its miss cleaned them by glob, deleting
934
- a same-tree upstream's root-anchored files before it read them);
935
- - a run that **removes** a file it found (a bundler deleting the
936
- upstream's intermediate) saves nothing: an artifact holds what a run
937
- wrote, never what it took away, and the upstream's restore puts the
938
- file back, so the dependant runs again on every warm run (X-32);
939
- - it **cleans by recorded rows**, never by glob, before a run (nothing:
940
- stale files of its own are its command's to clean, as under Turbo) and
941
- before a restore (its rows only, pruning emptied directories only
942
- inside its declared trees, so a sibling's fresh directory stays);
943
- - its "already current" check requires its rows present and current and
944
- ignores everything else under the glob;
945
- - it is **never restore-tier**: it restores or runs after its upstream,
946
- by the edge.
947
-
948
- The upstream keeps strict ownership of its glob — a miss or a restore
949
- wipes the whole tree, the dependant's additions included, and the
950
- dependant restores or runs after — and its "already current" check
951
- ignores strays a dependant's glob could have added, so a warm run stays
952
- a no-op for both. A file the dependant rewrites in place (refine's
953
- `types` regenerating `build`'s `.d.ts`) counts as the dependant's own
954
- (its ctime moved, even where a tool stamps the size and mtime back; X-33),
955
- which is correct and costs the upstream a restore on
956
- the next warm run; the design note keeps that shape out of scope.
957
-
958
- ## Invalidation paths
959
-
960
- A task's cache becomes invalid when any of these change:
961
-
962
- | Trigger | Mechanism |
963
- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
964
- | Edit a file in the task's `inputs.files` set | step 10 of key derivation |
965
- | Edit a file in the task's `inputs.workspaceFiles` set (root-anchored; may live in ANY project's dir — the documented boundary exception) | step 10 — resolved workspace files join the same input-file list |
966
- | Any package manager updates a lockfile (`pnpm`, `npm`, `yarn`, `bun`) | step 9 — the `key` material of the plugin that claims it (`@vzn/vx-lockfile`: only the projects whose dependency closure moved); **NOT a trigger** with no such plugin, since core keys no package file |
967
- | Edit an install setting (`.npmrc`, `bunfig.toml`, `pnpm-workspace.yaml`, `.yarnrc.yml`) | step 9 — the claiming lockfile plugin folds it whole into every task; **NOT a trigger** without one |
968
- | Edit `package.json`'s `workspaces` field | membership: a project that joins or leaves changes which projects exist and which nested dirs its parent's globs exclude (step 10) |
969
- | Edit the project's `package.json` (dep / version / scripts change) | step 10 — an input file of every cached task when `@vzn/vx-lockfile` is declared (it adds `package.json` to `inputs.files`), or when a task lists it; **NOT a trigger** otherwise |
970
- | Edit the task's `vx.config.ts` | step 3 (task config hash) |
971
- | Edit a config file that the task config imports | step 3 (configHash sees the resolved object after Bun evaluates imports) |
972
- | Change CLI `forwardArgs` (after `--`) | step 4 |
973
- | Change a `inputs.env` host value | step 5 |
974
- | Change the combined stdout+stderr of a `inputs.runtime` command (resolved at hash time) | step 6 |
975
- | Change the combined stdout+stderr of a `inputs.workspaceRuntime` command (resolved at hash time) | step 7 |
976
- | Upstream task's cache key changes (because its inputs changed) | step 8 |
977
- | Bump `CACHE_VERSION` | step 1 — orphans every entry |
978
- | Change `exec.env.passThrough` _values_ alone | **NOT a trigger** by design — passThrough values are host-specific |
979
- | Change a file not in `inputs.files` / `inputs.workspaceFiles` | **NOT a trigger** by design — declare it explicitly |
980
- | Edit `.vx/projects.lock.json` | **NOT a trigger** — globally excluded from inputs (v24); it's vx's own metadata, never a task input |
981
- | Change a file in a nested project's dir | **NOT a trigger** for the parent's `files` globs — project boundaries are hard (workspaceFiles is the explicit exception) |
982
-
983
- The cascade in step 8 is what makes monorepo caching work: edit a
984
- file in `lib/`, and every package that depends on `lib`'s `build` task
985
- re-runs automatically.
986
-
987
- ## Cross-project boundaries
988
-
989
- A project's `inputs.files` globs **never** reach into another
990
- project's directory, even if a `**/*` pattern would otherwise match.
991
-
992
- `workspace/nested-dirs.ts` computes the set of nested project
993
- directories (projects rooted inside this one) once per `vx run`. A
994
- workspace package counts whether or not it has a vx config: it is the
995
- project `--affected` gives its files to, and its default `build` keys
996
- them (X-57). The same set fences the output clean, so a root
997
- `outputs.files: ['**/*.js']` never removes a member's source. Every
998
- glob pass drops a path under one of them (an ancestor lookup,
999
- A-11). The only way
1000
- for project A to depend on project B's state via project-relative
1001
- globs is `dependsOn` + upstream-hash propagation (step 8).
1002
-
1003
- For a task with `exec.sandbox` and `cache`, the sandbox enforces that
1004
- "only". A workspace package reached through a `node_modules` link is
1005
- granted only when the task's key folds a task of that package, walking
1006
- the same selection `inputs.tasks` applies at hash time
1007
- (`orchestrator/keyed-projects.ts`, over `graph/folds.ts`'s
1008
- `selectFoldedDeps`); every other link target inside the root is
1009
- withheld, so an import of a sibling the key never sees fails and is
1010
- reported instead of caching a result an edit there would not re-run.
1011
- Any exec task counts, cached or not: its key folds its project's files
1012
- through its `inputs`, and one with no `inputs` is keyless, so a key that
1013
- folds it is never stored or read. A persistent task counts the same way,
1014
- so a cached e2e behind a dev server keyed on its sources re-runs when
1015
- they change.
1016
- The coverage is per package, not per file: an edge to `ui#source`
1017
- (inputs `src/**`) also admits a read of `ui/README.md`, whose edit moves
1018
- no key — the same limit a grant wider than a task's own inputs already
1019
- has. A task with no `cache` keeps every link, having no key to be stale.
1020
-
1021
- **Exception:** `inputs.workspaceFiles` /
1022
- `cache.outputs.workspaceFiles` are workspace-root-anchored and apply
1023
- NO boundary rule — a deliberate escape hatch (owner call: "they don't
1024
- care about boundaries; it is bad practice but is there"). Prefer
1025
- project-relative declarations; reach for workspaceFiles only for
1026
- genuinely root-anchored files.
1027
-
1028
- ## Clean filters (`text` / `eol` / `ident`, `core.autocrlf`)
1029
-
1030
- Git can store a file's blob in a different form than the bytes in your
1031
- working tree. Under a `text`, `eol` or `ident` attribute — or with
1032
- `core.autocrlf` set to `true`/`input` — the index holds the
1033
- LF-normalized (or ident-collapsed) blob while your editor and your
1034
- build see the CRLF (or expanded) file.
1035
-
1036
- That matters because `git status` compares **after** applying the
1037
- filter, so such a file reports _clean_: git considers it unmodified
1038
- even though the blob and the worktree file are different byte
1039
- sequences. Trusting the index OID as the file's content hash would
1040
- then let two genuinely different worktree contents fold the **same**
1041
- cache key, and a real change would be invisible.
1042
-
1043
- So vx does not trust an index OID where a filter can apply. The check
1044
- is gated in three steps, and the common case pays nothing:
1045
-
1046
- 1. `core.autocrlf` is `true`/`input` — conversion applies to every
1047
- auto-detected text file with no attribute needed, so no OID is
1048
- trusted.
1049
- 2. Otherwise, if no attributes source exists anywhere (no in-tree
1050
- `.gitattributes`, an ignored one included, which `git status
1051
- --ignored=matching` names from the walk it already does, no `$GIT_DIR/info/attributes`, and none of the
1052
- files git reads outside the tree: the global one, which is
1053
- `core.attributesFile` or by default `$XDG_CONFIG_HOME/git/attributes`
1054
- or `~/.config/git/attributes`, and the system one), no rule can name
1055
- a filter and vx does **no** extra work. This is the default
1056
- `git init` repo. The gate reads `git var -l`, one spawn, which from
1057
- git 2.42 names the global and system files itself
1058
- (`GIT_ATTR_GLOBAL`, `GIT_ATTR_SYSTEM`); for an older git the global
1059
- lookup is mirrored and the system file is looked for at
1060
- `/etc/gitattributes` and `<prefix>/etc/gitattributes` beside the
1061
- binary, where a standard build puts it. Before 2026-09-24 the gate
1062
- missed the default global file, so `* text` there left a CRLF file
1063
- keyed on its LF blob: a CRLF→LF edit was a stale hit.
1064
- 3. Otherwise `git check-attr` resolves `text`, `eol`, `ident`, `filter`
1065
- and `working-tree-encoding` from the index — without reading worktree
1066
- content — and only the paths actually carrying one lose their OID. A
1067
- `filter` driver was missing from the list until item 978: a clean
1068
- driver that drops comment lines (`sed '/^#/d'`, nbstripout's shape)
1069
- stores one blob for two worktree files, so an edit git calls clean
1070
- replayed the old output. Git LFS files are a `filter` too, and are
1071
- hashed from disk.
1072
-
1073
- `-text` (explicitly unset) and unspecified paths keep their OIDs:
1074
- both leave the blob byte-identical to the worktree file.
1075
-
1076
- Losing an OID is not over-invalidation. It routes that path to the
1077
- content hasher, which hashes the worktree bytes — the correct source
1078
- either way. The only cost is reading the file, which is exactly what
1079
- the gate exists to avoid paying needlessly.
1080
-
1081
- ## Runtime inputs and the lock (the env parallel)
1082
-
1083
- `inputs.runtime` / `inputs.workspaceRuntime` are modeled
1084
- exactly on `inputs.env`, and they share its asymmetry with the
1085
- lockfile:
1086
-
1087
- - **The command _strings_ live in the resolved config**, so `vx lock`
1088
- freezes them into `.vx/projects.lock.json` (just as it freezes the env _names_
1089
- a task declares).
1090
- - **The command _output_ is resolved live at hash time on every run**
1091
- — inside `resolveInputs`, the same place env _values_ are read from
1092
- the host `process.env`. The lock never stores it.
1093
-
1094
- A runtime command executes **once per run, per project** (memoized by
1095
- `projectDir + command`), at key-derivation time — which, with the
1096
- up-front classify/prefetch pass, is before any task runs. It is a
1097
- run-level reading of the ENVIRONMENT (toolchain versions, resolved
1098
- config), not a per-task probe: it is not asked again before a save, as
1099
- input files are, because that would be one spawn per command per miss
1100
- where a file costs one `lstat`. A command that reads another task's
1101
- OUTPUT reads whatever is on disk when it is asked. When the reader's key
1102
- folds that task's key, the upstream key covers it: an answer taken before
1103
- the upstream ran costs a spurious miss on the run after the output
1104
- changes, never a stale hit, and the answer stays shared. When it does
1105
- not (`tasks: []`, a filter that leaves it out, transitively), nothing
1106
- covered it until X-34: the save filed bytes built from the new state
1107
- under the old answer, and a later run that started from the old state
1108
- hit them. Now such a task (`probesAfterWrites`, stable-keys.ts) takes no
1109
- key up front and is never restore-tier, and its probes run for it alone,
1110
- after its upstream finished — one spawn per such task per run, not one
1111
- per project (`tests/in-run-writes.test.ts`). Declaring the producing
1112
- task's output as an input (`dependsOn` + files) is still the cheaper
1113
- spelling: files are re-checked, answers are not.
1114
-
1115
- A probe runs in its own process group. One still running when vx exits
1116
- — a Ctrl-C, or a refusal, while a hung `git` or `node -e …` answers — is
1117
- SIGKILLed with its whole tree; until 2026-09-27 (A-9) it ran on under
1118
- init. A `kill -9` of vx runs no exit hook, and leaves it.
1119
-
1120
- So a run loads the frozen command strings from the lock but still
1121
- spawns them and folds their current output into the key. A `node -v`
1122
- that goes from `v20` to `v22` after the lock was written busts the
1123
- cache, exactly as a changed `NODE_ENV` value would — the TypeScript
1124
- escape hatch (`define: { TSC_VERSION: execSync(...) }`) goes stale here
1125
- because its value was baked into the config object at lock time, whereas
1126
- a runtime input re-resolves.
1127
-
1128
- Consequently **`vx lock --check` does not — and need not — flag
1129
- runtime-output drift.** `lock --check` audits that the frozen config
1130
- object still matches a fresh evaluation; the command output was never
1131
- part of that object (only the strings are), so a changed probe output
1132
- is correct, expected, live behavior rather than lock drift. This is the
1133
- same reason `lock --check` ignores `inputs.env` value changes.
1134
-
1135
- ## Concurrent runs
1136
-
1137
- Two vx processes on one workspace (a `vx watch` beside a `vx run`, two
1138
- CI jobs on one checkout) take turns: a run takes the workspace's run
1139
- lock before it schedules and releases it with its cache handle — before
1140
- a persistent task's wait, so a dev server never holds it — and the
1141
- second run waits, saying after a second whom it waits for:
1142
-
1143
- ```
1144
- [vx] waiting for another vx run (pid 4821) on this workspace to finish…
1145
- ```
1146
-
1147
- The cache itself was always safe (SQLite waits on its lock, artifacts
1148
- land by rename; a transaction that reads before it writes takes the
1149
- lock at BEGIN, since SQLite answers its later write `database is locked`
1150
- at once: a run's history was lost so in 13 of 48 runs on one shared
1151
- cache dir, X-105); a task's OUTPUT TREE was not — both runs cleaned and
1152
- restored the same `dist/`, and a clean landing while the other run's
1153
- restore was staging took its files out from under it. The lock is an
1154
- atomic directory under the temp directory, keyed by the workspace root
1155
- (`--cache-dir` does not make two runs strangers) and holding the
1156
- holder's pid, so a lock a killed run left behind is reclaimed once its
1157
- pid is gone. The temp directory is the one each process sees, `TMPDIR`
1158
- included: two shells that set different ones (a `nix develop` shell
1159
- sets its own, as can direnv or `sudo`) hold two locks and do not take
1160
- turns (item 970). Run them under one `TMPDIR`. A lock under the
1161
- workspace would survive a reboot that `/tmp` does not, and where a
1162
- holder's start time is not readable (off Linux) a pid reused since
1163
- would read as a live holder forever. Where the directory cannot be made at all (another user's
1164
- lock, a temp directory this user cannot write) the run says so once and
1165
- proceeds unlocked — a courtesy between cooperating runs, never a
1166
- refusal — and a restore that then loses its staged files to the other
1167
- run's clean fails with `restore of <hash> into <dir> was interrupted: a
1168
- file it had just written vanished (ENOENT: …). Another vx run is using
1169
- this workspace — re-run once it is done.`; the artifact is intact
1170
- either way (a restore renames into place only once the whole archive
1171
- has staged). Machines sharing a workspace over a network file system
1172
- do not share a temp directory, so they do not share the lock.
1173
-
1174
- An eviction can still land between a hit's probe and its restore: a
1175
- `vx cache clean` in another shell, or the `cache.retention` of another
1176
- workspace that shares the `--cache-dir` (a different workspace, so a
1177
- different lock), which cannot see this run's pending `accessed_at`
1178
- bumps and reads its fresh hits as old. The restore then finds no
1179
- artifact, and that entry is a **miss**: the run says `[vx] <id>: its
1180
- cache artifact <hash> vanished before the restore … — running it`,
1181
- runs the task, and saves it again. It failed every such task as an
1182
- internal error until 2026-09-24 (upstream survey: nx#36688, nx#34032).
1183
- A hit the local short-circuit was restoring ahead of its dependencies
1184
- goes back to the schedule and runs once they are done, never in the
1185
- restore's slot: built before them, its bytes would be saved under the
1186
- healthy key (`tests/vanished-artifact.test.ts`).
1187
-
1188
- A local artifact whose bytes are wrong (a failed checksum, a torn
1189
- write, one past the artifact ceiling, an entry missing a recorded
1190
- output, a name that now reads unsafe, X-115) is a miss the same way: `[vx] <id>: cache: corrupt artifact
1191
- for <hash>: …; dropped it — running it`. The entry is dropped, so the
1192
- task's save stores the key again; it failed the task as an internal
1193
- error on every run until `--force` before A-52. A cache the run may
1194
- only read keeps the entry (`…; left it (this cache is read-only)`).
1195
-
1196
- ## Storage layout
1197
-
1198
- The run must be able to write here — it records its history at the
1199
- end of every run, hit or miss — so a directory this user cannot write
1200
- into (another user's `.vx/cache`, a read-only checkout) fails the run before
1201
- any task: `cache directory <path> is not writable (EACCES: …)`, with
1202
- `--cache-dir <path>` as the way out. `vx cache clean` is refused the
1203
- same way (its `--dry-run` only reads, and reads). The readers (`vx show`, `why`,
1204
- `last`, `info`) open such a directory read-only and go on.
1205
- Where the directory cannot be created at all (a read-only checkout with
1206
- no cache yet) a run says `cannot create cache directory <path>
1207
- (EACCES: …)`, naming the workspace `cache.dir` field and `--cache-dir`;
1208
- the readers and `vx cache clean` find no cache and go on.
1209
- A full disk is the same kind of failure and is reported the same way,
1210
- never as a corrupt artifact and never as a stack: a save that runs out
1211
- of room is `[vx] cache save failed: ENOSPC …` (the task's work ran, the
1212
- next run misses), a restore that does is the task's failure line
1213
- `could not write its outputs (ENOSPC: …). Free space on that disk and
1214
- re-run.`, and a run record that does is `[vx] run history not recorded:
1215
- … — the verdict above stands` (the run exits by its tasks; `vx last`
1216
- will not know that one). A full index (`SQLITE_FULL`) gives way where the
1217
- write is only a memo: the file-hash memo, the output stamps and the
1218
- access times are skipped and the run goes on; a prune unlinks the
1219
- artifacts first, so the rows it then deletes have room to go, and a
1220
- save's temp file is removed when its write fails.
1221
- A process out of file descriptors (`EMFILE`, `ENFILE`) is named the
1222
- same way: a save is `[vx] cache save failed: save of <hash> could not
1223
- open a file (EMFILE: …) — … raise the limit (ulimit -n 4096) and
1224
- re-run`, and a restore fails the task with that hint, never as a
1225
- corrupt artifact (A-39). Opening the index is named the same way: SQLite reports a
1226
- descriptor it could not get as `unable to open database file`, and vx
1227
- says `the cache index <path> could not be opened (…) — …raise the limit`
1228
- (A-56).
1229
- A restore that cannot READ its artifact (a cache directory another
1230
- user owns) names the cache, not the outputs: `restore of <hash> could
1231
- not read its artifact (EACCES: …). Make the cache directory readable
1232
- by this user, or point cacheDir / --cache-dir at one that is.` (A-40).
1233
- An input the key must hash that this user cannot read fails its task
1234
- naming the read: `<path> is not readable by this user (EACCES), and vx
1235
- reads it to derive a cache key. Make it readable, or, for a task input,
1236
- take it out of inputs.files.` (A-50).
1237
-
1238
- By default the entries and their artifacts live in a **shared store**
1239
- in `~/.vx/<id>/cache`, and each workspace keeps only its own index in
1240
- its `.vx/cache`: every checkout of the repository hits what another
1241
- saved (a second clone, a worktree), and none reads another's history.
1242
- Task timings are shared too: `task_durations`, what a duration forecast
1243
- reads, so a new worktree has one on its first run. So are plugins' own
1244
- entries (`plugin_blobs`, a plugin's `ctx.cache`).
1245
- The id is Nx 23's: 16 hex of a sha256 of the remote (`origin`, then
1246
- `upstream`, `base`, the first; `host/owner/repo` in lower case, so ssh
1247
- and https agree) and the workspace's path in the repository; with no
1248
- remote, the first commit. A repository with neither (no commit yet, a
1249
- shallow clone with no remote) shares nothing. Each level of `~/.vx` is
1250
- owner-only; vx closes one of yours that others can read (chmod 700), and one others can write, or owned by another user, is not used. Design: [`design/shared-store-2026-10.md`](./design/shared-store-2026-10.md).
1251
-
1252
- ```
1253
- ~/.vx/<id>/cache/ the shared store
1254
- ├── store.db entries, entry_stdout, output_files,
1255
- │ entry_inputs, task_durations,
1256
- │ plugin_blobs, store_meta; artifacts
1257
- │ of at most 32 KiB compressed (v33)
1258
- └── <hash>.tar.zst the larger artifacts (below)
1259
-
1260
- <workspaceRoot>/.vx/cache/ this workspace's own index
1261
- └── cache.db run history, memos, output stamps;
1262
- attaches store.db as `store`
1263
- ```
1264
-
1265
- The store's directory carries no version: every key is seeded with
1266
- `CACHE_VERSION`, which moves when hashing or the artifact layout does, so
1267
- two vx versions never read each other's artifacts. `store.db` is the
1268
- artifacts' inventory and records its schema (`store_meta.schema`): a vx
1269
- of another `SCHEMA_VERSION` drops its tables, prints nothing (the
1270
- cache is vx's to keep), and keeps every artifact, each indexed again
1271
- when its task next hits. The check, drop, re-create and stamp are one
1272
- write transaction, so another version's open waits rather than landing
1273
- between them. A home this user cannot write keeps the store
1274
- in `<workspaceRoot>/.vx/cache/` instead, silently. Name a
1275
- cache directory (`cache.dir` in .vx/workspace.ts, `--cache-dir`, or
1276
- `VX_CACHE_DIR`, in that order of precedence, relative to the workspace
1277
- root) and it holds everything, shared with no other workspace:
1278
-
1279
- ```
1280
- <cacheDir>/ (default .vx/cache when one is named)
1281
- ├── .gitignore `*` — written when the dir is created, or into an
1282
- │ existing dir that lacks one, so the cache is
1283
- │ never committed and never enumerated as an
1284
- │ input (a user's own file is left alone)
1285
- ├── cache.db SQLite metadata + run history, and the
1286
- │ artifacts of at most 32 KiB compressed,
1287
- │ the same bytes as a file below (v33)
1288
- ├── cache.db-wal write-ahead log
1289
- ├── cache.db-shm shared memory
1290
- ├── failures/<runId>.json a failed run's task output and the files it
1291
- │ names (`vx last --format json`, getFailures);
1292
- │ the newest 50 kept
1293
- └── <hash>.tar.zst one artifact per cache entry, the larger ones:
1294
- ├── stdout captured stdout (always present, may be empty)
1295
- ├── outputs/<rel> declared output files, project-relative (when any)
1296
- ├── workspace-outputs/<rel> declared outputs.workspaceFiles,
1297
- │ WORKSPACE-ROOT-relative (when any)
1298
- ├── .vx-meta.json per-output [mode, mtimeMs], the key it was
1299
- │ packed under (v35), the miss's CPU and RSS
1300
- └── .vx-sum CRC-32 of every entry above (v36)
1301
- ```
1302
-
1303
- `failures/` sits outside `cache.db` so the index layout, and every
1304
- shared store under it, stays as it was. Each file is
1305
- `{ runId, tasks: [{ taskId, project, task, exitCode, timedOut?, output, locations }] }`,
1306
- written at run end (temp file + rename) only when a task failed with
1307
- output; `output` is plain text (ANSI stripped, secrets masked, the first
1308
- 8 KiB and last 56 KiB). A refused write (`EACCES`, `ENOSPC`) costs only
1309
- that output, never the run's verdict.
1310
-
1311
- `<hash>` is the 16-hex xxh3 key. The `workspace-outputs/` namespace is
1312
- additive: tasks that don't declare `outputs.workspaceFiles` produce
1313
- byte-identical artifacts to the plain v17 format (which is why the
1314
- field needed no `CACHE_VERSION` bump). `output_files` rows mirror the
1315
- two namespaces — project rows store the bare rel, workspace rows store
1316
- the full `workspace-outputs/<rel>` name as the discriminator.
1317
-
1318
- The container is written and read by vx's own streaming tar code
1319
- (`src/cache/tar-stream.ts`): ustar with the name/prefix split and a pax
1320
- `path` record past it, header checksums, and nothing else — there is no
1321
- `tar` subprocess, no libarchive, and no staging copy. **Save streams
1322
- it**: each output is stat'd once, then read from disk as it is written
1323
- and compressed straight into the temp file (measured 2026-09-03 on a
1324
- 150 MiB output: peak +705 MiB → +241–269 MiB; the streamed compressor
1325
- is ~2.4× the one-call cost per byte, so a small artifact is packed in
1326
- memory and compressed in one call — tiny saves unchanged within
1327
- noise). Ingest lists entries through the reader without materialising
1328
- a byte, and **restore streams it**: the zstd
1329
- frame is decoded and the tar read as it arrives — ustar name/prefix
1330
- (the prefix under POSIX `ustar\0` magic only: old GNU's `ustar ` keeps
1331
- atime there, A-29),
1332
- pax `path`/`size`, GNU long names, header checksums, truncation; an
1333
- extended header (read whole) past 1 MiB or a pax `size` that is not a
1334
- whole number is refused as corrupt, since a 1 GiB pax header costs 2 GiB
1335
- of memory from a ~32 KB artifact — and
1336
- every regular entry is written beside its target as a short `.vx-tmp-*` sibling (never a suffix on the target's name, which pushed a legal 242–255-byte name past NAME_MAX) and
1337
- renamed into place only after the whole archive has ended cleanly and
1338
- the index's recorded outputs are all present. vx itself holds one
1339
- chunk of the tar at a time (measured 2026-09-03, incompressible
1340
- artifacts, fresh process: 150 MiB peaked at +644 MiB through
1341
- `Bun.Archive` and +49 MiB streamed at the same wall time; a single
1342
- 400 MiB entry restores at +30 MiB, the same as a 150 MiB one), while
1343
- the per-entry buffers of many mid-sized entries are garbage the
1344
- collector reclaims at its own pace (200 × 2 MiB measured +90–180 MiB,
1345
- never the artifact's size). An artifact up to 4 MiB compressed is decoded in one call
1346
- first — the stream setup costs ~35 µs each, 4% of the headline
1347
- restore row when every artifact is a one-file `dist/` — and then fed
1348
- to the same reader and extractor, so there is one extraction path.
1349
- The reader reads a header in place when it lies within one chunk and
1350
- its numeric fields off the bytes when they are plain octal (anything
1351
- else takes the full parse): a 4-entry artifact's read 50–57 µs → 22–23
1352
- (min of 15), and a 300-artifact, 20-file restore run's reader 224 → 92
1353
- ms of main thread (2026-10-02).
1354
- The 2 GiB decompression ceiling applies to both: declared size and
1355
- output length for the one-call decode, a running count for the stream.
1356
- An ingest bounds the compressed body first: a remote body past the
1357
- ceiling's zstd bound (a length header, a Blob's size, or a running count
1358
- on a chunked stream) is refused before it can fill the disk.
1359
- A frame that declares no content size (what a streaming compressor
1360
- writes — vx's own saves above 4 MiB) is always decoded as a stream, so
1361
- a sizeless bomb has nowhere to expand and vx's artifacts ingest
1362
- anywhere. So is a body that is not exactly one frame: the declaration is
1363
- the first frame's alone, while the one-call decoder decodes every frame,
1364
- so until 2026-09-27 (A-5) a 100-byte frame with a large one appended
1365
- expanded whole in memory (2 GiB from a 32 KB body) before its length was
1366
- checked. The frame's blocks are walked by their own sizes to tell. A save meets the same ceiling first: the pack plans the tar
1367
- from one stat per output, and a tar past 2 GiB is refused before a byte
1368
- is compressed — the run stays green, one status line names the task
1369
- (`[vx] cache save failed: <task> is not cached: its outputs pack to …,
1370
- past the 2.0 GB artifact ceiling a restore enforces`), and nothing is
1371
- stored for a later run to hit and fail to restore. Left to the scan, a
1372
- 2.2 GB output paid the whole compress and a decode (6 to 14 s) to learn
1373
- the same thing and called the task's outputs a corrupt artifact.
1374
-
1375
- The last entry, `.vx-sum`, is a CRC-32 over every entry before it (each
1376
- its name, a NUL, then its body) as 8 hex digits. Tar sums its headers
1377
- only and neither zstd writer asks for a frame checksum, so a byte flipped
1378
- in a raw zstd block (incompressible output: an image, a wasm, a tarball)
1379
- decoded clean and a hit replayed the wrong bytes: 1,141 of 1,141 flips in
1380
- a random 8 KB body went unseen (L-19). Scan and restore hash every entry
1381
- as they read it and refuse an artifact whose sum is absent, wrong, or
1382
- followed by another entry, before anything it holds lands; the refusal
1383
- is a corrupt artifact, so a restore degrades to a miss and an ingest
1384
- stores nothing. It catches damage in transit or at rest, not a store that
1385
- forges artifacts: nothing a key carries can tell those from honest ones.
1386
- Its cost is the CRC's (~10 GB/s): a 32 MB restore 11.3 → 14.4 ms and
1387
- 1,000 small files 16.2 → 18.9 ms on tmpfs, min of 15.
1388
-
1389
- Tar headers carry mode and second mtimes. vx needs both permission bits (a lost executable bit builds cold
1390
- and breaks warm) and millisecond mtimes (the skip-restore probe compares
1391
- them) exactly, so the pack stats each output once and writes
1392
- `.vx-meta.json` — `{ version, key, files: { <entry>: [mode, mtimeMs] }, exec? }` —
1393
- into the archive. Restore applies both, at their edges too: a mode of
1394
- 000, an mtime of 0 (`SOURCE_DATE_EPOCH=0`), one before 1970, whose
1395
- tar header carries 0 since ustar's field holds no sign, and one past
1396
- March 2242, whose header carries the field's 11-digit maximum (X-114:
1397
- the save failed `value … does not fit a 12-byte field`). Until 2026-09-27
1398
- (A-4) the first two were skipped, so the file came back 0644 and
1399
- stamped now and every later hit restored it again, and the third wrote
1400
- a header the reader refused, so its task never saved. `exec` (`{ cpuMs?, peakRssBytes? }`,
1401
- 2026-09-12) is what the PRODUCING execution used: it rides the artifact
1402
- so a machine that never ran the task — a fresh runner on a remote hit —
1403
- still learns what the task needs (`@vzn/vx-schedule-history` packs on
1404
- it), every wire ships the bytes verbatim, and an artifact without it
1405
- reads as before. The ingest side takes the numbers only as plain
1406
- non-negative numbers; anything else in a foreign sidecar is dropped. Entries that are not regular
1407
- files (symlinks, hardlinks, devices) are never materialised — the
1408
- reader reports them only to be skipped — so a
1409
- poisoned artifact cannot smuggle one onto disk. Nor can it name a file
1410
- the task did not declare: a remote artifact is ingested only when every
1411
- file it carries matches the task's `cache.outputs` (the lookup passes
1412
- them, `CacheGetContext.outputs`), and never when it holds one path as a
1413
- file and a directory at once. Either used to reach the tree, an input
1414
- overwritten or a `.git/hooks` file planted under a green
1415
- `cache-hit-remote`, or a restore that failed every later run from the
1416
- local copy (item 942); now the read is a miss and the task runs. On the save side a
1417
- **symlinked output** is captured as its target's bytes and comes back
1418
- as a regular file (a hit that finds the task's own link still current
1419
- leaves it); a link to a directory, or a dangling one, has no bytes to
1420
- store, so the save refuses it by name rather than cache an entry that
1421
- restores to nothing. So does a link whose target is outside the
1422
- project: vx reads outputs outside the task's sandbox, and a planted
1423
- link packed a file the task could not read (L-23). Each refusal names
1424
- the path as the config spells it (`workspaceFiles output gen/latest`). The clean before exec and restore removes every
1425
- file AND symlink the output globs cover (a link is unlinked, never
1426
- followed). An output directory that is a symlink (`dist -> real-out`) is
1427
- followed by the clean as by the save and restore, so its target is the
1428
- output and an entry holds only what its run wrote (X-88); one that
1429
- resolves outside the project refuses the task, naming the link, and
1430
- nothing is deleted through it (X-5). The clean prunes the directories it emptied (before a miss it keeps
1431
- the directory a wildcard glob is rooted at, `dist` for `dist/**`, as the
1432
- task writes there), so a task whose
1433
- output changed shape — `dist/out` a directory one run and a file the
1434
- next — restores either entry over the other's tree; a stray the globs
1435
- do not cover, or an empty directory where the entry holds a file, that
1436
- stands in an entry's way fails the restore naming it, not as a corrupt
1437
- artifact (item 1094). A directory on the way that is a
1438
- symbolic link OUT of the project (a `dist` made a link after the entry
1439
- was saved) is never written through and never replaced — the link is
1440
- the user's, and replacing it is the bug nx#37061 reports — so the
1441
- restore refuses, naming it: `<dir>/dist is a symbolic link to
1442
- <target>, outside <dir> — a cache restore never writes through a link
1443
- that leaves its directory. Remove the link and re-run (the restore
1444
- puts a real directory there), or stop declaring outputs under it.` A
1445
- link that stays inside the project is written through, and so is one
1446
- whose target is gone: the restore creates the directory it names —
1447
- following a chain of links to its end — and writes through it, the
1448
- link kept. Whether a link stays inside is decided on where it resolves,
1449
- so a dangling link to `../elsewhere` or to an absolute path out of the
1450
- project is the same refusal, nothing created outside, and a cycle of
1451
- links is refused by name. (A link the output globs themselves cover,
1452
- `dist/sub` under `dist/**`, is an output: the clean unlinks it.) Entry NAMES are
1453
- validated by vx before anything decides where to write, and a bad
1454
- entry anywhere, even the last, rejects the WHOLE archive: the temps
1455
- are unlinked and the empty directories the extraction created are
1456
- pruned (`tests/archive-security.test.ts`). A backslash in a name is a
1457
- name character (vx runs on Linux and macOS; Windows through WSL), so an
1458
- output like `dist/back\slash` caches and restores as written.
1459
-
1460
- **Key properties:** one entry is one artifact — a row of `artifacts`
1461
- when small, else one file, so eviction is one delete in the rows'
1462
- transaction or a single unlink; no per-entry manifest, no separate
1463
- `logs/` tree; and local + remote layers transport the exact same
1464
- tar.zst bytes end-to-end, wherever the local copy lives.
1465
- The artifact is the record and the index its inventory (owner,
1466
- 2026-10-06): a lookup reads the row first, and a key with no row whose
1467
- `<hash>.tar.zst` is on disk (a `SCHEMA_VERSION` drop, a deleted
1468
- `cache.db` or `store.db`) has the artifact indexed again from its own
1469
- bytes, checked as a remote's are (its recorded key, its names against
1470
- the task's declared outputs), and hits; one that fails the check is a
1471
- miss, and the save that follows replaces it. An inline artifact with no
1472
- row is indexed the same way, from its bytes, in one transaction; a reset
1473
- keeps the `artifacts` table, but deleting `store.db` or `cache.db` by
1474
- hand takes the inline artifacts with it. A `.tmp-*` a crashed save
1475
- left is never a hit. `vx cache clean` sweeps row-less files, and so does a run whose workspace declares `cache.retention`, at
1476
- most once an hour (the sweep's clock is `schema_meta.orphans_swept_at`;
1477
- the policy sums index rows, so orphans alone never make it due). A
1478
- row-less artifact may be in use: two vx versions share one store, and
1479
- each open drops the other's rows. So the policy judges it as it judges a
1480
- row, its file time standing for `accessed_at`: past `olderThan` it goes,
1481
- and under `maxSize` it counts, oldest use first with the rows. A hit
1482
- renews a file time over an hour old, so the last use is read as the file
1483
- time plus an hour. An inline artifact with no row is judged the same
1484
- way, its `at` standing for the file time, and `vx info` counts it with
1485
- the files. A temp a crashed save left goes once it is an hour
1486
- old, and so does a file an inline artifact of its key shadows; nothing
1487
- younger than an hour is taken. Re-indexing touches the
1488
- artifact's mtime before it links its temp, so the sweep sees that one
1489
- fresh too.
1490
-
1491
- A row's `accessed_at` is renewed the same way: a hit renews it only once
1492
- it is over an hour old (owner, 2026-10-08). Renewing every hit rewrote
1493
- 2,180 rows at a warm 1,090-package run's close, ~30 ms. So the policy
1494
- reads a row's last use as `accessed_at` plus an hour too: an entry used
1495
- within `olderThan` is never pruned, and one may stay up to an hour past
1496
- it (`tests/cache.test.ts` › "an entry used within the age limit is never
1497
- pruned").
1498
- Captured stdout is stored twice on purpose: in the artifact (so it
1499
- survives the remote round-trip) and in the `entries` row (so a local
1500
- hit replays it with pure SQL, never decompressing the artifact).
1501
-
1502
- ### SQLite tables
1503
-
1504
- `schema_meta.version` is the gate: an index written by any other
1505
- `SCHEMA_VERSION`, earlier or newer, is reset by the first run that opens
1506
- it (pre-alpha: no migrations; the index is an inventory, owner
1507
- 2026-10-06): every table but `schema_meta` is dropped and recreated,
1508
- so each comes back in its current shape (A-54: `output_dirs` kept an
1509
- earlier vx's columns). The check, drop, re-create
1510
- and stamp are one write transaction, so another version's open waits
1511
- rather than landing between them; an index already current is opened
1512
- without the lock.
1513
- A reading verb (`vx why`, `vx last`, `vx info`) leaves it untouched and
1514
- says why (item 896; `vx cache clean --dry-run` previews the reset
1515
- instead, item 1083).
1516
- That open prints nothing (owner, 2026-10-06: the cache is vx's to
1517
- keep). The artifacts stay: each is indexed again from its own bytes
1518
- when its task next asks for its key (below).
1519
-
1520
- ```sql
1521
- -- src/cache/schema.ts (SCHEMA_VERSION = 'v40', in cache.ts)
1522
- -- With a shared store, entries, entry_stdout, output_files, entry_inputs,
1523
- -- store_meta, task_durations, task_outcomes, blob_sizes and plugin_blobs live in its store.db, attached as `store`; the rest is
1524
- -- the workspace's cache.db. A named cache dir holds all of them.
1525
-
1526
- CREATE TABLE schema_meta (
1527
- key TEXT PRIMARY KEY, -- 'version', 'cache_version', 'orphans_swept_at', 'file_hashes_swept_at', 'store_dir'
1528
- value TEXT NOT NULL
1529
- );
1530
-
1531
- CREATE TABLE entries (
1532
- hash TEXT PRIMARY KEY, -- the 16-hex xxh3 cache key
1533
- project TEXT NOT NULL,
1534
- task TEXT NOT NULL,
1535
- command TEXT NOT NULL,
1536
- exit_code INTEGER NOT NULL,
1537
- duration_ms INTEGER NOT NULL,
1538
- size_bytes INTEGER NOT NULL, -- artifact size
1539
- created_at INTEGER NOT NULL, -- ms-epoch
1540
- accessed_at INTEGER NOT NULL, -- ms-epoch; a hit renews it once over an hour old (LRU)
1541
- cpu_ms INTEGER, -- v26: the producing execution's usage, from
1542
- peak_rss_bytes INTEGER -- the artifact's sidecar (save + ingest)
1543
- );
1544
-
1545
- -- v29: stdout apart from its entry. An UPDATE rewrites a whole record, so
1546
- -- the accessed_at bump rewrote each hit's stdout (up to 16 MB): 200 hits
1547
- -- of 1 MB cost the run's close 125-150 ms.
1548
- CREATE TABLE entry_stdout (
1549
- hash TEXT PRIMARY KEY, -- FK entries(hash) ON DELETE CASCADE
1550
- stdout TEXT NOT NULL -- captured stdout (pure-SQL hit replay); no row = ''
1551
- );
1552
-
1553
- CREATE TABLE runs (
1554
- id INTEGER PRIMARY KEY AUTOINCREMENT,
1555
- hash TEXT NOT NULL, -- '' when the outcome derived no key (see below)
1556
- project TEXT NOT NULL,
1557
- task TEXT NOT NULL,
1558
- status TEXT NOT NULL, -- success | failed | cache-hit | cache-hit-remote | skipped
1559
- exit_code INTEGER NOT NULL,
1560
- duration_ms INTEGER NOT NULL,
1561
- forward_args TEXT, -- salted xxh3 of the JSON-encoded `--` args; null when none
1562
- started_at INTEGER NOT NULL, -- ms-epoch
1563
- ended_at INTEGER NOT NULL,
1564
- run_id TEXT, -- UUIDv7 shared across all tasks in one invocation
1565
- cpu_ms INTEGER,
1566
- peak_rss_bytes INTEGER,
1567
- wallclock_start_ns INTEGER, -- bigint; serialized as SQLite INTEGER (signed 64-bit)
1568
- wallclock_end_ns INTEGER,
1569
- cache_hit INTEGER, -- 0/1; convenience for flamegraph color
1570
- attempts INTEGER, -- v23: attempts a retried task took (>1)
1571
- cached INTEGER, -- v25: 1 = declared a cache block; 0 = runs every time
1572
- -- v27: why the task failed or was skipped, as the run's footer said it
1573
- -- (items 267–270); NULL where the reason does not apply
1574
- blocked_by TEXT, -- a skip's root blocker, or what a task ran behind (a task id)
1575
- timed_out INTEGER, -- 1 when vx's own timeout killed it
1576
- sandbox_violations INTEGER, -- the sandbox's violation count
1577
- not_ready TEXT, -- 'timeout' | 'exited' | 'spawn' (persistent task)
1578
- restored INTEGER, -- v31, on a hit: 1 = outputs restored, 0 = up to date
1579
- remote_error TEXT -- v40: each remote read or write of the key that failed
1580
- );
1581
-
1582
- -- Two indexes, both append-only under a run's inserts: every row of a run
1583
- -- carries the same run_id and a started_at newer than everything before it.
1584
- -- There is deliberately NO (project, task) index — it scattered every run's
1585
- -- rows over one B-tree leaf per pair (a 1,000-hit warm run's record stage
1586
- -- went 57–79 ms → 14–19 ms without it) while its readers gained nothing;
1587
- -- the history reader bounds its scan by rowid instead (see history.md).
1588
- CREATE INDEX runs_started_at ON runs(started_at);
1589
- CREATE INDEX runs_run_id ON runs(run_id);
1590
-
1591
- -- Every non-group, non-aborted outcome of a run gets a row, so
1592
- -- `invocations.task_count` always equals `COUNT(*)` here for that run_id
1593
- -- and the terminal summary's "N total". Two of those outcomes never derive
1594
- -- a cache key — a `skipped` task (its upstream failed, so it never probed)
1595
- -- and a `persistent` one (a dev server is not cacheable) — and they store
1596
- -- `hash = ''`. `''` is impossible for a real key (16 hex chars), so it reads
1597
- -- unambiguously as "no key recorded"; the key-diff surfaces (`vx why`'s
1598
- -- whyDidThisRerun, the cache-key diff) guard it rather than reporting
1599
- -- "inputs unchanged" from two rows that never had inputs to compare.
1600
- --
1601
- -- A `skipped` row is a task of the run but NOT an execution, so the rate and
1602
- -- average aggregates in metrics.ts exclude it: counting a zero-duration
1603
- -- non-event would dilute success rate, hit rate and mean duration. The
1604
- -- completeness reads (listRuns / getRun / the run-detail timeline) include it.
1605
-
1606
- -- The file-hash memo: a content hash per input file that git could not
1607
- -- answer (untracked or dirty), keyed by the stat identity that proves
1608
- -- the bytes unchanged. Machine-local; § Cache key derivation step 10.
1609
- -- A writing close drops rows unwritten for 30 days, at most once a day
1610
- -- (a memo miss is the whole cost of a dropped row; item 1082).
1611
- CREATE TABLE file_hashes (
1612
- path TEXT PRIMARY KEY,
1613
- mtime_ms INTEGER NOT NULL,
1614
- size_bytes INTEGER NOT NULL,
1615
- ctime_ms INTEGER NOT NULL,
1616
- ino INTEGER NOT NULL,
1617
- content_hash TEXT NOT NULL,
1618
- seen_at INTEGER NOT NULL
1619
- );
1620
-
1621
- -- The size of each index blob the enumeration checked against the
1622
- -- worktree size git recorded (§ Cache key derivation, A-60): fixed for
1623
- -- its OID, so a warm run asks git for none. Swept with file_hashes by
1624
- -- seen_at, the time the row was written. v38: in the store, so a worktree
1625
- -- reads what another learned.
1626
- CREATE TABLE blob_sizes (
1627
- oid TEXT PRIMARY KEY,
1628
- size INTEGER NOT NULL,
1629
- seen_at INTEGER NOT NULL
1630
- );
1631
-
1632
- -- v30: the paths an index distrusts, by a hash of the index file and the
1633
- -- pathspecs (A-60): a warm run reads one row, not one per blob. Swept
1634
- -- with file_hashes.
1635
- CREATE TABLE blob_verdicts (
1636
- digest TEXT PRIMARY KEY,
1637
- paths TEXT NOT NULL,
1638
- seen_at INTEGER NOT NULL
1639
- );
1640
-
1641
- -- v16: per-output-file fingerprints, scoped by the entry that produced
1642
- -- them — what a hit stats to skip the restore when the tree is already
1643
- -- current (§ A current tree). ON DELETE CASCADE follows a prune.
1644
- CREATE TABLE output_files (
1645
- entry_hash TEXT NOT NULL,
1646
- path TEXT NOT NULL,
1647
- size_bytes INTEGER NOT NULL,
1648
- mode INTEGER NOT NULL,
1649
- mtime_ms INTEGER NOT NULL,
1650
- PRIMARY KEY (entry_hash, path),
1651
- FOREIGN KEY (entry_hash) REFERENCES entries(hash) ON DELETE CASCADE
1652
- );
1653
-
1654
- -- v28, its own table since v32: inode + ctime THIS workspace saw after
1655
- -- the save/restore that last wrote the file (item 886); no row is never
1656
- -- current. Apart from the shared entry: two worktrees overwrote each
1657
- -- other's stamps and every switch restored. No foreign key (the entry
1658
- -- may be the store's); prune and re-save delete what they orphan.
1659
- CREATE TABLE output_stamps (
1660
- entry_hash TEXT NOT NULL,
1661
- path TEXT NOT NULL,
1662
- ino INTEGER NOT NULL,
1663
- ctime_ms INTEGER NOT NULL,
1664
- PRIMARY KEY (entry_hash, path)
1665
- );
1666
-
1667
- -- Every directory under a whole-subtree output glob, with its mtime as
1668
- -- of the last save or restore on THIS machine: unchanged mtimes prove
1669
- -- the output SET unchanged without a glob walk. Machine-local — a remote
1670
- -- ingest writes none, and the first hit after it walks and records.
1671
- CREATE TABLE output_dirs (
1672
- entry_hash TEXT NOT NULL,
1673
- path TEXT NOT NULL,
1674
- mtime_ms INTEGER NOT NULL,
1675
- PRIMARY KEY (entry_hash, path) -- no foreign key since v32, as output_stamps
1676
- );
1677
-
1678
- -- v22 (Tier 3): one header row per `vx run` invocation. The `runs`
1679
- -- table is per-task; this is the per-invocation record carrying the
1680
- -- command, git/CI/host context, and run-level counts. Recorded
1681
- -- atomically alongside `runs` via recordRunBundle (one transaction).
1682
- CREATE TABLE invocations (
1683
- run_id TEXT PRIMARY KEY, -- UUIDv7, == runs.run_id
1684
- command TEXT NOT NULL, -- full argv, e.g. "vx run build --all"
1685
- requested_tasks TEXT NOT NULL, -- JSON string[] of options.tasks
1686
- cache_policy TEXT NOT NULL, -- the --cache-policy spec, e.g. "local:rw,remote:r"
1687
- concurrency INTEGER NOT NULL,
1688
- flow TEXT, -- 'focused' | 'broad' | NULL (programmatic)
1689
- started_at INTEGER NOT NULL, -- ms-epoch
1690
- ended_at INTEGER NOT NULL,
1691
- total_duration_ms INTEGER NOT NULL, -- wall clock of the whole run
1692
- task_count INTEGER NOT NULL, -- non-group, non-aborted tasks recorded
1693
- failed_count INTEGER NOT NULL,
1694
- hit_count INTEGER NOT NULL, -- cache-hit + cache-hit-remote
1695
- hit_local_count INTEGER NOT NULL, -- cache-hit
1696
- hit_remote_count INTEGER NOT NULL, -- cache-hit-remote
1697
- up_to_date_count INTEGER NOT NULL DEFAULT 0, -- v31: hits that restored nothing
1698
- restored_local_count INTEGER NOT NULL DEFAULT 0, -- v31: hits that restored, local layer
1699
- restored_remote_count INTEGER NOT NULL DEFAULT 0, -- v31: hits that restored, remote layer
1700
- exit_ok INTEGER NOT NULL, -- 1 if the run's `ok`
1701
- commit_sha TEXT, -- nullable: not a git repo / probe failed
1702
- branch TEXT,
1703
- dirty INTEGER, -- 1 if worktree had uncommitted changes
1704
- ci INTEGER NOT NULL, -- 1 if a CI env was detected
1705
- ci_provider TEXT, -- 'github' | 'gitlab' | 'buildkite' | 'circleci' | 'generic'
1706
- host TEXT, -- os.hostname()
1707
- os TEXT, -- process.platform
1708
- arch TEXT, -- process.arch
1709
- vx_version TEXT NOT NULL
1710
- );
1711
- CREATE INDEX invocations_started ON invocations(started_at);
1712
- CREATE INDEX invocations_branch ON invocations(branch);
1713
- CREATE INDEX invocations_ci ON invocations(ci);
1714
-
1715
- -- v22 (Tier 3): the input-fingerprint moat. One row per cache-key
1716
- -- component, keyed by the cache-ENTRY hash it belongs to (NOT a run
1717
- -- id). Written INSIDE the entry-save transaction — only on a cache
1718
- -- MISS, never on a hit — via INSERT OR IGNORE. A warm all-cache-hit
1719
- -- run writes nothing here. The "why did this re-run?" diff resolves a
1720
- -- run to its task hash (runs.hash), then joins two entries' components
1721
- -- over (kind, name), no recompute. v34: one row per entry, the
1722
- -- components one JSON array (a row per component cost a b-tree insert
1723
- -- each: ~0.5 ms a save at 50 input files). ON DELETE CASCADE sweeps the
1724
- -- row when a prune drops the entry.
1725
- CREATE TABLE entry_inputs (
1726
- entry_hash TEXT PRIMARY KEY, -- == entries.hash / runs.hash
1727
- components TEXT NOT NULL, -- JSON [[kind, name, hash], …] in (kind, name) code-unit order
1728
- FOREIGN KEY (entry_hash) REFERENCES entries(hash) ON DELETE CASCADE
1729
- );
1730
- -- kind: file|env|runtime|ws-runtime|upstream|package|config|forward|workspace|plugin|format
1731
- -- name: file: workspace-rel path; env: var name; upstream: task id; …
1732
- -- hash: env|runtime|ws-runtime|forward|plugin: xxh3hex(salt + value); an unset env var: 'unset'
1733
-
1734
- -- v32: what belongs to the entries, not to one workspace: 'value_salt',
1735
- -- the salt entry_inputs digests are taken under, so they compare with
1736
- -- another workspace's run.
1737
- CREATE TABLE store_meta (
1738
- key TEXT PRIMARY KEY,
1739
- value TEXT NOT NULL
1740
- );
1741
-
1742
- -- v36: each executed success's duration, appended in the run's history
1743
- -- transaction, in the store so every worktree forecasts from it.
1744
- -- source: 'branch:<name>'; the forecast reads the newest five per task.
1745
- -- v37: 'remote' rows are a default-branch commit's timings a plugin
1746
- -- imported, one per (sha, task).
1747
- CREATE TABLE task_durations (
1748
- id INTEGER PRIMARY KEY AUTOINCREMENT,
1749
- project TEXT NOT NULL,
1750
- task TEXT NOT NULL,
1751
- source TEXT NOT NULL,
1752
- sha TEXT,
1753
- duration_ms INTEGER NOT NULL,
1754
- recorded_at INTEGER NOT NULL
1755
- );
1756
- CREATE INDEX task_durations_task ON task_durations(project, task, source, id);
1757
- CREATE UNIQUE INDEX task_durations_remote
1758
- ON task_durations(sha, project, task) WHERE source = 'remote';
1759
-
1760
- -- v38: the flaky record (failure-mode.ts), in the store so a key that
1761
- -- passed in one worktree and failed in another is flaky in both. Every
1762
- -- executed success or failure that names its key (keyed, cached, not run
1763
- -- behind a failure), and a key's first hit: a later hit replays a pass on
1764
- -- record, so a warm run on passed keys writes no row (one index probe,
1765
- -- ~1 ms per 1,000 hits). Pruned by age with the run history.
1766
- CREATE TABLE task_outcomes (
1767
- id INTEGER PRIMARY KEY AUTOINCREMENT,
1768
- project TEXT NOT NULL,
1769
- task TEXT NOT NULL,
1770
- hash TEXT NOT NULL,
1771
- status TEXT NOT NULL,
1772
- attempts INTEGER,
1773
- recorded_at INTEGER NOT NULL
1774
- );
1775
- CREATE INDEX task_outcomes_hash ON task_outcomes(hash, status);
1776
-
1777
- -- v37: a plugin's own entries (`ctx.cache`), by core's key for its
1778
- -- name; written once, pruned by age with the run history.
1779
- CREATE TABLE plugin_blobs (
1780
- key TEXT PRIMARY KEY,
1781
- bytes BLOB NOT NULL,
1782
- at INTEGER NOT NULL
1783
- );
1784
-
1785
- -- v33: an artifact of at most 32 KiB compressed, its exact <hash>.tar.zst
1786
- -- bytes, written in the transaction that writes its entry rows. In the
1787
- -- store (or a named cache dir's cache.db), and outside every drop a
1788
- -- SCHEMA_VERSION reset makes: the artifact is the record.
1789
- CREATE TABLE artifacts (
1790
- hash TEXT PRIMARY KEY,
1791
- at INTEGER NOT NULL, -- last use (ms): a row-less sweep's file time
1792
- bytes BLOB NOT NULL
1793
- ) WITHOUT ROWID;
1794
-
1795
- -- 'layout' = 'a1': the artifacts table's own version; another value
1796
- -- drops the table, silently. Nothing else drops it. Read only where
1797
- -- the schema was not this vx's, so a layout change bumps the schema.
1798
- CREATE TABLE artifacts_meta (
1799
- key TEXT PRIMARY KEY,
1800
- value TEXT NOT NULL
1801
- );
1802
- ```
1803
-
1804
- WAL mode is on; readers don't block writers. `PRAGMA busy_timeout =
1805
- 5000` makes concurrent `vx run` invocations queue instead of failing
1806
- with `SQLITE_BUSY`.
1807
-
1808
- > **Trust boundary (Tier 3):** `entry_inputs` stores a digest of each
1809
- > value-bearing component — `env`, `runtime`, `ws-runtime`, `forward`
1810
- > and `plugin` rows hold `xxh3hex(salt + value)`, an unset env var the
1811
- > literal `'unset'` — never the value, so a secret read as a cache input
1812
- > does not land in `cache.db` as plaintext. The salt is 128 random bits
1813
- > the store draws once (`store_meta` key `value_salt`): `vx why` prints
1814
- > these digests, and an unkeyed xxh3 in a public CI log let anyone
1815
- > confirm or brute-force a short secret. The "why did this re-run?" diff
1816
- > only needs to know a component changed, which the digest tells it.
1817
- > `cache.db` still records commands and captured stdout; it is a local,
1818
- > gitignored, single-user file.
1819
-
1820
- The Tier-3 tables persist components that were **already fed to
1821
- `Cache.key()`** — the cache key derivation is unchanged, so the
1822
- `CACHE_VERSION` is NOT bumped (only `SCHEMA_VERSION` rolls to `v22`).
1823
- Capture happens as a pure side-channel inside the existing `key()` fold
1824
- (`CacheKeyInput.captureInto`), **only on a cache miss** (the warm path
1825
- captures nothing), and the rows are persisted with the entry — so a
1826
- warm all-cache-hit run does no extra hashing, I/O, or DB writes for the
1827
- moat.
1828
-
1829
- ### Why SQLite + a single artifact per entry
1830
-
1831
- - **Index queries are fast.** Stats (`SELECT COUNT(*) FROM entries`),
1832
- TTL pruning (`WHERE accessed_at < ?`), per-task lookup
1833
- (`WHERE hash = ?`) all hit a B-tree.
1834
- - **A hit costs SQL, not decompression.** Metadata + stdout live in
1835
- the row; the artifact is only opened when outputs actually restore.
1836
- - **One artifact = one wire payload.** The same tar.zst bytes serve
1837
- local storage and the remote round-trip — no repacking.
1838
- - **One handle, one schema-meta sentinel.** An older schema drops
1839
- and recreates every table but `schema_meta` (pre-alpha) — there's no migration code to maintain.
1840
-
1841
- ## Performance characteristics
1842
-
1843
- - **Hashing cost** on a clean tree is near-zero per file: git index
1844
- OIDs come from the bulk enumeration spawn, so key derivation does no
1845
- file reads. Dirty/untracked files — and any path whose OID is not
1846
- trustworthy (see "Clean filters") — hash in-process (whole-file
1847
- read, behind a `(mtime, size, ctime, ino)` memo). Narrow
1848
- `inputs.files` still helps on heavily dirty trees.
1849
- - **Cache read** is three indexed `SELECT`s (the `entries` row, which
1850
- joins whether the artifact is inline, its `output_files` and its
1851
- `output_dirs`), plus a `stat` of the artifact when it is a file.
1852
- Restore is a tar.zst extract, skipped entirely when the on-disk
1853
- tree already matches. `accessed_at` bumps (only rows over an hour
1854
- old) are batched into one UPDATE at flush time.
1855
- - **Cache write** is one in-process tar.zst pack + one SQLite
1856
- transaction, which holds a small artifact's bytes itself; a large one
1857
- adds a temp write and an atomic rename. Hashing dominates the run; storage itself
1858
- is cheap. The remote upload (if any) is backgrounded.
1859
- - **Claimed root files** (a lockfile plugin's lockfile and settings)
1860
- are read once per `vx run` invocation; after a task that may rewrite
1861
- one ran, one `stat` per file re-checks it (item 750). With no plugin
1862
- claiming one, nothing is read.
1863
-
1864
- ## What's NOT in the key (and why)
1865
-
1866
- - **`exec.env.passThrough` _values_.** Would force cache misses across
1867
- machines with different CI flags, regions, or shell prompts. The
1868
- _names_ are in the config hash (step 3) so adding/removing a
1869
- passthrough still bumps the key for affected tasks.
1870
- - **Files outside the project directory that aren't declared.**
1871
- Workspace-root configs (`tsconfig.base.json`, etc.) are not
1872
- auto-included — declare them via `inputs.workspaceFiles`
1873
- (root-anchored globs).
1874
- - **Gitignored files no entry names.** Vite and Next load `.env.local`
1875
- on their own; a broad glob skips it, so editing it replays the old
1876
- build. Name it: `files: ['src/**', '.env.local']`. Its bytes are
1877
- hashed, never stored, and a missing file is simply not an input.
1878
- Machines with different files compute different keys, so they miss
1879
- each other's shared entries. `--affected` ignores it (only what git
1880
- sees selects a task), and `vx watch` re-runs on its edit. A probe
1881
- (`runtime: ['cat .env.local 2>/dev/null | cksum']`) still works where
1882
- a command, not a path, decides what to read.
1883
- - **Node / Bun / OS / build-tool versions — unless you declare them.**
1884
- The canonical mechanism is `inputs.runtime` /
1885
- `workspaceRuntime` (e.g. `workspaceRuntime: ['node -v']`): the
1886
- command output is resolved live at hash time, so it stays correct
1887
- under the lock. Avoid baking versions via
1888
- `define: { X: execSync(...) }` — that value freezes into the config
1889
- object at lock time and goes stale.
1890
- - **`.vx/projects.lock.json`** — globally excluded (v24); also filtered out of
1891
- `--affected` change sets. So are the files `vx lock` and `vx init`
1892
- write beside it: each project's `vx.lock.json` review copy,
1893
- `.vx/.gitattributes` and `.vx/.gitignore`.
1894
- - **`exec.remote`.** Pure PLACEMENT: it decides _where_ a task runs,
1895
- never what it produces, so pinning a task to this machine does not
1896
- bust its cache. It must not — the
1897
- whole contract of a remote executor is that the same command over the
1898
- same inputs yields the same outputs, so a key that moved with
1899
- placement would split your laptop from the worker pool over nothing.
1900
-
1901
- **`exec.timeout` and `exec.retries` are the deliberate exception** —
1902
- they stay in the key. That asymmetry is easy to misread as an
1903
- oversight, so: a timeout or a retry budget can change _whether the
1904
- task completes at all_, which is a different question from where it
1905
- ran. They were folded in before the placement fields existed, and
1906
- stripping them now would be a `CACHE_VERSION` bump for no correctness
1907
- gain.
1908
-
1909
- ## Bumping `CACHE_VERSION`
1910
-
1911
- The cache records the version it was written under
1912
- (`schema_meta.cache_version`). After an upgrade every cached task
1913
- misses once and re-saves, with nothing printed (owner, 2026-10-06: the
1914
- cache is vx's to keep). The index survives, so the old entries stay
1915
- until they age out under `vx cache clean --older-than` or
1916
- `cache.retention`; no key derives to them again.
1917
-
1918
- Required when:
1919
-
1920
- - A new field is added to the cache key derivation (step list above).
1921
- - The order or framing of existing key fields changes.
1922
- - The on-disk layout changes (artifact format, entry naming).
1923
- - The `CacheEntry` shape changes in a way that affects restore.
1924
- - The SQLite schema changes in a way that affects existing rows
1925
- (`SCHEMA_VERSION` also bumps in that case).
1926
-
1927
- Not required when:
1928
-
1929
- - Behavioural changes that adjust _which_ values flow into existing
1930
- key components — those naturally produce different keys for
1931
- affected tasks.
1932
- - Changes to WHEN reads/writes fire (policy, prefetch, restore tier,
1933
- background uploads) — key derivation and artifact bytes untouched.
1934
- - Doc-only updates.
1935
- - Refactors that don't change the bytes fed into the hash.
1936
- - A key part leaves the chain: every key moves, so no unchanged key
1937
- holds wrong bytes (`v43` stayed when core stopped folding the
1938
- `workspace:` and `pkg:` parts, 2026-10-14).
1939
-
1940
- `tests/contract-stored-format.test.ts` holds the layout rows: it
1941
- records the index's DDL beside `SCHEMA_VERSION` and a fixture
1942
- artifact's entries, sidecar and digest beside `CACHE_VERSION`
1943
- (`tests/contract/stored-format.json`), and fails when either layout
1944
- moves under its recorded version. Every bump of either version
1945
- regenerates the record
1946
- (`VX_UPDATE_CONTRACT=1 bun test tests/contract-stored-format.test.ts`),
1947
- which refuses a layout that moved without one.
1948
-
1949
- The bump procedure has a dedicated skill at
1950
- `.claude/skills/bump-cache-version/` (used as `/bump-cache-version`).
1951
- Files touched, in the skill's order: `src/cache/key-fold.ts` (the constant),
1952
- this doc (history), `docs/modules/cache.md` (the quoted version, and the
1953
- key/entry shape if it changed), `CLAUDE.md` § Live invariants (the quoted
1954
- version — the decision log it once named was retired 2026-09-02),
1955
- `docs/STATUS.md` (the entry that says why the bump was needed, or why it
1956
- was not), the cache tests, `tests/contract/stored-format.json`
1957
- (regenerated, above), and
1958
- `packages/vx-docs/src/content/docs/guides/upgrading.md` (the bump's
1959
- breaking footer).
1960
-
1961
- ### History
1962
-
1963
- - **v43 kept** (2026-10-14): core stopped folding the project's
1964
- `package.json` and the root fingerprint files; every key moved, so
1965
- nothing replays wrong bytes and no bump was needed.
1966
- - **v42 → v43**: stored bytes wrong under an unchanged key (Security
1967
- F4, 2026-10-14). A scoped run stored its local entries under the
1968
- default key, so a later default run on the same disk replayed a PR's
1969
- bytes. A scoped run now stores under the scope's key locally as it
1970
- does remotely; the fix cannot reach an entry already saved that way.
1971
- - **v41 → v42**: the stored output became both streams in the order
1972
- the run printed them (`orchestrator/output-log.ts`), so a hit replays
1973
- stderr too. A v41 entry holds stdout alone.
1974
- - **v40 → v41**: stored bytes wrong under an unchanged key (X-88). An
1975
- output directory linked inside its project was never cleaned, so an
1976
- entry could hold files a run of another key left there. The fix
1977
- cannot reach an entry already saved that way.
1978
- - **v39 → v40**: stored bytes wrong under an unchanged key (X-32, X-33,
1979
- X-34). An additive task's entry a hit replayed over a file the task
1980
- had removed, one that missed a same-size rewrite, and a runtime probe
1981
- answered before its upstream wrote.
1982
- - **v38 → v39**: stored bytes wrong under an unchanged key (A-61). A
1983
- gitlink whose directory had lost its `.git` but held files listed
1984
- none of them, so an entry built from them sits under the key the
1985
- same directory empty derives.
1986
- - **v37 → v38**: stored bytes wrong under an unchanged key (A-60). A
1987
- file added under a clean filter that was later removed kept its LF
1988
- index blob, git held it clean by its stat, and the key folded that
1989
- blob while the task read the CRLF bytes. The blob-size check cannot
1990
- reach an entry already saved that way.
1991
- - **v36 → v37**: stored bytes wrong under an unchanged key (A-59).
1992
- `git status` paired a deleted file with a similar unmerged path as its
1993
- rename source and printed only `UU <path>`, so the file kept its index
1994
- OID and the key folded it while the task ran without it. The fix
1995
- (`--no-renames`) cannot reach an entry already saved that way.
1996
- - **v35 → v36**: the container changes (L-19). Every artifact ends in a
1997
- `.vx-sum` entry, a CRC-32 over the entries before it, and scan and
1998
- restore refuse one whose sum is absent or wrong: a byte flipped in a
1999
- raw zstd block restored as a hit, undetected. A v35 artifact carries no
2000
- sum, so the bump retires them rather than refusing each on read.
2001
- - **v34 → v35**: the container changes (item 943). The sidecar records
2002
- the cache key the artifact was packed under, and ingest refuses bytes
2003
- whose key is not the one it asked for, or that record none. Nothing
2004
- tied an artifact to its key before: a remote layer that answered one
2005
- key with another's bytes (a truncated or colliding key mapping, two
2006
- namespaces mixed) replayed the other task's outputs under a green
2007
- `cache-hit-remote`, probed with project `b` restoring project `a`'s
2008
- `out.txt`. An artifact from v34 records no key, so the bump retires
2009
- them rather than refusing each one on read.
2010
- - **v33 → v34**: stored bytes wrong under a key a CORRECT derivation now
2011
- produces (item 750). A root task that rewrote the lockfile mid-run
2012
- (`pnpm install` without `--frozen-lockfile`) let a reader after it save
2013
- a build made against the new install under the key of the lockfile the
2014
- run started with, and that key is exactly what the fixed code derives
2015
- when the tree is back on that lockfile. The fix stops new entries, not
2016
- old ones. Probed, not argued: seeds A then B through the previous
2017
- commit, then A twice through the fixed code under v33 — the last run
2018
- started on lockfile A, installed A, and restored the build made against
2019
- B; under v34 it built A. The item's other two edges poisoned nothing:
2020
- their stale restores happened in runs that saved nothing (a read-only
2021
- policy, a tainted upstream) or saved under a key the 743 re-check
2022
- already guarded.
2023
- - **v32 → v33**: stored bytes wrong under a key a CORRECT derivation now
2024
- produces (item 743). The three stale-hit fixes of that item stop new
2025
- poisoned entries, but not the ones already saved: a formatter's entry
2026
- sits under the key of its unformatted input, an uncached `gen`'s
2027
- consumer's under the key of the seed before `gen` ran, an edit-mid-run's
2028
- under the key of the file before the edit — and each of those keys is
2029
- exactly what the fixed code derives when the tree is back in that
2030
- state. Not self-healing, unlike a fix whose old key no correct run
2031
- derives. Probed, not argued: an entry saved by the previous commit's
2032
- formatter, the input checked out unformatted, and the fixed code under
2033
- v32 reported `up-to-date` and left it unformatted; under v33 it runs.
2034
- - **v31 → v32**: stored bytes wrong under a key the fix does not change
2035
- (item 739). A declared output whose name is not UTF-8 (`x\xffy`) came
2036
- back from `Bun.Glob` decoded lossily as `x�y`, which names no file, so
2037
- the save packed the tree without it and every hit restored a tree
2038
- missing that file under an unchanged key. vx now refuses such a name
2039
- by name; an artifact saved before the fix is the wrong bytes, so v31
2040
- entries are not trusted.
2041
- - **v30 → v31**: stored bytes wrong under a key the fix does not change
2042
- (item 726), v30's shape for a sibling. A sandboxed task that declared
2043
- `cache` was granted every workspace package linked in its
2044
- `node_modules`, so it could import a sibling its key never folded and
2045
- save what it built. The fix withholds that link unless the key answers
2046
- for the package (§ Cross-project boundaries), so the next miss fails
2047
- on the read; but an entry saved before it still hits when only the
2048
- sibling changes. Probed, not argued: an entry saved by the previous
2049
- commit, `@x/ui` edited, then this commit's run under v30 reported
2050
- `up-to-date` and left the old `ui` in `dist/`; under v31 the same run
2051
- misses and fails on the read, with the hint.
2052
-
2053
- - **v29 → v30**: stored bytes wrong under a key the fix does not change
2054
- (item 720). npm and Yarn link every workspace package at the root, the
2055
- task's own included, and the sandbox granted every link target whole,
2056
- so a sandboxed task was handed its own project back whatever its
2057
- `allow.read` said. An undeclared read of its own file ran unreported
2058
- and the result was saved under a key that never saw that file. The fix
2059
- withholds the self-link, so the next miss fails on the read; but an
2060
- entry saved before it hits for as long as only that file changes.
2061
-
2062
- - **v28 → v29**: every key moves, and the bump is for the notice, not
2063
- for wrong bytes (item 682). The key is a seed-chained xxHash3 fold,
2064
- one step per field and per input file, and Bun's xxHash3 reads only
2065
- the low 32 bits of its seed: a bare chain carried 32 bits of state, so
2066
- two input sets whose running digests shared their low halves merged at
2067
- the next step, a stale hit at about 2^-32 per step rather than 2^-64.
2068
- A birthday search over 2^17 values of one env variable found two that
2069
- gave one `Cache.key` in under a second. `xxh3` now feeds the seed
2070
- forward (`xxHash3(part, seed) ^ seed`): states that share their low
2071
- half keep their high-half difference through every later step. The
2072
- old keys were wrong but their stored bytes are not, so the fix alone
2073
- is self-healing; without the bump every entry would miss silently.
2074
-
2075
- - **v27 → v28**: stored bytes wrong under a key the fix does not change —
2076
- the v25/v26 shape (item 667). A bracket in a task glob became a literal
2077
- character; before, `Bun.Glob` read it as a character class. An INPUT
2078
- glob over a route directory folded the wrong files, and that fix is
2079
- self-healing: the file set, and so the key, moves. An OUTPUT glob is
2080
- not: `outputs: ['app/[id]/page.js']` folds as its text, which the fix
2081
- leaves unchanged, and the entries under it hold nothing (or the class's
2082
- namesake `app/i/page.js`). Proven through a real run: an entry written
2083
- by v27 code, read by the fixed code, was a `cache-hit` that cleaned
2084
- `app/[id]/page.js` and restored nothing; under v28 it is a miss, and
2085
- the next hit restores the route.
2086
-
2087
- - **v26 → v27**: the artifact CONTAINER changed, so the stored bytes
2088
- under an unchanged key are no longer readable the same way — the
2089
- layout case, not the wrong-bytes case. Packing moved from a `tar`
2090
- subprocess (with a staged copy of every output and a per-host
2091
- `--format=gnu` / `--format=gnutar` probe) to `Bun.Archive`, and the
2092
- per-entry mode + millisecond mtime that tar headers carried natively
2093
- now ride a `.vx-meta.json` sidecar. Measured on the real `Cache.save`
2094
- path (300 outputs / 12 MB, min-of-5, interleaved arms against a
2095
- `git worktree` of the previous commit): **158 ms → 11 ms** to pack,
2096
- the artifact grows ~7 compressed bytes per output for the sidecar.
2097
- Restore is indistinguishable up to ~12 MB, but on a 150 MB
2098
- incompressible artifact it costs +28% time and +19% peak RSS
2099
- (74 → 95 ms, 575 → 683 MB peak, fresh process per arm): `files()`
2100
- returns entries that OWN their bytes, so they coexist with the
2101
- decompressed tar where the old reader returned views into it. Peak is
2102
- ~4.5× artifact size, up from ~3.8×. The bump is mandatory rather than
2103
- self-healing: a v26 artifact has no sidecar, so a v27 reader would
2104
- restore its outputs mode-0644 and mtime-now — silently wrong on disk
2105
- rather than a miss. Since 2026-09-03 the same layout is written and
2106
- read by vx's own streaming tar code (no bump: the bytes are readable
2107
- either way), and the peak above is history — save, ingest and restore
2108
- hold one chunk now; see § Storage layout.
2109
-
2110
- - **v25 → v26**: the same shape as v25 — stored bytes that are wrong
2111
- under a key nothing about the fix changes — reached by a different
2112
- producer. A task whose child was killed by a shutdown signal reports
2113
- `aborted`, but `aborted` did not propagate to dependents the way
2114
- `failed` and `skipped` do. So a dependent ran against the aborted
2115
- task's PARTIAL outputs, succeeded, and cached what it had built.
2116
- Because a dependent's key folds its upstream's INPUT key — and a
2117
- signal changes no input — that entry sits under exactly the key a
2118
- healthy run derives, and the next run replays it as a green hit with
2119
- exit 0. Reproduced end to end: run 1 killed mid-write leaves
2120
- `PARTIAL`, run 2 is fully healthy and still serves `PARTIAL` from
2121
- cache.
2122
-
2123
- Making `aborted` propagate stops new poison but cannot reach entries
2124
- already written, and a `LayeredCache` uploads them — so the reach is
2125
- a whole team's shared cache, not one developer's disk. That is what
2126
- makes the trade worth it: one cold rebuild against a class of
2127
- silently-wrong output. The interactive Ctrl-C path was never the
2128
- vector (vx's handler exits before a dependent can cache); the
2129
- reachable ones are an external `kill`, a supervisor, `docker stop`, a
2130
- self-terminating script, and every `handleSignals: false` embedder —
2131
- which includes `vx watch` and the distributed agent loop.
2132
-
2133
- - **v24 → v25**: the ARTIFACT BYTES in every existing entry are wrong
2134
- while the key addressing them is unchanged — the one situation a
2135
- version bump exists for, and the opposite of the recent self-healing
2136
- no-bump cases. Two defects on the pack/restore path, both silent data
2137
- loss on an ordinary cache hit with no attacker involved:
2138
- - **The executable bit was stripped from every cached output.**
2139
- `packArtifact` staged each output with `Bun.write`, which creates
2140
- the destination under the process umask and does NOT carry the
2141
- source's mode, so the tar header recorded 0644 and the restore
2142
- faithfully reproduced 0644. Any build emitting a CLI shim, a
2143
- compiled binary or a generated script worked cold and broke warm —
2144
- including this repo's own `build.bun.*` release binaries. Fixed by
2145
- chmod-ing each staged copy to the source's mode.
2146
- - **Outputs whose archive entry name exceeded 100 bytes were dropped
2147
- on every restore.** POSIX ustar splits such a name into
2148
- `prefix` + `name`; the reader read only `name`, which no longer
2149
- starts with `outputs/`, so the file was neither restored nor
2150
- indexed. Not self-healing: with no `output_files` row, the
2151
- skip-restore check compared a truncated expectation against a
2152
- truncated tree and agreed forever. Threshold is a
2153
- project-relative output path of ~93 chars — ordinary for a modern
2154
- bundler. Fixed by reading `prefix` (gated on the POSIX magic, since
2155
- GNU headers reuse those bytes for atime) AND by packing
2156
- `--format=gnu`, which carries long names in an `L` record.
2157
-
2158
- The format switch also fixes a working build being reported as
2159
- FAILED: ustar cannot split a single path COMPONENT over 100 bytes and
2160
- exits non-zero ("file name is too long (cannot be split)"), which
2161
- `packArtifact` raised _after_ the task had already succeeded. 120-char
2162
- filenames are legal everywhere and routine in snapshot/fixture trees.
2163
-
2164
- Shipped with three defence-in-depth fixes that needed no bump of their
2165
- own: `restoreOutputs` now throws instead of returning quietly when the
2166
- artifact is gone or cannot produce an output the index recorded (the
2167
- caller has already wiped the declared outputs by then, so a quiet
2168
- return reported a green hit over an emptied tree — reachable via a
2169
- concurrent `vx cache clean`); the tar reader rejects an entry whose
2170
- declared size runs past the end of the archive (`subarray` clamps, so
2171
- it used to install short, NUL-padded content as a cache hit instead of
2172
- degrading to a miss); and directory entries now get the same
2173
- containment + realpath checks as file entries (`mkdir` follows a
2174
- pre-existing symlink, so directories could be created outside the
2175
- destination). No `SCHEMA_VERSION` bump — no table changed.
2176
-
2177
- - **SCHEMA v23 → v24 (no `CACHE_VERSION` bump)**: `file_hashes` gains
2178
- `ctime_ms` + `ino`. The memo keyed on `(mtime, size)` alone, and its
2179
- row persists across runs, so any producer that preserves mtime —
2180
- `tar -x`, `unzip`, `cp -p`, `rsync --times`, a `SOURCE_DATE_EPOCH`
2181
- generator — got the previous run's digest for genuinely different
2182
- bytes: a stale cache hit. `utimes` cannot suppress ctime
2183
- unprivileged and an atomic write-then-rename changes the inode, so
2184
- the two together close it (git's index keys on ctime+ino+dev for the
2185
- same reason); both come free from the stat already taken. The key
2186
- DERIVATION is unchanged — the memo simply stops answering wrongly —
2187
- so an affected task's key moves from a wrong value to the right one:
2188
- it misses once, re-runs, re-caches. Self-healing, never a wrong hit.
2189
- Landed alongside two other stale-hit fixes that needed no schema
2190
- change: the cache-miss path now marks the outputs `cleanOutputs`
2191
- wiped (it was the only one of four sibling call sites that dropped
2192
- the return, so a deleted output kept a live index OID and stayed in
2193
- a consumer's input set), and `skip-worktree` / `assume-unchanged`
2194
- entries no longer keep a trusted OID (they sit at stage 0 and
2195
- `git status` reports nothing for them, so a sparse-checkout path
2196
- that was absent from disk still counted as an input). The schema
2197
- gate drops + recreates on the version mismatch (pre-alpha, no
2198
- migration), so this costs one cold rebuild.
2199
- - **SCHEMA v21 → v22 (no `CACHE_VERSION` bump)**: Tier-3 dashboard
2200
- tables — `invocations` (one header row per `vx run` with command,
2201
- git/CI/host context, and run-level counts, recorded with `runs`
2202
- via `Cache.recordRunBundle`) and `entry_inputs` (one row per cache-key
2203
- component, keyed by the cache-ENTRY hash — the input-fingerprint
2204
- moat). `entry_inputs` is written **inside the entry-save transaction,
2205
- only on a cache miss** (`INSERT OR IGNORE`), so a warm all-cache-hit
2206
- run writes nothing for the moat — Tier 3 has **zero warm-run cost**.
2207
- The cache KEY derivation is unchanged: these tables persist components
2208
- already fed to `Cache.key()` (captured via a pure side-channel,
2209
- `CacheKeyInput.captureInto`, at the same fold sites — only on a miss),
2210
- so existing artifacts stay valid and `CACHE_VERSION` stays `v24`. The
2211
- schema gate drops + recreates on the version mismatch (pre-alpha, no
2212
- migration).
2213
- - **v23 → v24**: exclude `.vx/projects.lock.json` from the input file set
2214
- globally (`ALWAYS_IGNORE` in `cache/inputs.ts`). The lockfile is
2215
- committed, so git enumerates it, but it's vx's own frozen-config
2216
- metadata — never a task input. Without this, a `vx lock` re-write
2217
- busts every key on a project that globs the root lockfile (a broad
2218
- `**/*` on the root project). Tasks whose `inputs.files` never
2219
- matched it derive byte-identical keys. No SCHEMA bump — only the
2220
- hashed file set changed, not the key layout or on-disk format.
2221
-
2222
- - **v22 → v23**: fold `inputs.runtime` / `workspaceRuntime`
2223
- command output into the key (two namespaced sections after
2224
- env-values). The command _strings_ stay in the config hash (step 3);
2225
- their combined trimmed stdout+stderr is resolved live at hash time
2226
- and folded as `runtime-values:` (project-cwd) and `ws-runtime-values:`
2227
- (root-cwd) sections, each `command\0output`. No SCHEMA bump — only
2228
- `Cache.key` derivation gained two sections; the on-disk format is
2229
- unchanged. Tasks declaring neither field fold a `:0` count for both
2230
- and derive byte-identical keys to before the bump.
2231
-
2232
- - **v21 → v22: pure-input transitive** (+ SCHEMA v21): reverted the v21
2233
- output-fold. Downstream keys fold the upstream's **input key** (its
2234
- own task hash) — a pure function of the filesystem, like Turbo/Nx.
2235
- No output content participates in any cache key. **Early cutoff is
2236
- gone**: an upstream that re-executes (comment edit, env change) but
2237
- reproduces byte-identical output now still re-runs its dependents.
2238
- This was a deliberate simplification — cutoff is rare in practice
2239
- and not worth the cascade complexity (it forced output content into
2240
- keys, which blocks any upfront/batched probe). **Multi-state is
2241
- preserved**: branch ping-pong A→B→A still re-hits, because the
2242
- upstream's _input_ differs per state and folds transitively into
2243
- every dependent key. SCHEMA v21 drops the now-unused `outputs_hash`
2244
- column; `CacheLayer.save` returns `void`.
2245
-
2246
- - **v20 → v21: early cutoff** (+ SCHEMA v19, **reverted in v22**):
2247
- downstream keys folded the upstream's output content identity
2248
- (`outputsHash`) instead of its task hash. Removed — see v22.
2249
-
2250
- - **v7 → v8** (PR #2): folded `forwardArgs` into the key for CLI
2251
- argument-forwarding alignment.
2252
- - **v8 → v9** (PR #3): `TaskConfig` shape changed — `exec` collapsed
2253
- from an array to a single command, `tasks` nested under `run`.
2254
- - **v9 → v10** (PR #7): on-disk layout switched from per-entry
2255
- `meta.json` + `outputs/` directory to a workspace-wide `cache.db`
2256
- (SQLite) plus output files directly at `<hash>/` and log files at
2257
- `logs/<hash>.{stdout,stderr}`. Adds run history for `vx info`.
2258
- Removes the per-entry manifest.
2259
- - **v10 → v11** (PR #19): analytics columns added to the `runs`
2260
- table: `run_id` (UUIDv7), `cpu_ms`, `peak_rss_bytes`,
2261
- `wallclock_start_ns` / `wallclock_end_ns`, `cache_hit`. All
2262
- nullable; directly queryable via `sqlite3 cache.db`. The on-disk
2263
- `<hash>/` layout itself was unchanged.
2264
- - **v11 → v12** (PR #42): project's `package.json` bytes folded into
2265
- every task's cache key implicitly. Matches Turbo / Nx "implicit
2266
- dependencies" behavior — a `package.json` dep change invalidates
2267
- the project's tasks even when `inputs.files` is narrow and
2268
- doesn't cover the file.
2269
- - **v12 → v13** (PR #65): per-entry on-disk layout unified. Outputs
2270
- moved from `<hash>/<rel>` (mixed with metadata) to
2271
- `<hash>/outputs/<rel>`; stdout / stderr moved from the sibling
2272
- `logs/<hash>.{stdout,stderr}` into `<hash>/stdout` and
2273
- `<hash>/stderr`. Eviction collapses to a single `rm -rf <hash>/`.
2274
- Also dropped the runner's `logs/<run_id>/<project>__<task>.{stdout,stderr}`
2275
- dump — output is already streamed live, surfaced on the outcome
2276
- object, and the cache entry covers successful runs; CI captures
2277
- parent stdout natively. The duplicate sibling dump was pure
2278
- redundancy.
2279
- - **v13 → v14**: file enumeration switched from a `Bun.Glob` walker
2280
- with our own `ignore`-library filter to `git ls-files --cached
2281
- --others --exclude-standard`. Matches what Turborepo and Nx both do
2282
- at the bottom of their hash pipelines. Side-effects user-visible:
2283
- (a) nested `.gitignore` patterns are anchored to the gitignore's own
2284
- directory, fixing the v13 footgun where `pkg/.gitignore: src/skip.ts`
2285
- was misinterpreted as `<workspaceRoot>/src/skip.ts`; (b)
2286
- `.git/info/exclude` and global excludes participate; (c)
2287
- untracked-but-not-ignored files enter inputs immediately (no
2288
- `git add` required). (The non-git fallback walker was later removed
2289
- entirely — vx hard-requires git; a non-repo workspace gets a clean
2290
- `UserError` telling the user to `git init`.)
2291
- - **v14 → v15**: cache-key hash swapped from SHA-256 (via
2292
- `Bun.CryptoHasher`) to xxHash3 (via `Bun.hash.xxHash3`). Key strings
2293
- shrink from 64 hex chars to 16, matching Turbo's xxh64 output width;
2294
- derivation is ~5× faster, dominating the cache-warm path that
2295
- hashes hundreds of input files. xxHash3 has no streaming Hasher
2296
- API, so `Cache.key()` chains via the seed parameter (each
2297
- `xxh3(part, prevDigest)` folds one field into the running digest)
2298
- and `hashFileFromDisk` reads the whole file before hashing — fine
2299
- for source files (typically < 1MB each); the throughput win
2300
- outweighs the memory hit. `SCHEMA_VERSION` bumps to `v15` at the
2301
- same time (PR #86 already took `v14` for the tar.zst artifact
2302
- layout): the `file_hashes.sha256` column is renamed to
2303
- `content_hash`, and the schema-mismatch path now `DROP`s the stale
2304
- tables before `CREATE TABLE IF NOT EXISTS` runs so the rename
2305
- actually takes effect on existing DBs. Non-cryptographic by design
2306
- — cache keys never need collision resistance against an adversary,
2307
- just uniqueness across honest inputs.
2308
- - **v15 → v16** (PR #86 series): artifact storage moved to a single
2309
- compressed `<hash>.tar.zst` per entry; the manifest.json entry was
2310
- dropped (file fingerprints live in the `output_files` table).
2311
- - **v16 → v17**: artifact narrowed to exactly `stdout` +
2312
- `outputs/<rel>` — no `meta.json`, no stderr (only successful runs
2313
- are cached and their stderr is near-always empty noise). Local and
2314
- remote layers transport the same bytes end-to-end; entry metadata
2315
- lives solely in SQLite.
2316
- - **v17 → v18**: env-value folding in `Cache.key()` switched its
2317
- name/value delimiter from `=` to `\0`. `${n}=${v}` was ambiguous —
2318
- `("A", "B=C")` and `("A=B", "C")` folded identical bytes. Env names
2319
- containing `=` are unreachable from a real POSIX environ, so this
2320
- is contract hardening rather than a field bug, but the key
2321
- derivation's stated invariant is unambiguous part boundaries —
2322
- now it holds everywhere (file inputs already used `\0`).
2323
- - **v18 → v19**: `'^task'` dependsOn expansion switched from
2324
- transitive-deps to nearest-holder frontier semantics (Turbo/Nx
2325
- direct-deps parity, plus vx's sparse bridging through deps that
2326
- don't declare the task). Task graphs lose the redundant deep edges,
2327
- so the filtered-upstream-hash set (step 8) shrinks for any task
2328
- whose deps chain `'^task'` themselves — same inputs now derive a
2329
- different key. Reachability/ordering is unchanged whenever holders
2330
- chain `'^task'` (the universal pattern); a holder that doesn't is
2331
- now the documented stopping point. No on-disk format change.
2332
- - **v19 → v20**: input-file content hashes switched from xxh3 to
2333
- **git blob OIDs** (Turbo's technique). The bulk enumeration spawn
2334
- became `git ls-files -s --others --exclude-standard` — `-s` lines
2335
- carry `<mode> <oid> <stage>\t<path>` for tracked files, so one
2336
- spawn yields the file list AND the index OIDs; a second
2337
- `git status --porcelain -z` spawn prunes OIDs for paths whose
2338
- working tree diverges from the index (renames drop both sides;
2339
- stage>0 conflict entries never get one; symlinks did not either
2340
- until 2026-09-09, when the fallback started hashing a link the way
2341
- the index does). A clean
2342
- tree's key derivation does zero reads / stats / SQLite per file.
2343
- Everything else falls back to `Cache.hashFile`, which now computes
2344
- the identical blob OID in-process (object format auto-detected via
2345
- `git rev-parse --show-object-format`, sha1 default) behind the
2346
- existing mtime+size memo. `SCHEMA_VERSION` bumps to `v18` in the
2347
- same change: pre-v20 `file_hashes.content_hash` rows store 16-hex
2348
- xxh3 digests that must not leak into the OID domain through the
2349
- memo. File-set visibility semantics are unchanged (verified: the
2350
- `-s --others` path set is identical to `--cached --others`,
2351
- including staged-but-deleted files and per-stage conflict
2352
- duplicates).