Skip to content

OPE-155: Isolate v1 and v2 HTTP remotes behind repository ports #605

Closed

Description

@ivanfenenko

Hide v1/v2 HTTP dialect dispatch inside protocol-selected remotes so Screen Models and repository ports stay on product language. No user-facing change.

Parent

OPE-146 — Server API v2 Compatibility

Post-ship follow-up from the dual-stack architecture review. P0–P6 already put protocol behind existing repository interfaces; this ticket only deepens that implementation. Do not block the epic merge on this work.

Why

Repositories currently re-ask isV2() on almost every method (~30 branches per platform; isV2() copied across Session, Message, Command, Agent, Model, Filesystem, Project). Screen Models do not leak protocol — they read ServerCapabilities. The repository port is the right seam; the bodies are a shallow dispatcher.

ServerProtocol is infrastructure (HTTP generation). Product language is sessions, diffs, permissions, and capabilities (e.g. supportsSessionMessageDiff). Keep that split.

Target shape

Keep the external port forever. Add an internal remote seam inside each repository module:

SessionRepository                 ← port (product; Screen Models unchanged)
  DefaultSessionRepository        ← application: error map, model-selection cleanup
    SessionRemote                 ← internal seam (not injected into UI)
      V1SessionRemote             ← legacy HTTP + SessionDomainAdapter
      V2SessionRemote             ← /api/* + same adapter + v2 compensation

A thin facade holds both remotes and does remote = protocol == v2 ? v2 : v1 once per call, not once per method. Same shape for Command, Filesystem, Model, Agent, Project. Lift MessageProtocolRouter into the same remote pair. Event projection stays in EventDomainAdapter (payload sniffing). SSE path pick stays in the event client.

Protocol is still chosen on connect and cached on ActiveConnectionManager. Callers never see it.

What not to do

  • Protocol flags or isV2 in ViewModels / SwiftUI / Compose (capability flags only).
  • Regenerating OpenAPI into UI or forking Screen Models per protocol.
  • Swapping V1SessionRepository / V2SessionRepository in Hilt/Factory on connect. Protocol is unknown at singleton construction, updates in place via updateProtocol, and LiveStores already hold the bound instance.
  • One OpencodeServer god facade for session+message+event+command.
  • Per-method strategy objects (ListSessionsStrategy).
  • Persisting protocol on ConnectionProfile without a separate decision (stale dialect after server upgrade).
  • Treating ServerProtocol as ubiquitous language.

Implementation steps

Do this after feature/ope-146-server-api-v2 is on main (or at least after P6 lands). Both platforms in the same change.

  1. Centralize probe fallback. One ActiveConnectionManager.currentProtocolOrProbe() (cache → else probeServer() → default v1). Delete the seven copied isV2() helpers. Today a failed/missing probe silently means v1; parallel first calls can stampede probes (Android mutex is per repository). This is the real footgun; splitting remotes does not fix it unless probe is shared.
  2. Proof: Session. Extract SessionRemote + V1/V2 from DefaultSessionRepository only. Keep DefaultSessionRepository as the port adapter that also owns delete → model-selection cleanup. Existing SessionProtocolRepositoryTests should survive if they already speak product operations.
  3. Messages. Lift MessageProtocolRouter into the same remote pair (it is already the closest to this shape). Keep v2 prompt extras (agent/model POST then POST .../prompt) inside V2MessageRemote.
  4. Repeat for Command, Filesystem, Model, Agent, Project only when those files are next edited — not a big-bang rewrite.
  5. Keep Screen Models on ServerCapabilities, repositories/remotes on protocol (or remotes selected by protocol).

Hotspots

  • ios/.../Domain/Session/SessionRepository.swift (~20 if await isV2())
  • android/.../domain/session/DefaultSessionRepository.kt (~22 if (isV2()))
  • Same helper in Command, Filesystem, Model, Agent, Project on both platforms
  • MessageProtocolRouter (iOS + Android)
  • SSE: EventsAPIClient.subscribePath / DefaultForegroundEventStream (path pick only; leave there)
  • DI: AppContainer.sessionRepository, Hilt SessionModule — keep one bound implementation; do not protocol-select at construction

Remaining

  • Centralize protocol-or-probe; remove duplicated isV2() helpers on iOS and Android
  • Extract V1SessionRemote / V2SessionRemote behind SessionRepository on both platforms
  • Lift MessageProtocolRouter into v1/v2 message remotes
  • Extract remotes for Command, Filesystem, Model, Agent, Project when those files are next edited

Docs: docs/features/server-api-v2/


Imported from Linear OPE-155. Linear status: Done. Priority: Low. Created 2026-08-13. Completed 2026-08-13.
Parent: OPE-146.

Activity

  1. self-assigned this
    on Oct 11, 2026
  2. added
    ios
    on Oct 11, 2026
  3. added
    android
    shared
    improvement
    priority: low
    ready-for-agent
    on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

androidimprovementiospriority: lowready-for-agentshared

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions