Repository navigation
Closed
Labels
bugSomething isn't working
Description
Summary
Mode ?2026 synchronized output in src/libvt/terminal.py (#2) exhibits two coupled snapshot defects: Terminal.committed depends on feed() chunk splits and whether committed was previously read, and cursor/mode mutations inside an active ?2026h hold leak into committed before CSI ? 2026 l.
Reproduction
- Compare whole-chunk versus split-chunk
B+CSI ? 2026 h+Cafter readingcommittedatA:
$ uv run python -c 'from libvt import Terminal; a = Terminal(rows=1, cols=6); a.feed(b"A"); _ = a.committed; a.feed(b"B\x1b[?2026hC"); b = Terminal(rows=1, cols=6); b.feed(b"A"); _ = b.committed; b.feed(b"B"); b.feed(b"\x1b[?2026hC"); print("whole:", a.committed.lines, "split:", b.committed.lines)'- Move the cursor and hide
DECTCEM(?25l) inside?2026hwithout writing printable text:
$ uv run python -c 'from libvt import Terminal; vt = Terminal(rows=4, cols=8); vt.feed(b"A"); _ = vt.committed; vt.feed(b"\x1b[?2026h\x1b[2;3H\x1b[?25l\x1b[6n\x1b[?2026$p"); print("committed:", vt.committed.cursor, "live:", vt.cursor, "replies:", vt.drain_replies())'Expected
- Step 1 prints
whole: ('AB',) split: ('AB',)across whole-buffer, split-buffer, byte-by-byte, and uninspected runs, and updatescommitted.linesto('ABC',)onCSI ? 2026 l. - Step 2 keeps
committed.cursorat 0-based(0, 1)withvisible=TrueuntilCSI ? 2026 l, while updatingvt.cursorto(1, 2)(visible=False) and queuing live repliesb'\x1b[2;3R\x1b[?2026;1$y'immediately.
Actual
- Step 1 prints
whole: ('A',) split: ('AB',)becauseself._generationincrements only at the end offeed(), causingself.snapshot()inside_ensure_sync_snapshot()to hitself._cached_snapshot.generation == self._generationand return the stale'A'snapshot. - Step 2 prints
committed: Cursor(row=1, col=2, visible=False, ...)because_set_cursor()and_apply_mode()do not call_before_mutate(), deferring snapshot capture untilvt.committedis read after the cursor and visibility have already mutated.
Environment
libvt:#2(feat/v2-architecture,0.1.0a0)- Python:
3.15.0(unicodedata17.0.0) - Reference
tmux:3.8a(tmux -f /dev/null) - OS: Linux
x86_64
Affected code in src/libvt/terminal.py (#2)
def _ensure_sync_snapshot(self) -> None:
if self._sync_hold_pending and self._held_snapshot is None:
self._held_snapshot = self.snapshot()
self._sync_hold_pending = FalseProposal
Invariants
The invariants below are load-bearing; everything under Intent is open.
- At any byte offset where mode
?2026is reset,vt.committed == vt.snapshot(). - At the exact transition
?2026l -> ?2026h,committedlatches the presentation state (cells, styles, active screen, cursor coordinates/visibility/shape/blink, title, working directory, prompt zones, program status, and visual modes) produced by all bytes strictly precedingCSI ? 2026 h, independent offeed()chunking or observer reads. - Repeated
CSI ? 2026 hwhile mode?2026is already active is a no-op and never overwrites the latched frame; unfreezing occurs onCSI ? 2026 l,DECSTR,RIS,Terminal.resize(), or an explicit sync-timeout expiration call (never a wall-clock timer insidefeed()). - Protocol queries (
CPR,DECXCPR,DECRQM,DA1/DA2,XTVERSION,DECRQSS,CSI ? u,CSI ? 996 n,OSC 10/11 ?) continue to reply immediately from live parser and screen state.
Intent (non-binding)
- Capture lightweight scalar frame metadata plus shallow row references (or per-row
sync_epochcopy-on-write stamps on_Row) at?2026l -> ?2026hso cursor-only holds clone zero rows while keepingcommittedO(1) when?2026is inactive. - Advance
_generation(or invalidate_cached_snapshot = None) whenever terminal state mutates rather than only once perfeed()call.
Not doing
- Adding wall-clock
asynciotimers inside sans-I/OTerminal.feed().
References
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
Terminal(fix[sync]): Freeze ?2026 state at BSU (#5)
Terminal(fix[sync]): Freeze ?2026 state at BSU (#5)
tony commentedon Nov 23, 2026
Resolved in #2 (
0c7ee41).