fix(cli): prevent spinner freeze by running native calls in subprocess
Closed
JU
1y ago+232+232+012345678901234567890123456789-46-46-01234567890123456789
Summary
- Fix spinner animation freezing during native Rust calls by offloading them to a subprocess
- The main event loop now stays free to animate the spinner while heavy computation runs in isolation
Problem
The CLI spinner would freeze during native module execution because:
- Native Rust calls (via napi-rs) are synchronous and block the main thread
- Node.js/Bun only yields between async operations, not during blocking native FFI calls
- This caused the spinner to appear stuck while parsing files and generating reports
Solution
Run native calls in a separate Bun subprocess, communicating through temporary JSON files:
Main Process Subprocess (native-runner.ts)
│ │
├─ Write input to temp file ────────►│
│ ├─ Read input
│ (spinner animates freely) ├─ Execute native call
│ ├─ Write output to temp file
│◄─ Read output from temp file ──────┤
│ │
Changes
| File | Description |
|---|---|
native-runner.ts | New subprocess script for isolated native execution |
native.ts | Added async variants: parseLocalSourcesAsync, finalizeReportAsync, finalizeMonthlyReportAsync, finalizeGraphAsync |
cli.ts | Updated to use async native functions |
useData.ts | Updated TUI to use async native functions with Promise.all |
Testing
-
bun run cli --helpworks -
bun run cli modelsdisplays data correctly - Spinner animates smoothly during loading