Repository navigation
feat(link): fill ocx-child builds under ocx-child-builds/ when an upgraded Home starts, from digests in its verified package - #8624
Conversation
…the verified package After a successful, non-orchestrated ocx update to a newer version, the Home reads the ocx-child digests a release places beside the packaged ocx-child sources (native/ocx-child/SHA256SUMS), fetches each listed build from the GitHub release of exactly that version, and caches in $OPENCODEX_HOME/cache/ocx-child/<version>/ only builds whose SHA-256 equals that digest, with a SHA256SUMS naming exactly those. A package without the digest file fetches nothing; a downgrade or the same version fetches nothing; a failed build is skipped and never fails the update.
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
✅ Deterministic PR hygiene checks passed. |
…er through a symlink Review round 1 on #8624: - The fill moves from the end of ocx update (which the Node launcher bypasses for npm and pnpm, and which imported after the package swap) to a background task when a Home or standalone runtime starts. It reads the running package tree and its own package.json version, so every installer is covered, a downgrade target without the module is never asked to import it, and a pnpm group switch cannot point it at the old tree. src/update/index.ts is unchanged. - The module is plain ESM (child-binary-cache-fill.mjs) shared by Node and Bun. - cache, cache/ocx-child and the version directory must be real directories; each write goes to an exclusive 0600 temp and is renamed, with the directory identity checked before and after. - A listed build that cannot be verified is removed with its manifest line, and an empty manifest is removed, so nothing stays trusted under an older manifest. A newer version's cache means a downgrade and nothing is fetched.
…te directories, never from a source checkout
…ch a cached build the reader would refuse
…che fill at a time per home
…a completed fill that lost lines
…goes down, and never download on a same-version start
…ur an opt-out and the running version, and clean up a failed publish
…t-out, directory growth and uninstall
…ts gates, and stop during an uninstall The startup step recorded the whole cache/ directory as owned before any gate ran, so uninstall would delete builds an operator placed there and unrelated files, and it swallowed an uninstall in progress. It now claims cache/ only when absent, else cache/ocx-child only when absent, leaves an existing unlisted cache/ocx-child alone (operator_cache), and stops on an uninstall tombstone (uninstall_in_progress) or a full or busy manifest (ownership_unavailable). cache is no longer an initially owned path; configPathOwnership is the read-only check.
# Conflicts: # structure/remote-link.md
…he operator's cache/ untouched Claiming cache/ or cache/ocx-child for uninstall meant files an operator later placed there (the documented spot for hand-supplied builds) were removed with it, and a failed fill could leave a claim on a directory it never created. The fill now writes only to <OPENCODEX_HOME>/ocx-child-builds, an OpenCodex-managed name listed for new Homes and registered by older ones while absent or empty (one that already holds entries is left alone: foreign_directory), after the Home directory passed its ancestor checks. The reader checks the operator's cache/ocx-child first, then ocx-child-builds.
…adopt only an empty private one A listing made before the directory existed (initially owned, or a registration interrupted before mkdir) let a later directory at that name inherit the claim, and an existing empty directory was registered before its owner and permissions were checked. The claim now creates the directory exclusively (0700) and registers it afterwards, removing it if the registration fails; an unlisted directory is adopted only when empty, real, owned by this user and writable by nobody else.
…a mid-claim, and remove only a directory the claim created A registration answering unowned after this call saw an owned Home means an uninstall ran in between: the claim now removes the directory it created and stops (uninstall_in_progress). A failed registration no longer removes an empty private directory the claim adopted.
With no Home passed, resolveChildBinarySource read OPENCODEX_HOME literally while the startup fill uses getConfigDir() (trimmed, ~ expanded, resolved), so a ~ or otherwise unnormalised spelling filled one directory and probed another. Without an injected environment the reader now uses getConfigDir(); an absolute OPENCODEX_HOME resolves to the same path as before, so cache/ocx-child lookups are unchanged.
…ts temp file acquireFillLock ignored writeSync's return value and removed its temp only around the link, so a failed write or fsync left .ocx-child-cache.<token>.lock.tmp behind. It now writes the whole record or throws, and removes the temp on every path, as publish does.
…builds The fill's comments, the structure page and one test still gave "it may be an operator's" as the reason a refused build's file stays and unlisted lines are kept. The fill deletes no file and manages only the builds its digests name; operator builds live in cache/ocx-child. The server's startup comment now says the step creates ocx-child-builds/ and a marker rather than "a background read". No behaviour change.
…r temps ends removed Builds, the version manifest, markers, a lock whose process is gone and temp files in both the build root and a version directory all sit under the one owned ocx-child-builds/ entry, so uninstall removes them and the Home folder.
…ild-builds claim An uninstall between the claim's mkdir and its registration reports partial, the claim then removes the directory, and uninstall reruns answer "metadata missing or invalid" until the empty Home folder is deleted. Uninstall is unchanged here; the race is rare because uninstall first proves the proxy is down.
…that would list nothing Round-14 wording: "deletes no file" was too broad, since an empty SHA256SUMS is removed.
fillChildBinaryCacheForVersion fell back to OPENCODEX_HOME or ~/.opencodex when no Home was passed, so the fill and the reader agreed only because the startup step always passed getConfigDir(). The Home is now required (the .d.mts says so for both entry points) and a call without one throws before anything is read or written. Test first: such a call used to resolve and use OPENCODEX_HOME.
…tcome exactly "An unlisted one" followed the inserted race sentences and referred to nothing. A full, busy or vanished manifest stops the start after the claim's mkdir, which then removes that directory, so "before any write" was not literal. An uninstall rerun after the race ends removed when one of its own cleanup steps records state first (a registration in the empty Home starts ownership afresh), and is refused with "metadata missing or invalid" only otherwise.
|
Maintainer integration record.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a92fa656f1
ℹ️ 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".
| const version = options.version ?? onDisk ?? ""; | ||
| try { | ||
| // A source checkout (a developer's server, the test suite) never fetches a release. | ||
| if (detectInstallFromPath(packageRoot) === "source") return { kind: "skipped", reason: "source_checkout" }; |
There was a problem hiding this comment.
Distinguish compiled Homes from source checkouts
For standalone and desktop Homes produced by scripts/build-standalone.ts and desktop/scripts/prepare-sidecar.ts, the running module resides in Bun's compiled layout rather than an installed node_modules tree, so this gate classifies the packaged application as a source checkout. A compiled probe of this module returned source_checkout, with runningPackageVersion() also returning null. Consequently, these installations never record the baseline needed for upgrade detection and cannot fill the cache when digest-bearing releases become available, leaving the advertised any-installer upgrade path limited to package-manager installs. Use compiled-install-aware detection and provide the trusted version/digest metadata through the standalone packaging path.
Useful? React with 👍 / 👎.
Summary
This is lane O2 of the disposable-machines design. Today a packaged Home (npm, pnpm, bun or mise) can plant
ocx-childon a bare machine only from a build someone supplied by hand. No package ships the build. The reader's sources areOPENCODEX_CHILD_BIN_DIR,native-bin/sidecars next to the sources or the executable (none is packaged), a local Cargo release build in a source checkout, and$OPENCODEX_HOME/cache/ocx-child/<version>/. Without one of those, probe answersplantable: falsewithplantUnavailableReason: "artifact_not_found".Change. When an upgraded Home or standalone runtime starts,
src/link/child-binary-cache-fill.mjsfills the Home's own build directory,$OPENCODEX_HOME/ocx-child-builds/<version>/, in the background from the GitHub release of the running version. It never runs for a client runtime and never delayslisten. The single wiring line insrc/server/index.tsstarts it astrackBackgroundWorkbackground work throughsrc/link/child-binary-cache-start.ts. Nothing settles that work at shutdown (settling is opt-in and only tests use it), so a fill cut short by shutdown retries at the next start of that version. Trust comes from the update itself:native/ocx-child/SHA256SUMSfrom the running package tree, which its installer verified (registry integrity, then the tree check). The version comes from that tree'spackage.jsonand must equal the running code's own version (packageVersion()); a mismatch, as during an in-place install, records nothing (version_mismatch). The digest format is the one the reader already uses:<sha256> ocx-child-<target>[.exe].https://github.com/lidge-jun/opencodex/releases/download/v<version>/<file>, with a 32 MiB cap and 20 s per build.SHA256SUMSbeside the builds that names exactly the verified ones. The reader verifies every file against that list again at plant time.The reader.
resolveChildBinarySource(src/link/child-binary-source.ts) changes in two ways:$OPENCODEX_HOME/cache/ocx-child/<version>/, it also checks$OPENCODEX_HOME/ocx-child-builds/<version>/, with the same file andSHA256SUMSchecks.src/server/management/link-enrollment.tsdo, it resolves the Home withgetConfigDir(): trimmed,~expanded, resolved. That is the Home the fill writes to. Before, it readOPENCODEX_HOMEliterally, so a~/...spelling (service files do not expand it) or a relative one would fill one directory and probe another. An injected environment keeps its literal reading.Hand-placed builds in
cache/ocx-childbehave as before. That location is checked first and resolves to the same path for an absoluteOPENCODEX_HOME. A present but bad file there is still refused (checksum_mismatch) and is not passed over for the filled build.When it fills. Only after an upgrade.
ocx-child-builds/.versions/holds one empty marker per version:<version>.filledwhen its fill completed,<version>.baselinewhen it ran and fetched nothing. Markers are only ever added, so the newest recorded version never goes down, whichever of two overlapping fills writes last. Only a running version newer than the newest marker fetches:detectInstallFromPathanswerssource) never fills. That covers a developer's server, the test suite, and the compiled Desktop sidecar, whose path has nonode_modulessegment;OCX_DISABLE_CHILD_CACHE_FILL=1turns the fill off: nothing is read or written.Ownership and uninstall.
ocx-child-buildsis an OpenCodex-managed directory.claimChildBinaryCacheruns after the fill's gates, including the ancestor checks of the Home directory itself, and before the fill writes:0700) and only then registered as owned config state; if the registration does not succeed, the directory this call created is removed, so a listing names a directory OpenCodex made or adopted;foreign_directory);uninstall_in_progress); so do a Home whose ownership metadata disappears between the check and the registration (uninstall_in_progress) and a full or busy manifest (ownership_unavailable, retried at the next start); in those cases a directory the claim created is removed again;ocx uninstallremovesocx-child-builds/with everything in it (builds, manifest, markers, a stale lock, leftover temps) and keepscache/. The fill never reads, writes or claims anything undercache/, and the guide tells operators to keep their own builds incache/ocx-child. The new read-onlyconfigPathOwnershipinsrc/lib/config-ownership.tstells a listed path from an unlisted one and refuses under an uninstall tombstone.One uninstall race remains, and uninstall is not changed for it. An uninstall that runs between the claim's
mkdirand its registration finds the new directory unlisted and reports partial ("unowned files remain", exit 1). The claim then removes that directory. A rerun ofocx uninstallendsremovedwhen one of its own cleanup steps records state first, since a registration in the now empty Home starts ownership afresh; otherwise it answers "config ownership metadata is missing or invalid" until the user deletes that empty folder. The race is rare because uninstall first proves the proxy is down. A fill can also overlap an uninstall that starts after its claim; every startup writer in the Home has that window.Safety properties.
ocx-child-builds,ocx-child-builds/.versionsand the version directory must be real directories (created0700, never symlinks), owned by this user and writable by nobody else, and.versionspasses that check before any marker is read. Every directory above them, the Home directory included, must be owned by this user or root and writable by nobody else unless sticky (like/tmp). Otherwise the fill refuses before any download. An existing build counts only when it passes the reader's file checks as well as the digest; otherwise it is fetched again.ocx-child-builds/.fill.lockkeeps concurrent starts from downloading twice. It is linked whole from a private temp, names its process, and is reclaimed once that process is gone or after an hour. It is an optimisation, not the guarantee, since Node has no OS-held file lock.0600temp file, is written in full or throws, and is then renamed or linked; a failed write removes its temp file. The target directory's identity is re-checked before and after each write, so a directory swapped in during a download receives nothing. Counts come from what is verified on disk.checksum_mismatch). Apart from its own temp and lock files, the only file it removes is a manifest that would list nothing; a listed build is only ever replaced by bytes matching its digest. Lines for targets the release does not list are left as they are. A version directory removed by hand after a completed fill stays removed.The fill module is plain ESM with no Bun or TypeScript dependency; its one caller is the startup step. A test pins its target list and version ordering to the reader's (
CHILD_TARGET_TRIPLES,compareStrictSemver).Where this differs from the design text. The design says to fill
cache/ocx-child/<version>/"from the same release and the same SHA256SUMS it verified for its own update". Before this change no release published ocx-child digests, and the Home's update verifies registry integrity rather than a SHA256SUMS file. The owner chose this resolution: the digests ride inside the package the update verifies, and the binaries come from the GitHub release of that version. The fill writesocx-child-builds/<version>/becausecache/ocx-childis the documented place for hand-supplied builds: any ownership claim there would letocx uninstalldelete files an operator adds later. The fill runs when the upgraded runtime starts, not insideocx update. That way it covers every installer (the Node launcher's npm and pnpm path, the Bun path, and service restarts) and always reads the active package tree.src/update/index.tsis unchanged.What a packaged Home does today. No release ships
native/ocx-child/SHA256SUMSyet, so a packaged macOS or Linux Home makes no network request. At its first start after this change it writes:ocx-child-builds/(0700) and its entry in the ownership manifest;ocx-child-builds/.versions/(0700) and one empty<version>.baselinemarker;.fill.lockand its private temp, both removed before the step ends.A later start of the same version reads the marker to decide it has nothing to do and writes nothing. Source checkouts, the compiled Desktop sidecar and Windows read the running
package.jsonand then stop: no cache read or write and no request. A client runtime, and the opt-out, read and write nothing. The marker changes what a start does only once a release ships digests. Shipping the digest file, adding it topackage.jsonfiles, and uploading theocx-child-<target>assets belong to a separate release-side activation change that needs its own security review. A Home that jumps straight from a release older than this change to the first release with digests has no baseline, so it fills from its next update. A runtime with digests whose directories are unsafe or cannot be prepared logs one warning and keepsartifact_not_found; without digests it stays silent.Known limits, deferred to the release-side activation change:
cache/ocx-childhides a good filled build (fail closed), and the guidance does not say where the bad file is.Files. Code:
src/link/child-binary-cache-fill.mjsand.d.mts,src/link/child-binary-cache-start.ts,src/link/child-binary-source.ts,src/lib/config-ownership.ts,src/server/index.ts(one wiring line and its comment). Docs:docs-site/src/content/docs/guides/remote-link.mdanddocs-site/src/content/docs/es/guides/remote-link.md(item 4 of the plant sources),structure/remote-link.md,structure/config-ownership.md. Tests:tests/clients/link-child-binary-cache-fill.test.tswith its entries inscripts/test-layout/layout-clients.jsonandtests/fixtures/test-layout-expected.json.Verification
Tests that failed first.
tests/clients/link-child-binary-cache-fill.test.ts(new) does not load onorigin/dev, where no filler exists. Its first case confirms the baseline: before the fill, the reader answersartifact_not_found; after an upgrade, it answers a verified artifact. That is the design's "after an update, probe answers plantable". Every case added to prove a fix failed before that fix and passes now. The latest five:OPENCODEX_HOME);~spelling ofOPENCODEX_HOME(it looked under the literal spelling);.lock.tmp(one was left);The cases cover:
.versions, the Home directory or an ancestor writable by others, or owned by another user, is refused before any download; a sticky ancestor is accepted;ocx-child-buildsis refused before any write, and a version directory swapped for a symlink during a download receives nothing;ocx-child-buildsonly once the fill created it; an older Home registers an absent or empty private one; an unlisted directory holding entries, or an empty one others can write, is not adopted; a full manifest removes a directory the claim created and keeps one it adopted; an uninstall in progress, or one finishing between creation and registration, stops the fill and leaves nothing; a start stopped by a gate claims nothing; a Home without ownership metadata still fills;removed;cache/is never claimed or written, its files (including one added after a fill) survive uninstall, and the reader takes an operator's build before the filled one;At head a92fa65:
bun test tests/clients/link-child-binary-cache-fill.test.ts: 72 pass, 0 fail.tests/clients/link-child-plant-foundations.test.ts; the threetests/config/config-ownership-*suites;tests/server/link-enrollment-ephemeral-child.test.tsandlink-enrollment-operation.test.ts;tests/cli/cli-link-enrollment.test.ts;tests/ci-workflows/docs-spanish-localization.test.ts;tests/lab/core-lab-boundary.test.ts, which guards thestartServerstartup window against anyawait; and the file-size, import-cycle, test-layout and structure suites. Result: 403 pass, 0 fail.bun run typecheck,bun run structure:check,bun run privacy:scan: exit 0.tests/codex-integration/codex-catalog-writer.test.tsandcodex-catalog-write-audit.test.tseach have one case that times out on this machine (15 s and 5 s). They fail the same way with this branch's source files reverted, so this change does not cause them.NOT RUN:
bun run test;bun run test:changed, which on this machine also fails a cleanorigin/devin unrelated update and launcher suites (5 s timeouts);~expansion through the reader: the Home-resolution test spiesgetConfigDir()to return its temp Home, because Bun'sos.homedir()does not follow aHOMEchanged at runtime and a test may not write under the real home;package.jsonand returns before any cache read, write or request; the platform gate is tested through its option on macOS.Checklist
structure/remote-link.mdandstructure/config-ownership.md.cache/, and fills only after an upgrade. Today no release ships the digests, so a packaged POSIX Home makes no network request and writes only the directories, marker and manifest entry listed above. It needs the explicit security review MAINTAINERS.md requires for anything that installs code.