Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ jobs:
run: node e2e/run.mjs
- name: wasm playground (editor, preview, error strip)
run: node e2e/wasm-playground.mjs
- name: cross-worktree shared module store
run: node e2e/cross-worktree-cache.mjs
- name: oj store flag
run: node e2e/store-flag.mjs
- name: two servers on one store, one killed mid-burst
run: node e2e/store-concurrent.mjs
- name: constructive trace staleness
run: node e2e/trace-staleness.mjs
- name: remote store wire
run: node e2e/store-remote.mjs
- name: warm-cache plugin side effects
run: node e2e/warm-cache.mjs
- name: ssr dev + hydration
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- The oj store: a shared per-user content store (`OJ_STORE_DIR`, versioned `v1`) for cache entries whose keys and artifacts are worktree-independent, so a second worktree of an app, or a second app on the same dependencies, starts warm. It is off unless `OJ_STORE_DIR` is set, which `oj dev --store` does for itself and every child process, to the given DIR or to `$XDG_CACHE_HOME/oj/store` (else `~/.cache/oj/store`); a plain `oj dev` writes nothing outside the tree. It holds the V8 code cache, relocatable module-cache entries, Start codegen entries and Start client-bundle generations.
- `oj dev --store[=DIR]`: the one switch for the oj store. It turns the store on (and, given a DIR, says where) and the persistent module cache with it, which 0.4.x removed with `--enable-cache`. A plugin that collects state from every module's transform and serves it from a virtual (UnoCSS, WindiCSS, by name) keeps app modules out of the persistent cache: they compile each session, dependencies still serve from the store. The persistent cache is the dev server's memory cache written through to disk: entries whose stored form is worktree-independent go to the store's `modules/` directory, entries that still pin a checkout (absolute `/@fs/` imports, absolute metadata) stay in the app's own cache, and an entry is served only under the HMR import stamps it baked in, as the memory cache serves one. Its key covers everything that shapes compiled output: the dependency epoch (lockfiles, patches, package.json), the config graph (vite/oj config plus every file it imports), tsconfig.json, the resolver settings with alias targets hashed root- or workspace-relative, the defines, the JSX runtime and the asset URL settings. A config, lockfile, tsconfig or resolver edit is a clean miss instead of a possible stale hit.
- `oj store serve --dir DIR --port N` serves a store directory as an HTTP substituter (`GET/PUT /v1/ac/{ns}/{key}` write-once with 409 on conflict, `GET/HEAD/PUT /v1/cas/{blake3}` checked against the digest, `POST /v1/cas/missing`), with split bearer tokens: `OJ_STORE_READ_TOKEN` (unset = public reads) and `OJ_STORE_WRITE_TOKEN` (unset = writes refused). Dev servers read through it with `OJ_STORE_REMOTE=<url>` (+ `OJ_STORE_TOKEN`): local store first, remote on a miss with a local back-fill, and a fetched entry passes the same admission checks as a local hit (relocatability, import stamps, plugin virtuals, trace verification). `OJ_STORE_PUSH=1` pushes relocatable entries from a dedicated queue thread, never blocking compiles on the network. A substituter that does not answer (a 2 s connect, a 5 s fetch) three times in a row is not asked again for the session.
- Constructive traces: a cached module records every side file a plugin `transform` read, with a blake3 digest, and a warm hit re-verifies them; any mismatch is a clean miss instead of a stale serve. Reads are seen by the plugin host's `node:fs` interposition (per hook, through AsyncLocalStorage) and by TracingFs, a recorder under the engine's fs ops layer that also catches named `node:fs` imports. `import.meta.glob` expansions are traced too. `OJ_VERIFY_HITS=<0..1>` recompiles that share of persistent hits and logs any divergence.

### Changed

