Skip to content

feat(link): add, remove and reorder a Remote Link's routes with ocx link routes - #8603

Merged
lidge-jun merged 55 commits into
devfrom
feat/link-routes-manage
Nov 12, 2026
Merged

lidge-jun merged 55 commits into
devfrom
feat/link-routes-manage

Conversation

@lidge-jun

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

Copy link
Copy Markdown
Owner

Summary

Follows the multi-route Remote Link PR #8602, merged to dev as 44c3d7c95; this branch records that squash as an ancestor through a merge that changes no file. #8602 lets a Home-initiated link carry an ordered route list, direct routes first and the relay alias last, but nothing in the product could write the list. This PR adds the management API and the ocx link routes commands, and closes two host-key gaps in enrollment that the route checks exposed.

API. GET /api/link/{id}/routes and POST /api/link/{id}/routes (src/server/management/link-route-edit.ts) need the admin token on loopback or a dashboard session, the same as reconnect. Every success answers {linkId, pin, routes}.

  • {op: "add", route, position?} inserts a route just before the alias unless a position is given.
  • {op: "remove", route} removes a route. The alias is the pin and cannot be removed (route_is_pin).
  • {op: "order", routes} must name exactly the current routes (route_order_mismatch).
  • At most 8 routes (route_limit). An edit back to [alias] stores the old one-route record byte for byte.

A route is stored only after it proves the pinned key. Before an add, checkRouteTrust (src/link/route-trust.ts) requires the private link known_hosts file to hold only plain one-alias lines or well-formed hashed lines. Every line that matches the alias, as OpenSSH matches it, must carry the same key type and key, and that key must have the record's hostKeyFingerprint; otherwise pin_mismatch or trust_file_unexpected. The first such line is copied to a private temporary file, and the route probe runs against it with StrictHostKeyChecking=yes.

Hashed lines from older releases. Releases before 2.89 probed without HashKnownHosts=no, so on a Home whose ssh_config hashes known_hosts (the Debian and Ubuntu default) the link known_hosts file holds |1|salt|hash lines. A plain line matches the alias without case. A hashed line matches when it is HMAC-SHA1 of the lowercased alias: real OpenSSH 9.6p1 lowercases HostKeyAlias before hashing (a line hashed from pin-alias is accepted for HostKeyAlias=PIN-ALIAS, one hashed from PIN-ALIAS is not). Any other well-formed hashed line belongs to another host; a malformed one still fails the file. Those releases also appended a hashed line on every confirmation, and a later release adds a plain one beside it, so several lines for the alias count as one pin when they all carry the same key type and key, which is what OpenSSH accepts; the first is copied to the probe snapshot, and a second, different key for the alias is still refused. A new confirmation replaces every line for the alias.

  • A route that answers with another key, refuses the login or does not answer is refused with 409 route_unproven and a fixed class word in error.cause (hostkey, auth, forward, transient). No route name or ssh text appears in the error.
  • Each edit holds the per-alias operation set and the link's Child-operations reservation that removal takes, from snapshot to reload. Under the config mutation lock, the commit re-reads the store and the trust file. It requires the same identity, route list and pinned line (link_changed, pin_changed) and replaces only that record's routes.
  • If the supervisor reload fails after the write, the answer is 500 routes_stored_reload_failed with the stored document; a Home restart applies it.

CLI. ocx link routes --link-id <id>, ocx link routes add --link-id <id> --route <alias> [--position <n>], remove --link-id <id> --route <alias> and order --link-id <id> --routes a,b,..., each with --json. Route names are checked as SSH aliases before anything is sent, so a name starting with - is a usage error. Responses are validated strictly. Errors show the fixed code and, for an unproven route, a known class word only; exit codes are 4 for an unknown link, or an unknown route on remove (404), 5 for a refusal (409), and 1 when the routes were stored but the running proxy did not apply them (the message names ocx link routes --link-id <id> to read what was stored). The commands are in the capability registry and the generated skills/ocx surface. Like the Child-operation verbs, they are not served by the local control socket, so on a Home without a trusted loopback ingress they exit 1.

