Fix DeleteLineArea/InsertLineArea panic from stale replay scroll margins (BUG-083) - #970
Merged
Merged
Conversation
…ins (BUG-083) A DECSTBM/DECSLRM scroll-region margin the agent set while its PTY was larger than the emulator now replaying its log survives verbatim into replay/preview byte tails (PTY resizes are never encoded in the byte stream itself). Neither x/vt nor ultraviolet clamp the margin against the emulator's own current dimensions, so the next delete/insert-line call indexes past the buffer and panics; SafeEmuWrite recovers but drops the entire write, not just the offending sequence — explaining the ~400/min recovered-panic rate during Hera rail navigation. ClampScrollRegion (marginfilter.go) rewrites an out-of-bounds DECSTBM/ DECSLRM parameter down to the target emulator's dims before the sequence reaches x/vt, applied at the three replay/rebuild boundaries that feed a log tail into a freshly-sized emulator. Verified unfixed in both vendored libraries' newest upstream commits as of today. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…linearea-panic # Conflicts: # context/knowledge/gotchas/pty-terminal.md # context/knowledge/index.md
Merging this branch will decrease overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
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.
What
A DECSTBM (
CSI Pt;Pb r) or DECSLRM (CSI Pl;Pr s) scroll-region margin the agent set while its PTY was larger than the emulator now replaying its on-disk log survives verbatim into replay/preview byte tails — PTY resizes are never encoded IN the byte stream itself (they arrive out-of-band via SIGWINCH). Neither x/vt's DECSTBM/DECSLRM handlers nor ultraviolet'sBuffer.DeleteLineArea/InsertLineAreaclamp the margin/area against the emulator's own currentWidth()/Height(), so the nextCSI n M(DL) orCSI n L(IL) the log replays indexes past the end of aLinesrow/column slice and panics.SafeEmuWritealready recovers from this (pre-existing), but its recover-and-drop discards the entireWrite()call's content, not just the offending sequence — so every hit silently loses whatever came after the stale margin. Ground truth from~/.argus/ux.log: ~400 recovered panics/minute during active Hera rail navigation, specifically on coordinator-pane replay binds — far more frequent than the existing code comment's "rare edge case" framing assumed, and a strong candidate for a chunk of the ongoing Hera pane garbling reports (distinct mechanism from the BUG-078/#964/#965/#968/BUG-081/BUG-082 family already fixed this week — same subsystem, no shared root cause).Root cause, verified
xvt.NewEmulator(48, 10).Write([]byte("\x1b[1;50r\x1b[3M"))panics withindex out of range [10] with length 10— the same class as production's[48] with length 48.charmbracelet/x/vtnorcharmbracelet/ultraviolethas patched this. PR Fix inert OSC-8 hyperlinks: bump vendored x/vt to upstream parser fix #962's x/vt bump only touchedosc.go(unrelated OSC-8 fix); the newest ultravioletbuffer.godiff touches onlyRenderBuffer.SetCell/Clear/Fill, notDeleteLineArea/InsertLineArea.Fix
ClampScrollRegion(internal/tui/terminal/marginfilter.go) is aFilterOSC-style one-shot byte-stream filter that recognizes the exact, unambiguousCSI <digits>[;<digits>] r|sshape (no private markers, no intermediates, no sub-parameters — everything else passes through byte-for-byte untouched) and clamps an out-of-bounds second parameter down to the target emulator'srows/colsbefore the sequence ever reaches x/vt.Wired into the three "replay a log/ring tail into a freshly-sized emulator" boundaries:
asyncReplayRebuild(the reported site),renderLive'sreadLiveRebuildHistoryfull-replay feed, andPreviewVT.Feed's full-replay branch. Deliberately not applied to plain incremental/ring-wrap-catch-up feeds, where the emulator is already correctly sized and a genuine live resize goes throughemu.Resize()explicitly.SafeEmuWrite's recover-and-drop stays as defense-in-depth for genuinely unknown panics — this fix just removes the known, high-frequency cause.Testing
TestClampScrollRegion— table test over the clamp/no-op/pass-through matrix (oversized margins, in-bounds, omitted params, private markers, unrelated CSI finals, plain text).TestClampScrollRegion_StaleDECSTBMPanicsWithoutClamping/_FixesTheActualPanic— direct library-level repro, unclamped vs. clamped.TestTerminalPane_ReplayStaleScrollRegionDoesNotDropContent— end-to-end through the realasyncReplayRebuildpipeline; fails pre-fix with content written after the oversized DECSTBM missing from the rendered pane.context/knowledge/gotchas/pty-terminal.mdas BUG-083.make pre-pr: build/vet/fmt-check/lint-pr/test-cover-gate all pass.make vulnfails on pre-existing stdlib CVEs unrelated to this change (CI runs itcontinue-on-error: true, confirmed in.github/workflows/ci.yml).TestSmoke_NewTaskFormPaste(unrelatedinternal/tuipackage, new-task-form paste path) is a known pre-existing-raceflake — reproduced failing 1-of-5 in complete isolation onmastertoo, untouched by this change.🤖 Generated with Claude Code