Skip to content

perf: progressive cold start — paint the dated TUI first, index history in the background - #1109

Merged
iamtoruk merged 1 commit into
mainfrom
perf/1107-progressive-cold
Aug 23, 2026
Merged

iamtoruk merged 1 commit into
mainfrom
perf/1107-progressive-cold

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Fixes #1107. Stacked on #1108 (base = perf/1106-single-pass; retarget after the stack merges).

What

Cold start (empty cache) parsed all ~21k files before painting a dashboard that shows 7 days. Now, on a cold interactive TTY launch with a dated default view:

  1. First paint parses only files that can hold in-range data: fp.mtimeMs >= rangeStart − 48h (clock-skew margin). The safety argument: a session log's last event ≤ its mtime, so older files provably cannot affect the dated view. Files with a cache entry are never deferred; network sources always load.
  2. Background fill is the existing background reload — parses the deferred files without blocking keys, writes the per-file cache exactly as a full cold parse would, refreshes panels on completion.
  3. Honest UI: indexing history · N/M files · totals below cover what is indexed so far banner until converged.

Cold detection = session-cache envelope missing or complete !== true — the same condition the cold-hydration branch already uses. Gated by isTTY && no --day && no --from/--to: one-shot json/csv/markdown, report/sessions/models, serve/menubar/app payloads never enter the path and never return partial data.

Never-lose

  • A first-paint run that deferred anything cannot stamp the cache complete (daily cache stays complete:false, un-advanced lastComputedDate) — kill mid-fill and the next launch re-enters cold and converges; deferred files have no cache entry so they're still 'changed' next time. Nothing is marked seen without being parsed.
  • Pass-1 files are served from cache in pass 2 (fingerprint match → unchangedSources) — no double-parse, no double-count; deferral happens before changedFiles, so worker-result pairing stays aligned.
  • The floored parse's memo/burst key carries a :paint<floor> suffix — it can never be served to an unfloored request; warm keys are byte-identical to before.

Parity (vs perf/1106-single-pass)

  • Warm: 5 commands byte-identical except /generated; instrumented warm TUI shows the progressive path never activates.
  • Cold one-shots (empty cache): same 5, byte-identical.
  • Cold convergence (pty: launch cold, wait for both caches complete, quit): synthetic corpus — session cache 3547 files 0 differing, daily cache identical hash, all subsequent reports identical. Real 21k corpus — 2 differing files, both live agent logs appended between runs; daily cache byte-identical.

Perf (real 21k corpus, empty cache, pty, interleaved, median of 3)

base branch
time to first paint 36.3s 9.9s (3.7x)
fully indexed 36.1s 47.5s (+31% total work — paint files parsed once for the view, fill re-runs discovery)

Honest trade: a new user sees their dashboard in ~10s instead of ~36s, and pays ~11 extra background seconds while already looking at data.

Known limitations (deliberate)

  • Period switch during the fill queues behind it (existing in-flight queue) + shows the banner — not an instant partial slice.
  • Plan-usage bar can read low until the fill lands (plan window > 7d floor); the banner covers it. Widening the floor to the plan window would parse ~30 days and eat most of the win.
  • Fill uses the un-collapsed refresh path (not withSinglePassParse) — collapsing it is a separate change.

Tests

tests/progressive-cold-start.test.ts (8): margin boundary, cache-entry/null-floor exemptions, network inclusion, partial-hydration flags, convergence vs full cold parse, no re-parse in pass 2, kill-mid-fill resume, zero-deferral no-op. Full suite green (233 files / 3190 tests, lock suite included). No cache schema/version bump, no payload changes, no new deps.

…behind it

A cold start parsed the whole corpus before painting anything (~36s on a 21k
corpus) even though the default view only shows the last 7 days. A session log
is append-only, so its last event timestamp is <= its mtime: a file stamped
before the start of the displayed range provably holds nothing that range can
show. On a cold cache the interactive dashboard now parses only the files above
that floor, paints, and indexes the rest from the mounted UI.

- parser: `withColdFirstPaintFloor` scopes a parse to files that can hold
  in-range data (mtime >= rangeStart - 48h clock-skew margin), deferring only
  files with NO cache entry — nothing that has something to serve is held back,
  and network sources (synthetic now-stamped fingerprint) always load.
- A run that deferred anything is a partial hydration: it does not stamp the
  session cache complete and reports hydrationComplete false, so the daily
  backfill cannot finalize history off it and the next launch resumes cold.
  A floored run that deferred NOTHING keeps the normal stamps.
- The floor participates in the parse memo key, so a first-paint result can
  never be served to (or burst-reused by) an unfloored request.
- dashboard: cold + TTY + standard dated view only. The background fill is an
  ordinary unscoped background reload, so its cache writes and its refreshed
  panels are exactly what a full cold parse produces. While it runs, an
  "indexing history N/M files" banner states that the totals cover only what is
  indexed so far.

One-shot outputs (json/csv/markdown, report, sessions, models, serve/menubar/app
payloads) are non-TTY and never enter this path.

Fixes #1107
@iamtoruk
iamtoruk changed the base branch from perf/1106-single-pass to main August 23, 2026 11:28
@iamtoruk
iamtoruk merged commit 796a504 into main Aug 23, 2026
15 checks passed
@iamtoruk
iamtoruk deleted the perf/1107-progressive-cold branch August 23, 2026 11:29
pull Bot pushed a commit to TheTechOddBug/codeburn that referenced this pull request Aug 24, 2026
The TTY got the fast cold start in getagentseal#1109; every JSON surface still waited
for the full parse because a payload has no way to say "partial". Add one.

- `hydration: { complete, indexedFiles, totalFiles }` on the menubar payload,
  add-only and emitted ONLY by the resident serve child (which polls, and
  therefore converges). Absence keeps meaning "complete", so every one-shot
  output is byte-identical and no script can be handed partial data.
- serve: a cold child answers `status --format menubar-json` from the files
  the requested period can show (same mtime floor as the TUI) and schedules
  the unfloored fill behind it. Partial answers are never memoized; requests
  waiting behind the fill are heartbeated by id so the client's no-output
  watchdog stays armed.
- `stale` keeps its own meaning: a first paint is fresh but partial, so it
  reports through `hydration` and never sets `stale`.
- desktop app and web dash render an honest "indexing history · N/M files"
  notice while `complete` is false.
iamtoruk added a commit that referenced this pull request Aug 25, 2026
…d exit on Ctrl+C (#1142)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: progressive cold start — paint the default 7-day view first, index the rest in the background

1 participant