Skip to content

fix(cli): renderer bottom-output corruption — ✔ #5loop missing chars + U+FFFD in summary separator #652

Closed

Description

@admarble

Context

Spun out from #647 AC-4 per its own instructions: "If independent, file a separate issue with full repro and link back here. Do not bundle into the §3 fix."

While addressing #647 (duplicate-header bug), the same motivating transcript surfaced two additional rendering symptoms that are not explained by the duplicate-header mechanisms. Per #647 spec AC-4, they may or may not share a root cause; independent diagnosis is required before that determination.

Symptoms (from #647 transcript, npx sequant run 504 505 -q, v2.3.0)

Symptom A — missing characters mid-string

✘ #505 qa  QA verdict: AC_MET_BUT_NOT_A_PLUS
▸ #505 loop
✔ #5loop  Claude Code returned an error result: ...

✔ #5loop should be ✔ #505 loop. Characters 05 are missing from the middle of the event line. This is NOT a clearing artifact — characters vanished mid-string after the line was already written. Likely candidates:

  • Overwrite from concurrent live-frame redraw landing on a partial event line
  • appendEventLine (src/lib/cli-ui/run-renderer.ts:649-691) racing with renderer state mutation when the loop phase starts
  • String-slicing bug in event formatting

Symptom B — U+FFFD in summary table

├───────�     │ 33m 41s    │

A border row visually overlaid with a data row, with U+FFFD (replacement character) in the middle. Most likely in TTYRenderer.renderSummary (now run-renderer.ts:704) teardown path — non-UTF-8 byte emitted into a UTF-8 stream, or truncation at a multibyte boundary.

Why this is filed separately

The #647 issue's AC-4 explicitly required: "If neither shares a root cause with AC-1's mechanism, file a new issue with verbatim repro and link back to #647. Do not bundle into the AC-3 PR."

Without AC-1 production-instrumentation evidence yet captured (the AC-1 instrumentation infrastructure landed in the #647 PR but has not been replayed against a live duplicate-header run), shared-root-cause cannot be confirmed. Filing this issue keeps the corruption symptoms tracked independently while #647 focuses on the primary scrollback bug.

Acceptance criteria

Out of scope

Related

Activity

  1. added
    bug
    cli
    ui
    complex
    on May 15, 2026
  2. admarble commented on May 15, 2026

    @admarble
    ContributorAuthor

    Plan Complete (/fullsolve)

    This is a diagnose-first renderer issue. The plan below treats reproduction as the prerequisite for any fix.

    Hard dependency on #647

    AC-5 explicitly requires src/lib/cli-ui/scrollback-harness.test.ts — that file is introduced by PR #653 (issue #647) and does not yet exist on main. AC-3 also references #647's SEQUANT_DEBUG_RENDERER=1 instrumentation.

    Decision: Worktree is branched from feature/647-fix-cli-624-s-duplicate-header-fix-doesn-t-catch-r rather than main. If #647 merges first → rebase onto main (clean). If #647 is reworked → cherry-pick the harness files into #652's PR.

    AC checklist

    Working hypotheses (subject to AC-3 evidence)

    • Symptom A — appendEventLine's logUpdateClear() relies on log-update's previousLineCount, which under-counts when prior event lines exceeded terminal width. The next event-line write lands on a row that still has stale chars from the previous frame, eating chars mid-string when the new shorter line writes over a wrapped longer one.
    • Symptom B — In renderSummary, clearInterval(this.liveTimer) runs after logUpdateClear/logUpdateDone. The live-tick interval can fire between those calls, re-rendering the live frame into the output stream, splitting a multibyte box-drawing char at a byte boundary → U+FFFD.

    Implementation plan

    1. Worktree from fix(cli): #624's duplicate-header fix doesn't catch real log-update/scrollback bug (v2.3.0 regression confirmed) #647's branch (not main). All work targets src/lib/cli-ui/run-renderer.ts and extends scrollback-harness.test.ts.
    2. AC-1/AC-2 reproduction with synthetic events matching the motivating transcript.
    3. AC-3 instrumentation — reuse fix(cli): #624's duplicate-header fix doesn't catch real log-update/scrollback bug (v2.3.0 regression confirmed) #647's SEQUANT_DEBUG_RENDERER JSON-lines emitter.
    4. Fix candidates (try in order until tests GREEN):
      • Symptom A: cancel live timer at top of appendEventLine; or fix previousLineCount wrap math.
      • Symptom B: reorder renderSummary to clearInterval first, then clear/done log-update; or emit summary line-at-a-time so an interleaving write can't split a single line at a multibyte boundary.
    5. Regression gate: verify tests fail on HEAD~1 (or git stash the fix) and pass after.

    Open questions (proceeding with recommended defaults)

    1. Base on fix(cli): #624's duplicate-header fix doesn't catch real log-update/scrollback bug (v2.3.0 regression confirmed) #647 vs wait for it to merge? → Base on fix(cli): #624's duplicate-header fix doesn't catch real log-update/scrollback bug (v2.3.0 regression confirmed) #647's branch. Rebase if it merges; cherry-pick if it doesn't.
    2. What if Symptom B is non-deterministic? → Downgrade AC-5 for Symptom B to a call-order invariant assertion (clearInterval before any stdout write) instead of visible-output regression.
    3. Live claude subprocess vs synthetic events? → Synthetic events only (fix(cli): #624's duplicate-header fix doesn't catch real log-update/scrollback bug (v2.3.0 regression confirmed) #647 pattern); avoid live AI calls.

    Workflow

    Phases: spec → exec → qa (no browser test — ui here means terminal UI)
    Quality loop: enabled (complex label)

  3. admarble commented on May 15, 2026

    @admarble
    ContributorAuthor
    No description provided.
  4. admarble commented on May 15, 2026

    @admarble
    ContributorAuthor

    QA Review (/fullsolve)

    AC Coverage

    AC Description Status Evidence
    AC-1 Reproduce Symptom A MET (caveat) Scaffolding test + RED→GREEN column-mismatch invariant
    AC-2 Reproduce Symptom B MET (caveat) Scaffolding test + RED→GREEN call-order invariant
    AC-3 Diagnose each independently MET Hypotheses in commit messages and code comments
    AC-4 Decide shared vs independent root cause MET Shared mechanism (column/row mismatch under npx) but independent visible symptoms
    AC-5 Fix + RED→GREEN regression test MET Both symptoms have invariant tests that flip RED on pre-fix code

    Coverage: 5/5 ACs met

    Fixes

    1. Column-binding in TTYRenderer constructor: replace the unbound logUpdate singleton with createLogUpdate(boundStream), where boundStream.columns/rows getters delegate to the renderer's getColumns()/getRows(). Closes the process.stdout.columns === undefined mismatch window under npx.
    2. renderSummary teardown reorder: clearInterval(liveTimer) now runs before logUpdateClear/Done, so no pending tick can interleave between teardown and summary write.

    Tests

    • 3 new specs in scrollback-harness.test.ts (340 lines)
    • 2 RED→GREEN regression invariants (proven by reverting the fix and observing test failure)
    • All 93 existing renderer tests still pass

    Known Limits (documented in PR description)

    • The synchronous VT harness cannot model real OS-level pipe buffering or setInterval preemption, so the visible-symptom tests pass on both pre- and post-fix code. The RED→GREEN gates are property invariants (column binding, call order) tied to the documented mechanism.
    • Fix is hypothesis-driven. Production replay with SEQUANT_DEBUG_RENDERER=1 against the original transcript would validate the column-mismatch hypothesis; not performed here.

    Verdict

    AC_MET_BUT_NOT_A_PLUS — All ACs met with explicit caveats. Defensive fix is well-motivated and matches the issue's "likely candidates"; ship as a follow-up on top of #647 per the issue body's instructions.

    Follow-ups (not blocking)

    • PTY-based harness for true visible-symptom regression coverage
    • Production replay with SEQUANT_DEBUG_RENDERER=1 to validate the column-mismatch hypothesis empirically
  5. admarble commented on May 15, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Status: READY (with caveats)

    Summary

    Iterations

    Phase Iterations Status
    Spec 1/1 Complete
    Exec 1/1 Complete
    QA 1/2 Complete (AC_MET_BUT_NOT_A_PLUS — break, no /loop)
    PR 1/1 #654 created

    Risk Assessment (from QA self-evaluation)

    • Likely failure mode: Column-mismatch is the most likely mechanism per fix(cli): #624's duplicate-header fix doesn't catch real log-update/scrollback bug (v2.3.0 regression confirmed) #647's documented analysis, but if the production symptoms have a different root cause (e.g., concurrent SIGWINCH redraw, stderr-on-stdout interleaving from claude subprocess), this fix won't address it. Verdict: medium confidence; ship as defensive fix.
    • Not tested: Visible-symptom reproduction in a real terminal. The synchronous VT harness models cursor/erase semantics but not OS-level pipe buffering or pending setInterval ticks. Follow-up: PTY-based harness.

    Next Steps

    1. Review and merge feat(#647): AC-1 instrumentation + AC-2 harness scaffolding + AC-3 grid-math fix (diagnose-first foundation) #653 (parent issue fix(cli): #624's duplicate-header fix doesn't catch real log-update/scrollback bug (v2.3.0 regression confirmed) #647) first — this PR is stacked on it
    2. Then rebase fix(#652): renderer bottom-output corruption — column-binding + renderSummary teardown order #654 onto main and merge
    3. Optional follow-ups: PTY harness + production replay validation
  6. added a commit that references this issue on May 16, 2026
  7. admarble commented on May 16, 2026

    @admarble
    ContributorAuthor

    Gap-fix update on #654

    Four adversarial reviewers found gaps in the original PR. All HIGH-severity findings addressed in commit 89fb02a and reflected in PR #654's rewritten description.

    What changed

    Finding Severity Action
    isTTY: true hardcoded → ANSI pollution under pipes HIGH Now get isTTY() { return Boolean(process.stdout.isTTY) }
    Symptom B fix claim is theater (JS single-threaded) HIGH Comment rewritten; reorder kept as structural cleanup only
    Symptom A scaffolding tests bypass production fix path HIGH Deleted (2 tests). Replaced with one hardened invariant
    Symptom A invariant has false-GREEN risk MEDIUM Now asserts directly on _boundStream.columns/isTTY (private field)
    Symptom B invariant has tautology risk MEDIUM Added precondition + asserts logUpdateClear was actually called
    Type cast over-aggressive LOW Documented why double-cast is necessary (log-update requires WritableStream)
    PR description lacks stacking callout LOW Rewritten with explicit "files in scope" section
    Commit history messy LOW Will resolve at squash-merge

    Honest reframing

    The new PR description acknowledges:

    Still RED→GREEN

    Both invariants verified RED on pre-fix code by reverting each fix locally:

    • Symptom A: _boundStream = null → "expected null not to be null"
    • Symptom B: revert clearInterval to after clear/done → "expected true to be false"

    All 91 cli-ui tests pass on post-fix code; lint clean.

    Recommended follow-ups (filed in PR description, not blocking)

    1. PTY-based harness for visible-symptom regression coverage
    2. Production replay with SEQUANT_DEBUG_RENDERER=1 to validate the column-mismatch hypothesis
    3. SIGWINCH race investigation
  8. admarble commented on May 16, 2026

    @admarble
    ContributorAuthor

    Investigation update — PR #654 closed; tracking continues in #655

    Post-merge of #647, eight parallel agents investigated this issue:

    • PR fix(#652): renderer bottom-output corruption — column-binding + renderSummary teardown order #654's column-binding fix does not address Symptom A. Real-terminal reproduction in PTYs ruled out the column-mismatch hypothesis: wrapAnsi bakes \n into the output, so previousLineCount always matches the terminal's row count regardless of stream.columns.
    • log-update v7 cannot produce mid-string corruption internally — line-level diff with full ESC[2K per changed line, no partial overwrites.
    • No claude subprocess writes to stdout in non-verbose mode (the user's case here: -q). The SDK runs in-process and captures all output.
    • Byte-level forensics identified a precise pattern — corruption equals complete_line[0:8 bytes] + failed_line[col 9 onward] — but no proven single-process mechanism produces it.

    The actual cause remains unknown. Investigation continues in #655 with all ruled-out hypotheses listed up-front so future work doesn't relitigate them.

    Side find filed as #656: TTYRenderer.pause() / resume() are dead code in production because batch-executor.ts never passes the spinner argument. Affects --verbose mode rendering integrity. Unrelated to the symptoms here but discovered along the way.

    This issue stays open — the production bug is real and unfixed. Closing only after a targeted fix lands.

  9. admarble commented on May 17, 2026

    @admarble
    ContributorAuthor

    Closing as superseded — the umbrella has been split into three focused issues:

    PR #654's defensive column-binding fix was refuted by post-#647 adversarial review; that work is preserved on feature/652-fix-cli-renderer-bottom-output if any of it becomes useful once Mechanism #1's fix lands.

    No code lives under this issue; closing to keep the cluster traceable through the three focused successors.

  10. added 4 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclicomplexui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions