Skip to content

A hook's message rebuilds the sidebar once, finds PRs and rows by key, and Attention is worked out once per change - #288

Merged
Mpdreamz merged 1 commit into
mainfrom
fix/hook-path
Nov 16, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
fix/hook-path

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Part (a) of the code-health performance round (plan PR 11): the hook path, the sidebar, Attention. Screen reading, startup, GitHub sync and telemetry, and Audit/ExternalText/OriginKeeper come in their own PRs.

Every working-state hook commits its session. Each commit rebuilt the sidebar once per domain part it wrote (sessions, GitHub, PR details, feedback, pilot log), each rebuild O(sessions² × PRs). What the user sees does not change; each step is now cheaper or done once.

  • One rebuild per commit. The didSets of sessions, github, pullDetails, feedback and pilotLog ask a Coalesced rebuild (HeedCore). Outside a commit it runs at once, as before. commit and replace(with:) write every part in a batch and rebuild once at the end, then update the Dock and menu bar and note state changes, in the same order as before.
  • The next tool of a working turn. Session.changedOnlyActivity(from:) detects a commit that changed only what an agent is doing (the activity line, lastActivity, the reason of an unchanged state). Such a commit skips the five notices that read only other fields and so cannot fire on it: ledger, naming, turn ends, audit of new sessions, goal attach. The time-based notices (session panel, goal PRs) still run. Every reader of sessions still sees the new values.
  • Run hooks. A run's hook rebuilds the list only when the run's state changed.
  • PRs by ref. GitHubState.pull(_:) reads an index kept with pulls and still returns the first match. The index takes no part in equality, hashing or the cache.
  • Pilot state once per rebuild. Whether a PR has a session is now a lookup in a set kept with sessions. Within one rebuild, each PR's and each session's pilot state is worked out once and reused.
  • Rows by id. SessionList.index(of:) and pinIndex(of:) replace firstIndex(of:), which compared whole Session values, in the sidebar and the rail. The size sort asks each session's size once, and done sessions are dropped by id.
  • Attention. Entries and listing are kept (Derived, HeedApp) until something they read changes (withObservationTracking), or for at most one second because they read the clock. The badge, counts, coverage line and list share one computation. A per-value observed counter makes readers of the kept value redraw as before. [attention] rules are parsed when they change.
  • Presence. A hook writes agentPresence only when it changes which panes run an agent.

Deliberate deviations from the audit's suggestions

  • Activity is not moved out of Session into a separate store. lastActivity and activity have about 57 readers (sweep, ledger staleness, permission asks, away summary, control socket, swarm stuck), and a store that lags would change what they see. Instead, an activity-only commit stays exact and skips the work that cannot apply to it.
  • Row values are not precomputed in rebuildList. Several of them (watch labels, close readiness, pilot status) depend on runs, helpers and the clock, which do not trigger a rebuild, so precomputed values would go stale. The rows instead call helpers that are now cheap: O(1) index lookups and the PR index.
  • Timing nuance: a run's hook no longer triggers a rebuild on every tool call. Before, those calls incidentally re-checked time-based pilot states such as stalled. The other rebuild triggers still do.

Verification

  • swift build. Targeted tests pass: HookPathTests (new, 14 tests), DomainMirror, SessionsView, GitHub, QuietHours, ResumeBanner, AttentionListing, SettingsLayout (96 tests). mise run fmt and mise run lint are clean.
  • Mutation checks: making Coalesced.request run immediately, dropping the pulls index didSet, dropping the rules didSet, dropping the state comparison in changedOnlyActivity, and making AgentPresence.changes always true each made the matching tests fail. The size-memo mutation ran in the same batch, but its result line was cut from the output, so it is unconfirmed.
  • DomainMirrorTests now reads replaceParts(with:) and write(_:over:changed:), where the parts are written now.

Not done / untested

  • Full suite: not run after the last rebase (the coordinator validates on main). A run before the rebase failed only the then-broken SettingsLayout tests (fixed on main by The settings layout tests expect General's new Appearance section #281) and DomainMirror (fixed here).
  • Bench numbers: Tests/HeedCoreTests/Bench/SidebarBench.swift is added (200 sessions sorted by size; 600 PR lookups among 2,000), but the release builds did not finish on a machine at load average about 200, so there are no before/after numbers yet. Run mise run bench (filter SidebarBench, and CoreBench's sessionList) on main and on this branch.
  • mise run tutor-check and the app itself: not run. Derived's observation-driven invalidation is untested at runtime: there is no HeedApp test target.

🤖 Generated with Claude Code

…, and Attention is worked out once per change

Every working-state hook commits its session, and each commit rebuilt the
sidebar once per domain part it wrote (sessions, GitHub, PR details,
feedback, the pilot's log), each rebuild O(sessions² × PRs). Nothing a
user sees changes; each step is now cheaper or done once.

- **One rebuild per commit.** The didSets of `sessions`, `github`,
`pullDetails`, `feedback` and `pilotLog` ask a `Coalesced` rebuild
(HeedCore). Outside a commit it runs at once, as before; `commit` and
`replace(with:)` write every part in a batch and rebuild once at its end,
then update the Dock/menu bar and tell the notifier which sessions changed
state, in the same order as before.
- **The next tool of a working turn.** `Session.changedOnlyActivity(from:)`
says a commit changed only what an agent is doing (activity line,
lastActivity, the reason of an unchanged state). Such a commit skips the
notices that cannot fire on it: ledger, naming, turn ends, audit of new
sessions and goal attach. Everything time-based (session panel, goal PRs)
and every reader of `sessions` still see the new values.
- **Run hooks.** A run's hook rebuilds the list only when the run's state
changed, not on every tool call.
- **PRs by ref.** `GitHubState.pull(_:)` reads an index kept with `pulls`
(still the first match). The index takes no part in equality, hashing or
the cache.
- **Pilot state once per rebuild.** Whether a PR has a session reads a set
kept with `sessions`; one rebuild works out each PR's and each session's
pilot state once (the rows, sizes and close checks asked again).
- **Rows by id.** `SessionList.index(of:)` and `pinIndex(of:)` replace
`firstIndex(of:)` (full `Session` equality) in the sidebar and the rail;
the list sorts by size asking each size once and drops done sessions by id.
- **Attention.** Its entries and listing are kept (`Derived`) until
something they read changes, or for a second (they read the clock), so the
badge, counts, coverage line and list share one computation. The rules
are parsed when `[attention] rules` changes, not on every read.
- **Presence.** A hook writes `agentPresence` only when it changes which
panes run an agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
@Mpdreamz
Mpdreamz merged commit eccbe97 into main Nov 16, 2026
5 checks passed
@Mpdreamz
Mpdreamz deleted the fix/hook-path branch November 16, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant