perf: reduce headless memory usage - #22
Merged
Merged
Conversation
Defer interactive imports and retain only the requested file page to reduce peak RSS while preserving existing behavior.
Avoid retaining unrelated message payloads during session opening and source validation while preserving replay visibility and exact digests.
Stream permission grants, release the startup replay after use, spool shell overflow, and cap subprocess retention while preserving output and process cleanup.
wowi42
approved these changes
Sep 29, 2026
Mouhand-Kaddo
added this pull request to stack #28
September 29, 2026 08:24
This was referenced Sep 29, 2026
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.
Reduce headless memory use through lazy TUI imports, streamed file reads and session lookups, and bounded subprocess capture. Large shell output retains its complete log on disk. Capture now stays bounded even when the output cap is one byte.
Existing offline RSS measurements (median of five runs) show 71 → 60 MiB for a short prompt, 257 → 60 MiB for a 10-line read from a 64 MiB file, and 263 → 67 MiB for recall from a 64 MiB session. The 64 MiB shell-output case falls from 243 → 51 MiB with temporary disk storage. New regression coverage checks tiny caps and bounded Python allocations.
Failure cleanup now waits for the shell to exit, signals remaining process-group members, and drains output in bounded chunks. This fixes the live descendant observed on macOS after an output-write failure. Regression coverage checks the whole group and deterministically reproduces a child missed by the first signal.
The top JSON layer also preserves these gains by streaming session statistics instead of loading transcript copies.
Stack and validation
#22 → #23 → #24 → #25 → #26
Native GitHub stack #28. This PR targets main. Each layer contains the preceding layer; original branch history is preserved.
Ruff lint and formatting pass. The combined stack passes all 2,277 tests on Linux/Python 3.14.3. All four Linux/macOS Python 3.13/3.14 CI jobs pass on
be7c2ea.