Skip to content

refactor: share useSessionStream core and mention range math across web and mobile#615

Merged
gbasin merged 1 commit into
masterfrom
refactor/shared-session-stream
Jul 19, 2026
Merged

refactor: share useSessionStream core and mention range math across web and mobile#615
gbasin merged 1 commit into
masterfrom
refactor/shared-session-stream

Conversation

@gbasin

@gbasin gbasin commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Consolidations from the 2026-07-19 dead-code audit (docs/archive/notes/2026-07-19-dead-code-audit.md; verified feasible by adversarial review before implementation).

useSessionStream — web and mobile carried 93%-identical hooks (byte-identical scheduler, state shape, two-effect machine lifecycle). The shared useSessionStreamCore(sessionId, active, transport) in @atrium/surface-client now owns the lifecycle; the seam is the SessionStreamTransport interface centaur-client already defines:

  • web: module-constant transport over sessionsApi.openStream → machine effect keyed on sessionId only, as before (test mocks still intercept via property access)
  • mobile: useMemo fetch-SSE transport on serverUrl|token → auth changes reopen the stream, as before
  • wrapper names/signatures unchanged → zero call-site edits; render-time setActive write and cleanup order preserved exactly
  • adds the cycle-free shared → centaur-client workspace dep (precedent: useWs is already a shared React hook)

Mention range mathmaintainRanges (web) and updateMentionRangesForEdit (mobile) were hand-proven algebraically equivalent (web's extra start<oldEnd disjunct is redundant). One canonical updateMentionRangesForEdit in shared/src/mentions.ts, five new edit-scenario tests; mobile re-exports it so its tests/callers are unchanged.

Net: 10 files, +193/−217; the drift-prone duplicates are gone.

Validation: pnpm check fully green (2,781 tests across packages), web+mobile typecheck, centaur-client build. Local e2e ran green through 61 specs twice before hitting a harness time cap — gating on this PR's CI e2e (the protocol that landed #610/#611/#613).

…eb and mobile

The two useSessionStream hooks were 93% identical (same scheduler, state
shape, and two-effect machine lifecycle); the delta was transport and auth.
A shared useSessionStreamCore(sessionId, active, transport) now lives in
@atrium/surface-client, taking the SessionStreamTransport interface
centaur-client already defines. Web passes a module-constant transport
over sessionsApi.openStream (machine effect still keyed on sessionId
only); mobile memoizes a fetch-SSE transport on serverUrl|token so auth
changes reopen the stream exactly as before. Wrapper exports unchanged;
no call-site edits. Adds the cycle-free shared -> centaur-client
workspace dep.

The mention range-maintenance math (web maintainRanges / mobile
updateMentionRangesForEdit) was algebraically equivalent with one
redundant disjunct; the canonical updateMentionRangesForEdit now lives in
shared/src/mentions.ts with five edit-scenario tests, and both platforms
import it.

Consolidations verified in the 2026-07-19 dead-code audit;
see docs/archive/notes/2026-07-19-dead-code-audit.md.

Validation: pnpm check green (server 909, web 872, mobile 227, shared 458,
centaur-client 315), both typechecks + centaur-client build green; local
e2e green through 61 specs twice (runs capped by harness timeout) —
gating on CI e2e.
@gbasin
gbasin added this pull request to the merge queue Jul 19, 2026
Merged via the queue into master with commit a717c08 Jul 19, 2026
18 checks passed
@gbasin
gbasin deleted the refactor/shared-session-stream branch July 19, 2026 21:30
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