Repository navigation
feat(link): recover a force-revoked ephemeral Child by its link id (ocx-child owner record /2, detach --expect-link, ocx link recover) - #8612
Conversation
… detach --expect-link Attach now writes ocx.child.codex-home-owner/2 with the link id while it holds the lifecycle and CODEX_HOME locks, in the attaching phase, before any CODEX_HOME write. detach --expect-link <id> restores only when state.json and the owner record both name that link (or nothing is left at all); a /1 record or a missing state answers residual (exit 6), another link, an unreadable record or another OPENCODEX_HOME answers conflict (exit 5), and neither changes or purges anything.
…d POST /api/link/recover
A forced revoke of a Home-initiated ephemeral link now writes <configDir>/link/tombstones.json
(link id, alias, pinned fingerprint, platform, routes) before the key and record go, and refuses
the revoke if it cannot. POST /api/link/recover {linkId} runs the managed planted ocx-child's
disconnect --purge --json --expect-link <id> over the alias with the pinned host key and removes the
tombstone only on an exit 0 report naming that link with purged:true. {operationId} resolves through
a slot the O1 enrollment journal registers; until then it answers operation_journal_unavailable.
ocx link recover (--link-id <id> | --operation-id <id>) posts to POST /api/link/recover and accepts only a receipt naming that link with purged:true. A forced revoke of an ephemeral link now names it in its recovery instruction. structure/remote-link.md documents the /2 owner record, detach --expect-link and the tombstone; the guide and the CLI lifecycle reference list the verb.
|
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. |
…t, purges under the lock Review round 1 on #8612: - detach --expect-link also reads the link an unresolved attach rollback would put back; an interrupted attach between two links answers residual for those links (conflict for others), so recovery never restores and detaches a link it was not asked for. - --purge removes the planted binary before the lifecycle lock is released, so a waiting attach cannot start before the binary is gone. - A recover whose receipt was lost after the purge settles through a read-only check that neither the managed binary nor any ocx-child recovery record remains. - Recover failures answer fixed hints, never the machine's stderr.
…d receipt Review round 2 on #8612: - detach --expect-link writes $OPENCODEX_HOME/link-receipts/<id>.json (ocx.child.detach-receipt/1) before its purge and again after it; recover reads that receipt when the managed binary is already gone and settles only on one naming the link with restored and purged true. The absence-of-files check is gone: absence proves nothing. - The rollback snapshot is parsed and home-checked as recovery will before anything changes, so a malformed one is a conflict with no phase change.
…ipts to one attachment Review round 3 on #8612: - Every relay serving from the managed planted binary holds .ocx-child-in-use.lock beside it shared; a purge takes it exclusively without waiting and keeps the binary (purged:false) while a relay of any home runs from it, and serve refuses while a purge holds it. - The restore receipt is written once, before the purge, and records only the restore; recover reads the purge from the missing binary, so a crash after the purge stays provable. - An attach of a link removes that link's old receipt under the lifecycle lock first.
…k, prove the purge by absence Review round 4 on #8612: - The in-use lock file is never unlinked, so no relay can lock a fresh file of the same name while a purge removes the binary. - The enrollment rollback purge leaves a binary the Child kept for another home's relay (POSIX: purged:false in detach --purge --json; Windows: still present after the purge). - The receipt read exits non-zero while a planted file of that name exists, executable or not, or its directory cannot be searched, so only a confirmed absence proves the purge.
…able directories Review round 5 on #8612: a test for a path reads false both when it is absent and when an ancestor cannot be searched. The POSIX receipt read now walks from $HOME down to the planted binary and exits 4 on any directory it cannot search; the Windows read counts only Get-Item's ItemNotFoundException as absent.
GOAT reads the Home's contracts to know it can recover a force-revoked ephemeral Child.
The tombstone of a force-revoked ephemeral link keeps the link's explicit route and exclusive flag (an explicit route requires exclusive, as on the record), and recover passes that route's ProxyCommand, user and port on the ssh command line; a link without one still uses its alias. The operation-recovery slot's target carries the explicit route for O1.
…ever spliced into source
…mmitted or ordinary revokes, fold alias case, name a kept in-use binary, refuse an unreadable prior snapshot
… link is gone, and clean up only the tombstone a failed revoke wrote
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.
…one names the alias, so recover excludes them
…cle reference; settle a recover whose binary stays for another home; drop the tombstone when the revoke journal fails
…recover # Conflicts: # tests/fixtures/test-layout-expected.json
…recover # Conflicts: # docs-site/src/content/docs/es/guides/remote-link.md # src/server/management/link-enrollment.ts # src/server/management/link-routes.ts
… intent, as #8638 orders the revoke #8638 moved a force revoke's key_revoked intent ahead of stopLink, so the merge left the tombstone written after that intent and after the tunnel stopped. The tombstone is now written first, before any intent and with the tunnel untouched (a refused write needs no restart), and it is dropped when the first intent or the record_removed intent cannot be written, as it already was when the key revoke or the record removal fails. Tests: a damaged tombstone file refuses before the tunnel is touched; a journal that breaks during the revoke answers 500 operation_journal_failed, keeps the link and drops the tombstone.
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: b2e6af23fe
ℹ️ 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 resolver = operationRecoveryResolver(); | ||
| if (!resolver) return fail("operation_journal_unavailable", "This Home has no link operation journal; recover by --link-id.", 409); |
There was a problem hiding this comment.
Connect recovery to the existing operation journal
For an interrupted enrollment recorded in the existing operation journal, ocx link recover --operation-id <id> always returns operation_journal_unavailable, even when the journal contains that operation. Searching src/ finds no caller of registerOperationRecoveryResolver; the only registration is the synthetic resolver in tests/server/link-recover.test.ts. Consequently, the advertised enrollment-recovery path is unreachable, and the suggested --link-id fallback cannot help an enrollment that never committed a link or created a forced-revoke tombstone. Wire the journal's lookup and settlement implementation into this path and cover recovery using a real journal entry.
Useful? React with 👍 / 👎.
Brings in dev through 6f58f62, including #8612 (recover a force-revoked ephemeral Child by its link id: tombstones, ocx link recover), #8635 and #8644. Conflict resolution in removeReserved keeps both sides: dev's tombstone is written before the first intent for a forced revoke of an ephemeral Child, with this PR's cleanup condition (cleanup already recorded by the owner's journal is not rerun); every way out that does not commit (claim failure, a changed record, a failed key revoke or journal intent, the post-commit catch) drops the force's own tombstone, which dev's helper does only while the link still exists; a committed non-force removal settles earlier tombstones of the link. remove() admits the alias lock for a tombstoned alias using the removal target's record. The generated skill surface was regenerated.
One conflict, docs-site/src/content/docs/es/guides/remote-link.md: this branch's journal paragraph and #8612's recover paragraph are kept in the English page's order (journal, then recover). The generated skills reference is regenerated on the merged tree (51 declared capabilities); everything else merged on its own.
…g was changed After #8612, ocx link revoke --force --operation-id of an ephemeral Child can be refused with tombstone_limit (409) or tombstone_write_failed (503). tombstone_limit is answered before the tombstone is written, before the first journal intent and before the tunnel stops, so it joins the CLI's closed list of refusals that say nothing was changed; tests/server/link-recover.test.ts now pins that the key is not revoked and the tunnel not stopped. tombstone_write_failed stays generic: the tombstone file may already be written when its permissions step fails.
…rom a truth table; the operation journal keeps replays for at least 2 hours (#8654) * fix(link): the CLI explains a full operation journal and a journalled revoke that did not complete Final review of #8638: linkRequest replaces every API error with "Link management request failed (N)", operation_journal_full was not among the add refusals, and runRevoke rethrew everything but link_not_found, so a full journal, or a repeated open revoke that recovery settled unknown (409 operation_interrupted), printed only that generic line. operation_journal_full now carries a closed bound field (unsettled or recent); it is additive, and an older CLI drops it and still refuses. ocx link add and ocx link revoke with --operation-id print their own guidance for it, with the code and the bound, keeping exit 5. A journalled revoke that did not complete prints "(operation <id>: <outcome>) (code <code>)" from the filtered body (the caller's validated id, a closed outcome, the filtered code) and names ocx link operations resolve when the outcome is unknown. No server text is printed. * docs(link): say what an open revoke means and that its flags cannot be read back Final review of #8638: the open-suspension text said "the Home stopped during it", but an open entry also means the revoke failed before writing its outcome; "add --purge if it was a purge" cannot be checked from the entry, which records only a digest of the flags, so a wrong guess answers operation_mismatch; and the ALIAS_LOCK_WAIT_MS comment promised a waiter time to finish before the CLI deadline, which an apply's worst case does not give. The route, the CLI, the capability text, the guide (English and Spanish) and structure/remote-link.md now say "did not record its outcome (the Home stopped or the revoke failed before writing it)" and tell the caller to repeat with the flags of the first attempt, naming operation_mismatch for a different --purge. The alias-lock comment says the bound limits the wait and promises no time to finish. * docs(link): state the operation journal's throughput limit by churn Final review of #8638: the comment on OPERATION_JOURNAL_MAX_RECENT_SETTLED argued by machine count. The limit it sets is a burst of 1024 and about 42 journalled operations per hour sustained (1024 / 24.05 h); ten disposable machines that live ten minutes each make about 120 per hour and reach it in about 8.5 hours. The comment, structure/remote-link.md and the ocx link operations capability text now say so. The constants are unchanged until the owner chooses a replay horizon or a higher cap. * docs(link): a suspension needs the revoke's cleanup intent and no live revoke Lane review (P3): the ocx link operations resolve text said any revoke that did not record its outcome keeps the link down, but suspension needs the remote_cleanup intent, and an open entry only when no revoke in this Home still runs it. The capability text and the generated skill reference now say so. * docs(link): the cleanup-intent condition covers an open revoke too Final review of #8654 (P3): the ocx link operations resolve text tied the remote_cleanup intent to the unknown case only, but suspendingRevoke requires it for an open entry as well, so an open forced revoke or an open revoke of a Child-initiated link never suspends. The capability text and the generated skill reference now read as structure/remote-link.md does. * fix(link): a journalled revoke refused before it ran says nothing was changed Final review of #8654 (P3): operation_mismatch, link_operation_open, link_operation_in_progress and operation_journal_unreadable on ocx link revoke --operation-id printed 'Link revoke did not complete (code X)'. They now get the CLI's own text that nothing was changed, with the code, as add's refusals do. The list is closed: any other code, including ones a newer Home adds, keeps the generic text and makes no such claim. Exit codes are unchanged. * fix(link): the journalled revoke helper re-checks the outcome and code itself Final review of #8654 (P3): journalledRevokeError accepted any string outcome and was safe only because linkRequest's filter had limited it. It now re-checks the outcome against OPERATION_OUTCOMES and the code against the filter's pattern, as journalFullGuidance re-checks bound; a test passes an unfiltered body straight to the helper. * docs(link): say when the CLI adds the operation note and the bound Final review of #8654 (P3): structure/remote-link.md said an unfinished journalled revoke always prints the operation note and a full journal always the bound. The operation part appears when the answer names this operation and a known outcome, the bound when the Home sends it; the doc now says so and lists the refusals that say nothing was changed. * docs(link): a cleanup intent means cleanup may have started; a full journal also says nothing changed Lane review (P3s): the remote_cleanup intent is written before the tunnel stops and before the Child is contacted, so the capability text now says the Child's cleanup may have started instead of that it reached the Child (generated skill reference regenerated). structure/remote-link.md lists operation_journal_full's guidance among the texts that say nothing was changed. * fix(link): a forced revoke refused at the tombstone limit says nothing was changed After #8612, ocx link revoke --force --operation-id of an ephemeral Child can be refused with tombstone_limit (409) or tombstone_write_failed (503). tombstone_limit is answered before the tombstone is written, before the first journal intent and before the tunnel stops, so it joins the CLI's closed list of refusals that say nothing was changed; tests/server/link-recover.test.ts now pins that the key is not revoked and the tunnel not stopped. tombstone_write_failed stays generic: the tombstone file may already be written when its permissions step fails. * feat(link): keep a settled journal entry replayable for 2 hours instead of a day Decision for disposable-machine churn: with a one-day replay horizon the 1024 recently-settled bound allowed about 42 journalled operations per hour, and ten machines that live ten minutes each (about 120 per hour) hit it after about 8.5 hours. OPERATION_REPLAY_MIN_MS is now 2 hours; the alias-lock wait and the minute of margin stay, so the prune floor is 2 h + 120 s + 60 s, and the 1024 bound stays: about 500 journalled operations per hour sustained, 4.2 times the example churn, with a worst-case file of about 1.5 MiB. The guarantee: a repeat with the same operation id within 2 hours of the answer always gets that answer; later it may be treated as a new operation, which meets a safe refusal (link_exists for an enrollment whose link is there, link_not_found for a revoke whose link is gone). Unsettled entries are never pruned and the 30-day retention is unchanged, so the window matters only after more than 256 settled entries. The constant's comments, the 409 text for the recent bound, the CLI's own guidance, the ocx link operations capability text (and its generated skill reference) and structure/remote-link.md say so. * docs(link): state the replay guarantee with its conditions, and pin a repeat after the window Lane review of the 2-hour horizon: 'a repeat within 2 hours always gets that answer' overstated it. A repeat that reaches the journal within 2 hours gets the recorded outcome (status, code and outcome, not the identical body); a refusal before the journal is read (the alias lock busy past its wait, an unreadable journal) changes nothing and is retried. After the window the id may be treated as a new operation, and that is not always a refusal: an enrollment whose link was removed meanwhile enrolls the machine again, now pinned by a regression test. The constant's comment, the capability text (and its generated reference) and structure/remote-link.md say so. * test(link): pin a repeat after the window through real pruning and a revoke; the replay needs the same parameters Lane review (P3s): the post-window test now revokes the link through the route, lets 256 later operations settle, advances the clock past the prune floor and asserts that a journal write pruned the original entry before the repeat enrolls again. The replay guarantee in the constant's comment, the capability text (and its generated reference) and structure/remote-link.md now says the repeat must use the same parameters; another set answers operation_mismatch. * fix(link): a tombstone_limit refusal says a repeat of its operation id replays it Final review of #8654 (P3): a forced revoke refused at the tombstone limit is recorded failed_clean, so repeating the same operation id returns the same refusal even after the person recovered tombstones. The CLI's guidance now says so and to retry with a new operation id. Its test now uses --force, the only way to meet that limit. * docs(link): the guide's replay sentence names its conditions Final review of #8654 (P3): the Remote Link guide (English and Spanish) said a repeat of the same command returns the recorded outcome without conditions. It now says: with the same flags, within 2 hours of its answer, as the structure doc and capability text do. * test(link): the replay test's comment names the replay window, not a day Final review of #8654 (P3): a comment in tests/server/link-enrollment-operation.test.ts still said the burst settles 'within the same day'. It now says inside the replay window. (The other half of this item, a tombstone_limit test sent for a --purge revoke, is fixed in 825132f, which moved it to --force.) * fix(link): link_operation_in_progress claims only that the link, key and Child were untouched Found while re-reading the merge of #8416: a resumed revoke (one that owns its retirement receipt) can re-own that receipt and then answer 409 link_operation_in_progress when a Child job holds the link. The link, its key and the Child are untouched, but 'Nothing was changed' is too strong for that path. The CLI text for this code now says the attempt did not touch the link, its key or the Child; the other refusals keep 'Nothing was changed'. structure/remote-link.md says so. * fix(link): tombstone_limit guidance holds for a resumed revoke too Lane review (P2): a resumed force revoke can re-own its retirement receipt before removeReserved meets the tombstone limit (#8416), and such an operation can stay open or unknown, so 'Nothing was changed', 'recorded as failed_clean' and 'retry with a new operation id' could all be wrong for it. The CLI now says the attempt did not touch the link, its key or the Child, and to check ocx link operations --operation-id <id> before reusing the id: a failed_clean entry replays this refusal (use a new id), any other state is repeated with the same id. structure/remote-link.md says so. * docs(link): the guide's replay sentence says the repeat must reach the journal Lane review (P3): the guide (English and Spanish) said a repeat within 2 hours returns the recorded outcome; a lock-busy or unreadable-journal refusal can stop it first. It now says a repeat that reaches the journal within 2 hours returns it, and to retry a transient refusal such as link_operation_in_progress, as the capability and structure text do. * fix(link): tombstone_limit guidance repeats the same operation id first Lane review (P2): failed_clean alone does not mean a fresh refusal. A failed_clean operation can still own a retirement receipt; if its resumed force revoke meets the tombstone limit, the entry stays failed_clean, and once capacity is freed the original id resumes and finishes while a new id is refused with link_retirement_owned. The CLI now says to repeat the same operation id first and to use a new id only if that repeat answers the same refusal again. tests/server/link-revoke-operation.test.ts pins the server side (refused at the limit, a new id refused with link_retirement_owned, the same id committed after a slot is freed); structure/remote-link.md says so. * fix(link): tombstone_limit guidance never declares a refusal recorded Lane review (P2): a second tombstone_limit does not prove the refusal was replayed; a resumed revoke meets the live limit again while capacity stays full, and its receipt still belongs to the original id. The CLI now says to free capacity and repeat the same operation id, to try a new id only if the refusal comes back although capacity is free, and to keep the original id if the new one answers link_retirement_owned (a safe refusal). The server test now repeats the resumed revoke with capacity still full (tombstone_limit again) before a new id is refused and the original id commits once a slot is freed. * fix(link): tombstone_limit no longer says the link and its key stay active Final review of #8654 (P2): a resumed forced revoke can meet the tombstone limit after an earlier attempt of the same operation already revoked the key and stopped the tunnel, then failed before the record went and dropped its own tombstone; the repeat re-records one and is refused. 'so the link and its key stay active' was then false. The text keeps only 'this attempt did not touch the link, its key or the Child', which holds on every path, also once #8661 drops the tombstone on every exit before the commit. * fix(link): tombstone_limit guidance names the owner of an unfinished removal instead of claiming it Final review of #8654 (P2): 'if that answers link_retirement_owned, the removal still belongs to this id' can be false. A fresh refusal recorded failed_clean owns no receipt, and another removal of the same link (a journalled operation or a plain revoke) may hold it; repeating this id then replays the same refusal and loops. The text now says an unfinished removal holds the link, and to repeat the operation id that owns it (ocx link operations lists the link's revokes) or finish it with ocx link revoke --force without --operation-id. * fix(link): closed guidance for an interrupted removal on a journalled revoke Final review of #8654 (P3): link_retirement_owned and link_retirement_mode_mismatch (#8416) printed only 'Link revoke did not complete (code X)'; the owning operation and the way out were in the server's message, which the CLI never prints, although the tombstone_limit guidance points the person at link_retirement_owned. They now get closed texts that name where to look (ocx link operations, a plain revoke without --operation-id, the same options, --force) and claim nothing about what an earlier attempt changed. structure/remote-link.md lists them. * docs(link): the replay guarantee names a revoke that resumes its own removal Final review of #8654 (P3): a revoke repeat whose own retirement receipt is outstanding resumes that removal first and answers that attempt (#8416), not the recorded outcome; the PR's own test repeats an entry recorded failed_clean and gets tombstone_limit, then committed. structure/remote-link.md, the capability text (and its generated reference), the constant's comment and the guide (English and Spanish) now say so. * docs(link): keep the guide's outcome list next to 'recorded outcome' Final review of #8654 (P3): '(retry a transient refusal such as link_operation_in_progress) (committed, failed_clean, residual or unknown)' read as if the second parenthesis listed transient refusals. In the English and Spanish guide the outcome list now follows 'recorded outcome' and the retry advice is its own clause. * test(link): point the tombstone_limit comment at journalledRevokeError Final review of #8654 (P3): the comment in tests/server/link-recover.test.ts said the CLI prints 'nothing was changed' for tombstone_limit through REVOKE_REFUSALS; at the head it comes from journalledRevokeError and says only that the attempt did not touch the link, its key or the Child. * docs(link): the journal's size bound includes entries a retirement receipt pins Final review of #8654 (P3): entries pinned by an outstanding retirement receipt (#8416, ownsRetirement) are kept past retention and the settled cap, at most two per receipt, and receipts have no cap of their own. The comment on OPERATION_JOURNAL_MAX_RECENT_SETTLED and structure/remote-link.md now include them in the stated file size. * fix(link): link_retirement_owned offers only the retries that can finish a journal-owned removal Lane review (P2): when a journalled operation owns the receipt, foreignRetirement refuses a revoke without --force that is not its id, whether or not the Child cleanup can run, so 'revoke without --operation-id (add --force if its cleanup cannot run again)' offered a retry that cannot finish. The text now says: repeat the owning operation id (ocx link operations lists the link's revokes) or ocx link revoke --link-id <link id> --force --yes without --operation-id; a revoke without --operation-id and without --force finishes it only when no journalled operation owns it and its cleanup can run again. The tombstone_limit hint names --force --yes too. * fix(link): operation_journal_unreadable makes no state claim on a journalled revoke Final review of #8654 (P2): a repeat of a journalled revoke whose own retirement receipt is outstanding resumes the removal first (#8416); if that finishes and the replay's journal read then fails, the answer is operation_journal_unreadable while the link is already gone, and 'Nothing was changed; ... retry' sent the caller into link_not_found with exit 4. The text now makes no state claim, names the way out (keep a copy, move it aside, repeat with the same id) and says that a link_not_found then means the link is already gone. The 'changes nothing' lists in structure/remote-link.md and the constant's comment no longer include an unreadable journal or a 5xx. * docs(link): the structure doc describes the tombstone_limit advice the CLI now gives Final review of #8654 (P3): structure/remote-link.md still said the tombstone_limit text tells the caller to keep the original id when a new one answers link_retirement_owned, the advice 08ce109 removed because it could loop. It now describes the current text: an unfinished removal holds the link; repeat the revoke that owns it, or finish with ocx link revoke --link-id <link id> --force --yes without an operation id. * fix(link): name the owner of an unfinished removal by what the CLI can show Final review of #8654 (P3): 'repeat the operation id that owns it (ocx link operations lists this link's revokes)' pointed at a list that shows no link id and marks no owner; the owner id is only in the server's message, which the CLI drops. The tombstone_limit and link_retirement_owned texts now say: repeat the open or unknown revoke of this link (ocx link operations --json shows each entry's linkId), or finish with a plain forced revoke. A closed owner field is a later change. * fix(link): generic revoke refusals name a next step, and an unknown outcome repeats before resolving Final review of #8654 (P3): link_changed and operation_journal_failed printed a bare 'Link revoke did not complete (code ...)'. They now add a next step that holds on every path that answers them: repeat the revoke with the same operation id (for operation_journal_failed, a new id if the same code comes back; for link_changed, after reading ocx link status). For an unknown outcome the CLI said 'check the Child, then resolve', skipping the repeat that finishes a removal this id still owns (#8416); it now says to repeat with the same id first and only then check the Child and resolve. * fix(link): the mode-mismatch text makes no state claim and offers no retry that answers operation_mismatch Final review of #8654 (P3): 'interrupted after its cleanup ran' claimed a state that is false for a force-mode receipt, and 'or with --force' with the same operation id answers operation_mismatch. With --operation-id the code is unreachable at this head (foreignRetirement admits only this operation's own receipt, resumed in its own mode), but the closed text now says only that the removal was interrupted in another mode and offers the revoke that started it with its options, or ocx link revoke --link-id <link id> --force --yes without --operation-id. * fix(link): the tombstone_limit message and the guide no longer say the link and key stay active Final review of #8654 (P3): the clause the CLI dropped in 74bf9a2 survived in the server's tombstone_limit message and in the recover paragraph of both guides. A repeat of an interrupted forced revoke can meet the limit after its earlier attempt already revoked the key and stopped the tunnel. The server message now says only that this attempt was refused before its own effects and names ocx link recover --link-id/--list; the guide (English and Spanish) says a fresh refusal changes nothing and to check ocx link status after a repeated one. * docs(link): resumes rather than finishes, a qualified pin bound, a valid recover command and --link-id in the hint Final review of #8654 (P3 nits): a revoke whose own removal was interrupted resumes it first (the resume can fail), in the guides, the capability text and its generated reference, structure/remote-link.md, the constant's comment and the CLI; the receipt pin is at most two entries per readable receipt and every revoke entry of a link whose receipt cannot be read; the tombstone_limit text names ocx link recover --link-id <id> (bare ocx link recover is a usage error) and the full repeat command with the link id the CLI knows; the describe title of the CLI tests now covers every refusal it holds. * docs(link): the truth table every journalled-revoke refusal text follows Final review of #8654 asked to change the method: structure/remote-link.md now holds the table, per code a journalled revoke can answer, of where it arises, what may already have changed on a first and on a resumed attempt (#8416, #8661), and what the CLI prints. A text claims a state only when it holds in every row for its code; journalledRevokeError's comments point here. * fix(link): the owner of a removal can be in any state, and operation_journal_failed keeps the same id Lane review (P2, P2, P3): a failed_clean revoke can own a retirement receipt too, so the tombstone_limit and link_retirement_owned texts now say to repeat the revoke of the link that owns it, whatever its recorded state (another revoke's id answers its own outcome or the same refusal). A resumed owner can meet the same live journal-write failure again and keep its receipt, so operation_journal_failed now says to fix the journal's disk and repeat the same id, and that a new id, if tried and answered with link_retirement_owned, means this id may still own the removal. The table's tombstone_write_failed row now says the write's outcome is uncertain: recordTombstone can throw after its atomic write, before this revoke counts the tombstone as its own. The table in structure/remote-link.md follows all three. * fix(link): link_changed says what a second answer means instead of claiming the link changed during this revoke * fix(link): an unknown revoke resumes a removal on repeat only if its id still owns one * fix(link): revoke and recover commands in the guidance carry the link id so they run as printed * docs(link): the truth table says what operation_journal_failed and a resumed tombstone_limit can leave behind * fix(link): an add refusal says only that the apply changed nothing, since confirm-host already pinned the host key * fix(link): the tombstone_limit message and the guide name only what the refused attempt left alone * fix(link): an unknown revoke resolves only once its entry reads unknown or residual; an open one is repeated * docs(link): the truth table tells a replayed link_changed from a resumed one and names what a first-intent failure leaves
Summary
Lane O5 of the disposable-machines design: a Home can now prove that an ephemeral (
ocx-child) Child it force-revoked, or that an interrupted enrollment left behind, has been cleaned, and only that link's leftovers are ever restored.Problem.
ocx link revoke --force --yesis the only revoke for a machine that does not answer, and it skips the remote cleanup. Afterwards the Home keeps nothing about that link, and the Child'sCODEX_HOMEownership record (ocx.child.codex-home-owner/1) does not say which link it belongs to. When the machine comes back, nothing can tell whether its leftover state belongs to the revoked link or to a newer enrollment of the same machine, so a cleanup could restore the wrong attachment.Change.
ocx-child, owner record
/2.attachnow writeslinkIdinto.ocx-child-owner.json(schemaocx.child.codex-home-owner/2, phaseattaching) while it holds the local lifecycle lock and theCODEX_HOMElock, before anyCODEX_HOMEwrite (CodexHomeGuard::acquire_for_attach). A refused attach puts back the exact record it replaced./1records are still read; a/2record without a validlinkId, or a/1record that has one, is unreadable.ocx-child,
detach --expect-link <id>. After it takes both locks, detach restores only whenstate.jsonand the owner record both name<id>, or when nothing is left at all (NotAttached). It keeps both locks from that check through the restore, and its JSON report then carrieslinkId. Two refusals change and purge nothing:/1record; an owner record withoutstate.json(an interrupted detach);state.jsonwithout an owner record; noCODEX_HOMEwhile records remain; or an interrupted attach that replaced another link's attachment. The last case is detected when the state, the owner record and the link an unresolved attach rollback would put back do not all agree, and the owner record is still in theattachingphase or a rollback snapshot remains. Without that check, recovery could restore the previous link and then detach it.OPENCODEX_HOME.ocx-child, rollback check. The rollback snapshot is parsed and home-checked the same way recovery parses it, before anything changes. A malformed snapshot is therefore a conflict, and the owner phase stays as it was.
ocx-child, purge under the lock.
--purgenow removes the planted binary before the lifecycle lock is released, for plaindetach --purgeas well. An attach waiting on that lock therefore cannot start before the binary is gone.ocx-child, shared planted binary. The managed binary is one per OS user and is shared by every
ocx-childhome. Every relay that serves from it holds.ocx-child-in-use.lock, which sits beside the binary, as a shared lock for the relay's lifetime. A purge takes that lock exclusively without waiting. If a relay of any home is still running, the purge keeps the binary (purged:false).serverefuses to start while a purge holds the lock. This applies to every--purge. The lock file is never unlinked, so a relay can never lock a fresh file of the same name. As a result the plant directory keeps an empty lock file. The enrollment rollback purge also leaves a binary that the Child kept.Home, tombstone.
DELETE /api/link/:id {force:true}on a Home-initiated link withchildKind: "ephemeral"first writes<configDir>/link/tombstones.json(mode0600, strict schema, under the config mutation lock). The tombstone holds the link id, alias, pinned host-key fingerprint, platform, route list andrevokedAt, and no key. If the write fails, including when the file is damaged, the revoke is refused with503 tombstone_write_failedand the link is kept.Home,
POST /api/link/recover {linkId}andocx link recover --link-id <id>. The route:409 link_present);409 host_key_changed, before any SSH);disconnect --purge --json --expect-link <id>over that alias only, serialized per alias with enrollment;restored:true, together with eitherpurged:trueorpurged:falseplus the in-use marker (ocx-purge-kept:binary_in_use: the link was restored and only the shared binary stayed for another home's relay).Residual and conflict answers become
409 child_residualor409 child_conflict, with the record name as the hint. A planted binary older than the flag (exit 2) answers409 child_recover_unsupported. Every other failure answers502 remote_recover_failedwith a fixed hint (ssh_failed,child_failed,platform_unknown,managed_child_missing,receipt_unboundorpurge_incomplete). The Child's stderr, free text and file paths are never echoed.An answer can be lost after the purge already ran, or the tombstone removal can fail afterwards. In both cases the next recover finds no managed binary. For that case,
detach --expect-linkwrites a link-bound restore receipt to$OPENCODEX_HOME/link-receipts/<id>.json(ocx.child.detach-receipt/1, mode0600, no credential) once, before the purge. The receipt outlives the removedchilddirectory. An attach of the same link deletes it under the lifecycle lock before changing anything, so an old receipt never vouches for a newer attachment. When the binary is missing, recover reads that receipt read-only (remoteRecoverReceiptArgv, POSIX and Windows; the link id travels as data, a positionalshargument on POSIX and the$d.argsdata line on Windows, as does--expect-linkin the managed purge script, never spliced into script source). It settles only on a receipt that names the link withrestoredtrue, and only while the planted binary is confirmed absent. The read exits non-zero if a file of that name exists, executable or not, or if any directory from$HOMEdown to it cannot be searched. On Windows, onlyItemNotFoundExceptionfromGet-Itemcounts as absent. The missing binary is the purge's own evidence. The mere absence of files proves nothing.{operationId}/--operation-id. This resolves throughsrc/link/operation-recovery-slot.ts, a core-owned slot that the O1 enrollment journal registers into. Until O1 registers, the answer is409 operation_journal_unavailable.Limits and the operator's way out. At most 256 tombstones wait; a forced revoke beyond that answers
409 tombstone_limitand keeps the link, so a tombstone is never dropped to make room.ocx link recover --list(GET /api/link/recover) lists link id, alias, revokedAt and platform, never the fingerprint or route.ocx link recover --forget --link-id <id> --yesdrops a tombstone without contacting the machine, for one that is gone for good. It has no management API: the CLI removes the tombstone on the Home under the config mutation lock and refuses while the link still exists, without--yes, and whenever it detects an agent or CI runner (src/cli/agent-driven.ts). Future tombstone fields go underext(a JSON object of at most 4 KiB that this Home keeps verbatim and never reads), so a newer Home's tombstone never makes an older one refuse forced revokes; a change older Homes must not ignore bumps the store version.Revokes settle tombstones. A forced revoke whose key revoke or record removal fails removes the tombstone it wrote, identified by a random per-attempt token, and only while the link still exists (the link stays). An ordinary or
--purgerevoke that commits removes any tombstone left for that link.Alias serialization. Recover runs under O1's cross-process alias lock (
underAliasLock,src/link/alias-lock.ts) and the per-alias operation set within one runtime, both keyed without case as OpenSSH and apply's duplicate check read the alias, so it never overlaps an enrollment or revoke of the same machine. Apply and revoke take that lock not only with an operation id or a journal (O1's rule) but also whenever a tombstone names the alias; a Home with no tombstone sees no new lock.A purge that keeps the binary says why. When another home's relay runs from the planted binary,
ocx-childprintsocx-purge-kept:binary_in_use, and the Home answers hintbinary_in_usefor--purgerevoke only; recover treats that marker, with the link restored, as settled. A relay whose managed binary was purged just before it took the shared in-use lock now refuses to serve.An unreadable prior state is a conflict. An attach rollback snapshot that holds earlier files without a readable prior state is refused, so recover never restores files no link can be named for.
The forced-revoke recovery hint for an ephemeral link now names
ocx link recover. The capability is registered, the skill surface is regenerated, andstructure/remote-link.md, the Remote Link guide and the CLI lifecycle reference are updated.Capability contract.
ocx capabilities --contracts --jsonnow listslink.recover/1beside O1'slink.route/1andlink.operation/1, so GOAT can tell that a Home supports recovery.Merged with O1.
origin/devwith O1 (#8623) is merged in a normal merge commit. The forced-revoke tombstone is written before O1'sjournal.intent("key_revoked"), both/api/link/operationsand/api/link/recoverare routed, and usage, docs and the regenerated skill surface carry both lanes' commands. Registering O1's journal intooperation-recovery-slotis a follow-up pull request.Contracts with the other lanes.
{lookup(operationId) → {kind:"target", target:{linkId, alias, hostKeyFingerprint, remotePlatform?}} | {kind:"not_found"} | {kind:"not_residual"}, settle(operationId)}.settleis called after the Child's bound receipt.explicitRouteandexclusiveflag, under the same rule as the record: an explicit route requiresexclusive. Recover passes that route's ProxyCommand, user and port on the ssh command line for the platform probe, the detach and the receipt read. A link without an explicit route uses its alias. In both cases the pinned key is required and no sibling route is tried.Where this differs from the design text. The design names only residual and conflict cases. I added a clean outcome for a Child that holds nothing at all (
NotAttached), so a recover that runs after cleanup already happened can settle the tombstone. A missing managed binary (managed_child_missing) keeps the tombstone; a person resolves that case.Stays inert by default. Existing users see no change until someone runs a forced revoke on an ephemeral link, which writes a tombstone, or runs the new
ocx link recoververb.--purgerevokes behave as before, except that a committed one also removes a tombstone left for that link (a no-op when there is none), and a--purgethat kept the binary for another home's relay now namesbinary_in_useinstead ofpurge_incomplete.childKindlinks write nothing new."$@", which is empty for a revoke.ocx-childrefuses a/2owner record (unknown field linkId) for every lifecycle command, which fails safe but strands the attachment until a current binary is planted; a downgraded Home or an older second Home enrolling the same machine hits this. Documented in the guide andstructure/remote-link.md. The newocx-childkeeps reading/1records.DELETE, probe and apply, is not refused on a Child runtime.Final review round 2 (head 4053ddd).
origin/devis merged again (normal merge, no conflicts). The Spanish pages now mirror the English ones astests/ci-workflows/docs-spanish-localization.test.tsrequires:es/guides/remote-link.mdhas the threeocx link recoverusage lines and a Spanish recover paragraph, andes/reference/cli/lifecycle.mdhas the recover section with the same code block and code spans (30/30 pass). A recover whose Child restored the link but kept the shared binary for another home's relay (purged:falsewithocx-purge-kept:binary_in_use) now settles the tombstone and answers{linkId, outcome:"clean", purged:false}; before, every repeat answeredbinary_in_useand the tombstone never cleared. A revoke-journal write that throws before the key revoke drops the tombstone that attempt wrote. Thetombstone_limitmessage and the guide say that past 256 waiting tombstones a forced revoke keeps the link and its key active, and how a person clears them. The structure page documents that an apply or ordinary revoke in another runtime that started before the alias's first tombstone can overlap recover, at the cost of a failed enrollment or recover;--expect-linkstill prevents a wrong-link restore. The fr, ja, ru, tr and zh guides carry only the first recover usage line; they are intentionally partial (not CI-checked) and follow the English page in a later docs pass. Three new tests failed before this commit and pass now; the focused suites pass 689/689.Verification
Tests that failed first on
origin/dev:native/ocx-child/tests/owner_link.rs(new): 10 of 10 tests failed before the change. Attach wrote/1with nolinkId, anddetachrejected--expect-linkwith a usage error (exit 2). Two more tests were added with the implementation: a refused attach restores the replaced record, and a schema/linkIdmismatch is unreadable.Review round 1 added three Rust tests. All three failed against the round-0
cli.rsand pass now:It also added Home tests for the lost-receipt settle, for records that remain beside a missing binary, and for path-bearing stderr becoming a fixed hint.
tests/server/link-recover.test.ts(new): 18 of 21 tests failed before the wiring. No tombstone was written,POST /api/link/recoverwas unhandled, and the damaged-file refusal was missing. The 3 that passed are the cases where no tombstone should exist.tests/cli/cli-link-recover.test.ts(new): 10 of 15 tests failed because the verb did not exist. The 5 that passed are usage refusals, which an unknown verb also refuses.Commands run at head b599e27 (macOS arm64, Bun 1.4.4, Rust 1.100 stable):
cargo test --lockedinnative/ocx-child: exit 0 (lib 2, conformance 26, lifecycle_guards 11, owner_link 21, relay_and_lifecycle 11).bun testontests/clients/link-ocx-child-e2e.test.tsandtests/clients/link-ocx-child-conformance.test.ts: pass.cargo fmt --check: exit 0.cargo clippy --locked --all-targets -- -D warnings: exit 0.bun test tests/server/link-recover.test.ts tests/cli/cli-link-recover.test.ts tests/cli/cli-link.test.ts tests/cli/cli-link-force.test.ts tests/server/link-enrollment-ephemeral-child.test.ts tests/clients/link-child-plant-foundations.test.ts tests/cli/cli-capabilities.test.ts tests/server/management-route-registry.test.ts tests/ci-workflows/skill-ocx.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts: all pass.bun run typecheck,bun run privacy:scan,bun run structure:check,bun run skill:surface:check: exit 0.bun run test:changed: exit 1. The latest run, after merging dev at c0763b1, selected 1631 files: 38665 passed and 91 failed, almost all on the 5 s timeout.origin/dev(46a3db0) on this machine, for exampleocx-launcher-desktop-handoff(10 fail),client-link-connect(3),update-home-launcher(11),catalog-omit-disabled-native(8) andnative-codex-toggle(8). They come from this machine's environment, not this PR.tests/cli/cli-link.test.ts, which is fixed in this PR.Final-review fixes at head a324e94 (one P2, nine P3s; the tenth is deferred, below). Each new test failed before its fix:
owner_link.rsan_attach_over_an_unreadable_state_never_restores_the_files_it_snapshotted: the old code did not refuse (exit 1 instead of conflict 5).platform.rsa_relay_whose_managed_binary_is_gone_refuses_instead_of_serving_unlocked: failed on the oldhold_managed_plant_in_use.tests/server/link-recover.test.ts"tombstone bound, cleanup and the operator's way out": 6 of 7 failed against the old routes (uncommitted forced revokes, purge revoke settling, the bound, list and forget, alias case); theextcase passes on the parser alone.binary_in_userows inlink-recover.test.tsandlink-enrollment-ephemeral-child.test.ts;--listand--forgetintests/cli/cli-link-recover.test.ts.Review round 8 of the delta (gpt-6.1-terra) found three more: forget could race an uncommitted forced revoke (P1), failure cleanup could remove another process's tombstone (P2), and forget was reachable through the management API (P2). Forget now has no API and refuses while the link exists; cleanup removes only the exact tombstone it wrote while the link exists. Four tests failed before that fix and pass now.
Review round 10 (the merge) found that a legacy apply or revoke in another runtime skipped the alias lock recover holds; they now take it whenever a tombstone names the alias, with a two-runtime test that failed first. Its other point, registering O1's journal into
operation-recovery-slot, is the planned follow-up pull request; until then--operation-idanswersoperation_journal_unavailableas documented.After the merge (head 75b5c2a):
bun teston the link CLI, capability, recover, enrollment and revoke-operation, O1 journal and alias-lock, route registry, skill, layout, file-size and Lab boundary suites: 656 pass, 0 fail;cargo test --locked74 pass, fmt and clippy clean; typecheck, privacy, structure and skill-surface checks exit 0. Review round 9 found that two attempts writing identical tombstones in one millisecond could remove each other's; each attempt now stamps a random token, with a same-millisecond regression test.Commands at a324e94 (rerun for the touched suites at e440e3d: link recover, CLI recover and link, enrollment, route registry, skill and layout suites 132 pass, 0 fail; typecheck, privacy, structure, skill surface exit 0):
cargo test --lockedexit 0 (74 tests: lib 4, conformance 26, lifecycle_guards 11, owner_link 22, relay_and_lifecycle 11);cargo fmt --checkandcargo clippy --locked --all-targets -- -D warningsexit 0;bun teston the link recover, CLI link, enrollment, plant foundations, ssh-argv discovery, route registry, skill, layout, file-size and Lab boundary suites: 218 pass, 0 fail;bun run typecheck,privacy:scan,structure:check,skill:surface:checkexit 0.Deferred: a CI job that runs
cargo test,fmtandclippyfornative/ocx-child. It is a workflow change (path filter,changesoutputs, the aggregate gate and the scope tests that pin them), which needs its own security review, so it goes in a separate pull request instead of putting this one under workflow review.Known limit: another home's attach that has not yet started its relay does not hold the in-use lock, so a purge in that window still removes the binary. Its relay start then fails cleanly.
NOT RUN:
bun run test:changedat a324e94; the fullbun run test(too heavy for a shared machine; left to CI withci:fullif a maintainer wants it); a recover against a real remote VM; Windows execution of the PowerShell variant (only its argv builder is covered).Checklist