Skip to content

Add byte-oriented TmuxControlParser and two-phase -CC PaneAttach #27

Open

Description

@tony

Summary

src/libvt/tmux.py (#18) provides decode_tmux_capture() and unescape_tmux_control_output() for 0.1.0, but does not yet provide a streaming sans-I/O TmuxControlParser (%begin/%end/%error command blocks, %output, %extended-output, %layout-change) or a lossless live tmux -CC pane-attachment state machine (0.2.0 deferral).

Motivation

Attaching a live Terminal to a running tmux (>= 3.3a floor; control.c at 17c016750) pane via tmux -C / -CC has three protocol subtleties proven against live tmux 3.4, 3.8, and trunk (17c016750):

  • Naive single-command bootstrap (issuing capture-pane and discarding %output %N lines arriving before capture-pane's %begin) loses bytes under multi-pane load (6 of 18 3-pane flood trials dropped output) because another command's pending block delays the capture reply while fresh pane output flushes ahead of %begin.
  • Passing refresh-client -A '%N:off' before on triggered a crash on tmux 3.4, whereas a non-pipelined two-phase refresh-client -A '%N:pause' barrier (wait for %end so no further %output %N can arrive -> run display-message + capture-pane + capture-pane -P -p -C for incomplete escape state -> refresh-client -A '%N:continue') passed 72 of 72 stalled-client flood trials (100%).
  • In control.c (17c016750), CONTROL_WRITE_MINIMUM (32) is a per-pane write floor under CONTROL_BUFFER_HIGH (8,192 bytes), pause-after emits "%%extended-output %%%u %llu : <escaped>" (requiring parsing up to the : separator before octal-unescaping), and control_write_output octal-escapes only bytes < 0x20 and '\\' while passing 0x7F (DEL) and split multi-byte UTF-8 continuation bytes raw.

Proposal

Invariants

The invariants below are load-bearing; everything under Intent is open.

  • TmuxControlParser operates strictly on bytes (memoryview / bytearray), never decoding %output or %extended-output lines as UTF-8 text prior to octal unescaping (so split multi-byte UTF-8 sequences across two %output notifications reassemble inside Terminal's incremental UTF-8 decoder without U+FFFD corruption).
  • Live pane attachment uses the two-phase refresh-client -A '%N:pause' -> %end -> capture + -P -p -C -> continue handshake rather than discarding pre-%begin %output, and keeps libvt sans-I/O (subprocess transport stays in libtmux / libvt.aio).

Intent (non-binding)

  • Target 0.2.0: add TmuxControlParser emitting typed %begin/%end/%error, %output (pane_id, raw unescaped bytes), %extended-output (pane_id, age_ms, raw bytes), %subscription-changed, and %exit events, plus a sans-I/O TmuxPaneSync state machine coordinating two-phase pause -> decode_tmux_capture (+ -P incomplete escape seed) -> continue.

Not doing

  • Blocking 0.1.0 on live -CC streaming attachment (0.1.0 ships decode_tmux_capture and unescape_tmux_control_output).

References

Activity

  1. added
    enhancement
    on Nov 23, 2026
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions