feat(cli-rs): share event streams and run the connection loop

SharedEvents ports shared-events.ts: one upstream per subscriber set, a types filter, the latest server.connected for late subscribers, and a 4,096-event cap per subscriber. connect() ports createClientConnection: server.connected first, the 2 s connect and 45 s idle limits, resync, 1 s reconnect, and 10 ms batches with adjacent deltas merged on a bounded queue. Both are generic over an Event trait. An opt-in live test (OPENCODE_LIVE=1) reads the running service.
This commit is contained in:
Simon Klee 2026-11-04 18:04:18 +01:00
parent 00695b7119
commit e5800a0de2
No known key found for this signature in database
GPG key ID: B91696044D47BEA3
2 changed files with 1532 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,15 @@
# A09: bounded event batch queue
TypeScript: `createClientConnection` (`packages/client/src/solid/connection.ts:65-74`) appends every
event to an unbounded `pending` array and flushes it to `onEvent` every 10 ms on the UI thread. Only
`SharedEvents` subscribers are bounded, at 4,096 queued events
(`packages/client/src/shared-events.ts:33,113-115`).
Rust: the connection loop (`crates/api/src/events.rs`, `connect`) runs on a tokio task and sends each
10 ms batch over a bounded channel (`Options::queue`, 256 batches by default). When the consumer
falls that far behind, the loop drops the stream, records "Event queue full", and reconnects. The
consumer gets `server.connected` again and resynchronizes from the server, as it does after any
reconnect.
Reason: the Rust UI thread is separate from the network task, and `AGENTS.md` requires every queue
between tasks and the UI to be bounded. A UI that stops reading cannot grow memory without bound.