Skip to content

Reuse terminal buffer cells during readiness scans - #25161

Merged
nwparker merged 1 commit into
mainfrom
nwparker/ci-cursor-read-cells-20261004
Oct 4, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/ci-cursor-read-cells-20261004

Conversation

@nwparker

@nwparker nwparker commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42

ELI5

Terminal context scans reuse one buffer cell instead of allocating one for each column. Captured composer and readiness output stays identical; three hosted pairs cut a slow census workload by 10.1%.

What Changed

Accept the adapter's optional reusable-cell method and pass one local scratch cell through the existing scans. Keep the allocating fallback. Add controls for per-call lifetime and complete fallback output. Returned context contains the same strings, flags and wrapping information.

Why

Repeated cell allocations were a measured CPU cost in long captured transcripts. Reusing cells reduces that cost while retaining every frame and predicate. Skipping frames would weaken the readiness contract.

Linked Issue

N/A — internal CI performance work.

Visual Proof

N/A — no rendered or interaction change; full context/projection captures match.

Testing

  • Local cursor/composer checks, Node/web typecheck, lint and formatting passed.
  • Added scratch-lifetime and adapter-fallback controls.
  • Hosted measurement: three alternating one-worker ARM pairs, same 19 cases. Complete invocation median 37.141 → 33.387s (10.1%).
  • Separate six-suite captures retained all 192 cases and matched every context/projection: 643,926 of each, 7,465,308,324 length-prefixed payload bytes. Canonical per-test/type/order SHA256 f7440c0f1b5bbb57127cd29245530029415c8e9e243c1744359f330b3c7ace19.
  • All 41 consumer controls passed. Seven faults for dim/wide/bold/color/wrap/fallback/reuse failed expected assertions.
  • Focused workload savings do not establish whole-shard or queue-delay improvements; final-head required CI must pass before merge.

Review

The optional method preserves compatibility with minimal adapters. Scratch cells stay local to each call; returned data retains no cell references. Both browser and headless consumers typecheck. SSH execution and wire payloads are unchanged, as confirmed by full captured output parity.

Agent skill upstream boundary

  • Not applicable; no upstream skill source is copied.

Checklist

  • Focused on one allocation bottleneck.
  • Explained behavior, mechanism and rejected frame reduction.
  • N/A visual proof has a reason.
  • Reviewed cell lifetime and adapter compatibility.
  • Cross-platform, SSH and browser/headless behavior considered.
  • Local verification passed; required CI covers the final head.

@nwparker
nwparker marked this pull request as ready for review October 4, 2026 07:56
@coderabbitai

coderabbitai Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 95cd6462-b3a3-4ef8-b731-c63431c1b532
📥 Commits

Reviewing files that changed from the base of the PR and between ce07786 and 0fa3ebf.

📒 Files selected for processing (3)
  • docs/reference/ci-runner-efficiency.md
  • src/main/daemon/terminal-cursor-line-context.test.ts
  • src/shared/terminal-cursor-line-context.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Terminal cursor-context types and scan helpers now support an optional reusable cell. The reader obtains it from the active buffer and passes it to scans; adapters without getNullCell retain the allocating path. Tests cover cell reuse, per-read allocation, and adapter parity. Documentation records unchanged output parity, validation results, and a focused timing comparison.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 0fa3e

The reusable-cell path and adapter fallback have no identified merge-blocking issue. Normal final-head checks remain pending.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 0fa3e

The inspected change preserves the existing output structure and compatibility fallback. No new external access or privilege path was identified. Risk remains low rather than minimal because the underlying adapter’s overwrite and reentrancy behavior could not be fully verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated propagation scope is terminal context supplied to existing composer and readiness consumers. Incorrect adapter reuse could alter that projection, but the inspected change does not demonstrate expanded tenant, credential, service, or environment authority.

Trust Boundaries and Controls

  • observed — Terminal-origin characters and styling continue through the same text and visibility predicates into value-only context. The new capability comes from the active buffer object; terminal text does not select a factory, adapter, or privileged operation in the inspected reader.

Resilience and Maintainability Implications

  • inferred — Reader-side interruption does not leave a stored scratch reference or publish a partially assembled context: progress is local until return. This limits reader-side cleanup obligations, but does not resolve an adapter that shares storage or reenters during cell access.

Hardening Proposals

  • proposed — Document the optional adapter capability’s ownership and overwrite guarantees: scratch storage must remain safe across overlapping or reentrant reads, and getCell must populate every consumed character, width, and style property before returning. This would make the currently implicit assumptions explicit for future adapters.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: reusing terminal buffer cells during readiness scans.
Description check ✅ Passed The description covers the change, motivation, implementation, testing, visual proof, compatibility, and review considerations. It marks the linked issue as not applicable for internal CI work and not…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Single scratch cell per scan — readTerminalCursorLineContext now fetches one reusable cell via the optional buffer.getNullCell?.() and threads it through undimmedText, firstVisibleCellIsBold, and firstVisibleCellHasCustomForeground; the source/line types gained a Cell extends TerminalCursorCell generic plus optional getNullCell?().
  • Allocating fallback kept — adapters without getNullCell call getCell(column) and allocate per column; output is unchanged.
  • Test controls — new tests pin one cell allocation per invocation, no scratch retention between reads, and full output parity for the fallback adapter.
  • Docs — appends an October 4 entry to docs/reference/ci-runner-effiency.md.

I verified the reuse is behaviorally safe against the installed xterm: both @xterm/headless and @xterm/xterm BufferApiView.getNullCell() return a fresh CellData (not the internal shared null cell), getNullCell is not allowProposedApi-gated, and BufferLineApiView.getCell(x, cell) runs loadCell, which fully repopulates content/fg/bg/combinedData/extended. No cell reference escapes into the returned context. The focused suite passes (7/7).

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit b407d06 into main Oct 4, 2026
71 checks passed
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