You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cli): TUI turn stream dies permanently when its local event consumer falls behind (no resubscribe, unlike Desktop) #3180
When the TUI's per-turn event consumer falls more than MAX_PENDING_EVENTS_PER_TURN (1024) events behind — e.g. a slow terminal under dense Agent Graph / tool activity — the RuntimeHostSessionChannel permanently kills that turn's event stream:
// packages/cli/src/runtime-host-session-channel.ts (SessionEventQueue.push)if(this.#items.length>=MAX_PENDING_EVENTS_PER_TURN){this.fail(newError('Runtime Host Session event consumer is too slow'));return;}
The Host turn keeps running, but runMakaPiTuiTurn (drainGoalTurn) sees the iterator reject, marks the turn as errored, and live projection stops. The channel itself stays healthy and keeps consuming host frames into the dead queue, so nothing ever recovers — the user only heals when the turn reaches its terminal transcript refresh. This is the same “stream appears frozen” symptom class that #2630 fixed on Desktop.
Note: host-side slow-consumer eviction is already handled — #canRecover covers slow_consumer and the channel resubscribes (verified with a driver test pushing subscription.closed { reason: 'slow_consumer' } on a reconnecting connection: the channel auto-reopened the subscription and the live turn stream continued). The gap is only the client-local slow-consumer path above, which never reaches the recovery machinery.
Desktop reference
apps/desktop/src/main/runtime-host-session-subscription-owner.ts (#2630) treats local slowness as recoverable: its pump awaits frame acceptance, so a slow consumer overflows the bounded subscription queue, the failure surfaces as RuntimeHostSubscriptionError('slow_consumer'), and the owner re-establishes the subscription, restoring canonical state without the renderer resubscribing. The TUI has the equivalent recovery machinery (#scheduleRecovery / #recover) but the per-turn queue failure never invokes it.
Proposal
Make the per-turn overflow recoverable instead of fatal:
On overflow, shed offset-bearing deltas (text_delta / thinking_delta, healed by the next canonical resync / text_complete) and evict the oldest sheddable delta to make room for non-delta events, so terminal events still land — never fail the stream for slowness.
Notify the channel once per lag episode (latched until the backlog drains); the channel retires the healthy-but-lagged subscription and runs the existing #scheduleRecovery path, resubscribing and re-syncing canonical state (transcript replacement heals the rendered view), matching Desktop behavior.
Verification plan
Driver tests: flood an unconsumed turn queue past 1024 deltas → assert the channel auto-resubscribes (replacement subscription opened), the turn stream never rejects, terminal events still arrive, and live deltas continue after recovery.
Activity
fix(cli): resubscribe instead of failing when a turn consumer falls b…
fix(cli): resubscribe instead of failing when a turn consumer falls b…
fix(cli,runtime-host): recover from turn consumer lag without evictio…