Skip to content

feat(#647): AC-1 instrumentation + AC-2 harness scaffolding + AC-3 grid-math fix (diagnose-first foundation) - #653

Merged
admarble merged 4 commits into
mainfrom
feature/647-fix-cli-624-s-duplicate-header-fix-doesn-t-catch-r
May 16, 2026
Merged

admarble merged 4 commits into
mainfrom
feature/647-fix-cli-624-s-duplicate-header-fix-doesn-t-catch-r

Conversation

@admarble

@admarble admarble commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the width-misreporting class of the duplicate-SEQUANT WORKFLOW · header regression — when the renderer + log-update agree on a column width that disagrees with the physical terminal (cached process.stdout.columns, TTY emulation layers, npx-piped stdout, SIGWINCH timing). Lands the diagnose-first foundation (instrumentation, harness, false-green warning) along with the surgical fix and a regression test that fails on master and passes with the fix.

Mechanism #1 (scrollback erasure from event-line scrolling) is still open — capping the grid width doesn't address it. AC-1 instrumentation is in place; production replay is the next gate. Tracked back in #647.

Filed #652 for AC-4 (renderer bottom-output corruption symptoms) per spec's "do NOT bundle into the AC-3 fix" requirement.

What landed

  • AC-1 — production instrumentation: SEQUANT_DEBUG_RENDERER=1 env gate emitting JSON-lines per logUpdate* callsite. Wrap-aware: wrappedLineCount uses stringWidth to approximate log-update's post-wrapAnsi previousLineCount; logicalLines reports the pre-wrap newline count separately so a debug-log reader can spot wrap-induced divergence directly.
  • AC-2 — virtual-terminal harness + RED-on-master test: scrollback-harness.ts drives a real createLogUpdate against a VT model with separate visible viewport and scrollback. The width-misreporting test fails on master (header count > 1) and passes with the AC-3 fix. A Mechanism feat: Complete remaining v1.0 features (AC-10, AC-13, AC-14) #1 scenario remains as it.skip(...) scaffold — production-evidence-gated.
  • AC-3 — fix: cap the rendered grid at min(cols, 78) (was min(cols, 110)). With the cap, the rendered grid is always narrower than any standard 80-col terminal even when cols is reported wider than the physical terminal. The previous -7 → -9 correction is preserved as the underlying box-drawing arithmetic fix. AC-3 derived test: new invariant test asserts rendered border width equals min(cols, 78) at practical widths (80/100/200), locking the math against future drift.
  • AC-D3 — getTestStub() warning: comment at run-renderer.ts:668 warns that the stub does not model log-update's scrollback semantics; future header-count assertions MUST use the scrollback-harness. Prevents a feat(cli): run renderer follow-ups — frame stability, attempt counter, summary teardown (#618 follow-up) #624-style false-green recurrence.
  • AC-1 docs: new "Debugging renderer regressions" section in docs/features/run-renderer.md with the JSON-lines schema and divergence diagnostic guidance.
  • AC-4 — separate issue: filed as fix(cli): renderer bottom-output corruption — ✔ #5loop missing chars + U+FFFD in summary separator #652.

Acceptance criteria status

AC Status Why
AC-1 MET (instrumentation + smoke) with one open sub-item Instrumentation infrastructure landed, runs cleanly (exit 0, 10 JSON-lines, valid JSON, all fields populated), and the metric is now wrap-aware. The "verified repro + frequency baseline" sub-bullets still require a human-driven production replay; the instrumentation is the prerequisite.
AC-2 MET Harness drives real createLogUpdate. Width-misreporting test fails on master (RED) and passes with the AC-3 fix (GREEN). Spec's "Test must FAIL on main" literal requirement is satisfied for this mechanism class. Mechanism #1 reproduction is a deferred follow-up.
AC-3 MET for width-misreporting class min(cols, 78) cap + box-drawing math correction (-9). AC-2 test passes. Mechanism #1 remains an open follow-up; not bundling speculative fixes per the issue's diagnose-first requirement.
AC-4 MET (per spec) Filed as #652 with verbatim repro and link back. Spec explicitly says: "If independent, file a separate issue... Do not bundle into the §3 fix." Independent-vs-shared determination is gated on AC-1 evidence, also captured in #652.
AC-D1 (PR cites mechanism + AC-1 evidence) PARTIALLY_MET This PR description cites which mechanism class (width misreporting) was fixed and references the test that catches it. AC-1 production debug-log evidence (the other half) awaits the human-driven replay.
AC-D2 (PR includes RED-on-master output) MET RED-on-master output captured locally during this PR's preparation (sed-revert + vitest run produced header count > 1 + grid width = 82 instead of 78); see commit c244f5d description for the methodology.
AC-D3 (getTestStub() warning) MET Comment landed at run-renderer.ts:668.

Quality gates

RED→GREEN evidence (AC-D2)

With the prior Math.min(cols, 110) - colW - 7 formula, the width-misreporting scenario (streamColumns=100, rendererColumns=100, vt.cols=80) produces grid rows 102 cols wide that the 80-col VT wraps; log-update's previousLineCount undershoots; the prior frame's header survives in scrollback each redraw. The harness reports header count > 1 and dumps visible + scrollback for inspection.

With this PR's min(cols, 78) cap, the same scenario produces exactly one header (the grid is 78 cols wide, fits in the VT without wrap, log-update's line tracking matches). The grid-width invariant test additionally confirms borderRow.length === min(cols, 78) at cols=80/100/200.

