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
+7 -2
View File
@@ -310,7 +310,7 @@ async function staticFile(base, pathname, req, res) {
* It serves the built probe bundle and upgrades /connect on the same origin, so
* the normal web composition infers this server from Uri.base.
*/
export async function startFixture({ root, runs = RUNS, runDetail, files = {}, chatMessages }) {
export async function startFixture({ root, runs = RUNS, runDetail, files = {}, chatMessages, chatHistoryDelayMs = 0, onChatHistory }) {
const base = await realpath(root);
const connections = new Set();
const sockets = new Set();
@@ -440,7 +440,7 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
`Sec-WebSocket-Accept: ${accept(req.headers['sec-websocket-key'])}\r\n\r\n`,
);
const connection = new Connection(socket, {
onMessage: (client, request) => {
onMessage: async (client, request) => {
if (request.type === 'subscribe') {
// The real server may not acknowledge `subscribe`; keep it silent so
// the app's send-only path is exercised.
@@ -561,6 +561,11 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
}
if (request.type === 'chat_messages') {
chatHistory++;
onChatHistory?.('request');
// Optional loopback latency for a probe that separates the history
// read from rendering; the default replies immediately as before.
if (chatHistoryDelayMs > 0) await new Promise((r) => setTimeout(r, chatHistoryDelayMs));
onChatHistory?.('reply');
client.send({
id: request.id, type: 'chat_history',
chat_history: {