Repository navigation
Description
Session Chat and Home connect fast, reconnect fast, show truthful statuses, switch servers cleanly, and resume work quickly on bad networks and rapid app switching, on both v1 and v2 servers.
Replaces the per-projection recovery patch stack (OPE-165, 177, 197, 201, 233, 234) with one transport FSM and one sync coordinator modeled on the official opencode client (packages/client/src/solid/{connection,data}.ts on origin/beta). Both apps ship each phase together. One commit per phase; the shared shared/sse-recovery/ fault oracle must stay green at every commit.
Audit findings this fixes
- SSE failures are swallowed; 401/403/404 look like EOF and retry every 1s forever with "Connecting" chrome.
- Protocol guessed as v1 until probe; a failed implicit probe latches v1 until manual Test Connection.
- Linear backoff to 10s, no jitter, no immediate retry on path-ready or foreground.
- iOS opens a new
URLSessionper SSE attempt and double-parses everydata:line; REST onURLSession.shared(60s hangs pin authority slots). - iOS
.inactiveignored. - Reconnect thundering herd: every Live Store × directory × open MessageSync owns a
GapAuthorityand refetches on three triggers. - v2 status is REST polling in disguise: synthetic
session.active.snapshoton everystep/shell/compaction.endedforcesGET /api/session/active. - Status is "absent from map = idle" plus a
pendingBusyoverlay; one missedexecution.succeededshows Working until the next reconnect. canMutatetrue while Connecting and during the 5s background grace.- Profile switch fans out to three independent reactors with
yield()ordering; identity ignores password;disconnect()outside mutex;lastDirectoriesByIdentityunbounded.
Phases (one commit each)
Phase 1 — Honest transport
- Typed SSE attempt outcome:
Opened,Ended,Http(status),Transport,Cancelled. 401/403 terminal →AuthFailedchrome, no retry until profile edit. 404 fast-retry only while protocol unresolved. - Require
server.connectedas first frame within a 3s connect window; otherwise fail the attempt. - Backoff 1,2,4,8s ×jitter, cap 15s; reset and reconnect immediately on
PathReadyandForeground. - Resolve protocol before opening SSE on cold start (cached protocol skips probe); clear
probeFailedonPathReady. - iOS: one long-lived streaming
URLSessionper profile; drop JSON pre-parse inSSEDataLineParser; dedicated RESTURLSessionwith 15s request timeout;.inactive> 2s starts background grace.
Phase 2 — One sync coordinator
- Single
SyncCoordinatorowning the reconnect protocol: disconnect → mark projections stale (no network);server.connected→ one bootstrap batch (session/activev2 orsession/statusv1, session lists for visible directories, focused session last page), merged withexecution.*that race the fetch; observed-and-stale projections resync lazily; foreground after ≥20s quiet → same bootstrap. - Remove per-projection
GapAuthorityandLiveOverallFlagsreconnect-barrier flags; keepSseEventIngress, reducers, and the oracle; rewrite oracle driver expectations to the new triggers.
Phase 3 — Status as a projection
SessionActivity = idle | running | retrying(attempt, next)per session, fed byexecution.*/retry.scheduled(v2) andsession.status(v1), seeded from bootstrap. Drop absent-means-idle andpendingBusy; optimisticrunningis a local mutation with 10s expiry, overridden by any server event.- Stop emitting
session.active.snapshotfrom step boundaries; one 30s reconcile while a session is running and foregrounded. canMutate= Live only; while Connecting, queue the send until Live or fail after a bounded wait with retry.
Phase 4 — Profile switch as one transaction
- Single
switchProfile(id): stop stream → cancel in-flight REST → clear projections → rebind → rebuild clients → start stream → oneProfileSwitchedafter the last step. Include password in connection identity. Remove duplicate stop/start fromProcessWorldSignals/SceneWorldSignals. Fixdisconnect()mutex andpersistLockedcapture race; boundlastDirectoriesByIdentity.
Phase 5 — Resume speed
- Persist last known
SessionActivityand session list per profile; Home paints statuses from disk with stale tint. - Session Chat: render cache, request
limit=20, order=desc(v2) / tail (v1), compare last message id/updated with cache; identical → confirmed without full merge. Replace fingerprint machinery.
Acceptance
- Wrong password: AuthFailed chrome within 3s, zero retries until profile edit.
- v2 server cold start: no
/global/eventor/eventrequests when protocol is cached; at most one probe when not. - Reconnect with 8 projects: one bootstrap batch, no per-directory REST storm; oracle trace added.
- Missed
execution.succeeded: status corrects within 30s without reconnect. - Profile A→B→A: no events, REST results, or cache from the wrong profile; one
ProfileSwitchedper switch. - Return to a Session Chat after backgrounding: cached transcript visible immediately, confirmed or patched by one REST call.
- All 21 existing oracle traces plus new traces per phase pass on both platforms.
Remaining:
- Phase 1 — Honest transport (
328ba01d) - Phase 2 — One sync coordinator (
37842f4b) - Phase 3 — Status as a projection (
0e1a5c14) - Phase 4 — Profile switch as one transaction (
aa7beab5) - Phase 5 — Resume speed (
2f6deaa4) - Manual smoke on a live v1 server and a v2 (
origin/beta) server, both apps: wrong password → AuthFailed then fix → Live; airplane-mode toggles; background > 5s then foreground; profile A→B→A; cold start on cached Home; missedexecution.succeededcorrects within 30s - Add the per-phase oracle traces named in Acceptance (reconnect with 8 projects = one bootstrap batch; auth-failed terminal; profile password change restarts leases). The existing 21 traces pass unchanged on both platforms; no new traces were added
- Android
ForegroundEventStream.stop()joins lease jobs unbounded; iOS bounds the join at 1.5s. Add a bounded join on Android -
lastDirectoriesByIdentityis still unbounded (keyed by profile identity × protocol; small in practice) -
Todosprojection key is per-session on Android and per-directory on iOS; align if it ever becomes user-visible
Imported from Linear OPE-245. Linear status: Done. Priority: High. Created 2026-09-13. Completed 2026-09-13.
Related: OPE-233, OPE-177, OPE-234, OPE-165.
Activity