Repository navigation
fix(tui): keep input alive during the cold-cache save; Ctrl+C exits the dashboard (#1141) - #1142
Merged
Merged
Conversation
…d exit on Ctrl+C The progressive cold start introduced by #1109 paints the dashboard from recent files, then runs a background fill that parses the deferred history and writes the per-file session cache. On a real 21k-file corpus that fill's cache save publishes one JSON.stringify + fsync per provider shard in a tight loop, and the whole save held the event loop long enough that Ink's stdin reader never ran - a q or Ctrl+C pressed in the post-paint window was swallowed, not buffered, and the user saw a frozen terminal (#1139, #1141). saveCache now yields to the event loop between every shard write, so the Ink input handler fires between publishes. The yield sits BETWEEN shards, never inside one, so each shard's temp+rename atomicity and the lost-fence cleanup that owns the canonical envelope are preserved; nothing marked seen without being parsed, the kill-safe resume invariant from #1109 is intact, and the floored-parse memo key suffix keeps warm reads byte-identical. The fill still parses every deferred file, so money totals are unchanged. The dashboard's useInput now exits on Ctrl+C through the same path as q, so a raw 0x03 from the terminal lands as soon as the loop breathes. Pinning tests: - tests/save-cache-yields.test.ts: a setImmediate probe must interleave with saveCache's shard writes. - tests/dashboard-exit.test.ts: a raw \x03 exits the dashboard the same way q does. - tests/parser.test.ts: the copilot validated-clean re-parse test tightens its fake-timer scope to only Date, so the new event-loop yield inside saveCache still resolves under vitest's fake timers. The #1109 cold-start one-shots (report, sessions, models, json/csv/ markdown, the desktop and menubar payloads) are unchanged.
iamtoruk
added a commit
that referenced
this pull request
Aug 25, 2026
…ess quits immediately (#1143) (#1144) * fix(tui): show quit feedback during the cold-start fill and exit on the second q (#1143) Follow-up to #1142. With the input fix in place, q pressed during the post-paint background index landed instantly but the exit path drained the fill first - a deterministic ~16.5s silent wait on a 21k-file corpus. The first q while the fill is active now arms a confirmation and renders 'Finishing background index so the next launch starts warm - press q or Ctrl+C again to quit now' in the footer area, styled to match the StatusBar (DIM border, ORANGE accent on the action key). The second q takes the abrupt path, which #1109 already proved kill-safe (nothing marked seen without being parsed, resume converges). Ctrl+C is unchanged: it always exits through the abrupt path, whether or not the confirmation is armed. q with no fill active exits immediately as before, with no status-line flicker. The confirmation auto-clears the moment the fill lands so a stale flag can never trap a later q. The fill's indexing signal already flows to the dashboard (the #1109 banner reuses it), so no new global state was introduced. Pinning tests added to tests/dashboard-exit.test.ts. BREAKING NOTE FOR 0.9.22: ships in 0.9.22, not Unreleased. * test: flush the unmount frame before the no-flicker assertion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1141 (root cause of #1139). The post-paint cache save wrote every shard in one synchronous burst, starving the event loop so Ink never processed keystrokes - a single early q or Ctrl+C was swallowed unbuffered, which reads as a total freeze to a first-run user with a large history. saveCache now surrenders the event loop between shard writes (never inside one, preserving temp+rename atomicity and the written-set ownership fence), and Ctrl+C is wired to the dashboard exit path.
Measured on a real 21k-file corpus, cold cache, pty-driven, 5 trials: Ctrl+C after paint exits in 0.0-0.1s at every press time (was: swallowed indefinitely). q exits via the pre-existing graceful index-drain (~16.5s, deterministic) - that latency predates this fix and gets its own follow-up for instant-quit-or-feedback.
Full suite 3708 green, tsc clean; new tests: save-phase yield probe and Ctrl+C exit. Money invariants untouched (the fill still parses and saves everything; #1109 kill-safety preserved).