Keep the task note honest about the committed branch and the server-owned landing.
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
draftis the exact field text (untrimmed). Only the wire copy is trimmed, matching the task's "trim wire text only".setDraftupdates 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. loadDraftis 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 exposedraftError = "This draft could not be saved on this device.".MemoryChatDraftStoreis fixture-only; the production default isSharedPreferencesChatDraftStore.
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)}}, nofilesorattachmentskeys; ChatComposerSendgives the threadoperationId,nativeMessageId,optimisticId(nativeChatMessageId, elselocal-<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 throughdraftErrorand 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 == trueon the prompt reply setsqueued; an absent/false field clears it.- Only a
chat_eventfor this controller's session clearsqueued, and only for a frame that means the turn moved on.usageandcompactionframes are ignored, mirroringqueuedAfterFrameinweb/src/chat.js. Other sessions' frames are ignored. stop()sends exactlychat_interrupt{'chat_query': {'session_id': <session>}}. A failure stays inerror; success/failure changes neitherqueuednor 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_promptbody 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_interruptbody, 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_controlleror a screen yet; the callbacks andloadDraftare the integration seam for that later item. Attachments remain unsupported. - Queued clearing copies the web's
queuedAfterFramerule 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 mergedmaininto 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.