Skip to content

feat(update): orchestrated ocx update plan/apply contract (update.orchestrated/1) - #8103

Merged
lidge-jun merged 90 commits into
devfrom
feat/ocx-update-orchestrated
Nov 2, 2026
Merged

lidge-jun merged 90 commits into
devfrom
feat/ocx-update-orchestrated

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

External orchestrators (GOAT) need to update an OpenCodex install safely and machine-readably. Today ocx update is interactive-shaped, decides against whatever install the ocx on PATH belongs to, and can update an install that is not the one serving the running proxy (seen on a Remote Link child: PATH ocx is npm 2.50.0 while a different install serves 2.83.0).

This adds contract update.orchestrated/1:

  • ocx update --plan --json [--tag latest|preview | --version X.Y.Z] — read-only plan (ocx.update.plan/1): currentVersion, targetVersion, installer, runtimeOwner, servingPath, cliPath, canApply, reason, restartRequired, planToken, updateInFlight, mutationBoundMs. Always exit 0; usage 64. The decision is made against the install that serves the live runtime: the runtime now records its relaunch command in runtime-port.json, and the listener must prove the record's attestation secret. CLI ≠ serving install → cli-not-serving-install; unknown → serving-install-unknown; desktop-app installs → desktop-app-owned (the Tauri updater has no external trigger). Plan entry is passive: no Desktop handoff, boot-restore, Bun install or shim repair.
  • ocx update --yes --json [--version X] [--expect-plan T] [--not-after MS] — non-interactive apply (ocx.update.result/1), one JSON document on stdout. Exit 0 applied+verified or up-to-date, 10 refused (nothing touched), 11 failed with the previous version verified active, 12 unverified, 64 usage. Apply pins the planned version in npm, pnpm and Bun lanes, reuses the existing guarded updaters, and fences mutation in this order before any tray/runtime/package change: sync/update mutex → ownership lease → in-flight marker → deadline / plan-token / attested identity re-check. Outcomes are classified from child-reported phases plus passive tree and runtime verification. npm/pnpm are driven from the Node launcher so the bundled Bun is idle during replacement.
  • ocx sync takes the same sync/update mutex and exits 7 update-in-flight while an update holds it.
  • ocx capabilities --json gains top-level contracts (every output shape); ocx capabilities --contracts --json prints only {"schemaVersion":1,"contracts":[...]}.

Design and four audit rounds: devlog/_plan/261102_ocx_update_orchestrated/010_plan.md.

Verification

  • bun run typecheck, bun run structure:check, bun run skill:surface:check, bun run privacy:scan: exit 0.
  • Focused suites (30 files: all tests/update/update-orchestrated-*, sync mutex, stop-first, capabilities, sync expect-link, launcher Desktop handoff, shim autorestore, client start fence, file-size ratchet, test layout, core–Lab boundary, skill-ocx, structure-ssot, repo-hygiene) with a temp HOME: 512 pass, 1 skip, 0 fail, exit 0.
  • New tests were written failing first; real launcher subprocess tests use npm/pnpm/Bun-global-shaped temp packages with fake package managers; nothing touches a real home, service or desktop app.
  • bun run test:changed could not complete locally on a heavily shared host (interrupted after >5 min). Failures seen in its partial run were environment leaks reproduced on this host (inherited GOOGLE_ANTIGRAVITY_USER_AGENT; a version-manager PATH putting a real npm/codex ahead of fixtures in codex-cli-update-* tests) or load timeouts. ci:full is set so the full Ubuntu shards cover the subprocess and read-as-data paths.
  • NOT RUN: Windows/macOS cross-platform CI (manual dev batch per policy), live service/desktop update.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • New Features
    • Added ocx update --plan --json to preview update eligibility, installation details, and runtime status.
    • Added JSON plan-and-apply workflows with plan matching, deadlines, and structured results.
    • Added ocx capabilities --contracts to list versioned machine contracts, including in JSON output.
  • Updates
    • ocx sync refuses without making changes when an update is in progress or coordination is unavailable; it exits with code 7.
    • Update results distinguish verified installation, verified rollback, and uncertain outcomes. npm and pnpm updates honor a selected version when provided.
  • Documentation
    • Expanded CLI help and lifecycle guidance for planning, applying, and understanding update outcomes.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration record (dev-only exception, MAINTAINERS.md).

  • Exact head: b298402 (base dev, merge with feat(sync): Home ocx sync fans out to linked Children (sync.home-fanout/1) #8100 resolved in 4d9f3e8; dev has since advanced without conflicts).
  • Exact-head CI (ci.yml with ci:full): gates, structure gate, storage policy, api usage, docker smoke, docs site build, npm-global ubuntu-latest, desktop shell, linux-systemd, Catalog async contracts, test 1/4–4/4 and the ci aggregate all SUCCESS; hygiene, enforce-target, label, resolve-pr SUCCESS. Skipped by policy on pull requests: macOS/Windows lanes, keyring, remote helper, setup action, privacy gate (covered by gates), test changed (full shards ran).
  • Independent review: ten rounds by fresh reviewers (GPT-6.1 Terra, xhigh); rounds 1–9 FAILED and every finding was fixed with a failing-first regression test; round 10 PASS at this exact head.
  • Local: typecheck, structure:check, skill:surface:check, privacy:scan exit 0; focused update/sync/launcher suites green (latest 118 pass / 1 root-only skip for the final guard change; 396 pass for the update lane set).
  • scripts/ci/assert-mergeable-review.sh --maintainer-integration 8103: OK snapshot at this head.
  • Accepted documented residuals: POSIX installer descendants that leave the process group can outlive the 15-minute fence; the Windows Job Object supervisor path is not exercised by PR CI; an older Desktop CLI child has a spawn-to-delegate-publication window if the launcher is SIGKILLed at that instant.
  • Not run: full local bun run test (host contention; the full Ubuntu shards ran in CI), macOS/Windows CI lanes (batched dev dispatch per policy).

@lidge-jun
lidge-jun merged commit 4d93716 into dev Nov 2, 2026
33 checks passed
@lidge-jun
lidge-jun deleted the feat/ocx-update-orchestrated branch November 2, 2026 16:51
lidge-jun added a commit that referenced this pull request Nov 2, 2026
… and shorten the pinned-sync watchdog case

PR test 4/4 at 7f4924e hit the 15-minute job timeout (job 125416446261) with no failing test. Its
merge with dev ran tests/update/update-orchestrated-entry.test.ts (#8103) for 98 s, and like the
other files #8099, #8100, #8103 and #8104 added it had no recorded duration and weighed the 176 ms
median: the shard predicted 728 s and ran 852 s of tests.

Both tables are refreshed with scripts/ci/test-durations.ts. Linux/macOS: run 41462914814 (dev
09b5585, Linux and macOS shards) plus the Linux shards of pull_request runs 41485932590,
41482553737 (#8103) and 41483744349 (#8104); every test file now has a row and the four Linux
shards predict 716 s each. Windows: run 41462914814's eleven shards; the #8103/#8104 files and
three files of the two stopped shards have no Windows measurement yet and still weigh the median.

The POSIX "version writer ignoring signals" case waited out the production ten-second watchdog. It
now runs the same script with a one-second watchdog and asserts the shipped script keeps
"sleep 10": the case drops from about 10.4 s to 1.4 s.
lidge-jun added a commit that referenced this pull request Nov 2, 2026
…fan-out test fixture (#8106)

* fix(link): keep Windows containment refusal at 126 and correct the fan-out test fixture

#8100 packed every Windows remote command and inflated it before the
containment helper existed, outside any try. A Child whose PowerShell
runs in Constrained Language Mode could not inflate it and exited 1,
which the Home reads as an ordinary ocx failure. Guard only the inflate
so it exits 126; Invoke-Expression stays outside the guard so the
inflated script's own errors and exit codes pass through.

The new local-only fan-out test spawned the CLI with a stripped POSIX
environment (no SystemRoot, a ':' PATH, a sh-script ssh) and without the
owned-service-home preload that keeps Codex write admission away from the
runner's real Task Scheduler. It timed out on Windows and could not prove
"no ssh" there at all. Give CLI children the inherited environment and
the owned-service-home fixture, add a Bun-spawn ssh sentinel with
positive controls, and prove local-only in process as well.

* docs(structure): separate inflation refusal from contained-run failures in the Windows contract

* docs(devlog): record the measured encoded-size cost of the inflate guard

* docs(devlog): quote the shipped wrapper and control in the plan

* test(link): pin the fan-out Home outcome and keep inflated script errors out of 126

Address review: the local-only subprocess case now asserts the Home outcome its fixture is built for, and a Windows case shows an error raised by an inflated script keeps its own exit instead of the containment refusal (packedPowerShellArgv is exported for it).

* ci(test): record durations for the #8099/#8100/#8103/#8104 test files and shorten the pinned-sync watchdog case

PR test 4/4 at 7f4924e hit the 15-minute job timeout (job 125416446261) with no failing test. Its
merge with dev ran tests/update/update-orchestrated-entry.test.ts (#8103) for 98 s, and like the
other files #8099, #8100, #8103 and #8104 added it had no recorded duration and weighed the 176 ms
median: the shard predicted 728 s and ran 852 s of tests.

Both tables are refreshed with scripts/ci/test-durations.ts. Linux/macOS: run 41462914814 (dev
09b5585, Linux and macOS shards) plus the Linux shards of pull_request runs 41485932590,
41482553737 (#8103) and 41483744349 (#8104); every test file now has a row and the four Linux
shards predict 716 s each. Windows: run 41462914814's eleven shards; the #8103/#8104 files and
three files of the two stopped shards have no Windows measurement yet and still weigh the median.

The POSIX "version writer ignoring signals" case waited out the production ten-second watchdog. It
now runs the same script with a one-second watchdog and asserts the shipped script keeps
"sleep 10": the case drops from about 10.4 s to 1.4 s.
lidge-jun added a commit that referenced this pull request Nov 2, 2026
…ithSession

#8103 moved the three reviewed guardedStartWindowsTray deferred imports from runUpdate into runUpdateWithSession, and the policy table follows the code. The fixture now uses that context; the fourth binding, raw namespace, unreviewed binding and other-context cases stay rejected. Windows-only lint; reproduced and verified under Node.
lidge-jun added a commit that referenced this pull request Nov 3, 2026
* fix(ci): make the Windows batch shards green after #8103

Run 41491122166 left four Windows shards red; dev was green on all eleven
in 41262132337 before #8103.

- update-orchestrated-identity: the fixture used POSIX paths that are not
  native on win32. The product also rejected a Windows source path written
  with '/' separators, so a live install could read as unknown; win32 now
  equates only the separators (dotted, doubled and wrong-suffix forms
  still fail closed).
- update-bun-ownership-lease: the fixture did not recognize the Windows
  installer bridge (runWindowsInstallerSync) that #8103 introduced, so it
  answered unconfirmed and the updater kept its fence.
- claude-intercept-acl-barrier: stub the PowerShell owner-ACL probe like
  the writer-barrier suite, so a slow cold probe cannot use up the 1 s ACL
  budget before the mocked icacls runs.
- update-mutation-guard (windows 9/11): this lint runs only on Windows,
  where Bun can start the TypeScript sync client, so #8103 landed with 1258
  unreviewed findings. Review every #8103 site into the existing tables plus
  two orchestrated-module sidecars; accept exit 10 only for the exact
  enterMutation refusal branch, with mutants; orchestrated-entry launches
  its child through probeSpawn, as job.ts does.
- Windows durations refreshed from runs 41491122166 and 41462914814.
- storage-policy and lab-read-surfaces left unfinalized prepared
  statements that keep SQLite files open, so each Windows afterEach
  removal waited its 15 s retry budget (about 210 s per run) and leaked the
  home.

Plan and evidence: devlog/_plan/261103_windows_batch_shards/010_plan.md

* test(update): reject relaxed mutation-entry refusal shapes

Add mutants for an unawaited or different initializer, an inverted entered.ok predicate and an else branch (CodeRabbit review).

* test(update): pin the deferred-import admission fixture to runUpdateWithSession

#8103 moved the three reviewed guardedStartWindowsTray deferred imports from runUpdate into runUpdateWithSession, and the policy table follows the code. The fixture now uses that context; the fourth binding, raw namespace, unreviewed binding and other-context cases stay rejected. Windows-only lint; reproduced and verified under Node.

* fix(update): hand the orchestrated child a parent-issued result channel

The orchestrated update child now writes its outcome records only into a
result file its parent created for it. The parent creates a fresh temp
directory holding one exclusively created capability file and passes the
token in OCX_UPDATE_RESULT_CAPABILITY. Before any session write, mutex
use or identity probe, the child accepts only a canonical, single-link,
non-symlink regular file (owner-only on POSIX) whose size and entire
content equal that capability document, then publishes every record
through the descriptor it validated (truncate, then write at explicit
offsets). The parent reads, unlinks and non-recursively removes only the
file and directory identities it recorded, and bounds the record size.

Update-lint rows are re-reviewed for the new sites, and the POSIX
supervisor and marker rows now state only what the code enforces.
Tests cover rejected destinations left byte-identical, a path swap after
validation, interrupted and oversized records classifying as uncertain,
identity-bound cleanup, and real Bun and Node parent-to-child handoffs
under a symlinked temp root.

* fix(update): compare result-channel file identity with BigInt stats

NTFS and ReFS file ids can exceed Number.MAX_SAFE_INTEGER; every identity-bearing lstat/fstat in the result channel and destination validation now uses { bigint: true } (CodeRabbit review).

* fix(update): scope the result handoff token and channel cleanup

Remove the result capability from the parsed environment so probes and
installers never inherit it; the Node launcher passes it only to the Bun
process continuing the same child. Channel cleanup removes by path only on
POSIX with non-replaceable ancestors, and otherwise leaves the channel.
Cover symlinked and junction destinations in both Node and Bun.

* test(update): qualify result channel and marker review rows

State that cleanup identity checks precede path-based removal on POSIX only,
and that marker publication assumes the OpenCodex home cannot be replaced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the four full Ubuntu test shards on this pull request enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant