Repository navigation
fix(j5): j5 pair --person goes through a running server - #717
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
This review includes 8 billable files and costs up to $2.00.
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. View limit details
Comment |
`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
force-pushed
the
j5code/643-cli-pairing-through-server
branch
from
October 25, 2026 04:09
53a6112 to
89b0a66
Compare
…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]>
# Conflicts: # FORK.md
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
j5 pair --personandj5 auth pairing createwrote 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
POST /api/j5/people/pair(apps/server/src/j5/sharing/CliPairingHttp.ts, registered inJ5AuthenticatedRoutes.ts; schemasCliPairingRequest/CliPairingResponseinpackages/contracts/src/j5/people.ts). The body is the commands' flags. The route runs the samepairingLinkForPersonthe 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, soPairingPersonUnknownErrorstill reaches the live-test rig'sguestcommand under the same name.access:writeand with subjectcli-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 403cli_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 acceptsAuthGrantScopescopes, soa2a:*can't be asked for.pairingLinkFromCliincliPairing.ts). It tries the home's server lock (serverOwnership.ts, upstream's one-server-per-home lock).j5 projectdoes, holding onlyaccess:writeand living 2 minutes, makes the POST (10 s timeout), and revokes the session afterwards, on failure too.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 revokeis 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 serveon a throwaway--base-dirunder/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.auth pairing create --json --base-url …→ link for an unknown device, JSON intact.auth session listafterwards: noj5 pair clisession left.auth pairing create --person Sam --level viewerwrote 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 viewerreached the server, whose log shows/api/j5/people/pair, and thej5 pair clisession was revoked afterwards. With no server,auth pairing create --person "Ana Direct" --level collaboratorwrote 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 ofmintPairingLinkis now one call topairingLinkFromCli, passing--ttland--labelthrough. The now-unused imports are gone.apps/server/src/cli/auth.ts(case 79): theauth pairing createhandler resolves upstream's config and makes the same call.runWithEnvironmentAuthis back to upstream's signature, because the extra type parameter J5 had added is no longer needed.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:
auth pairing createfail (Fable, Medium). Desktop's SSH setup runsauth pairing createas soon asGET /answers, which can be before the server publishes its runtime file. With the lock held and no file yet, the CLI now waits the wayj5 pairdoes. It uses upstream's own retry count and delay, whichpair.tsnow exports asruntimeFileActivation. 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.j5 auth pairing listbefore 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 projectoffline path takes the same lock and behaves the same way.Still open, for the maintainer:
j5 auth session revokeis 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
CliPairingHttp.test.tscovers 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. ExistingcliPairing.test.ts,cli/pair.test.tsandruntimeLayer.test.tspass.FORK.md(case text and file-table row) in this PRBuilt by Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code