Repository navigation
Background work costs less: each pane read once a tick, the cached sessions drawn before the tools are found, a GitHub sync with nothing new redraws nothing, telemetry costs kept as running totals - #289
Merged
Conversation
…ssions drawn before the tools are found, a GitHub sync with nothing new redraws nothing, telemetry costs kept as running totals What heed does while you work now costs a fraction of what it did, and launch draws your sessions sooner. What you see, and when, is the same. - **Screen reading.** The once-a-second tick reads each pane at most once (a run's, review's or worker's pane and a session's agent pane were read up to three times), and only after the cheap checks say it is needed. Each agent's patterns are compiled once (`ScreenGuess.Compiled`, again only when `[agents.<name>.patterns]` change) instead of ~11 regexes per pane per tick. A pane whose screen and agent did not change since the last tick keeps its last guess without matching anything (`ScreenGuesser`): a guess depends only on the screen and the patterns. The stuck signal uses the same compiled patterns. Screen reading still runs while the window is hidden: notifications, the Dock and menu bar counts, run, review and worker endings, quiet turns and Hunch all depend on it then. - **Startup.** The cached domain is read while the call log opens and is drawn as soon as config.toml is read, before tool detection (login shell, Tailscale, zmx check), the LLM spend seed and telemetry. A pane drawn before the search path, zmx and zmx's live sessions are known waits in its host for its terminal (`TerminalSurfaces.holdPanes`/`releasePanes`), so a pane still reattaches to its zmx session and gets the detected PATH. Telemetry opens while tools are detected. Today's model spend is read from the call log off the launch path; the runner's first call that gets a slot, and `spentToday`, wait for it, so the daily cap still counts it (`LLMRunner.seedSpend(loading:)`). Everything after the panes start runs in the order it did. New signpost `start.toPanes`. - **GitHub sync.** A sync changes `syncedAt`, each source's fetch time and the team-mention bookkeeping every time, so it reassigned `github` (a sidebar rebuild and every GitHub notice in `commit`) every poll. These are now the sync's stamp (`GitHubSyncStamp`). A sync whose data equals what is there (`GitHubState.sameData`) only updates `githubStamp` and saves the full state to the store as before; the next sync starts from the newest stamp. "synced … ago" and Attention's coverage read the newest stamp (`githubNow`, `freshened(by:)`). - **Telemetry costs.** Each export with a cost re-read up to 200k spans and re-summed every session. `TelemetryStore` now reads the store once, then keeps what costs depend on (model spans grouped by request, cost samples, the latest of each cumulative series) indexed by whose they are (`TelemetryCosts`), and sums only the touched sessions' own records, with the context of now. A prune that removed rows makes it read again. The sessions it raises are committed in one `commit`. Benches (`mise run bench`, `BackgroundBench`; this machine was under a load average of ~170, so the absolute numbers are high): - Guessing a pane: 1042 µs compiling each time, 679 µs compiled once, 0.0 µs for an unchanged screen. - Costs per telemetry batch over 29k spans: 1951 ms reading everything, 11.3 ms with running totals. Verification: `mise run lint` passes; `mise run test` passes. New tests: compiled guesses give the expected states, an agent's patterns compile once until they change, an unchanged screen keeps its guess, a sync with nothing new has the same data, the newer stamp wins, running totals equal a full read after every batch (three seeds, the agents' own OTLP fixtures, an agent session learned later) with one read of the store, a prune that removed rows reads again, and a call made while the spend is read waits for it and is capped. Mutations applied and reverted, each failing its test: no compile cache, a remembered guess that ignores the screen, `sameData` as plain equality, inserts not added to the totals, the first call not waiting for the spend, prunes not invalidating, no span-over-event preference, no `since` filter, agent sessions not mapped. Not covered by tests: the AppModel wiring (no app test target): the per-tick read cache in `readScreens`, holding panes at launch, the GitHub stamp path in `syncGitHub`, batching the cost commits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What heed does while you work now costs a fraction of what it did, and
launch draws your sessions sooner. What you see, and when, is the same.
(a run's, review's or worker's pane and a session's agent pane were read
up to three times), and only after the cheap checks say it is needed. Each
agent's patterns are compiled once (
ScreenGuess.Compiled, again only when[agents.<name>.patterns]change) instead of ~11 regexes per pane pertick. A pane whose screen and agent did not change since the last tick
keeps its last guess without matching anything (
ScreenGuesser): a guessdepends only on the screen and the patterns. The stuck signal uses the
same compiled patterns. Screen reading still runs while the window is
hidden: notifications, the Dock and menu bar counts, run, review and
worker endings, quiet turns and Hunch all depend on it then.
drawn as soon as config.toml is read, before tool detection (login shell,
Tailscale, zmx check), the LLM spend seed and telemetry. A pane drawn
before the search path, zmx and zmx's live sessions are known waits in its
host for its terminal (
TerminalSurfaces.holdPanes/releasePanes), so apane still reattaches to its zmx session and gets the detected PATH.
Telemetry opens while tools are detected. Today's model spend is read
from the call log off the launch path; the runner's first call that gets
a slot, and
spentToday, wait for it, so the daily cap still counts it(
LLMRunner.seedSpend(loading:)). Everything after the panes start runsin the order it did. New signpost
start.toPanes.syncedAt, each source's fetch time andthe team-mention bookkeeping every time, so it reassigned
github(asidebar rebuild and every GitHub notice in
commit) every poll. These arenow the sync's stamp (
GitHubSyncStamp). A sync whose data equals what isthere (
GitHubState.sameData) only updatesgithubStampand saves thefull state to the store as before; the next sync starts from the newest
stamp. "synced … ago" and Attention's coverage read the newest stamp
(
githubNow,freshened(by:)).and re-summed every session.
TelemetryStorenow reads the store once,then keeps what costs depend on (model spans grouped by request, cost
samples, the latest of each cumulative series) indexed by whose they are
(
TelemetryCosts), and sums only the touched sessions' own records, withthe context of now. A prune that removed rows makes it read again. The
sessions it raises are committed in one
commit.Benches (
mise run bench,BackgroundBench; this machine was under aload average of ~170, so the absolute numbers are high):
µs for an unchanged screen.
11.3 ms with running totals.
Verification:
mise run lintpasses;mise run testpasses. New tests:compiled guesses give the expected states, an agent's patterns compile
once until they change, an unchanged screen keeps its guess, a sync with
nothing new has the same data, the newer stamp wins, running totals equal
a full read after every batch (three seeds, the agents' own OTLP fixtures,
an agent session learned later) with one read of the store, a prune that
removed rows reads again, and a call made while the spend is read waits
for it and is capped. Mutations applied and reverted, each failing its
test: no compile cache, a remembered guess that ignores the screen,
sameDataas plain equality, inserts not added to the totals, the firstcall not waiting for the spend, prunes not invalidating, no span-over-event
preference, no
sincefilter, agent sessions not mapped.Not covered by tests: the AppModel wiring (no app test target): the
per-tick read cache in
readScreens, holding panes at launch, the GitHubstamp path in
syncGitHub, batching the cost commits.Not run:
mise run tutor-check(asked to open the PR without waiting for it; the machine was at a load average of ~170).🤖 Generated with Claude Code