fix(cli): prevent spinner freeze by running native calls in subprocess

Closed
JU
1y ago
+232-46

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:

  1. Native Rust calls (via napi-rs) are synchronous and block the main thread
  2. Node.js/Bun only yields between async operations, not during blocking native FFI calls
  3. 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

FileDescription
native-runner.tsNew subprocess script for isolated native execution
native.tsAdded async variants: parseLocalSourcesAsync, finalizeReportAsync, finalizeMonthlyReportAsync, finalizeGraphAsync
cli.tsUpdated to use async native functions
useData.tsUpdated TUI to use async native functions with Promise.all

Testing

  • bun run cli --help works
  • bun run cli models displays data correctly
  • Spinner animates smoothly during loading