Files
alan d6e6a65db1 docs(app): record the C3 composer candidate as committed
Keep the task note honest about the committed branch and the server-owned landing.
2026-10-21 21:27:10 +01:00

6.4 KiB

C3-state — per-chat composer draft, prompt identity, queued flag and Stop

Plain-message composer state for one conversation. Nonvisual item: no UI, widget, shell, transport, server, pubspec or platform change. The existing ChatRepository.prompt/interrupt/nativeChatMessageId are reused unchanged.

What changed

New files only (no existing file edited):

File Lines Responsibility
lib/features/chat/conversation/chat_draft_store.dart 92 injected draft store, shared_preferences implementation, in-memory fixture store
lib/features/chat/conversation/chat_composer_controller.dart 249 one conversation's draft, single in-flight prompt, queued flag, Stop, optimistic/rejection seam
test/features/chat/conversation/chat_composer_fixtures.dart 40 fake gateway recording chat_prompt/chat_interrupt and pushing frames
test/features/chat/conversation/chat_composer_send_test.dart 240 wire identity, guard, retry, queue/frames, Stop, disposal
test/features/chat/conversation/chat_composer_draft_test.dart 180 exact persistence, isolation, load race, storage failures

Draft state

  • draft is the exact field text (untrimmed). Only the wire copy is trimmed, matching the task's "trim wire text only".
  • setDraft updates memory at once and persists in a serialised write chain, so rapid edits cannot land out of order. It adds no UI copy of its own.
  • The key is pipelines.next.chatDraft.v1.<session_id>; blank drafts remove the entry. No legacy web/Android key is read or written. Attachments are not modelled or persisted.
  • loadDraft is explicit (the thread/screen integration calls it). A store read that completes after the operator has typed, or after a new load, is ignored, so a slow store cannot replace newer text. Storage reads that fail mean "no saved draft"; saves return false, keep the in-memory text and expose draftError = "This draft could not be saved on this device.".
  • MemoryChatDraftStore is fixture-only; the production default is SharedPreferencesChatDraftStore.

Send and identity

send() is a no-op for a blank/whitespace-only draft and while a previous send is awaiting its reply (sending guard). It clears the draft and broadcasts, then emits the optimistic seam before the request:

  • wire: {'chat_prompt': {session_id, text: trimmed, operation_id, native_message_id: nativeChatMessageId(operation_id)}}, no files or attachments keys;
  • ChatComposerSend gives the thread operationId, nativeMessageId, optimisticId (nativeChatMessageId, else local-<operationId>), trimmed text and session. No transcript rows are built here.
  • A refused send keeps its operation id; sending the same trimmed intent again reuses that id and native message id (response-loss retry). A different intent mints a new id. Success clears the retry id, so the next message is new.
  • A refusal sets error, restores the exact original draft and persists it only when the composer is still empty. Newer typing wins and is not overwritten; the rejection callback still reports the refused intent. A failed draft write is reported through draftError and does not prevent the prompt being sent.

Default operation ids are native-chat-<microseconds>-<sequence>; tests inject a deterministic factory.

Queued and Stop

  • chat_queued == true on the prompt reply sets queued; an absent/false field clears it.
  • Only a chat_event for this controller's session clears queued, and only for a frame that means the turn moved on. usage and compaction frames are ignored, mirroring queuedAfterFrame in web/src/chat.js. Other sessions' frames are ignored.
  • stop() sends exactly chat_interrupt {'chat_query': {'session_id': <session>}}. A failure stays in error; success/failure changes neither queued nor any running bit. The thread's frame owns settlement; no synthetic settle or notice is invented.

Checks actually run

flutter pub get
dart format lib/features/chat/conversation test/features/chat/conversation
  # formatted 5 files
flutter analyze                         # No issues found! (ran in 1.4s)
flutter test test/features/chat         # 74 passed
flutter test test/features/chat/conversation   # 28 passed

New regressions (17) cover:

  • exact chat_prompt body plus trimmed text, exact native id, cleared draft;
  • whitespace-only/no request and double-send guard;
  • refusal exposes the server words, restores the exact draft, reuses the same operation/native id for the unchanged retry, and mints a new id for a new intent;
  • newer typing survives a refusal while the rejected callback still carries the original intent;
  • reply queued flag, other-session/usage/compaction frames ignored, owned frame clears it, absent reply flag clears a previous one;
  • exact chat_interrupt body, refusal visible and no queued state change;
  • late reply after disposal changes nothing and calls no rejection seam;
  • SharedPreferences exact round-trip and blank-key removal;
  • per-session isolation, explicit load, load-versus-typing race, unreadable store, failed save recovery, ordered rapid edits, failed clear still sends.

Honest limits

  • No UI, keyboard, Enter/Ctrl/Cmd+Enter, slash, attachment picker or model work. Draft typing, send, Stop and queued notices are not wired into chat_thread_controller or a screen yet; the callbacks and loadDraft are the integration seam for that later item. Attachments remain unsupported.
  • Queued clearing copies the web's queuedAfterFrame rule but does not own the running bit; a UI must read the thread controller for Send/Stop choice.
  • No browser capture or fixture proof. Nothing renders in this item; only unit/controller tests with fake gateways and mock SharedPreferences ran. The real-device preference write path was not exercised (no device/ADB).
  • Mobile unverified. Source is pure Dart/Flutter and portable; no Android, iOS or emulator build was run.
  • No production session, provider turn or network fixture was used.
  • Committed, not pushed or deployed. The feature lives on flutter/chat-composer; the landing stage merged main into it and the server owns landing. This lane pushed nothing and changed no service.

Preserved work

git status --short shows only the six new paths (the five above plus this note); no tracked file, pubspec/lock, shell, server, web/, legacy client or platform file changed. Concurrent lanes' and manager commits are untouched.