docs(code-runtime-python): restate the buffered-chunks pre-check comment as invariant-preserving

The review's revision: the buffered-chunks pre-check's open-aware overhead is
observationally inert — when the +3 form trips and the open-aware form does not
(pending + newline in [remaining - 2, remaining]), _push_bounded_prefix
re-slices the same newline-free line text and _push_locked admits it under the
same open-aware billing, byte for byte. The comment now states that the
open-aware form keeps _push_bounded_prefix's 'certain to reject' precondition
true, contrasting with the scan pre-check whose slice carries the newline and
therefore genuinely truncates.
This commit is contained in:
Chinesezjc
2026-08-31 15:04:43 +08:00
committed by Tianyi Cui
parent fdcfec4977
commit 909d5c334b
@@ -300,8 +300,16 @@ class _LogStream(io.TextIOBase):
# NEW entry. While an `open` entry is accumulating, the closing
# line is that entry's TAIL: its cheap bound is the content
# length alone, matching `_push_locked`'s open-aware bound.
# Charging +3 here truncates an exact-fit merged tail or
# over-rejects it, then flushes a truncated prefix instead.
# This bound's observable behavior is invariant under the
# overhead either way: when the +3 form trips and the open-aware
# form does not (pending + newline in [remaining - 2, remaining]),
# _push_bounded_prefix re-slices the SAME line text (the extra
# slice `text[:newline]` carries no newline) and _push_locked
# admits it under the same open-aware billing, byte for byte.
# The open-aware form only keeps _push_bounded_prefix's "certain
# to reject" precondition true, which is exactly what the scan
# pre-check below does NOT preserve (its slice carries the
# newline, so push genuinely rejects and truncates).
overhead = 3 if not self._logs._open_started else 0
if self._pending_chars + newline + overhead > self._logs.remaining:
# The reconstructed first line cannot fit the ledger, so