Test plan

Commits

  • 73acdea — initial AC-1 instrumentation + AC-2 harness extension + AC-3 grid-math math correction + AC-D3 warning
  • f1a0adb — merge origin/main
  • c244f5d — gap-fix pass: un-skip AC-2 test, cap at 78 (the real AC-3 fix), wrap-aware AC-1 metric, AC-3 invariant test, docs section, smoke-verified instrumentation

Related

admarble added 3 commits May 14, 2026 03:25
Wires a real `createLogUpdate` instance through a virtual-terminal model
that tracks both visible viewport and scrollback, so future tests can
assert on `(visible + scrollback)` instead of just the most recent frame
(which is what `getTestStub()` exposes and is the reason #624's tests
shipped green despite the bug).

What this commit lands:
- `scrollback-harness.ts`: VirtualTerminal modelling rows + scrollback +
  the ANSI escape vocabulary that `log-update@7` + `ansi-escapes` emit
  (cursor up/down/forward/back, eraseLine variants, SGR strip, mode
  set/reset, save/restore).
- `RenderOptions.logUpdateInstance`: test-only injection point so
  TTYRenderer can drive the harness's real log-update instead of the
  existing `getTestStub()` mock. Production paths unchanged.
- `scrollback-harness.test.ts`: two scenarios (basic + pause/resume with
  verbose subprocess streaming) that drive the renderer through the
  harness and count `SEQUANT WORKFLOW · ` occurrences in
  (visible + scrollback).

Status against AC-2 (test must FAIL on `main` before fix):
- Both assertions currently PASS. The harness does not yet reproduce the
  production bug. log-update@7 internally pre-wraps via `wrapAnsi` and
  tracks the wrapped line count, so `eraseLines(previousLineCount)`
  covers the full rendered height in the model.
- The production bug therefore lives in a real-terminal behaviour the
  VT doesn't model — most likely candidate-mechanism #2
  (subprocess/log-update stream.columns disagreement) or #4
  (`process.stdout.rows` undefined under `npx` causing log-update's
  `fitToTerminalHeight` to clip while the renderer assumes the full
  height). AC-1 instrumentation is the intended next step to pin which.
- Once the mechanism is identified, the harness can be extended (e.g.
  decouple stream.columns from VT.cols to simulate the mismatch) to make
  the assertions fail on `main` as AC-2 requires.

Remaining ACs for follow-up work in this PR:
- AC-1: production instrumentation under `SEQUANT_DEBUG_RENDERER=1`
- AC-2: harness extension that reproduces (red on main, green on fix)
- AC-3: surgical fix once AC-1 pins the mechanism
- AC-4: independent diagnosis of `✔ #5loop` + U+FFFD corruption
…3 grid math fix

Lands the diagnose-first foundation for the duplicate-header regression
without committing to a fix direction before AC-1 evidence is captured.

AC-1: Production instrumentation
- `SEQUANT_DEBUG_RENDERER=1` gate at every `logUpdateImpl`/`logUpdateClear`/
  `logUpdateDone` callsite. Emits one JSON line per call to stderr with
  `{t, op, frame, rendererCols, rendererRows, stdoutCols, stdoutRows,
  wrappedLineCount}` so a real `npx sequant run ... 2> debug.jsonl` pins
  which of the candidate mechanisms in the #647 issue body is firing.
- Stderr keeps stdout clean for the live zone; user redirects when needed.

AC-2: Harness extension
- `HarnessOptions.streamColumns` / `streamRows` overrides let the harness
  decouple what `log-update` is told (via `stream.columns`/`rows`) from the
  VirtualTerminal's physical dimensions. Useful for future scenarios that
  reproduce width-misreporting bug classes.
- Test file header updated to be honest about scope: the existing
  scrollback-harness scenarios pass on master AND with the AC-3 grid fix,
  so they do NOT yet reproduce Mechanism #1. A `.skip`'d scaffold for the
  event-only flood scenario captures the intent; AC-1 instrumentation
  evidence is the prerequisite for tightening it.

