Skip to content

perf: reduce headless memory usage - #22

Merged
wowi42 merged 6 commits into
mainfrom
perf/reduce-headless-memory
Sep 29, 2026
Merged

wowi42 merged 6 commits into
mainfrom
perf/reduce-headless-memory

Conversation

@Mouhand-Kaddo

@Mouhand-Kaddo Mouhand-Kaddo commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

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
wowi42 merged commit 29e1ca7 into main Sep 29, 2026
4 checks passed
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.

2 participants