Skip to content

Clean up Program state when a session is deleted - #650

Merged
edwin-zvs merged 1 commit into
mainfrom
fix-split-program-lag
Jul 1, 2026
Merged

edwin-zvs merged 1 commit into
mainfrom
fix-split-program-lag

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

Summary

  • on_session_deleted cleaned up terminal/history state but left program_popups, program_runs, program_view_memory, and program_collaborators entries behind forever, and never cleared an active program_popup pointing at the deleted session.
  • open_program_session_ids() sorts every entry in program_popups and runs once per visible split pane on every frame. Left uncleaned, that leak turns into an ever-growing per-frame render cost, paid once per split pane — this is the reported "TUI gets laggy after deleting a session from a split view, then creating a new split."

Reproduction

Added a temporary stress test (not included in this diff) that populated program_popups with N stale entries (simulating N delete cycles without cleanup) and timed 200 ui::render calls with two split panes open:

stale entries render time/frame
0 (baseline) 0.17ms
1,000 0.36ms
10,000 2.6ms
50,000 19.7ms

Isolating program_popups alone (no other maps populated) reproduced the same scaling, confirming open_program_session_ids() — called per visible split pane per frame in render_detail — as the hot path.

Fix

on_session_deleted now also:

  • Clears program_popup if it belongs to the deleted session.
  • Removes the deleted session's entry from program_popups, program_runs, program_view_memory.
  • Drops any program_collaborators cursors for the deleted session.

Test plan

  • New regression test deleting_a_session_clears_its_program_state asserts all four cleanups happen and that an untouched sibling session's Program state survives.
  • cargo test -p agentd-cli — 512 passed, 0 failed.
  • cargo build / cargo clippy -p agentd-cli --no-deps — no new warnings.

on_session_deleted removed terminal/history state but left
program_popups, program_runs, program_view_memory, and
program_collaborators entries behind forever, and never cleared an
active program_popup pointing at the deleted session. Program state
is otherwise never expired, so a long-running TUI that opens/closes
Program views over many short-lived sessions accumulates stale
entries without bound.

open_program_session_ids() sorts every entry in program_popups and
runs once per visible split pane on every frame, so the leak turns
into an ever-growing per-frame cost that gets paid once per split —
reproduced with a stress test showing render cost climb from
~0.17ms/frame at baseline to ~20ms/frame at 50k stale entries. This
matches reports of the TUI getting laggy after deleting a session
from a split view and then creating a new split: more splits pay the
growing cost more times per frame.
@edwin-zvs
edwin-zvs merged commit 107b99d into main Jul 1, 2026
1 check passed
@edwin-zvs
edwin-zvs deleted the fix-split-program-lag branch July 1, 2026 17:49
edwin-zvs added a commit that referenced this pull request Jul 1, 2026
PR #650 added scroll_offset/preferred_col cleanup but left a
ProgramViewMemory test literal missing the cover_percent field added by
#651, breaking cargo test on main (E0063).
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.

1 participant