Skip to content

feat(link): journal ocx link add and revoke under an operation id, with --require-ephemeral - #8623

Merged
lidge-jun merged 25 commits into
devfrom
feat/link-enroll-journal
Nov 13, 2026
Merged

lidge-jun merged 25 commits into
devfrom
feat/link-enroll-journal

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

A provisioning caller (a hub that builds a disposable machine and links it to its Home) has to know exactly what an enrollment or a revoke did, even when it loses the answer or the Home process dies halfway. Today ocx link add and ocx link revoke leave nothing behind but their effects: after a crash the caller cannot tell whether a key was issued, a link recorded or the Child enrolled, and repeating the command enrolls again. A revoke also has no receipt that a planted ocx-child was purged, and a force revoke can run while a purge is still in flight.

This adds an operation journal, <configDir>/link/operations.json (src/link/operations-journal.ts), used only when a caller passes an operation id:

  • Reserved identities before any effect. ocx link add --operation-id <id> (which needs --expect-fingerprint) writes an entry that reserves the link id and the data key id it will create, plus the explicit route and exclusive flag from feat(link): let a Remote Link carry an explicit, exclusive SSH route #8615. The key is issued under the reserved id (issueApiKeyInProcess accepts a reserved UUID). The Child picks the tunnel port after a plant, so the port is recorded before the first Home effect.
  • An intent and a completion mark around every effect: plant, key_issued, link_recorded, child_enrolled and relay_verified for apply; remote_cleanup, key_revoked and record_removed for revoke. A purge's completion records {purged: true, linkId} as its receipt.
  • Outcomes: committed, failed_clean, residual (the Child may still hold an enrollment or a plant) and unknown. An entry also records childResidual whenever the Child may keep something, whatever the outcome says about the Home's key, and answers carry a closed residualKind (plant or enrollment).
  • Replay and recovery. A repeat with the same id and parameter digest returns the recorded outcome without SSH; another digest answers 409 operation_mismatch. An entry left open by a process that died is settled from its own marks, comparing by reserved id only: a completed relay verification committed; otherwise whatever carries the reserved link id or key id is undone. Another link for the alias, or compensation that fails, makes the outcome unknown; an enrollment intent or a plant makes it residual. A recovered revoke counts a missing link as its own removal only after its own removal intent.
  • Serialization. A per-alias SQLite lock file (src/link/alias-lock.ts) is held for the whole operation. A second holder waits on an injected clock, then answers 409 link_operation_in_progress, so a force revoke cannot run between a journalled purge and its receipt. In the runtime, a revoke also takes the link's Child-operation reservation, and journalled revokes join the per-alias operation set apply holds, so an apply and a revoke of one alias never overlap. That set is now keyed without case, like the lock and the journal. Only one runtime per state directory serves these routes (spend-ledger owner lease).
  • --require-ephemeral runs a census before any plant, key or Child change. It counts every runnable full ocx the gated argv could select (served-runtime census, Desktop, system and every PATH directory) and never stops at an ocx-child the way runtime inspection does. Any one answers 409 full_install_present, also beside an ocx-child; an unfinished census fails closed; a Windows Child answers 409 require_ephemeral_unsupported.
  • Management and CLI: GET /api/link/operations[/{id}] and POST /api/link/operations/{id}/resolve (marks a residual or unknown entry resolved; resolveLinkOperation is the call the O5 recovery work will make). Also ocx link revoke --operation-id, ocx link operations [--operation-id] and ocx link operations resolve --operation-id --yes. With an id, ocx link add first reads the operation and replays a recorded one without a new probe. Error answers keep their operation id, outcome and residual kind through the CLI's error filter, and the CLI maps the kind to its own fixed guidance.
  • Contracts: ocx capabilities --contracts lists link.route/1 (the explicit, exclusive route of feat(link): let a Remote Link carry an explicit, exclusive SSH route #8615) and link.operation/1 (this change).
  • Retention: committed and failed_clean entries are pruned 30 days after they finish; residual and unknown entries stay until resolved, then 30 days. links.json is unchanged.

The branch starts with four small follow-ups to #8615 from its final review, each its own commit: every SSH builder's route-less argv is compared to the literal pre-#8615 argv; the supervisor restarts a tunnel whose explicit route was edited in links.json; the docs say a ProxyCommand must not hold a secret (it shows in ps, the pidfile, status rows and ocx link status --json); and they note that an older CLI's status validation rejects rows of exclusive links. This branch was stacked on #8615 and joined to dev through the merge of 51de887 (the #8615 line after its squash); it is clean against current dev (git merge-tree exit 0).

What stays unchanged by default

Nothing passes --operation-id or --require-ephemeral until a caller does. On a Home whose operations.json does not exist, an apply or revoke without an operation id behaves and answers exactly as before: no lock file, no journal read, no new refusal, and the file is never created. Once the journal exists, plain applies and revokes also take the alias lock and respect open entries. Two deliberate changes apply without the new flags: ocx link probe/add/routes operations on two case variants of one alias now refuse to overlap (one gets 409), the rule the alias lock, the journal, OpenSSH and link_exists already apply; and the CLI's port-busy and external-provider messages ("no Child files were modified") are no longer printed for a residual answer.

Contract for the O5 recovery lane

O5 calls resolveLinkOperation(id) (or POST /api/link/operations/{id}/resolve) when it proves a Child clean. It reads reserved.linkId, reserved.explicitRoute and alias from residual entries to run detach --purge --expect-link over the link's route; SSH builders take a required route argument, so its commands must pass record.explicitRoute ?? entry route. The Child's purge report names no link id today, so the revoke receipt binds purged:true to the link id the Home revoked; a report from --expect-link that names the link would let the receipt rest on the Child's own statement.

Verification

Tests that failed first, and why (each run with the change's src stashed, so against the code before it):

  • tests/server/link-enrollment-operation.test.ts (21 cases at first): before, apply refused operationId as an unknown body key, so all failed. Live outcomes with reserved ids and the exact mark order; replay without SSH; digest mismatch; an open entry refusing other enrollments; the alias lock; a crash table that builds the journal, keys and store for every boundary (after each intent and each completion, plant included) and checks the outcome and what is undone; a foreign link and a failing revoke giving unknown; a residual entry older than 30 days still present and recoverable.
  • The same file, --require-ephemeral: 3 failed before the census existed (a full ocx beside ocx-child refused before any plant or key; the census runs once, before the port; an unfinished census fails closed).
  • tests/server/link-revoke-operation.test.ts: 8 of 9 failed (the purge receipt and its replay; a failed purge; mode mismatch; a force revoke waiting for, or refused by, a held lock; crash recovery). The guard "without an operation id nothing is written" passed before and after.
  • tests/cli/cli-link-operation.test.ts: the five behavioural cases failed (first run, replay without probing, recorded failure keeping its outcome, revoke receipt, ocx link operations).
  • Review rounds 1 to 7 each added tests that failed before their fix: key revoke and removal intents counting as touched; a key issue that persists then throws settling unknown and still purging a fresh plant; an unfinished plant being residual; recovery not crediting another removal; an open revoke refusing others; plain callers taking no lock before a journal exists; an apply and a journalled revoke of one alias not overlapping; case variants sharing admission; the Child residual surviving replay with plant-specific, platform-complete guidance; the CLI's own guidance on replay and on conflict answers.
  • tests/clients/link-explicit-route.test.ts (P3 follow-up): a reload after a links.json route edit did not restart the tunnel (killed 0, expected 1); now it restarts on the new port.
  • Also new: tests/clients/link-operations-journal.test.ts (strict parse, 0600, retention, digest), tests/clients/link-alias-lock.test.ts (waits, bound, symlink refused), tests/clients/link-full-install-census.test.ts (the real census script under /bin/sh against a fake home holding ocx-child state and a full ocx), tests/server/link-operations-routes.test.ts.

Commands (Bun 1.4.4, TMPDIR=/tmp), on head 3a3283d:

  • bun run typecheck → exit 0
  • bun run privacy:scan → exit 0
  • bun run structure:check → exit 0
  • bun run skill:surface:check → exit 0
  • bun scripts/test.ts --parallel=2 over tests/clients/link-, tests/clients/client-link-, tests/server/link-, tests/cli/cli-link, tests/cli/sync-, tests/cli/link-, tests/codex-integration/messaging-remote*, the layout, structure, file-size ratchet and skill-ocx tests, the CLI capability tests, management-route-registry, readyz-features, persistent-dashboard-consent, cli-api-protocols, api-keys-routes, api-key-attribution, api-access-endpoints and ocx-launcher-desktop-handoff (158 files) → exit 1: 2623 pass, 29 skip, 3 fail. The 3 failures are the Rust-toolchain cases under NOT RUN; they fail the same way on origin/dev.
  • git merge-tree --write-tree origin/dev feat/link-enroll-journal → exit 0 against origin/dev 522a6cd.

NOT RUN: the full bun run test suite (this machine is limited to focused files); tests/clients/link-ocx-child-e2e.test.ts (2 cases) and the Rust conformance runner in tests/clients/link-ocx-child-conformance.test.ts, which need a Rust toolchain this machine lacks (rustup has no default toolchain); a real crash of a running Home (crash boundaries are covered by constructing the journal, key and store state each boundary leaves); a second process contending for the alias lock (the lock is SQLite BEGIN IMMEDIATE, exercised with two connections in one process); Windows and macOS.

Review: an independent read-only reviewer went through eight rounds on this branch (crash safety, concurrency, replay, census, inertness, exposure). It raised 4 P1 and 12 P2 findings. Each was answered in its own commit above; one P1, the first-use race between a plain and a journalled revoke, was answered with a regression test that shows the existing exclusion (the link's Child-operation reservation in the runtime, the spend-ledger owner lease across processes) rather than a code change. Its last round reported no open P0-P2. It did not run tests (read-only).

Docs: structure/remote-link.md gains "Operation journal" and the follow-up notes in "Explicit route"; the English Remote Link guide documents the flags and ocx link operations; the capability registry, the management route registry and the generated skill surface list the new flags and routes.

Checklist

  • Targets dev
  • Behaviour changes in src/ have focused regression tests in their domain folders, registered in the test layout maps
  • Owned structure doc updated in the same change
  • Inert by default (see above)
  • No GUI change

A Home-initiated link may now record explicitRoute {proxyCommand, user, port}
and exclusive. Every SSH builder takes a required route, so each caller decides;
the route reaches ssh on the command line for enrollment, revoke, purge, every
exec and every tunnel start, where ssh_config cannot change it. An exclusive
link refuses route edits. No link has either field until a caller passes the
new flags.
The inspection dependency now takes the link's explicit route after the alias;
the mock records it so a routed inspection would show up.
The privacy scan reads tracked files and flags user@domain text; the fixtures
keep their @ words without a domain.
…literals

Only the tunnel argv was compared to a literal; exec, probe, route probe and
Windows probe are now compared to the argv origin/dev e85a975 built, so a
drift in any option of any builder fails.
The supervisor's record instance left out explicitRoute and exclusive, so a
hand edit of links.json on a running Home kept the live tunnel on the old
route until it exited. Both fields are now part of it. The comment on the
multi-route spawn now says what happens instead of assuming null.
… secret

The command is visible in the process list to every local user and is written
to the tunnel pidfile, the link status rows and ocx link status --json. The
test fixtures no longer use a value that reads like a key.
…inks

Beside the store downgrade trade-off: an older validateStatus, which ocx sync
also uses, refuses a row with exclusive or explicitRoute, so an older
ocx link status or ocx sync against a Home with an exclusive link fails for
every row.
… line

Parents: the reviewed head 0c47081 and the squash. The tree is the squash's tree, which equals 0c47081 merged onto dev 2c0a9ef. Lanes stacked on 0c47081 merge this commit instead of origin/dev.
A provisioning caller reads the contract list to know whether this Home's
OpenCodex supports the explicit, exclusive route of a Remote Link (the
--proxy-command, --ssh-user, --ssh-port and --exclusive flags and the
explicitRoute and exclusive body keys).
… recovery

An apply that carries an operation id writes <configDir>/link/operations.json:
the link id and key id it will create are reserved before any effect, each
Home effect gets an intent and a completion mark, and the outcome is recorded
(committed, failed_clean, residual, unknown). A repeat with the same id and
parameters replays it; another digest is refused. An entry left open by a
process that died is recovered by reserved id. Apply and the alias take a
per-alias lock file. Nothing passes an operation id yet.
…hemeral

Apply with requireEphemeral runs a census over every full ocx candidate the
gated argv could select (served-runtime census, Desktop, system and PATH),
without stopping at an ocx-child, before any plant, key or Child change. A
runnable full ocx answers 409 full_install_present; an unfinished census fails
closed; a Windows Child answers 409 require_ephemeral_unsupported.
…operation-id

Every revoke takes the alias lock, so a force revoke waits while a purge holds
it and cannot land between the purge and its receipt. With an operation id the
revoke is journalled: remote cleanup, key and record each get an intent and a
completion, a purge's purged:true is recorded as the receipt for that link id,
and a repeat replays the outcome even after the link is gone. Without an
operation id nothing is written and the answer is unchanged.
GET /api/link/operations[/{id}] reads the journal; POST
/api/link/operations/{id}/resolve marks a residual or unknown entry resolved,
which starts its 30 days of retention (resolveLinkOperation is the call O5
makes once it proves a Child clean). The enrollment digest leaves plant out:
it follows from the probe, which a replay does not repeat.
ocx link add takes --operation-id (with --expect-fingerprint) and
--require-ephemeral; with an id it first reads the operation and, when it is
recorded, replays it through apply without a new probe. ocx link revoke takes
--operation-id and prints the outcome and purge receipt. ocx link operations
lists, reads and (with --yes) resolves entries. Error answers keep their
operation id and outcome through the CLI's error filter; the new refusals get
fixed guidance. The capability registry, the management route registry and the
generated skill surface list the new flags and routes.
… the lock wait

structure/remote-link.md gains "Operation journal": the file, the reserved ids,
the effect marks, how outcomes are classified, recovery by reserved id, the
per-alias lock, the full-install census and the routes and CLI. The guide
lists the new flags and command. New tests cover the journal file's strict
parse, privacy and retention, and a second enrollment that waits for the lock.
…lain callers inert

Review round 1: a force revoke that died after revoking the key, a revoke
whose link something else removed, a key issue that threw after the config
may have been saved, and a plant that did not report completion were each
settled too optimistically. They now settle unknown or residual from the
operation's own marks, and an open revoke entry refuses other revokes of its
link. Without an operation id, apply and revoke take the alias lock and read
the journal only once this Home has a journal file, so a Home that never
journalled behaves exactly as before.
A provisioning caller reads it to know that ocx link add and revoke take
--operation-id, ocx link add takes --require-ephemeral, and the operation
journal and its routes are served.
…link-enroll-journal

Brings this stacked branch onto dev: 51de887 joins 0c47081 with the #8615
squash b1b6dca and carries the squash's tree.
Review round 2: an apply whose reserved key issue threw returned before the
plant rollback, leaving a planted binary behind; it now goes through the same
failure path, which purges it, and the outcome stays unknown. A regression
test pins that the first journalled purge on a Home cannot be overtaken by a
plain force revoke (the link's Child-operation reservation excludes it in the
runtime; the spend-ledger owner lease keeps it to one runtime per store), and
the structure doc states that guarantee. The link CLI leaf test lists the two
operations leaves and no longer names a count in its title.
…esidual with any outcome

Review round 3: a plain apply on a Home without a journal and the first
journalled revoke of the link it had just recorded could overlap, because
revoke did not consult the per-alias operation set apply holds. A journalled
revoke, and any revoke once the journal exists, now takes that set too. An
enroll entry records childResidual when the Child may keep an enrollment or a
plant, so a replay of an unknown outcome still reports it.
… for a residual plant

Review round 4: the in-memory per-alias set compared spellings, while the alias
lock and the journal ignore case, so a plain apply of one spelling could
overlap the first journalled apply of another. The set is now keyed without
case. A replayed residual whose entry shows a plant now gives the managed
binary's detach --purge, since a disconnect would leave the plant.
Review round 5: the replayed plant step named only the POSIX path, and on a
replay the CLI, which never probed, fell back to full-install advice and
ignored the server's step. Journalled answers now carry residualKind (plant or
enrollment); the CLI maps it to its own fixed guidance, and the plant step
names both managed locations with detach --purge.
…on Child conflicts

Review round 6: the Windows plant step now also names the location used when
LOCALAPPDATA is not set, with quoted paths. The CLI's port-busy and
external-provider messages, which say no Child file changed, now apply only to
answers that are not residual, so a plant whose rollback failed gets the purge
guidance instead.
…ommands

Review round 7: %LOCALAPPDATA% and a bare quoted executable are Command Prompt
syntax; PowerShell expands neither. The guidance now says where they run.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 44efa74 and 3a3283d.

Files selected for processing: 35

  • docs-site/src/content/docs/guides/remote-link.md
  • scripts/test-layout/layout-clients.json
  • skills/ocx/references/01_management_surface.md
  • skills/ocx/references/01_surface_access-remote.md
  • src/cli/capabilities-access-remote.ts
  • src/cli/capabilities-base.ts
  • src/cli/capability-contracts.ts
  • src/cli/link-enrollment.ts
  • src/cli/link-operations.ts
  • src/cli/link.ts
  • src/link/alias-lock.ts
  • src/link/operations-journal.ts
  • src/link/remote-plant.ts
  • src/link/supervisor.ts
  • src/server/management/context.ts
  • src/server/management/link-enrollment.ts
  • src/server/management/link-operation.ts
  • src/server/management/link-route-state.ts
  • src/server/management/link-routes.ts
  • src/server/management/oauth-account-routes.ts
  • src/server/management/route-registry.ts
  • structure/remote-link.md
  • tests/cli/cli-capabilities-arguments.test.ts
  • tests/cli/cli-link-explicit-route.test.ts
  • tests/cli/cli-link-operation.test.ts
  • tests/cli/cli-link.test.ts
  • tests/clients/link-alias-lock.test.ts
  • tests/clients/link-explicit-route.test.ts
  • tests/clients/link-full-install-census.test.ts
  • tests/clients/link-operations-journal.test.ts
  • tests/fixtures/test-layout-expected.json
  • tests/server/link-enrollment-explicit-route.test.ts
  • tests/server/link-enrollment-operation.test.ts
  • tests/server/link-operations-routes.test.ts
  • tests/server/link-revoke-operation.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 13, 2026
@lidge-jun
lidge-jun marked this pull request as ready for review November 13, 2026 03:04
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 03:04
@lidge-jun
lidge-jun merged commit 600939d into dev Nov 13, 2026
34 checks passed
@lidge-jun
lidge-jun deleted the feat/link-enroll-journal branch November 13, 2026 03:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T03:09:28.483446Z 3a3283d Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

lidge-jun added a commit that referenced this pull request Nov 13, 2026
Conflicts resolved: CAPABILITY_CONTRACTS is the union (link.route/1, link.operation/1,
link.recover/1); the forced-revoke tombstone is written before O1's journal.intent("key_revoked");
both the /api/link/operations and /api/link/recover blocks are kept; usage, docs and the
skill surface (regenerated) carry both lanes' commands; serialized() keeps dev's case-folded set.

Also in this commit: recover runs under O1's underAliasLock as well as serialized() (item 3);
each forced-revoke attempt stamps its tombstone with a random attempt token and a failed
attempt removes only its own (review r9); GET /api/link/recover is covered by the link
recover capability, whose flags and usage name --list, --forget and --yes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant