Skip to content

test(#647): AC-1 re-analysed — Mechanism #1 was wire traffic; deterministic repro via out-of-band write harness - #663

Merged
admarble merged 1 commit into
mainfrom
feature/647-fix-cli-624-s-duplicate-header-fix-doesn-t-cat
May 18, 2026
Merged

admarble merged 1 commit into
mainfrom
feature/647-fix-cli-624-s-duplicate-header-fix-doesn-t-cat

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Resumes #647 after PR #653 (foundation) and PR #661 (AC-1 capture). Conservative scope: investigation + reproduction, no fix in this PR.

Forensic VT replay of the AC-1 capture (docs/incidents/647/captures/2026-05-17/terminal.typescript) shows PR #661's "Mechanism #1 at 2181× over 36m" was reading the wire-traffic byte count, not actual scrollback. log-update's eraseLines escapes appear in the typescript file but don't delete prior bytes — those bytes only disappear in a real terminal.

Replay through 213×31 VT Headers in (visible + scrollback) In scrollback only
WITHOUT stderr SEQUANT_DEBUG_RENDERER lines 4 1
WITH them (as script(1) recorded) 2180 2171

Amplification: 2171×. The "scale" was the SEQUANT_DEBUG_RENDERER=1 instrumentation writing to the same pty as stdout. In a real user terminal without that flag, log-update's eraseLines works correctly. The underlying bug is Mechanism #2-class — any out-of-band writer (stderr instrumentation, subprocess output landing outside a paused window) breaks log-update's cursor model. See docs/incidents/647/captures/2026-05-17/analysis.md for the full writeup.

What this PR adds

  • docs/incidents/647/captures/2026-05-17/analyze-trace.ts — reproducible forensic script that extracts the SEQUANT_DEBUG_RENDERER trace from the typescript file, bucket-counts header occurrences by trigger pattern, and replays raw bytes through VirtualTerminal both with and without stderr interleaving.
  • docs/incidents/647/captures/2026-05-17/analysis.md — human-readable writeup with sanity checks (width-mismatch = 0/2210, wrap-mismatch = 0/2210), the differential finding, and recommended next steps (clean-baseline HITL capture, instrumentation fix to use a file sink).
  • src/lib/cli-ui/scrollback-harness.ts — minimal stderrWrite injection on TerminalHarness (test-only file; +11 -0) so the test renderer's stderr writes route into the same VT.
  • src/lib/cli-ui/scrollback-harness.test.ts — lifts the prior .skip on the Mechanism feat: Complete remaining v1.0 features (AC-10, AC-13, AC-14) #1 reproduction. New test exercises out-of-band writes between log-update redraws and asserts headerCount === 1 in (visible + scrollback). Marked it.fails per the AC-2 contract: test reproduces the bug on main (produces 7 occurrences instead of 1), passes once AC-3 lands.

AC status

Out of scope (deferred to next iteration)

  • Modifying run-renderer.ts production code — fix direction now clear (handle out-of-band writes), but a clean-baseline HITL capture is recommended before committing to a specific approach.
  • Moving SEQUANT_DEBUG_RENDERER output to a file sink so future investigations don't suffer the same amplification.
  • Re-running the original 2-issue parallel scenario without instrumentation to confirm post-fix(#656): wire renderer pause/resume into phase execution #659 baseline magnitude.

Test plan

  • npx vitest run src/lib/cli-ui/ → 92 passed, 1 expected fail (the new test, as required)
  • npm run build → clean
  • Reproducibility: npx tsx docs/incidents/647/captures/2026-05-17/analyze-trace.ts → outputs the differential report
  • (next iteration) Clean-baseline capture WITHOUT SEQUANT_DEBUG_RENDERER=1

Refs #647, #662.

…ollback

Forensic VT replay of `docs/incidents/647/captures/2026-05-17/terminal.typescript`
shows PR #661's "Mechanism #1 confirmed at 2181× over 36m" was reading the wire
traffic count (`grep -c`), not actual scrollback occurrences. log-update's
eraseLines escapes appear in the typescript file but don't delete prior bytes —
those bytes only disappear in a real terminal.

When the raw bytes are replayed through a 213×31 VirtualTerminal:
  - WITHOUT the embedded SEQUANT_DEBUG_RENDERER stderr lines: 1 scrollback header
  - WITH them (script(1) merged them into the same pty): 2171 scrollback headers
  - Amplification: 2171×

The "Mechanism #1 at scale" was an instrumentation artifact. In a real user
terminal without `SEQUANT_DEBUG_RENDERER=1`, log-update's eraseLines works
correctly. The underlying bug is Mechanism #2-class: any out-of-band writer
(stderr instrumentation, subprocess output landing outside a paused window)
breaks log-update's cursor model and strands prior frames in scrollback.

Deliverables in this commit:

- `docs/incidents/647/captures/2026-05-17/analyze-trace.ts`: reproducible
  forensic script. Extracts SEQUANT_DEBUG_RENDERER JSON from the typescript,
  bucket-counts header occurrences by trigger pattern, replays raw bytes
  through VirtualTerminal both with and without stderr interleaving.

- `docs/incidents/647/captures/2026-05-17/analysis.md`: human-readable writeup
  of the finding with TL;DR, sanity checks (width-mismatch and wrap-mismatch
  both confirmed at 0/2210), and recommended next steps.

- `src/lib/cli-ui/scrollback-harness.ts`: minimal `stderrWrite` injection on
  `TerminalHarness` so the test renderer's stderr can be routed into the same
  VT (mirrors how a real pty merges stdout/stderr when both share a tty).

- `src/lib/cli-ui/scrollback-harness.test.ts`: lifts the prior `.skip` on the
  Mechanism #1 reproduction. New test exercises out-of-band writes between
  log-update redraws and asserts `headerCount === 1` in (visible + scrollback).
  Marked `it.fails` per the AC-2 contract: test reproduces the bug on main
  (currently produces 7 occurrences instead of 1), passes once AC-3 lands.
  Also includes the AC-C Symptom 2 byte-integrity assertion bundled from #662.

No production renderer code changed — fix lands in a separate iteration once
the diagnosis is socialised.

Refs #647, #662.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant