Repository navigation
Clean up Program state when a session is deleted - #650
Merged
Merged
Conversation
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.
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.
Summary
on_session_deletedcleaned up terminal/history state but leftprogram_popups,program_runs,program_view_memory, andprogram_collaboratorsentries behind forever, and never cleared an activeprogram_popuppointing at the deleted session.open_program_session_ids()sorts every entry inprogram_popupsand 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_popupswith N stale entries (simulating N delete cycles without cleanup) and timed 200ui::rendercalls with two split panes open:Isolating
program_popupsalone (no other maps populated) reproduced the same scaling, confirmingopen_program_session_ids()— called per visible split pane per frame inrender_detail— as the hot path.Fix
on_session_deletednow also:program_popupif it belongs to the deleted session.program_popups,program_runs,program_view_memory.program_collaboratorscursors for the deleted session.Test plan
deleting_a_session_clears_its_program_stateasserts 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.