Repository navigation
feat(mobile): add the Linger Mobile App and its computer side - #685
jeffrey-bin wants to merge 5 commits into
Conversation
The Mobile App (apps/mobile) reaches its own computer over a Noise XK session, on the local network or through Relay nodes that forward only ciphertext (apps/relay). TeamHub gains the Mobile Gateway, Paired Phones, the Relay node list, push delivery through the Push Service, and the Voice Bridge for recording and Live from the phone. Web Settings > Phones pairs and approves phones and manages Relay nodes; docs/mobile.md specifies the protocol. The mobile migrations follow main's (00894 to 00896).
There was a problem hiding this comment.
Approve with nits (1 P2, 2 P3)
Scope: base main, merge base 8b7fe39b, 5 commits, 517 files (+41,346 / −846). Loaded coderbook, ponytail-review and karpathy-guidelines; ran in a separate session. The PR is very large, so most of the time went to the security boundary on the computer side: the TeamHub Mobile Gateway (handshake, allowlist, dispatch, streams), Paired Phones, Relay nodes, push, the Voice Bridge proxy and config/env. The React Native app under apps/mobile (about 22k lines) got only a targeted look at its pairing and refusal handling. The Relay server internals got only -race tests, not a line-by-line read.
Findings
P2
apps/teamhub/internal/mobilegateway/session_test.go:36: thepipeWiretest double races with the gateway, so this test file is flaky.servewrites the encrypted refusal welcome and then callsw.Closeright away (session.go,refuse(closeRefused, code)).pipeWire.Readusesselecton bothp.inandp.closed. When both are ready, Go picks one at random, so the phone side sometimes getsio.EOFeven though the welcome is already buffered. A real WebSocket delivers queued messages before the close frame, so the fake behaves worse than the real wire. I rango test -count=3 -run TestPairingIsRateLimited ./internal/mobilegateway/on this head and gotsession_test.go:448: EOFin one of three runs. A plain-racerun of the package also failed once.make -C apps/teamhub testruns this package, socheck (teamhub)will fail now and then. Fix: inRead, first tryp.inwith a non-blockingselect, and only then wait onin,closedandctx.
P3
apps/teamhub/internal/pairedphone/pairedphone.go:103: everyCreatePendingPairedPhoneerror becomesErrBadPairRequest. That includes a lost connection, a constraint error or a NUL byte inname. The phone showsBAD_HELLOand nothing is logged. The comment says this branch is a retry that must resume, but a real retry fails first atConsumeMobilePairingInvite, because the invite was already spent, and getsINVITE_INVALID. The app handles that case inapps/mobile/src/computer/pairing.ts:122. Map only the unique violation onpublic_key(pgconn code23505) toErrBadPairRequest, and wrap and return the rest, sophoneErrorCodelogs them asUNAVAILABLE.apps/teamhub/internal/mobilepush/mobilepush.go:29: the comment says "the trigger in migration 00887 names it", but the trigger is in00894_paired_phones.sql.
Verified as fine
- Allowlist runs before dispatch.
dispatchRequestmatches the decodedtarget.PathagainstmobileRoutesbefore building the request, and rebuilds it fromtarget.RequestURI()(mobilegateway/dispatch.go). Gin routes on the same decodedURL.Path, so%2For..cannot make the allowlist and the router see different paths. Gin answers unmatched paths with a redirect, not an internal re-dispatch.mobile_allowlist_test.gochecks that every entry is a real public route. Sign-in, password, logout, phone approval and removal, and relay PATCH/DELETE are not on the list. - Identity comes only from the session.
Authorization,Cookie,Origin,Hostand the forwarding headers are stripped (dispatch.go).optionalPrincipaltakes the digest from the context set byWithPhoneSessionbefore it looks at cookies (app/app.go:1194).PhoneSessionreturns false for an empty digest (gateway.go:292), so a pending phone gets no principal. Pending sessions also reset every request and socket frame withPAIRING_PENDING(session.gohandle). The device session'stoken_hashis random and no raw token exists for it (pairedphone.createSession), so no cookie can present it./v0/session/renewis not on the allowlist, so a phone never renews a cookie session. - Handshake. Noise XK uses a prologue bound to the computer's public key, and the first message must have an empty payload (
handshake.go). The phone's identity is the static key proved in message 3. The pair attempts are rate-limited, andTestAHandshakeForAnotherComputerFailscovers a wrong-key handshake. - Approve/remove races with a live handshake. After
track,servecallsResumeagain, so a removal or approval that lands between admission and tracking still takes effect (session.go).Approverequiresapproved_at IS NULL AND removed_at IS NULLand the pending lifetime (queries/paired_phone.sql).Removerevokes the device session in the same transaction. - Password change. It does not unpair phones;
Resumerotates the revoked session. This is a deliberate choice and is documented indocs/mobile.md:45. - Decision kinds. The phone-only restriction is enforced on the server inside the authorization step (
typedcard/decisions.go,OnlyKinds) and returnsDECIDE_ON_COMPUTER. It does not depend on what the client shows. - Push grants. A push grant is accepted only when
service_urlequals the configured Push Service (handlers_mobile_phones.go).callingPhonereturns 403 to browser sessions. The push HTTP client refuses redirects (app.go,CheckRedirect). On 410/401 the worker clears the grant with a compare-and-clear on the same grant value. - Relay links. Relay links are forced off on the public development seed (
config/service_credentials.go), because every checkout on that seed shares one host key. Relay dials reject link-local, multicast and unspecified addresses after DNS (transport.gorelayDialer). The Relay checks host ownership with an X25519+HMAC proof bound to a nonce (apps/relay/internal/relay/proof.go). - Voice Bridge. The proxy requires TeamHub's node-services credential (
bridge-proxy.ts). The Bridge worker trusts only a per-process random token, and checks the LiveKit grant for eachstartand that a resumed session belongs to the same phone (voice-runtime/src/bridge.ts:197-210). - Env and config. The new variables are in
.env.exampleorscripts/env-inventory.json, andapps/relay/**/*.gowas added to the inventory scan. TeamHub reads the env only ininternal/config.user.envdrops empty values (local-installation/src/user-environment.ts,readUserEnvironment), so the template's emptyTEAMHUB_MOBILE_RELAY_URL=does not turn Relay links off for Desktop users. - Migrations. The new migrations are forward-only.
voice_sessions.clienthas a default, so existing rows and old callers keep working.00894to00896do not collide withmain, whose latest migration is00893. - Language. No CJK in added lines outside the locale catalogs, and none in any commit message. The added-line grep hit only on
·(U+00B7), which is not CJK.
Not verified: most of the apps/mobile UI and offline outbox logic; the Relay's splice and rate-limit code beyond its tests; the Push Service sealing in apps/relay/internal/push; and how a phone recovers when a password change revokes its device session mid-session (requests get 401 until it reconnects).
Process notes
- The branch is 9 commits behind
main.mainrequires up-to-date branches, so it needs a rebase before merge. - No merge commits. No fixup or "address review" commits that need squashing.
CI
- All required checks pass on
8bc9865e. - CI does not run
check-relay,check-mobileorcheck-voice-runtime.scripts/check-plan.mjsgives them nocikey, so they only run locally, the same as the existing voice-runtime convention. The Relay is a public internet-facing service with no CI coverage. - I ran locally:
go test -race -count=1 ./...inapps/relay: pass.go test -race -count=1oninternal/mobilerelayandinternal/mobilepush: pass.internal/mobilegateway:TestPairingIsRateLimitedfailed intermittently with and without-race(the P2 above), and passed in a 3×-racererun.
Automated review by Claude Code
Automated review of 8bc9865 by Claude Code.
What and why
Adds the Linger Mobile App (
apps/mobile, React Native + Expo): a phone client for the user's own computer. The phone has no account of its own. It pairs with a computer and then reaches it end to end encrypted, over the local network or through Relay nodes that only forward ciphertext./v0/mobile/relays), push delivery through the Push Service, and the Mobile API allowlist.apps/relay): host control links, splices, spare data sockets, and the Push Service.docs/mobile.mdspecifies the protocol..agents/skills/verify-linger/features/mobile.mdadds the app's acceptance recipes.An adversarial review hardened both sides, for example:
How it was verified
make check BASE=origin/main. One unrelated failure remains locally:scripts/ci/desktop-release.test.tsunder macOS's bash 3.2. This branch does not touch that script.features/mobile.mdagainst a Desktop running this branch: pairing, routes and pinned nodes, Relay node refusals, messaging, offline outbox across a computer restart, Agent sheet, Library, meeting recording, Live entries, diagnostics, and removal. Push, QR scanning, a second computer and attachments need hardware and were not run.Boundary
docs/mobile.md,apps/teamhub/AGENTS.md,apps/voice-runtime/AGENTS.md, the OpenAPI contracts and.env.exampleare updated.00894to00896add the mobile tables and avoice_sessions.clientcolumn with a default. A trigger enqueues push jobs only for phones that hold a grant.TEAMHUB_MOBILE_RELAY_URL(an extra node; empty turns Relay links off) andTEAMHUB_MOBILE_PUSH_SERVICE_URL. Both have code defaults.relaykeep working, and an explicitly emptyrelaysmeans every node is off.