Enrollment fixes the route checks exposed.

  • confirm-host refuses to replace the key of an alias that a Home-initiated link already pins, ignoring case (409 link_pin_conflict). The check and the write share one locked section, and putKnownHost now replaces every line OpenSSH would use for the alias, case variants and hashed lines included. Before this, a later confirmation could swap the key that every route of an existing link trusts.
  • Apply stores a new link only if, in the same locked section as the store write, two checks pass. No Home-initiated link may own the alias in any case (link_exists). The trust file must pass the same whole-file check, with the confirmed key on every line for the alias (host_key_changed, or trust_file_unexpected for a wildcard, host-list, marker or malformed line). OpenCodex never writes those shapes, so a one-route apply now refuses a hand-edited file too, with a message that says to remove the line. Hashed lines from older releases pass as above.
  • A failed apply never stores a record that has not passed those checks. Before the checks pass, cleanup revokes only the issued key (500 key_cleanup_failed when it cannot). After a store write that threw, cleanup stores the record again only if the same checks still pass in that same locked section. When even that transaction fails, the answer is 500 link_cleanup_uncertain. ocx link add prints its own fixed guidance for both codes and says when the Child may still be connected.

Docs: the Remote Link guide has a "Several routes" section, which says a link picks its route when it connects and does not move back to an earlier route by itself; structure/remote-link.md describes the endpoints, the checks and every error above.

The branch merges the updated feat/link-routes (with dev at 7e3cefd16). The only manual resolutions: the test-layout fixture keeps both sides' entries, and src/cli/link.ts, the capability list and the link CLI test keep both ocx link routes and dev's ocx link activity clear (22 link commands); the skills/ocx references were regenerated.

Follow-ups from the review of #8602, which belong here because they touch route selection and its docs:

  • A candidate's readiness budget now runs twice: 30 s from spawn for the grant of its remote listener, then 30 s from the grant for discovery, health and the proof (readinessDeadline in src/link/route-rounds.ts). A slow route that spends most of its first 30 s on the ssh handshake keeps the full time for its readiness execs; one candidate takes at most 60 s. No real slow route (for example a relay to a Windows Child) was measured.
  • A one-route link that was flagged at startup as possibly having a live earlier tunnel, and whose spawn failed so nothing cleared the flag, is now watched from its pidfile when it gains routes, or loses the flag when no pidfile remains (src/link/supervisor.ts). Before, it stayed blocked with nothing watching it.
  • The guide and structure/remote-link.md say what status shows for such a block (failed, "stale tunnel may hold the port") and the way out: stop that ssh, or, when its pid now names an unrelated program, check that no ssh for the link runs, delete <config dir>/link/<link id>.pid and restart OpenCodex on the Home. The guide states that a link never returns to an earlier route by itself and what ocx link reconnect does, and no longer says the route kind is not reported.
  • The hub-link admission's report of a route proof is now tested end to end: a test-only StartServerDeps.observeAuthenticatedCatalog seam sees what the served admission reports to the link listener.

Not in this PR: the dashboard maps the five new enrollment error codes (link_pin_conflict, host_key_changed, trust_file_unexpected, key_cleanup_failed, link_cleanup_uncertain) to its generic error; a follow-up adds them with their translations. The API and CLI carry the guidance.

Unchanged by default: a link without routes, the status document, and enrollment on a link known_hosts file that only OpenCodex wrote.

Verification

