Terminals: flow-controlled output, immediate echo, sliced emulator writes

Machine terminals no longer skip output for live viewers. Each connection's
subscription is a cursor into the 1 MiB retained tail, drained by the
connection's writer as soon as the PTY reader writes (no 50 ms tick; a
streaming frame gathers for at most 2 ms). A subscription opened with
flow: true gets window (256 KiB) in its reply and acknowledges drawn output
with terminal_ack; while one is full the reader stops reading the PTY, so
the program waits. A subscription full for 3 s without acking stops holding
the terminal and later sees a gap; a gone connection drops its
subscriptions. Clients that never ask for flow keep the old pacing (newest
64 KiB per 50 ms). terminal_open/terminal_output replies precede the frames
that follow them, which start exactly at the reply's output_end.

Chat shell runs share the buffer code: output is pushed as it arrives,
oldest first, while the chat's watchers keep short queues; 256 KiB unpushed
stops the reader, and watchers behind for 3 s get the old pacing.

The app asks for flow, takes offsets from the server (frame end, reply
output_end) instead of re-encoded text length, acks per quarter window, and
writes replays and bursts into the emulator in slices that yield to the
event loop (ChatShellTerminalFeed, shared with chat shells).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 23:57:18 +00:00
parent 5ab1ec9e00
commit 0963a071d0
30 changed files with 1958 additions and 182 deletions
+13
View File
@@ -382,6 +382,19 @@ func (h *chatHub) detachClient(clientID string) {
// fanout delivers one frame to every client watching sessionID except the one
// named by except (the sender, who already has it locally).
// roomBacklog is the most frames any client watching sessionID has queued.
func (h *chatHub) roomBacklog(sessionID string) int {
h.mu.Lock()
defer h.mu.Unlock()
most := 0
if room := h.rooms[sessionID]; room != nil {
for _, sub := range room.subs {
most = max(most, len(sub.ch))
}
}
return most
}
func (h *chatHub) fanout(sessionID string, msg protocol.Message, except string) {
h.mu.Lock()
var targets []*chatSub