Skip to content

fix(j5): j5 pair --person goes through a running server - #717

Merged
Jacksondr5 merged 3 commits into
j5/mainfrom
j5code/643-cli-pairing-through-server
Oct 25, 2026
Merged

Jacksondr5 merged 3 commits into
j5/mainfrom
j5code/643-cli-pairing-through-server

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Problem

j5 pair --person and j5 auth pairing create wrote people, levels and pairing links to the database from their own process. A running server never heard about them, so an open People page didn't update until it was reloaded. Closes #643.

What changed

  • New J5 route, POST /api/j5/people/pair (apps/server/src/j5/sharing/CliPairingHttp.ts, registered in J5AuthenticatedRoutes.ts; schemas CliPairingRequest / CliPairingResponse in packages/contracts/src/j5/people.ts). The body is the commands' flags. The route runs the same pairingLinkForPerson the CLI used, against the server's own services, so the server's change signals fire (ReadChanges "sharing", which the People page follows). Refusals come back with the refusal's tag, so PairingPersonUnknownError still reaches the live-test rig's guest command under the same name.
  • Auth rule. A Bearer session holding access:write and with subject cli-issued-session (the session the CLI issues itself). Anything else is refused: no token gives 401, a session without Manage access gives 403, and a session with Manage access but another subject gives 403 cli_session_required. So a person's device (Owner or not), a peer or a machine participant can't use the route. Upstream already refuses MCP tokens on the HTTP API, and narrowed connections (Viewers, project- or thread-scoped people) are refused by the access gate, since this route isn't on its allow-list. The route only accepts AuthGrantScope scopes, so a2a:* can't be asked for.
  • CLI side (pairingLinkFromCli in cliPairing.ts). It tries the home's server lock (serverOwnership.ts, upstream's one-server-per-home lock).
    • If a server holds the lock, the CLI reads its origin from the runtime file. It issues itself a session the way j5 project does, holding only access:write and living 2 minutes, makes the POST (10 s timeout), and revokes the session afterwards, on failure too.
    • If the server holds the lock but hasn't published an origin, or doesn't answer, the command fails with a clear message and writes nothing.
    • If no server is running, the CLI holds the lock itself and writes directly, as before. No server can start partway through that write.
    • An older server without the route gets a "restart it on this build" message.
  • Second bullet of the issue (lowering or removing from the CLI cuts open connections): the CLI has no command to lower or remove a person. j5 pair --person <existing> with a level refuses and points to the People page. So there is nothing on the CLI to test for it. Open question, deliberately not in scope: j5 auth session revoke is upstream's command and still writes directly. From reading the code, a device revoked that way keeps its open socket on a running server until that socket next re-authenticates. Upstream has the same gap. Routing it through the server would change upstream's command, so that's left for the maintainer to decide.

Live testing