New tests failed first because the modules and endpoints did not exist on the base: tests/server/link-route-edit.test.ts (26 cases: add, remove and order; proof against the private snapshot; refusals; races during probe and commit; reload failure; the reservation shared with removal; the endpoints absent from the Child relay and the local control socket), tests/clients/link-route-trust.test.ts, tests/cli/cli-link-routes.test.ts and tests/server/link-confirm-pin.test.ts. Each review fix added a case that failed on the previous commit and passes now. These cover: several same-key lines for the alias (two hashed, hashed plus plain, a case variant) and a different key still refused; a late grant that still proves within the new budget, and a stop exactly 30 s after the grant; a one-route orphan flag watched when the link gains routes; the served admission reporting the proof id and nothing without the header; a link that stays on a later route until ocx link reconnect moves it back to the first rested route; hashed lines (a hashed pin proves a route over the hashed snapshot line, another link's hashed line lets apply pass, a hashed second key for the alias is refused, a hash of another spelling is ignored, putKnownHost drops a hashed line for the alias); two case-variant confirmations before apply; a wildcard, host-list or hashed line beside the confirmed key; a refused or thrown apply whose key will not revoke; a failed store write followed by a pin or alias change while cleanup waits; a failed cleanup transaction; the CLI cleanup guidance.

Commands, with exit codes, on 17b068d8f; the head d63921fa2 only merges a95715e5ea (which records the #8602 squash) and has the same tree, and git merge-tree against dev at 44c3d7c95 is clean:

NOT RUN: the full bun run test suite (the build machine allows focused files only; CI covers the rest); the Rust ocx-child tests (no toolchain there); Windows and macOS, which use the same argv builders; the real-OpenSSH fixture in CI (opt-in). No real slow route was timed for the readiness budget.

The design and code were reviewed by an independent reviewer: 5 plan rounds, then 8 code rounds, ending with no open P0–P2. Fresh final reviews: 5d998e9fc found the hashed-line P2, fixed in V2c-3; 6b0f45ffe approved with three P3s (several same-key lines for one alias, the per-test fixture timeouts, the exit codes on the wrong command), all fixed here, together with the four P3s and one nit that the final review of #8602 assigned to this PR. The author's own review rounds (morph/morph-dsv41flash-1017): the round on V2c-3 found the several-lines P2, fixed here (8cb3ab8b6); the round on these V2c-4 commits (6b0f45ffe..17b068d8f) approved them, with two P3s answered without change: the never-granted half of the readiness bound is already pinned by an existing supervisor test, and lifting a one-route orphan flag when its pidfile is gone can only be reached with a hand-removed pidfile and then fails as a forward refusal that rests 60 s.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. The Remote Link guide, structure/remote-link.md and the generated skills/ocx surface are updated.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. Covered: every route proves the one pinned key against a private snapshot, with nothing trusted on first use; known_hosts matching follows OpenSSH (case, patterns, lists, hashes); confirmation cannot replace a pinned key; route names are refused as options and kept out of errors and logs; the endpoints take the reconnect authority and are not on the Child relay or the local control socket.

Implemented by Claude Opus 5.5 (anthropic/claude-opus-5-5) in GOAT through the Codex harness. Received as a git bundle from the VM that built it and pushed by the coordinator.

…a confirmed-termination ssh run

A link record may list several SSH routes to the same machine. The alias stays the pinned host-key name and is required in the list; a one-route link keeps the exact record an older Home reads. Tunnel and exec argv can connect to a route while HostKeyAlias stays the alias, and buildRouteProbeArgv checks a route strictly against the pinned key. SshRunner.run gains an opt-in AbortSignal with one termination path for timeout and abort.
…rrelated readiness proof

A link with several routes is connected by selection rounds: each eligible route is probed against the pinned host key, the -R tunnel starts on the first that answers, OpenSSH must confirm the granted remote listener, and the Child must fetch its own catalog with a fresh proof id that this Home admits under the tunnel generation. Failed routes cool per class at today's per-alias rates; the link reports the most recoverable outcome over all routes. One-route links keep the existing path.
…ssion

A key-admitted catalog request on the hub-link listener reports the proof id it carried; the optional listener set owns the proof registry and checks it against the tunnel generation the supervisor reports.
GET /api/link/status?routes=1 adds routes, route (name, index, since) and routeBlocked to links with several routes; the default document is unchanged. ocx link status asks for it and validates the fields strictly. An unsupported ssh client reads as a failed multi-route link.
…enSSH

ssh -G shows the pinned alias, strict checking and the link known_hosts win over a hostile per-destination config. An opt-in fixture (OCX_OPENSSH_ROUTE_FIXTURE=1) runs a private sshd -i through ProxyCommand: the pinned probe passes, another key is refused without touching known_hosts, a granted -R carries bytes, and a second session or a server without forwarding is refused with OpenSSH's failure line.
…, and take the proof header off the request

A tunnel is owned and watched before its pidfile is written, and a failed write stops it before the next route. An orphan whose identity cannot be read keeps the link blocked and is never signalled; a link whose orphan is gone starts its first round. New probes and tunnels wait while lifecycle work runs, and changed links lose their round before the first stop is awaited. A proof that settles after its candidate exited cannot promote it. The hub-link catalog admission deletes the proof header before dispatch.
…thout a deadline, and recheck proof deadlines

A multi-route link blocked by an earlier tunnel keeps a non-signalling watch and starts its first round once the process is gone or its pid names another process. A probe that settles while lifecycle work runs moves to a deferred phase no deadline applies to. A readiness proof promotes only before both its attempt and candidate deadlines.
…te probe results

An orphan watch belongs to one multi-route record instance and pidfile; removal, replacement or a change to one route retires it before any further signal, and a pidfile is removed only when it is still exactly the watched one. A route probe that settles after its deadline counts as a timeout even before the tick runs.
…te probe answer as a timeout

An orphan watch signals, lifts the block or starts a round only while the pidfile is still exactly the one it watches; a replacement is only watched and keeps the link blocked. A route probe that answers after its deadline is a transient timeout whatever its exit code or stderr says.
…laced

An orphan watch keeps every process its pidfile has named; after a replacement nothing is signalled, and the link stays blocked until all of them are gone.
… management API

GET and POST /api/link/{id}/routes. A new route is stored only after it proved the pinned key over itself, probed against a private snapshot of the one known_hosts line that matches the alias (case-insensitive, whole-file shape checked, fingerprint equal to the record). Edits hold the per-alias set and the link job reservation that removal uses; the commit re-checks identity, route list and pin under the mutation lock and edits the fresh store. confirm-host refuses another key for an alias a Home-initiated link owns (link_pin_conflict), checked atomically with the write, and replaces case variants of the alias.
… routes

The command reads and edits /api/link/{id}/routes on the Home, validates the {linkId, pin, routes} document strictly, and names a refusal by its code and fixed cause. Capability entries and the generated skill surface are updated.
…e alias is the confirmed key, and never stores a link it refused
…ocked checks, and names a hand-edited known_hosts file
@lidge-jun lidge-jun added the enhancement New feature or request label Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

…lp names exit 4 and the reload-failure read-back
# Conflicts:
#	tests/fixtures/test-layout-expected.json
# Conflicts:
#	src/cli/link.ts
#	src/link/status-projection.ts
#	src/server/management/link-routes.ts
#	tests/cli/cli-link-check.test.ts
#	tests/cli/cli-link.test.ts
#	tests/server/local-control-socket.test.ts
# Conflicts:
#	skills/ocx/references/01_management_surface.md
#	skills/ocx/references/01_surface_access-remote.md
#	src/cli/capabilities-access-remote.ts
#	src/cli/link.ts
#	tests/cli/cli-link.test.ts
…so a slow route keeps its full time to prove
Base automatically changed from feat/link-routes to dev November 12, 2026 23:34
…anage

The branch already held #8602's head 01f954d, whose tree equals the squash's, so the tree is unchanged; this commit only records the squash as an ancestor.
@lidge-jun
lidge-jun marked this pull request as ready for review November 12, 2026 23:50
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 12, 2026 23:50
@lidge-jun
lidge-jun merged commit e85a975 into dev Nov 12, 2026
40 checks passed
@lidge-jun
lidge-jun deleted the feat/link-routes-manage branch November 12, 2026 23:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-12T23:53:06.838380Z d63921f 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.

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