Repository navigation
Description
Summary
A synchronized-output application can commit a progress frame and replace it before the transport finishes a single read. The documented per-commit predicate can miss that first frame despite being registered before the bytes arrived.
Reproduction
-
From the tagged
libvtcheckout, install the locked development dependencies withuv sync --frozen --python 3.14 --all-groups --all-extras. Use the checkout root as the working directory. -
Save the following as
case.pyat the checkout root.
import asyncio
from libvt import Terminal
from libvt.aio import AsyncTerminalStream
from libvt.exc import TerminalTimeoutError
from libvt.terminal import StopOn
def frame(text):
return b"\x1b[?2026h\r" + text + b"\x1b[?2026l"
async def wait_for_first(data, size):
reader = asyncio.StreamReader()
stream = AsyncTerminalStream(reader, rows=2, cols=20, chunk_size=size)
waiting = asyncio.create_task(stream.wait_for("draft", timeout=2, attach_note=False))
await asyncio.sleep(0)
reader.feed_data(data)
reader.feed_eof()
try:
return (await waiting).text
except TerminalTimeoutError as exc:
return f"EOF={exc.eof}, final={stream.terminal.committed.text!r}"
finally:
await stream.aclose()
async def main():
first = frame(b"draft")
data = first + frame(b"saved")
term = Terminal(rows=2, cols=20)
offset = 0
history = []
while offset < len(data):
offset = term.feed_until(data, offset=offset, stop=StopOn.SYNC_END).offset
history.append(term.committed.text)
print("commits:", history)
print("one frame per read:", await wait_for_first(data, len(first)))
print("both frames in one read:", await wait_for_first(data, len(data)))
asyncio.run(main())- Run the case.
$ uv run --no-sync python case.pyExpected
A predicate promised every committed snapshot sees the same draft frame at every read size.
Actual
The parser reports two commits, draft and saved. The stream waiter sees draft with one frame per read and reaches EOF on saved when both frames arrive together.
Environment
Tested versions
CPython 3.14.6 on Linux under WSL2 ARM64. Identical output on release v0.0.1a4 (09611e5) and trunk (0864aa2).
Evidence
Observed output
commits: ['draft', 'saved']
one frame per read: draft
both frames in one read: EOF=True, final='saved'
Proposal
Step through commit boundaries before passing the remaining bytes to the parser, or expose a separately documented commit iterator and keep a settled-screen convenience. Bound the lifetime of retained snapshots for slow consumers.
- Developer experience — A test no longer needs a custom byte splitter to observe a state the guest already committed.
- Immediate benefit — Removes a read-size dependency from frame-sensitive tests.
- Longer-term benefit — Aligns interactive observability with deterministic replay and high-throughput streams.
- End-user experience — A test catches short-lived prompts and progress messages even when the operating system coalesces terminal writes.
Activity
tony commentedon Dec 3, 2026
On master, a wait matched
draftwhendraftandsavedarrived in separate reads. When one read contained both frames, the same wait reached EOF onsaved. The two updates also reproduced the failure on each parent and on their combined changes.The frame fix builds on the shared reader in #159. On Linux it delivered
draftin both read layouts. A native PTY replay deliveredFRAME0449from 450 frames and both concurrent close calls returned 0. PR #192 · PR #159The writer-shutdown change in #160 can land independently. The patches overlap in stream close. In the combined replay, draining frames inside the shared close task delivered the final frame and closed the writer after an input error. PR #160