Repository navigation
Cache the parsed plugin inventory by file identity - #152
Conversation
A real inventory runs to tens of megabytes — a 482-plugin machine's plugins.json is 75 MB, almost all of it param tables — and one compileSession read and zod-validated it twice: loadProject's pin-drift validation and toPluginWire's path hint. Profiled on bloom, that parse was 36% of the compile's CPU plus most of its GC, putting a watch edit's session swap at ~1.75 s of which the daemon needed only ~120 ms. readInventory now caches the parsed object keyed by path and invalidated on mtime or size, so a fresh scan lands the moment the file changes and every other read is a stat. The watch loop is one long-lived process, so edits after the first compile in ~70 ms instead of ~1,350 ms — the felt swap drops from ~1.75 s to ~0.5 s, now dominated by the watcher's 300 ms debounce. Sharing the parsed object is safe because every caller treats the inventory as read-only; writers go through the file.
|
Starting review of affce46. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: affce46d7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… size Codex on #152: a same-length replacement that preserves timestamps — cp -p, a restored backup — leaves mtime and size unchanged and would be served stale indefinitely; bigint exposes the filesystem's precision, it does not create invalidation. ctime catches it because the filesystem stamps it on any write and userland cannot set it back, and the inode catches a rename-replace. The test pins mtime with utimesSync around a same-size rewrite and fails against the mtime+size key on exactly the stale read.
minjudd
left a comment
There was a problem hiding this comment.
Reviewed affce46 in a scratch worktree at that exact commit.
The design is right and I want to say so before the one finding, because the finding is not an argument against it. mtime + size is the correct key here: content-hashing would re-read the 75 MB the cache exists to avoid, so a cheap stat is the only invalidation that pays for itself. Sharing the parsed object holds up too — I traced every caller rather than taking the claim on faith. listCommand and scanCommand iterate, findInstalled is a find, pinProject reads inventory.plugins and writes only into the YAML Document, toPluginWire spreads installed.name/installed.path into a fresh object, and project.ts's validation only filters installed.params. A grep for .plugins.push|sort|splice|reverse|shift|pop, inventory.plugins = and .failed.push comes back empty. Nothing mutates what the cache hands out.
What I ran, all in the scratch worktree: pnpm typecheck clean; pnpm test with FIELD_AUDIOD pointed at the prebuilt daemon → 42 files passed, 1 skipped, 664 passed / 1 skipped of 665. (Without that env var 78 tests fail on field-audiod is not built, which is the worktree lacking a native build, not this change.) I also checked the negative claim in your Testing section and it holds exactly as written: git checkout <base> -- src/audio/plugins.ts and the new test fails at plugin-hosting.test.ts:741 on expected … to be … // Object.is equality, Compared values have no visual difference — the assertion is load-bearing.
On the granularity worry that mtimeNs invites, I probed it rather than assuming: 200 same-length rewrites of one file in a tight loop produced 200 distinct (mtimeNs, size) pairs on APFS, with sub-microsecond spacing between consecutive writes. The key is sound on this platform, and ext4 and NTFS both carry sub-second resolution too. This is background for the finding below, not a defect.
Two non-blocking observations. The cache is a module-level Map with no eviction, so the parsed inventory is retained for the process lifetime — for a one-shot CLI command the process exits, and for the watch loop retaining exactly one root's inventory is the trade you are buying, so this is fine as it stands; it is only worth remembering if something long-lived ever serves several project roots. And "one compileSession read and zod-validated it twice" describes bloom's single-insert case: toPluginWire is called per hosted insert (live.ts:81, stem.ts:476), so a chain with several hosted arms read it N+1 times and the win is larger than the body claims, not smaller.
No documentation is owed that I can find — docs/ describes the inventory's contents (project-model.md:44, tracks.md:169) but never its read semantics, and nothing user-visible changes. Not a plan pull request, so the open-question gate does not apply.
|
Starting review of 4766d0d. |
minjudd on #152: both writes in the test changed byte length, so size alone explained every re-read and the timestamp half of the key was untested — while a same-length rewrite is the realistic drift (a version bump). His block lands verbatim, length-guard included so a later entry() edit cannot silently retire the coverage. Verified it guards what it claims: against a size-only cache key it fails on exactly the not-toBe assertion.
|
Starting review of 87221d8. |
minjudd
left a comment
There was a problem hiding this comment.
Reviewed 87221d8. Two heads landed while I was reading, so for the record: I reviewed 4766d0d in full and it was clean — I never published that verdict only because 87221d8 arrived first, and I would rather re-review than let an approval imply it covered a SHA it did not.
The ctime + inode fix is right, and I checked the mechanism rather than trusting the reasoning. A probe on this machine — write, utimesSync to a pinned date, rewrite at the same byte length, utimesSync to the same pinned date — comes back size equal: true, mtimeNs equal: true, ino equal: true, ctimeNs equal: false. So ctime really is the only discriminator in the cp -p case, and the claim that userland cannot set it back holds where I can test it. The new re-reads a same-size replacement that preserves mtime test is a genuine regression test: against 4766d0d's parent implementation it fails at plugin-hosting.test.ts:767 with 'aaa' where 'bbb' was expected — the exact stale read. Keeping mtimeNs alongside ctimeNs is the right call even though any POSIX write touches both, because mtime is what still discriminates where ctime semantics differ.
At this head: pnpm typecheck clean, pnpm vitest run src/audio/plugin-hosting.test.ts -t "inventory cache" → 2 passed, and pnpm test with FIELD_AUDIOD pointed at a prebuilt daemon → 42 files passed / 1 skipped, 665 passed / 1 skipped of 666, matching what the body claims. The body also tracks the code now — it names ctime, inode and the cp -p case, and credits where the finding came from — which matters here because it becomes the commit message verbatim.
My P3 thread on affce46 is answered, by 4766d0d's test and by the block this head adds. I am leaving it for you to resolve rather than resolving it myself.
One P3 below and it is the only thing between this and an approval — the wording is mine, copied out of my own review comment, and it stopped being true one commit before it landed.
Two things I could not close and am recording rather than blocking on. Node's ctime on Windows does not obviously carry the POSIX guarantee the comment states unconditionally, and I have no Windows machine here and CI is ubuntu-latest only, so I am flagging it as unverified rather than asserting it either way — worth a look before any Windows job is added, since the same-size test would be the thing that tells you. And the cache is a module-level Map with no eviction: right for a one-shot CLI process and for the watch loop's single root, worth remembering only if something long-lived ever serves several projects at once.
minjudd on #152: "only mtime can catch it" was true against the mtime+size key it was written for and false one commit later, when ctime and inode joined the key — an ordinary same-length write moves both timestamps, and the line contradicted the plugins.ts comment that exists to say mtime is not sufficient. His suggested wording, verbatim: size cannot catch it; the timestamps do.
|
Starting review of 3a23407. |
minjudd
left a comment
There was a problem hiding this comment.
Approving 3a23407. The only change since 87221d8 is the comment wording, applied as suggested, and it is now accurate: size is indeed what cannot see a same-length rewrite, and both timestamps move on one. pnpm typecheck clean, and pnpm test with FIELD_AUDIOD pointed at a prebuilt daemon → 42 files passed / 1 skipped, 665 passed / 1 skipped of 666.
For the record of what this approval covers, since four heads went by: the cache itself, verified across them rather than only on this diff. mtimeNs + ctimeNs + ino + size is the right key — content-hashing would re-read the 75 MB the cache exists to avoid, so a stat is the only invalidation that pays for itself, and I confirmed on this machine that ctime is genuinely the discriminator in the cp -p case (same size, same mtime, same inode, ctime differs). Both regression tests fail against the implementations they were written for, which I checked by reverting plugins.ts and re-running: the first at the toBe reference-equality assertion, the second with 'aaa' where 'bbb' was expected. The read-only-caller claim holds under a caller-by-caller audit — pinProject writes only into the YAML Document, toPluginWire spreads into a fresh object, findInstalled is a find, and nothing mutates the shared parse.
The two things I could not close are unchanged and still not blockers: Node's ctime semantics on Windows, which I have no way to test here and CI does not cover, worth a look before any Windows job is added; and the unevicted module-level Map, which is right for a one-shot CLI process and for the watch loop's single root.
Not re-litigating the performance numbers — I have no 482-plugin machine to reproduce them on, and the mechanism they rest on is sound.
Five findings from Codex and one from minjudd, all against claims the cited code contradicts. Placement gets a scriptable spelling: --at <position|end>, with a named plugin on a populated chain defaulting to the end without a TTY, so no path hangs a script. The duplicate-id promise now covers the half it was silent on — the duplicate check quantifies over the whole identity group, so the command prompts for both handles and discloses the incumbent edit, and refuses that case without a TTY. The chooser filters entries that report no version (the pinner's refusal, shown on the row before a write), shows identifiers where name+format+version still collide, and names #152 as an in-review dependency instead of citing its cache in the present tense.
Adding an insert today is a hand edit with three edges the tool already knows how to file down: the inventory knows the real plugin names (the hand edit guesses at them), the pinner knows the identity fields (the hand edit leaves an unpinned window for `field check` to close), and chain order is audible (serial chains are not commutative, so placement deserves a deliberate answer rather than a cursor position). The plan adds one command — `field insert add <track> [plugin]` — that writes a fully pinned insert through the existing comment-preserving YAML machinery, with an interactive search chooser over the scanned inventory when no plugin is named on the command line, and an order chooser when the chain already has inserts. The flow ends in the plugin's own editor, which answers a question worth recording: there is no way to open a plugin UI today. That is plugin-hosting.md chunk 3 (`field open <track>/<handle>`, decision 7's gesture write-back), designed and not yet built — so the plan composes with it (hand off to `field open` on the insert just added; until chunk 3 lands, print the line it would have run) rather than duplicating any of its design. Nothing here blocks on chunk 3 except that final step. Status is `Draft`, so the open questions do not block this PR; the PR that flips it `Active` answers them. Three closed on Justin's answers mid-review: the `add` subcommand spelling, recents-first rows with format-token search, and a hand-rolled disposable picker — a full TUI is eventually wanted and stays its own stack decision against project-core.md §5, which a prompts library adopted now would quietly pre-answer. Two remain: track addressing when names collide across songs (shared with `field open`), and built-ins — deliberately framed as a discussion in §7, actual AU/VST3 wrappers versus special-cased chooser rows, with the byte-identity golden and analytic latency arithmetic named as what wrapping would demote. The `next.md` line rides the same diff, replacing "Nothing committed yet." ## Testing Docs-only — nothing builds or runs. What to check instead: `docs/projects/all/add-insert.md` renders with its `status: Draft` frontmatter and the section numbering the citations rely on (§2 command, §3 plugin chooser, §4 order chooser, §5 editor handoff, §7 open questions); the [next list](docs/projects/next.md) links it and no longer reads "Nothing committed yet."; and every doc citation in the plan was grepped against its source before writing (decision 2/6/7 and §4 in plugin-hosting.md, `yaml/emit.ts`, the `field plugins scan` refusal string in `src/commands/plugins.ts` (lines 38 and 217), the #152 inventory cache — named in the plan as an in-review dependency). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > <sup>[Cursor Bugbot](https://cursor.com/bugbot) is generating a summary for commit 5a2cbd9. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
…lready ports (#154) Assessment of `main` at `766e532` — the tip of main when the reading was done; #152 landed underneath during review and the citations were re-verified against it (minjudd on this PR) — scoped to the **core** — the CLI, the build graph, and the daemon including live evaluation. No code changes: this is `status: Draft`, so per [docs/projects/README.md](../blob/main/docs/projects/README.md) its open questions do not block it merging, and the change that answers them is the one that flips it to `Active`. Windows is currently an explicit V1 non-goal in `docs/README.md` "V1 platform scope". This plan does **not** amend that line — §2.4 records that the amendment belongs to whichever change starts the work, and that Linux's framing (a build-and-test target, not a second product platform) is probably the right one to reuse. ## The finding worth leading with **Live rendering is not the obstacle.** `live.cpp`, `render.cpp`, `plan.cpp` and every file in `dsp/` contain no platform branches whatsoever. `player.h`'s `hardwareListenersAvailable` already returns `false` off macOS with the heartbeat rescan standing in — [linux-portability.md](../blob/main/docs/projects/all/linux-portability.md) decision 2 working correctly on a platform it was not written for. JUCE supplies WASAPI without being asked. What blocks Windows is the **control socket**, and before that, the **checkout**. ## The checkout, measured There is no `.gitattributes` in this repository and Git for Windows defaults `core.autocrlf=true`: ```text examples/bloom/shared/instruments/creek-kit.scd on-disk size: 2323 bytes, CR bytes present: 71 sha256 on disk : 197c273b353c35ce3a7ecc00774f3aff9553b51daa33522efa7495fb2b496d46 sha256 as LF : 49f970a7db30fc972b8ef060e55e3ae2991107137fbf9dd1a6ebb88e59dcea61 ``` `git status` stays clean throughout, because git compares normalized content. The divergence is invisible to git and load-bearing for field, which hashes what is on disk: `sc-render`'s action key, `check`'s byte-wise formatting comparison, and asset `sha256` pins all read those bytes. Committing this branch printed the warning itself — *"LF will be replaced by CRLF the next time Git touches it."* The archived standalone sample-project repo carried exactly the right `.gitattributes`; it did not come across when bloom moved in-tree. Chunk 1 is that one file, and it is worth landing whether or not the rest is ever built — it makes the checkout byte-defined on every platform rather than dependent on each contributor's git config. ## The rest | | | | --- | --- | | §1.2 | `server.cpp` is AF_UNIX + `flock` + raw fds by hand, and `server.h:15` says so. Node implements the local domain on Windows as named pipes only, so both ends fail and neither can be fixed alone. | | §1.3 | `main.cpp:306`'s `SIGPIPE` ignore, whose comment claims "every platform" and would become false. | | §1.4 | MSVC is not in the `-ffp-contract=off` list, which threatens [render-pipeline.md](../blob/main/docs/projects/all/render-pipeline.md) §4's byte-identical claim. Must be measured, not reasoned about. | | §1.5 | `daemonBinary()` hardcodes a POSIX path; MSVC is multi-config so `-DCMAKE_BUILD_TYPE=Release` is ignored. | | §1.6 | `afplay` has no Windows answer and probably should not get one, now that `field play` *is* live evaluation. | ## Sequencing Five chunks. **Chunk 2 is a milestone on its own** — `render-daemon.ts` shells `field-audiod --render` as a subprocess, so the entire offline render path works once the binary compiles, with no socket work. Chunks 2 and 4 are independent given chunk 1. ## One tension recorded rather than resolved [linux-portability.md](../blob/main/docs/projects/all/linux-portability.md) decision 2 rejected a platform abstraction because "fourteen lines do not earn an abstraction," which was right about hot-plug. The socket is ~150 lines of `server.cpp` plus the client, with three platforms' semantics behind it, so the seam is probably earned here. Reversing that instinct should cite it as a decision, not happen quietly — §2.1. ## Out of scope, recorded so it is not re-derived AU hosting **cannot exist on Windows** (already guarded in `plugins.ts:71`, the `PLATFORM_ID:Darwin` genex, and `hosting.cpp:33`); VST3 hosting is unaffected and `examples/bloom` pins no plugins. The Python workers and SuperCollider are out too, with §4 recording what each would take — SuperCollider is nearly free, the workers need §1.2's decision made a second time. One claim is marked **unverified** rather than asserted: whether CPython exposes `AF_UNIX` on Windows. It does not change the conclusion, since the client end is Node either way. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Justin Balthrop <[email protected]>
A real inventory runs to tens of megabytes — a 482-plugin machine's
plugins.jsonis 75 MB, almost all of it param tables — and onecompileSessionread and zod-validated it twice on bloom: once inloadProject's pin-drift validation, and once per hosted insert intoPluginWire— a chain with several hosted arms pays N+1 reads, so the single-insert numbers below understate the win. Profiled on bloom, that parse was 36% of the compile's CPU plus most of its GC, putting a watch edit's session swap at ~1.75 s — of which the daemon needed only ~120 ms, and the watcher's debounce a fixed 300 ms. The engine was never the slow part.readInventorynow caches the parsed object keyed by path and invalidated on mtime, ctime, inode, or size (bigint stat, so nanosecond resolution — and ctime catches a same-length replacement that preserves mtime, like cp -p or a restored backup, since the filesystem stamps it on any write and userland cannot set it back; Codex's finding on this PR), so a fresh scan lands the moment the file changes and every other read is a stat. The watch loop is one long-lived process, so edits after the first compile in ~70 ms instead of ~1,350 ms — the felt swap drops from ~1.75 s to ~0.5 s, now dominated by the debounce. Sharing the parsed object is safe because every caller treats the inventory as read-only; writers go through the file. The deeper fix — splitting the param tables out of the inventory so even a cold read is trivial — is worth its own plan section if the cold path ever matters; this one removes the per-edit cost without touching the scan format.Testing
From the repo root:
pnpm build, thenpnpm vitest run src/audio/plugin-hosting.test.ts -t "inventory cache"→ 2 passed. The first test's claim is reference equality — an unchanged file returns the same object, a rewritten one a fresh parse — and it fails against the uncached implementation on exactly that assertion (expected … to be … // Object.is equality), verified by stashing theplugins.tschange and re-running. The second pins mtime withutimesSyncaround a same-size rewrite and fails against an mtime+size key on exactly the stale read. Full suite:pnpm test→ 43 files, 666 tests green.The measurement, if you want to feel it instead: in
examples/bloom,field play creek --loop --watch, then nudge the AUDelayDelay Timeinsongs/creek/tracks/drums.yamla few times. Before this, each save took ~1.7 s to sound; now the swap lands in about half a second, and the remaining lag is mostly the watcher's 300 ms write-coalescing debounce. Requirespnpm buildfirst so thefieldon your PATH carries it; the daemon needs nothing — it was never the bottleneck.