- The goldens and the TanStack Start fixture (`e2e/fixtures/start-app`) are recorded from Vite 8.4.0, the release, in place of 8.4.0-beta.1; rolldown stays 1.3.2, the crate oj builds with (8.4.0 declares `~1.3.2`; 8.4.1 declares `~1.3.4`, whose Rust crates are not published, and its build import analysis hands rolldown a field 1.3.2 rejects). Recorded from `/tmp`, so a recording carries no path depth of the machine it was made on.
- Compiled modules are path-free, with or without the store: the compiler names an in-root module by its served path (`/src/App.tsx`) in the jsx dev `__source` and the sourcemap `sources` entry (Vite names it by its absolute path), so the bytes are identical in every worktree. `fs_allow`/`watch_files` metadata and `/@id/...?importer=` params encode `ws:`/`mono:`-relative and decode against the serving worktree. Sourcemaps from earlier transforms (StyleX, plugins) name in-root files by served path too.
- Files outside the app root but inside the workspace (hoisted node_modules, monorepo packages) are served at `/@fs/@mono/<rel>`, which each server resolves against its own workspace root, so cached artifacts that import them share across worktrees.
- The V8 code cache keys modules by their root-relative identity instead of the absolute `file://` URL and lives in the shared store, so worktrees of one app share every entry and `node_modules` bytecode is shared across apps with the same layout. Old per-app `code-cache` directories can be deleted.
- The Start client-bundle store is shared across worktrees (bundle format 6, rebuilt once): closure keys, the stored closure, the inputs outside the closure (the route trees, the config and its imports) and the bundle's `import.meta.glob` patterns are root-relative, and dev asset URLs are `/@oj-start/fs/@ws/<rel>`, resolved against the serving root. A generation whose globs reach outside the root stays keyed to the root that built it. `current` and the memo stay per root; each root mirrors its `current` into `pins/`, and eviction never removes a generation (or its blobs) a fresh pin protects; pins unrefreshed for 7 days stop protecting. A worktree with no `current` probes the most recently used shared generations, so the first `oj dev` in a new worktree restores the bundle another one built. A generation's StyleX rules and its plugin-served-stylesheet mark travel with it as attachments.
- Start codegen entries (route tree, server fns) live in the shared store; the mtime memo stays per root.
- StyleX apps share across worktrees too: the plugin's fingerprint, which keys every compiled module, hashes its options with paths under the app root spelled root-relative (the default `rootDir` is the app root).
- The deps prebundle key hashes `resolve.alias` targets root- or workspace-relative, so one vite.config in two worktrees yields one prebundle key.
- Dep URL versions are content-derived instead of per session. Each `/@oj-deps/` URL is recorded write-once with its file's content hash in a ledger (in the oj store, else the app's cache), and versions are salted with the ledger's epoch instead of a per-process timestamp. Restarts and worktrees that bundle the same bytes mint the same URLs, so modules compiled against them are shared. Other bytes under a URL an earlier session served move every URL to a version of the new bytes and reload the page, so an `immutable` URL never names two bundles. Wiping the ledger starts a new epoch, which moves every URL.
- The dev server records the config's imported files per config file instead of in one process-wide slot, so two apps in one process never hash or watch each other's config imports.
- Without the store a dev server does none of the store's work: no module key salt (the config graph, every tsconfig and the lockfile by content), no plugin read tracing in the engine (a read costs one atomic load), no trace digests, no dependency ledger (versions are per session, as Vite's `sessionTimestamp`) and no cache writer thread. `oj dev` without `--store` clears an inherited `OJ_STORE_DIR` for itself and its children, so an exported variable alone shares nothing (it used to share the Start bundle, codegen and bytecode while the module cache stayed off); `--store` with no directory to resolve exits with an error instead of running without it.
- The module key covers more of what shapes an entry: the tool build (the package version plus a digest of the sources it was built from, so two builds of one version never serve each other's output through a shared store), the root's place in its workspace (two checkouts whose roots sit at different depths name in-workspace files differently), the manifests and entry files of packages linked into `node_modules` from outside it (a workspace plugin changes without a lockfile change), and patch files by content (the patches directory's mtime differs per checkout and kept worktrees from sharing).
- A warm hit verifies more: a stylesheet's `@import`ed files, Sass partials and PostCSS dependencies are trace rows (an edit to an imported file between sessions served the sheet with the old file inlined); the directories a plugin listed (`readdir`, `opendir`) are rows digesting their names; existence checks (`exists`, `stat`, `access`, `realpath`, a read-only `open`), reads by file `URL` or `Buffer` path and reads through a descriptor are rows; relative paths are recorded against the process's directory; an entry whose `/@fs/@mono/<rel>` import names no file in the reading server's workspace is a miss. A side file stamped in a whole second within two seconds before its compile started counts as written during it (a filesystem that keeps whole seconds may stamp a later write below the compile's start); a stamp with nanoseconds compares exactly, so a fresh checkout persists from its first boot.
- The shared store directory is a trust boundary: it is created with mode 0700, and an existing one owned by another user or writable by group or others is refused (one line on stderr, the server keeps its own cache). Temp files are created exclusively with a random suffix, so a symlink planted at a predictable name is never followed. The modules directory is kept under 2 GiB (oldest entries first, once per boot, off the boot path; an entry served is touched when its stamp is older than six hours) and temp files of killed processes are swept after an hour. The plugin host's bytecode directory has a 1 GiB budget when it is the store's, in place of the per-app 128 MiB that had every app's boot evict the others, and its directory name carries a digest of the V8 flags. A Start bundle pin names the process as well as the root, so two sandboxes running the app at the same path over one store protect their own generations, and the generation window is counted per app and config.
- `oj store serve` defaults to the user's store directory (`--dir` for another; it no longer creates `oj-store/` under the current directory), keeps a byte quota (`--max-bytes`, 10 GiB by default, 507 past it, counted on boot), stores only entries it could serve (relocatable module JSON, else 422), purges a key or blob on `DELETE` under the write token, compares tokens in constant time, and streams bodies off the runtime's workers. A dev server's read-through counts an answer slower than 500 ms as a failure, trips after three, and after 30 s lets one probe decide; its pushes are queued (256 entries or 64 MiB, a full queue drops and says so once), stop while the breaker is open, and never fetch a body past 16 MiB. Stamped keys (this session's HMR state) are never asked of a substituter.
- With the store, dependency URL versions come from the inputs alone (the pre-bundle hash and the dependency names, as Vite's committed browserHash), not from a per-store epoch: two stores, two machines, a fresh sandbox and a substituter that bundled one plan mint the same `/@oj-deps/...?v=` URLs, so the modules compiled against them are one entry everywhere (under an epoch no two stores ever shared a module key), from a checkout's first boot on. The ledger still records what each URL served, and other bytes under a recorded URL re-mint a version from the bytes and reload, as before.
- A plugin's trace is the host's own account of what the hook read (exact, per hook) plus whatever the engine's shared window saw that no hook in flight read through the host (a named `node:fs` import bound before the patch). A module beside a plugin that scans a thousand files is no longer charged those files, and an entry with more than 256 rows stays in memory. The racy-mtime rule also counts a stamp within 20 ms before the compile's start (the kernel stamps files from a coarser clock than the one the compile read). A module hard-invalidated by an edit this session is not persisted: its key carries the process's invalidation counter, which no other session computes. The tool build id reaches every shared artifact (Start bundles, codegen, the dependency ledger and the pre-seed stamp), and covers embedded assets and the bundler fork. Packages linked into the workspace's `node_modules` above the app are salted like the app's own. `oj build`, `preview`, `lint` and `typecheck` clear an inherited `OJ_STORE_DIR` as a flagless `oj dev` does; the commands a server spawns keep it.
- A stylesheet's `@import` and a Sass `@use` record the paths they looked for and did not find ahead of the file they resolved to (a partial or sheet added there later shadows the hit and is a miss), the files a PostCSS plugin reads on its own are traced through the CSS engine's own read window, and a declared `dir-dependency` is a listing row per directory walked, so a file added under it is a miss.
- A substituter probe that the browser's navigation cut short (hyper drops the handler) no longer leaves the breaker open for the session: the probe is a lease that clears itself when dropped and expires after the fetch timeout; at most 16 fetches are in flight at once, and a tripped breaker answers waiters at once. The wire sweeps the temp files of crashed PUTs after an hour before counting its quota, caps `POST /v1/cas/missing` at 4,096 digests (400 past it), and writes every temp file exclusively with a random suffix, as the dependency ledger and the Start bundle and codegen touch files do now. A Start bundle pin names the boot and the process as well as the root, ages out after an hour instead of seven days, is refreshed every ten minutes by a running server and ignored once its process is gone (same boot, no `/proc/<pid>`), and the pins directory is read once per persist.

### Fixed

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading