BaihuBaihu
Architecture

concurrency

structured concurrency with JoinSet, parking_lot, and DashMap

daemon concurrency

the daemon uses tokio JoinSet for structured concurrency. all subsystems (gateway, channels, heartbeat, cron) are spawned into a single JoinSet. benefits:

  • automatic lifecycle management
  • clean shutdown propagation
  • if one task panics, others continue
  • no orphaned tasks

mutex strategy

parking_lot::Mutex everywhere instead of std::sync::Mutex:

  • 1 byte vs 40 bytes on windows
  • no poisoning — .lock() returns the guard directly, no Result
  • faster contention handling

caching

DashMap concurrent hashmap for response caching:

  • 60-second TTL per entry
  • prevents duplicate API calls for identical prompts
  • lockfree reads, sharded writes

backoff

provider calls use exponential backoff with ±25% random jitter:

  • prevents thundering herd when multiple clients retry simultaneously
  • configurable max retries and base delay

On this page