Skip to content

feat(mobile): add the Linger Mobile App and its computer side - #685

Open
jeffrey-bin wants to merge 5 commits into
mainfrom
feat/mobile-app
Open

jeffrey-bin wants to merge 5 commits into
mainfrom
feat/mobile-app

Conversation

@jeffrey-bin

Copy link
Copy Markdown
Contributor

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.

  • Phone app: Messages-first menu with the Another Me card, chats and group faces matching the desktop, an offline outbox, run status and Stop, answering phone-safe decision cards, a read-only Agent sheet, the Library (meetings, documents, Wiki), meeting recording, Live voice with every Agent, push notifications, and a local log with Save or Send Diagnostics.
  • TeamHub: the Mobile Gateway (Noise XK sessions, LAN listener, Relay links with spare data sockets), Paired Phones with approval by confirmation code, the stored Relay node list (/v0/mobile/relays), push delivery through the Push Service, and the Mobile API allowlist.
  • Relay (apps/relay): host control links, splices, spare data sockets, and the Push Service.
  • Voice Runtime: the Voice Bridge that publishes the phone's audio to LiveKit.
  • Web: Settings > Phones to pair, approve and remove phones and to manage Relay nodes.
  • Docs and acceptance: docs/mobile.md specifies the protocol. .agents/skills/verify-linger/features/mobile.md adds the app's acceptance recipes.

An adversarial review hardened both sides, for example:

  • the phone deletes data only on a refusal inside the handshake;
  • recordings are deleted only after delivery;
  • dialed Relay addresses are checked;
  • a phone may answer only four decision kinds and may add only public Relay nodes;
  • push grants go only to the trusted Push Service;
  • Relay links stay off on the public development seed.

How it was verified

  • Focused tests: mobile (113 tests, typecheck, lint), relay and push, Voice Bridge, and the TeamHub mobile, phone and decision integration tests on a real PostgreSQL.
  • make check BASE=origin/main. One unrelated failure remains locally: scripts/ci/desktop-release.test.ts under macOS's bash 3.2. This branch does not touch that script.
  • Contracts regenerated.
  • A fresh iOS Simulator ran every Simulator-capable recipe in features/mobile.md against 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.
  • TestFlight build 10 and an Android APK were built from this branch. Both Relay nodes run this branch's Relay.

Boundary

  • Docs: docs/mobile.md, apps/teamhub/AGENTS.md, apps/voice-runtime/AGENTS.md, the OpenAPI contracts and .env.example are updated.
  • Message to provider_ready path: Web and Desktop requests add no network round trip and no file walk. A phone's request reaches TeamHub's handler in process through the Gateway. The phone's own hop over LAN or a Relay is the transport.
  • Migrations: 00894 to 00896 add the mobile tables and a voice_sessions.client column with a default. A trigger enqueues push jobs only for phones that hold a grant.
  • Compatibility:
    • New configuration: TEAMHUB_MOBILE_RELAY_URL (an extra node; empty turns Relay links off) and TEAMHUB_MOBILE_PUSH_SERVICE_URL. Both have code defaults.
    • Older phones that read only relay keep working, and an explicitly empty relays means every node is off.
    • No existing request shape changes.

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).

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: the pipeWire test double races with the gateway, so this test file is flaky. serve writes the encrypted refusal welcome and then calls w.Close right away (session.go, refuse(closeRefused, code)). pipeWire.Read uses select on both p.in and p.closed. When both are ready, Go picks one at random, so the phone side sometimes gets io.EOF even 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 ran go test -count=3 -run TestPairingIsRateLimited ./internal/mobilegateway/ on this head and got session_test.go:448: EOF in one of three runs. A plain -race run of the package also failed once. make -C apps/teamhub test runs this package, so check (teamhub) will fail now and then. Fix: in Read, first try p.in with a non-blocking select, and only then wait on in, closed and ctx.

P3

  • apps/teamhub/internal/pairedphone/pairedphone.go:103: every CreatePendingPairedPhone error becomes ErrBadPairRequest. That includes a lost connection, a constraint error or a NUL byte in name. The phone shows BAD_HELLO and nothing is logged. The comment says this branch is a retry that must resume, but a real retry fails first at ConsumeMobilePairingInvite, because the invite was already spent, and gets INVITE_INVALID. The app handles that case in apps/mobile/src/computer/pairing.ts:122. Map only the unique violation on public_key (pgconn code 23505) to ErrBadPairRequest, and wrap and return the rest, so phoneErrorCode logs them as UNAVAILABLE.
  • apps/teamhub/internal/mobilepush/mobilepush.go:29: the comment says "the trigger in migration 00887 names it", but the trigger is in 00894_paired_phones.sql.

Verified as fine

  • Allowlist runs before dispatch. dispatchRequest matches the decoded target.Path against mobileRoutes before building the request, and rebuilds it from target.RequestURI() (mobilegateway/dispatch.go). Gin routes on the same decoded URL.Path, so %2F or .. 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.go checks 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, Host and the forwarding headers are stripped (dispatch.go). optionalPrincipal takes the digest from the context set by WithPhoneSession before it looks at cookies (app/app.go:1194). PhoneSession returns false for an empty digest (gateway.go:292), so a pending phone gets no principal. Pending sessions also reset every request and socket frame with PAIRING_PENDING (session.go handle). The device session's token_hash is random and no raw token exists for it (pairedphone.createSession), so no cookie can present it. /v0/session/renew is 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, and TestAHandshakeForAnotherComputerFails covers a wrong-key handshake.
  • Approve/remove races with a live handshake. After track, serve calls Resume again, so a removal or approval that lands between admission and tracking still takes effect (session.go). Approve requires approved_at IS NULL AND removed_at IS NULL and the pending lifetime (queries/paired_phone.sql). Remove revokes the device session in the same transaction.
  • Password change. It does not unpair phones; Resume rotates the revoked session. This is a deliberate choice and is documented in docs/mobile.md:45.
  • Decision kinds. The phone-only restriction is enforced on the server inside the authorization step (typedcard/decisions.go, OnlyKinds) and returns DECIDE_ON_COMPUTER. It does not depend on what the client shows.
  • Push grants. A push grant is accepted only when service_url equals the configured Push Service (handlers_mobile_phones.go). callingPhone returns 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.go relayDialer). 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 each start and 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.example or scripts/env-inventory.json, and apps/relay/**/*.go was added to the inventory scan. TeamHub reads the env only in internal/config. user.env drops empty values (local-installation/src/user-environment.ts, readUserEnvironment), so the template's empty TEAMHUB_MOBILE_RELAY_URL= does not turn Relay links off for Desktop users.
  • Migrations. The new migrations are forward-only. voice_sessions.client has a default, so existing rows and old callers keep working. 00894 to 00896 do not collide with main, whose latest migration is 00893.
  • 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. main requires 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-mobile or check-voice-runtime. scripts/check-plan.mjs gives them no ci key, 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 ./... in apps/relay: pass.
    • go test -race -count=1 on internal/mobilerelay and internal/mobilepush: pass.
    • internal/mobilegateway: TestPairingIsRateLimited failed intermittently with and without -race (the P2 above), and passed in a 3× -race rerun.

Automated review by Claude Code


Automated review of 8bc9865 by Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant