App: replace a silent socket instead of hanging; blink the terminal cursor on a timer; keep one markdown cache entry per streamed reply

A socket that outlived a sleep or network change looked open, so every
queued request waited its own 30 s timeout behind the last until the page
was reopened. The client now replaces a socket whose request times out
unheard (or after two timeouts in a row), and probes it with a ping after
a quiet spell or on returning to the foreground.

The terminal's blinking cursor ran a Ticker (a frame every vsync); a 530 ms
timer now flips it. Streamed deltas no longer flood the markdown cache and
evict finished answers.

Adds tool/perf/idle_session_bench.mjs (idle frames, long-session heap,
snapshot census) and notes/perf-hangs-idle.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 20:47:22 +00:00
parent 23d8658e80
commit 2889d59119
17 changed files with 589 additions and 47 deletions
@@ -67,4 +67,19 @@ void main() {
cache.blocksFor(long);
expect(cache.parses, 6);
});
test('ChatMarkdownCache holds one entry for a streamed reply, so finished '
'answers are not evicted by its intermediate texts', () {
final cache = ChatMarkdownCache(maxEntries: 4, maxChars: 5000);
final finished = cache.blocksFor('# Finished answer');
var streamed = '';
for (var delta = 0; delta < 200; delta++) {
streamed += 'word$delta ';
cache.blocksFor(streamed);
}
expect(cache.blocksFor('# Finished answer'), same(finished));
final parses = cache.parses;
cache.blocksFor(streamed);
expect(cache.parses, parses, reason: 'the final text stays cached');
});
}
@@ -22,16 +22,22 @@ void main() {
expect(shown(tester, harness), isTrue);
await tester.pump(_phase + const Duration(milliseconds: 10));
expect(shown(tester, harness), isFalse);
// Between phase flips nothing asks for a frame: one frame per phase,
// not one per vsync.
expect(tester.binding.hasScheduledFrame, isFalse);
await tester.pump(_phase);
expect(shown(tester, harness), isTrue);
expect(tester.binding.hasScheduledFrame, isFalse);
// Output shows it again and restarts the phase.
await tester.pump(_phase);
expect(shown(tester, harness), isFalse);
await harness.write(tester, 'x');
expect(shown(tester, harness), isTrue);
// Unfocused: steady, and the ticker stopped.
// Unfocused: steady, and the blink stopped (the unfocused cursor's
// own repaint is the last frame).
harness.view(tester).focusNode!.unfocus();
await tester.pump();
await tester.pump(_phase * 2);
expect(shown(tester, harness), isTrue);
expect(tester.binding.hasScheduledFrame, isFalse);
});