Files
pipelines/app/notes/C2-thread.md
T
alan 76437db018 feat(app): add chat thread controller for live conversations
Owns one open chat session: subscribes with chat_subscribe, reads the newest
history page, folds only this session's chat_event frames, pages older history
with the opaque cursor, and replaces the held turn on resync. Failures keep the
held transcript and surface an error; disposal only cancels the local stream.

Co-authored-by: C2 pipeline <noreply@pipeline.local>
2026-10-21 20:04:38 +01:00

1.9 KiB

C2 — Chat thread controller

lib/features/chat/conversation/chat_thread_controller.dart owns one open conversation without any UI. It is constructed with the shared ApiGateway and one sessionId, reuses ChatRepository for the wire and domain/chat_transcript.dart for the fold, and exposes messages, running, loaded, loading, hasMore, cursor and error through ChangeNotifier.

Behaviour:

  • load() calls chat_subscribe with the exact session body, then reads the newest chat_messages page with limit: 200 and an empty cursor. A refused subscribe leaves history usable.
  • loadOlder() is explicit only, requires hasMore, passes the server's opaque next_cursor back verbatim, and prepends the older page by id.
  • Only chat_event envelopes for this session are folded; replayed/live text, reasoning, tool, step and user frames use the existing domain fold, so unknown message and part fields survive.
  • resync() settles the held turn, re-subscribes, then replaces the transcript, cursor and hasMore with the newest authoritative page. Activity replayed while re-attaching (for example a running step) survives the replacement. A pushed resync event invokes the same path.
  • History failures set error and keep the held transcript; they are never reported as an empty success. Superseded reads and replies after disposal are ignored.
  • Disposal cancels only the local stream subscription. There is no chat_unsubscribe request.

Checks (run from app/):

  • flutter test test/features/chat/conversation — 10 tests passed.
  • flutter test test/features/chat — 43 tests passed.
  • flutter analyze lib/features/chat test/features/chat — no issues.

Not done: the controller is not yet wired to a screen, so there is no rendered or browser change to capture; mobile builds and device verification were not performed. No shared domain, shell, main, pubspec or server files changed.