Skip to content

test(term-fidelity): cursor-convention normalization + divergence discriminator#416

Merged
khaliqgant merged 2 commits into
mainfrom
feat/term-fidelity-divergence-forensics
Jul 17, 2026
Merged

test(term-fidelity): cursor-convention normalization + divergence discriminator#416
khaliqgant merged 2 commits into
mainfrom
feat/term-fidelity-divergence-forensics

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jul 17, 2026

Copy link
Copy Markdown
Member

Two diagnostic improvements to the term-fidelity matrix, distilled from the #403 fixer investigation (lead-endorsed evidence-first method). Test-harness only — no production/renderer code changed.

1. Cursor-convention normalization (deliverable)

The renderer cursor comes from xterm's buffer API (0-indexed [row,col]); the broker plain-snapshot cursor is 1-indexed — it mirrors the raw CUP coordinates. A stream ending in ESC[40;3H reports broker cursor [40,3] while xterm reports [39,2] for the same cell. Comparing the raw values makes a faithful render look like an off-by-one bug — this is exactly what misread #403's headline [39,2] vs [40,3].

The bundle meta now records:

  • rendererRaw0Indexed / brokerRaw1Indexed (raw values, labeled with their conventions),
  • normalized0Indexed (both converted to a common 0-indexed base),
  • match (bool) — a false here on an otherwise content-matching bundle is a real cursor divergence, not the convention artifact.

2. Raw-stream divergence discriminator

Taps the raw broker→renderer byte stream (onPtyChunk, post main-process dedup) and, on any divergence — including a telemetry-only reconciler repair — replays those exact bytes through a clean @xterm/headless at broker dims and diffs vs the broker snapshot and the live grid:

  • rawVsBroker == 0 → delivery is byte-clean; the divergence is RENDERER-INTERNAL.
  • rawVsBroker > 0 → bytes were lost/reordered before the renderer (DELIVERY-LOSS).

Plus: a scrollToBottom probe (distinguishes a stranded viewport from real content corruption), PEAR_DIAG_PTY per-chunk logging, and renderer-console capture. Writes raw.bin, raw-replay.txt, discriminator.txt, renderer-console.log into the divergence bundle and the reconciler-telemetry dir.

This is the tooling that classified #403 as a viewport-pin regression (not byte loss) and #415 (opencode) as delivery-clean / renderer-internal — turning "infer from aggregates" into "read the actual bytes" for every future divergence.

Verification

Refs #403 (fixed by #412), #415 (opencode vector, filed with this tooling's evidence).

🤖 Generated with Claude Code

Review in cubic

@khaliqgant khaliqgant added the no-agent-relay-review Disable agent-relay automated PR review/fixes label Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@khaliqgant, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f6284db-23ab-4cf7-b490-5c0bef901b9b

📥 Commits

Reviewing files that changed from the base of the PR and between 8e8b2e7 and 849e8ba.

📒 Files selected for processing (2)
  • tests/term-fidelity/harness.ts
  • tests/term-fidelity/oracle.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/term-fidelity-divergence-forensics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

khaliqgant and others added 2 commits July 18, 2026 00:59
…criminator

Two diagnostic improvements to the term-fidelity matrix, from the #403 fixer
investigation (lead-endorsed evidence-first method).

1. Cursor-convention normalization (bundle meta). The renderer cursor is xterm's
   0-indexed [row,col]; the broker plain-snapshot cursor is 1-indexed (it mirrors
   the raw CUP coords — a stream ending in ESC[40;3H reports broker [40,3] while
   xterm reports [39,2] for the SAME cell). Comparing the raw values makes a
   faithful render look like an off-by-one bug — this misread #403's headline
   "[39,2] vs [40,3]". Meta now records the raw values WITH their conventions,
   both normalized to a common 0-indexed base, and a computed `match` bool: a
   false there on an otherwise content-matching bundle is a REAL cursor
   divergence, not the convention.

2. Raw-stream divergence discriminator. Tap the raw broker->renderer byte stream
   (onPtyChunk, post main dedup), and on any divergence — including a
   telemetry-only reconciler repair — replay those exact bytes through a clean
   headless xterm at broker dims and diff vs broker and vs the live grid:
     rawVsBroker==0 -> delivery byte-clean; divergence is RENDERER-INTERNAL
     rawVsBroker >0 -> bytes lost/reordered before the renderer (DELIVERY-LOSS)
   Plus a scrollToBottom probe (stranded-viewport vs real content corruption),
   PEAR_DIAG_PTY per-chunk logging, and renderer-console capture. Writes
   raw.bin / raw-replay.txt / discriminator.txt / renderer-console.log into the
   bundle (and the reconciler-telemetry dir). This is what classified #403 as a
   viewport-pin regression (not byte loss) and #415 as delivery-clean.

Test-only; no production/renderer code changed. Refs #403, #412, #415.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@khaliqgant
khaliqgant force-pushed the feat/term-fidelity-divergence-forensics branch from e99eb1c to 849e8ba Compare July 17, 2026 22:59
@khaliqgant
khaliqgant marked this pull request as ready for review July 17, 2026 23:05
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@khaliqgant
khaliqgant merged commit 06137e1 into main Jul 17, 2026
5 checks passed
@khaliqgant
khaliqgant deleted the feat/term-fidelity-divergence-forensics branch July 17, 2026 23:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 849e8ba769

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let discriminator = 'raw-stream unavailable'
try {
const raw = await getRawStream(harness.page, agentName)
const rawReplay = await replayRawToGrid(raw, broker.rows, broker.cols)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replay resize history before classifying delivery loss

For the canonical resize-mid-stream workload (tests/term-fidelity/workloads.ts:326-357), PTY dimensions change repeatedly while these bytes are produced, but this replays the entire session once at the final dimensions. Resizes are out-of-band events, and xterm can reflow its buffer differently from the broker emulator during width changes, so even a perfectly delivered stream can produce rawVsBroker > 0 and be mislabeled DELIVERY-LOSS; the cumulative telemetry path repeats the same inference. Record and replay the dimension timeline, or avoid assigning a delivery verdict for sessions containing resizes.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-agent-relay-review Disable agent-relay automated PR review/fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant