[STACKED on #968] fix(vmm): retain the serial boot delimiter at the cap - #970
Open
kvinwang wants to merge 4 commits into
Open
[STACKED on #968] fix(vmm): retain the serial boot delimiter at the cap#970kvinwang wants to merge 4 commits into
kvinwang wants to merge 4 commits into
Conversation
This was referenced Jul 31, 2026
kvinwang
force-pushed
the
codex/fix-vmm-serial-log-cap
branch
from
August 6, 2026 03:23
93b8593 to
4ff2c0c
Compare
The trimming logic grew inline inside `rotate_serial_log`: it materialized
the front-trimmed buffer, scanned it for a boot separator, then scanned the
original buffer again and rebuilt from scratch when the separator was gone.
Two scans, a discarded allocation, and four levels of nesting for what is a
single range calculation.
Extract `trim_serial_history`, which resolves the retained range in one
`rposition` and returns a `Cow` so the common front-trim path borrows.
This also fixes a byte-duplication bug the inline version could produce. The
tail offset was measured from the end of the buffer while the header was
sliced from its own position, so the two ranges could overlap. When the
previous boot ends in an unterminated line, the front trim lands on the
newest separator's own leading newline: the separator misses surviving by one
byte, the splice path runs, and the tail re-includes a fragment of the header:
\n===== boot @ 2026-01-02T00:00:00Z =====\n\noot @ 2026-01-02T00:00:00Z =====\n\nBBB...
Serial logs routinely end without a trailing newline (panic, abrupt
poweroff), so this is reachable in practice. Clamping the tail offset to the
header end removes the overlap.
Also share `BOOT_SEPARATOR_PREFIX` between the writer and the trimmer. The
separator format was duplicated as a literal in three places, and a drift
would have disabled trimming silently.
The `max_bytes > 0` guard is dropped: `header.len() <= max_bytes` already
rejects a zero cap, since a header is never empty.
Tests: split the single case-matrix test into focused cases, drop the
`DSTACK_SERIAL_ROW` stdout markers (nothing in the tree consumes them), and
move the config-default assertion out of the rotation test. Add a sweep over
pad and boot-body sizes covering the duplication regression, plus the
header-does-not-fit and truncated-header boundaries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Serial-log trimming enforced the byte cap by discarding the boot delimiter together with older output. Consumers could no longer find the boundary between boot attempts after rotation.
Root cause and fix
Trim around and retain the boot delimiter while enforcing the configured maximum size, so bounded logs remain parseable.
Implementation
The branch records the following focused implementation work:
test(vmm): cover serial rotation boundariestest(vmm): read serial default through configfix(vmm): retain serial boot delimiter at capChanged paths:
dstack/vmm/src/app.rsScope
This PR addresses one logical
vmmfinding. It intentionally excludes the acceptance-test infrastructure from #841 and unrelated product fixes from #840.Dependency and merge order
codex/fix-vmm-restart-policyVerification
git diff --check origin/codex/fix-vmm-restart-policy..origin/codex/fix-vmm-serial-log-cap: passed.