Show a reopened chat's last transcript while it refreshes

ChatScreen keeps a bounded in-memory cache of recently left transcripts
(16 chats / 4000 messages, LRU). A reopened chat is seeded from it with no
loading state, still re-subscribes and re-reads, and the newest page replaces
the cached copy while live frames received during the read are kept. /close
removes the entry; only transcripts backed by a successful read on the
current connection are written.

Adds tool/chat_reopen_probe.mjs and an optional history delay in the loopback
fixture. Measurement shows a second cost the cache does not remove: opening at
the end of the top-anchored transcript lays out every row (notes).
This commit is contained in:
2026-10-24 18:14:27 +01:00
parent ef575898f2
commit 0a19ef229f
12 changed files with 887 additions and 8 deletions
@@ -5,6 +5,7 @@ import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/conversation/chat_transcript_cache.dart';
import 'chat_composer_bar_fixtures.dart';
@@ -50,7 +51,11 @@ void main() {
closed = 0;
});
Future<void> pump(WidgetTester tester, {String directory = '/w'}) async {
Future<void> pump(
WidgetTester tester, {
String directory = '/w',
ChatTranscriptCache? transcripts,
}) async {
await tester.pumpWidget(
materialHost(
ChatThreadView(
@@ -60,6 +65,7 @@ void main() {
session: {'id': 's', 'title': 'Old', 'directory': directory},
onBack: () {},
drafts: MemoryChatDraftStore(),
transcripts: transcripts,
newOperationId: () => 'op-1',
onCreatedSession: (session, notice) {
created = session;
@@ -159,4 +165,22 @@ void main() {
expect(closed, 1);
expect(find.text('chat is locked'), findsOneWidget);
});
testWidgets('/close forgets the cached transcript, also after leaving', (
tester,
) async {
final transcripts = ChatTranscriptCache()
..write('s', ChatTranscriptSnapshot(messages: const []))
..write('other', ChatTranscriptSnapshot(messages: const []));
await pump(tester, transcripts: transcripts);
await run(tester, '/close');
await tester.tap(find.text('Close chat'));
await tester.pumpAndSettle();
expect(closed, 1);
expect(transcripts.sessionIds, ['other']);
// Leaving the closed conversation does not write it back.
await tester.pumpWidget(const SizedBox.shrink());
expect(transcripts.sessionIds, ['other']);
});
}