No browser pass, and nothing in the UI changed. I ran an end-to-end check against a real j5 serve on a throwaway --base-dir under /tmp (stopped by the PID I captured; the directory has been removed):

  • pair --person Priya --level collaborator → "Added Priya (Collaborator on the server)", with the server holding the lock, so only the route could have written it.
  • pair --person priya --ttl 10m --label "Priya phone" → link for the existing person, with the given expiry and label.
  • pair --person Nobody → ERROR (#1): PairingPersonUnknownError: … (matches the rig's regex). An owner at project scope → PairingPersonError: Owner is held at server scope only.
  • Bare auth pairing create --json --base-url … → link for an unknown device, JSON intact.
  • auth session list afterwards: no j5 pair cli session left.
  • With the server stopped, auth pairing create --person Sam --level viewer wrote directly.

GPT-6-Astra's round-1 review also ran it live at 89b0a667da. A sharing subscription that was already open advanced without reconnecting. The route refused anonymous callers, insufficient scope, peer sessions, Owner cookies and Bearer tokens, invalid DPoP and machine-only scopes. The CLI session was revoked after success, refusal, connection failure, a malformed response and SIGTERM.

Re-check at the head that merges, 94d308a110, by the lead: a dev server on a throwaway home. pair --person "Sam Tester" --level viewer reached the server, whose log shows /api/j5/people/pair, and the j5 pair cli session was revoked afterwards. With no server, auth pairing create --person "Ana Direct" --level collaborator wrote directly. The round-2 error paths (a server still starting, a stalled body, a lost answer) are covered by tests that run a real server, not live.

Not exercised live: an open People page refreshing in a browser. The unit test checks the server's own ReadChanges "sharing" revision moves, which is what that page follows.

Upstream impact

  • apps/server/src/cli/pair.ts (case 79): the body of mintPairingLink is now one call to pairingLinkFromCli, passing --ttl and --label through. The now-unused imports are gone.
  • apps/server/src/cli/auth.ts (case 79): the auth pairing create handler resolves upstream's config and makes the same call. runWithEnvironmentAuth is back to upstream's signature, because the extra type parameter J5 had added is no longer needed.
  • FORK.md case 79 is rewritten to describe this. The file-table rows already cite 79. No change to what upstream's product does.

Reviews

Round 1: Claude Fable 5.1 and GPT-6-Astra. Neither found a way to gain access through the route. Both checked that only CLI-issued sessions reach it, the session's lifetime and revocation, the scope ceiling, the refusals and the upstream edits. Astra also ran it live. Changed in response:

  • A starting server made auth pairing create fail (Fable, Medium). Desktop's SSH setup runs auth pairing create as soon as GET / answers, which can be before the server publishes its runtime file. With the lock held and no file yet, the CLI now waits the way j5 pair does. It uses upstream's own retry count and delay, which pair.ts now exports as runtimeFileActivation. A runtime file whose pid is dead is skipped, so a crashed owner's file isn't trusted. Tests: a server that publishes during the wait (after a crashed one's file) succeeds; one that never publishes still fails clearly after three waits.
  • The timeout didn't cover the body (Astra P2, Fable Low). It now covers the whole request and the body read. Test: a server that sends headers and then stalls partway through the body ends in an error, and its session is revoked.
  • A lost answer said nothing was written (Astra P2). Only a failure to connect (connection refused, unreachable, DNS, connect timeout) still says nothing was written. Any failure after the request was sent now says the change could not be confirmed, and to check the People page or j5 auth pairing list before retrying. Test: a proxy drops the connection after the server answered 200. The person is on the server, and the CLI says it cannot tell.

Known behavior, not changed: if a server starts while the CLI is writing directly, the server exits with code 78, because the CLI holds the home's lock. Upstream's j5 project offline path takes the same lock and behaves the same way.

Still open, for the maintainer: j5 auth session revoke is upstream's command and still writes directly (see What changed). The issue's second bullet has nothing to test, because the CLI can't lower or remove a person.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior: CliPairingHttp.test.ts covers the live path (the server's change signal moves, the session is revoked), tag-preserving refusals, the auth rule (401 / 403 scope / 403 subject / 400 for a machine scope), a server that holds the home but doesn't answer (nothing written, no session left), waiting for a starting server, a stalled body, a lost answer, and the direct path with no server. Existing cliPairing.test.ts, cli/pair.test.ts and runtimeLayer.test.ts pass.
  • UI changes: none
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR
  • Upstream product: not applicable, no change to what upstream's product does
  • Surfaces: entry points (both CLI commands that make links; the app already went through the server), contracts (new schemas), connection modes (the CLI calls the origin in the runtime file, on the same host). Clients and providers are unaffected.
  • Docs: the user docs and the product definition stay accurate. FORK.md case 79 is rewritten.

Built by Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Oct 25, 2026 4:48am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 8 billable files and costs up to $2.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 17 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 5 included reviews currently available. Your 17 included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4b57edf and d347a2c.

Files selected for processing: 8
  • FORK.md
  • apps/server/src/cli/auth.ts
  • apps/server/src/cli/pair.ts
  • apps/server/src/j5/a2a/J5AuthenticatedRoutes.ts
  • apps/server/src/j5/sharing/CliPairingHttp.test.ts
  • apps/server/src/j5/sharing/CliPairingHttp.ts
  • apps/server/src/j5/sharing/cliPairing.ts
  • packages/contracts/src/j5/people.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

`j5 pair --person` and `j5 auth pairing create` wrote people, levels and
links to the database from their own process, so a running server never
heard of them and an open People page stayed stale until it was reloaded.

While a server holds the home's lock, the CLI now asks it to make the
link on a new J5 route, POST /api/j5/people/pair, using a two-minute
session it issues with only access:write and revokes afterwards. The
route answers only that CLI session subject and runs the same
pairingLinkForPerson the CLI used, so the server's own change signals
fire. A server that holds the lock but does not answer gets nothing
written behind it. With no server, the CLI holds the lock and writes
directly, as before.

Closes #643

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jacksondr5
Jacksondr5 force-pushed the j5code/643-cli-pairing-through-server branch from 53a6112 to 89b0a66 Compare October 25, 2026 04:09
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 effective changed lines (test files excluded in mixed PRs). labels Oct 25, 2026
…is lost

Round 1 review fixes for #717. With the home's lock held and no runtime
file yet, the CLI now waits as `j5 pair` does (upstream's bounded
activation delay, exported from cli/pair.ts) and skips a dead owner's
file. The timeout covers the response body too. A failure after the
request reached the server is reported as unconfirmed, pointing at the
People page and `j5 auth pairing list`, rather than as nothing written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size:XL 500-999 effective changed lines (test files excluded in mixed PRs). and removed size:L 100-499 effective changed lines (test files excluded in mixed PRs). labels Oct 25, 2026
@Jacksondr5
Jacksondr5 merged commit c7df761 into j5/main Oct 25, 2026
31 checks passed
@Jacksondr5
Jacksondr5 deleted the j5code/643-cli-pairing-through-server branch October 25, 2026 05:03

This branch was successfully deployed

1 active deployment
Preview — d347a2cb Deployed Oct 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A people or level change made from the CLI reaches a running server at once

1 participant