#6728·CodeWhale

CPU Usage Regression: v0.9.12 (idle) → v0.9.13 (moderate) → v0.10.0 (heavy)

Author: Gabriel-DegretCreated Sep 29, 2026Updated Sep 30, 2026
Labelsbugneeds-triage

Platform: FreeBSD 15.0 (x86-64) Binaries analyzed:

  • cw00912 — Codewhale v0.9.12 (82 MB ELF, dynamically linked)
  • cw00913 — Codewhale v0.9.13 (89 MB ELF, dynamically linked)
  • cw01000 — Codewhale v0.10.0 (90 MB ELF, dynamically linked)

All three binaries are Rust executables (ELF 64-bit LSB pie, compiled for FreeBSD).

Observed Behavior

Version Idle CPU (top) Threads event_loop.rs size
v0.9.12 ~1% (uwait) 17 ~4264 lines
v0.9.13 ~5-8% ~25-30 ~7323 lines
v0.10.0 ~8-15% ~30+ ~7323 + dispatch

uwait state = waiting on user event (interrupt-driven). Later versions show active polling.

Root Cause Analysis

Between v0.9.12 and v0.9.13 (+7 MB, major CPU increase)

The event loop grew from ~4264 to ~7323 lines (+70%). Multiple background polling workers were added:

  1. @-mention discovery worker (crates/tui/src/tui/mention_completion.rs)

    • Background thread codewhale-mention-discovery that continuously scans the workspace for @-mention candidates
    • Polls filesystem even when user is idle
  2. LSP (Language Server Protocol) integration

    • New modules: crates/tui/src/lsp/mod.rs, lsp/client.rs, core/engine/lsp_hooks.rs, tools/lsp.rs
    • Spawns lsp-writer, lsp-reader, lsp-dispatcher threads
    • Supports rust-analyzer, gopls, typescript-language-server, clangd, etc.
    • Background language analysis runs continuously, even with no files open
  3. Runtime event tap / store monitoring

    • runtime event tap lagged; a store-failure notice may have been missed
    • Polls runtime store state periodically
  4. Thread goal stall monitoring

    • failed to initialize durable goal stall schema
    • Tracks stalled_ms, pause_reason, repeated_gap_count, last_gap_fingerprint
    • Continuously checks if threads are stalled
  5. Engine tick & telemetry bucket aggregation

    • engineTick increments every iteration, bucket aggregation every 12 ticks
    • Telemetry events with timestamps, agent IDs, tool tracking
  6. Session persistence polling

    • Polls session_index.jsonl for job status changes
    • Periodic SQLite queries for thread status (SELECT id, rollout_path, preview...)
  7. File frecency tracking (crates/tui/src/tui/file_frecency.rs)

    • Background tracking of file access frequency
  8. Models.dev live fetch (crates/tui/src/models_dev_live.rs)

    • Periodic HTTP fetch of model catalog

Between v0.9.13 and v0.10.0 (+1 MB, additional CPU)

  1. Fleet manager (crates/tui/src/fleet/manager.rs:1338)

    • Fleet worker coordination with active polling
    • Fleet worker coordination is not currently admissible
  2. Background hooks

    • background hooks cannot deny tool calls because they exit immediately with no result
    • Hooks run for every tool call/event
  3. Dispatch completion mailbox

    • dispatch completion mailbox is unavailable/full/closed
    • Polls mailbox for dispatch results
  4. VM thread management

    • VM thread exited without reporting a result
    • VM admission gate closed
  5. Agent profile permissions (AgentProfilePermissionsToml)

Architectural Shift

v0.9.12 uses an interrupt-driven event loop: it sleeps on kevent/kqueue and wakes only on user input. The TUI event loop had ~4264 lines.

v0.9.13+ switches to a polling-driven architecture: background workers wake periodically regardless of user activity. The event loop grew to ~7323 lines with runtime tap lag detection, persistence health checks, and session validation — all running on every iteration.

Impact

  • Significant battery drain on laptops
  • Unnecessary CPU contention on shared/small VPS
  • Background LSP scanning may be redundant with external editor LSP