mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
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:
parent
00695b7119
commit
e5800a0de2
2 changed files with 1532 additions and 0 deletions
File diff suppressed because it is too large
Load diff
15
packages/cli-rs/parity/deviations/A09-bounded-queue.md
Normal file
15
packages/cli-rs/parity/deviations/A09-bounded-queue.md
Normal 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.
|
||||
Loading…
Add table
Reference in a new issue