AC-3: Box-drawing grid-width overflow (partial)
- `renderSingleIssueFrame` and `renderRunGrid` both used `cols - colW - 7`,
  but the rendered grid actually consumes `colW + innerWidth + 9` chars
  (2 leading spaces + 3 vertical bars + 4 cell padding). The prior formula
  produced rows 2 chars wider than `cols`, which made log-update wrap every
  grid border line internally. Fixed to `- 9` so total grid == cols.
- This addresses one class of wrap-induced previousLineCount divergence
  but does NOT solve Mechanism #1 (scrollback erasure when event-line
  writes scroll the frame above the visible viewport). The full fix awaits
  AC-1 evidence per the issue's diagnose-before-fix requirement.

AC-D3: `getTestStub()` warning
- Comment added on `getTestStub()` warning that the stub does not model
  log-update's scrollback semantics, so header-count assertions MUST use
  the scrollback-harness — preventing the #624 false-green recurrence.

AC-4: Unaddressed in this commit; will be filed as a separate issue per
spec ("do NOT bundle into the AC-3 fix" if independent).

Tests: 89 pass / 1 skipped across src/lib/cli-ui/ (the skipped test is the
deferred Mechanism #1 scaffold). lint + build clean.
…s, wrap-aware metric

Closes the gaps from the previous diagnose-first commit (73acdea):

AC-2: un-skip the width-misreporting scenario
- Removed `it.skip(...)` on the column-mismatch test. With the prior `-7/110`
  formula it fails on master (header count > 1, grid renders at 102 cols and
  the 80-col VT wraps it, breaking log-update's `previousLineCount`
  accounting). With this commit's cap fix it passes (grid stays at 78 cols,
  fits within the VT, no wrap, no scrollback divergence).
- Reframed the test name and surrounding comments away from "Mechanism #2"
  toward Mechanism #4-adjacent (width misreporting between
  renderer/log-update and the physical terminal) — the honest classification.

AC-3: real fix — cap rendered grid at `min(cols, 78)` instead of `min(cols, 110)`
- Both `renderSingleIssueFrame` and `renderRunGrid` now cap at 78. This keeps
  the rendered width narrower than any standard 80-col terminal even when
  `process.stdout.columns` is wider than the physical terminal (cached value,
  TTY emulation layer disagreement, `npx`-piped stdout, etc.).
- The previous `-7 → -9` correction is preserved as the underlying box-drawing
  math fix. The cap is the user-visible behavior change.
- UX trade-off: wide-terminal users see an at-most-78-col progress grid
  instead of up-to-110-col. The displayed data (issue numbers, phase names,
  durations) is short and fits comfortably; we accept the narrower display
  in exchange for wrap-resistance under width misreporting.

AC-3 derived (grid-width invariant test):
- New test asserts that the rendered border row width equals `min(cols, 78)`
  at practical widths (80/100/200). Locks the arithmetic against future
  drift in `colW`, padding, or the cap.

AC-1: wrap-aware `wrappedLineCount` metric
- Previously emitted `text.split("\n").length`, which is the LOGICAL line
  count, not what `log-update`'s `previousLineCount` actually tracks.
- Now uses `stringWidth` to approximate the post-`wrapAnsi` line count at
  `stream.columns`. Matches log-update's render path closely enough to
  spot divergence — the diagnostic case AC-1 was designed for.
- Also emits `logicalLines` separately so a debug-log reader can see when
  the two diverge (wrap is the culprit).

AC-1 smoke verification:
- Ran `SEQUANT_DEBUG_RENDERER=1 npx tsx -e '<test renderer>'` end-to-end.
  Exit 0, 10 well-formed JSON-lines emitted to stderr, all fields populated,
  `stdoutCols/stdoutRows` correctly reported as `null` in the
  no-real-TTY context (which is itself a useful diagnostic signal).

Documentation:
- Added `SEQUANT_DEBUG_RENDERER=1` to docs/features/run-renderer.md's
  "Modes & Settings" table and a new "Debugging renderer regressions"
  troubleshooting section with the JSON-lines schema and divergence
  diagnostic guidance.

Mechanism #1 (scrollback erasure from event-line scrolling) remains an
open follow-up — capping doesn't address it. AC-1 instrumentation is in
place; production replay is the next gate.

Tests: 97 passed / 1 skipped (the deferred Mechanism #1 scaffold).
Lint + build clean.
@admarble
admarble merged commit 7412850 into main May 16, 2026
5 checks passed
@admarble
admarble deleted the feature/647-fix-cli-624-s-duplicate-header-fix-doesn-t-catch-r branch May 16, 2026 04:38
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