Skip to content

Perf: explain and bound RSS after cancelling a 32-worker storm #4326

Description

@Hmbown

Problem

The new 32-worker PTY benchmark proves that high fan-out is responsive enough to operate, but its one-shot RSS sample increased again after cancellation instead of settling. We should distinguish allocator high-water retention from a real worker/runtime leak and bound the post-cancel state.

Evidence

Live macOS run on 2026-07-09 from the #4316 release-runtime QA lane:

  • 32 workers live: 1.36s
  • sidebar visible: 1.98s
  • typing echo samples: 137–925ms
  • Esc cancellation: 0.80s
  • RSS: about 62MB idle → 178MB during storm → 328MB immediately after cancellation

The interaction acceptance passed; the 328MB post-cancel sample is the residual signal. The benchmark is loopback-only and makes no paid provider calls.

Reproduction:

cargo test -p codewhale-tui --test release_runtime_qa --locked -- \
  --ignored bench_thirty_two --nocapture --test-threads=1

Expected behavior

Cancellation should terminate all 32 child tasks promptly and memory should reach a stable, explainable plateau. If mimalloc intentionally retains pages, the benchmark/report should separate allocator retention from reachable worker/session state rather than treating raw RSS as a leak by default.

Likely inspection points

  • crates/tui/tests/release_runtime_qa.rs (release_bench_thirty_two_worker_fanout_stays_live)
  • sub-agent task/record teardown in crates/tui/src/tools/subagent/
  • runtime thread and completion-channel ownership
  • transcript/activity caches that retain child output after cancellation
  • mimalloc purge/high-water behavior on macOS

Acceptance criteria

  • Sample RSS at idle, storm, cancel, +5s, +15s, and +30s across at least three runs.
  • Prove all child tasks/processes/channels are terminal after cancel.
  • Identify retained reachable state versus allocator-reserved pages.
  • If reachable state leaks, fix it and add a regression assertion.
  • If allocator retention is expected, document it and add a stable plateau bound that does not create flaky CI.
  • Keep 32-worker spawn, typing echo, and cancellation latency within the v0.8.68 Performance: TUI lag and memory pressure from high agent fan-out sessions #4014 thresholds.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingperformanceRuntime/render performancesubagentsSub-agent orchestration, lifecycle, and completion handlingtuiTerminal UI behavior, rendering, or interaction

    Projects

    Status
    Backlog

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions