Skip to content

fix(cli): TUI turn stream dies permanently when its local event consumer falls behind (no resubscribe, unlike Desktop) #3180

Closed

Description

@me2seeks

What happens

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(new Error('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.
  • Existing CLI suite stays green.

I’d like to work on this fix.

Activity

  1. added 2 commits that reference this issue on Aug 18, 2026
    472e4ee
    f395930
  2. added a commit that references this issue on Aug 20, 2026
    f39194f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions