Skip to content

Migrate terminal scrollback setting from bytes to rows - #6593

Merged
AmethystLiang merged 5 commits into
mainfrom
investigate-scrollback
Jun 28, 2026
Merged

AmethystLiang merged 5 commits into
mainfrom
investigate-scrollback

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

Migrates the terminal scrollback buffer setting from bytes (MB presets) to a row-based count (Row presets: 5k, 10k, 25k, 50k). This provides a more standard terminal configuration experience, optimizes memory usage, and allows dynamically applying scrollback updates to live, mounted panes without pane recreation or PTY interruption.

Key changes:

  • Replaced terminalScrollbackBytes with terminalScrollbackRows across settings types and store defaults.
  • Introduced terminal-scrollback-policy containing row presets (5,000 to 50,000 rows) and mapping logic from legacy byte settings to rows.
  • Added data migration in the main process persistence layer (Store) to convert legacy settings on startup and strip deprecated terminalScrollbackBytes.
  • Sanitized renderer-to-main IPC updates to drop stale byte settings and enforce row normalization.
  • Updated Settings UI (presets and custom input) and added full localization coverage across all supported locales (EN, ES, JA, KO, ZH).
  • Dynamically update live xterm.js terminal instance scrollback options via applyTerminalScrollbackRowsToMountedPanes on settings change without PTY disruption.

Screenshots

  • Settings UI updated from Megabytes (MB) to Rows (e.g., 5k, 10k, 25k, 50k). No other new UI behavior.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Evidence of testing:

  • Added comprehensive unit tests in src/shared/terminal-scrollback-policy.test.ts checking defaults, normalization, and byte-to-row migration.
  • Added migration integration tests in src/main/persistence.test.ts.
  • Added IPC sanitization tests in src/main/ipc/settings.test.ts.
  • Added reactive xterm.js option update tests in src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts.

AI Review Report

The code changes were thoroughly reviewed for correctness, edge cases, and cross-platform stability.

  • Migration Edge Cases: Verified that legacy settings are seamlessly converted upon first startup, writing back rows and removing old byte keys.
  • IPC Safety: Validated that malformed payloads from the renderer are caught, clamped, and normalized on the main-process side.
  • Cross-Platform Compatibility: Verified compatibility for macOS, Linux, and Windows; the row settings are applied identically to all terminal environments without platform-specific divergence.

Security Audit

  • Input Handling: The IPC handler sanitizes the renderer payload and enforces type and bounds normalization (clamping between 1,000 and 50,000 rows).
  • Execution & Storage: No command execution, external path handling, or secrets are involved. The storage writes strictly validated keys.

Notes

  • Deprecated terminalScrollbackBytes setting is gracefully stripped from the persisted storage.

Transition terminal scrollback configuration from a byte-based (MB)
limit to a row-based count to align with standard terminal emulator
behavior.

- Introduce a shared scrollback policy to handle normalization and
  safe migration of legacy byte presets to row equivalents.
- Update persistence logic to automatically convert and clean up legacy
  settings on startup and write-back.
- Refactor the advanced settings interface and localization strings
  to let users configure scrollback in terms of rows (up to 50k).
- Live-apply row limit changes directly to mounted xterm instances
  without recreating panes or restarting PTY sessions.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c104c392-2c51-4f73-9a9b-8ac231c677c4

📥 Commits

Reviewing files that changed from the base of the PR and between 54403d8 and ff42e02.

📒 Files selected for processing (3)
  • src/main/ipc/settings.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts

📝 Walkthrough

Walkthrough

The PR replaces terminal scrollback configuration from bytes (terminalScrollbackBytes) to rows (terminalScrollbackRows) across shared policy, persistence, IPC, renderer state/UI, terminal lifecycle, and locale strings. A new shared policy module defines row-based constants, normalization helpers, and legacy byte-to-row conversion. GlobalSettings now uses the rows field. Persistence and IPC strip legacy bytes and normalize rows. Renderer settings controls, terminal pane behavior, tests, and localization strings were updated to the row-based model.

🚥 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%. 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 summarizes the main change: migrating terminal scrollback from bytes to rows.
Description check ✅ Passed All required template sections are present and filled with relevant migration, testing, review, security, and notes details.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/shared/terminal-scrollback-policy.ts (1)

12-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the legacy MB→rows bucketing rationale.

The 17.5/37.5/75 MB cutoffs are policy-driven, not obvious from the code, so this migration will be hard to safely maintain without a short why-comment near the thresholds or conversion function.

As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Suggested diff
 export const LEGACY_TERMINAL_SCROLLBACK_BUCKET_5K_MAX_BYTES = 17_500_000
 export const LEGACY_TERMINAL_SCROLLBACK_BUCKET_10K_MAX_BYTES = 37_500_000
 export const LEGACY_TERMINAL_SCROLLBACK_BUCKET_25K_MAX_BYTES = 75_000_000
+
+// Why: legacy byte presets were coarse intent signals, not exact row budgets.
+// Bucket by nearest row preset so old settings land on the closest new preset.

Also applies to: 38-54

Source: Coding guidelines

src/shared/terminal-scrollback-policy.test.ts (1)

38-46: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the midpoint cutoffs explicitly.

The migration behavior depends on strict boundary choices at 17.5MB, 37.5MB, and 75MB, but the suite only checks representative preset values. Add exact-threshold assertions so an accidental </<= flip is caught immediately.

src/main/persistence.ts (1)

419-435: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short “Why” note for the migration precedence.

terminalScrollbackRows winning over legacy bytes and needsSave forcing a rewrite are compatibility rules, not obvious normalization behavior. A brief note here would make that intent much easier to preserve during future cleanup.
As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bade6d5d-962d-4acb-9204-6c89d7794dbc

📥 Commits

Reviewing files that changed from the base of the PR and between e51b2df and 54403d8.

📒 Files selected for processing (27)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/ipc/settings.test.ts
  • src/main/ipc/settings.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/renderer/src/components/settings/Settings.tsx
  • src/renderer/src/components/settings/SettingsConstants.ts
  • src/renderer/src/components/settings/TerminalAdvancedSection.tsx
  • src/renderer/src/components/settings/TerminalPane.pwsh.test.ts
  • src/renderer/src/components/settings/terminal-advanced-platform-search.ts
  • src/renderer/src/components/settings/terminal-search.test.ts
  • src/renderer/src/components/settings/useGhosttyImport.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-options.ts
  • src/renderer/src/store/slices/settings.ts
  • src/shared/constants.ts
  • src/shared/terminal-scrollback-policy.test.ts
  • src/shared/terminal-scrollback-policy.ts
  • src/shared/types.ts

Comment on lines 12 to +18
keywords: [
...translateSearchKeyword('auto.components.settings.terminal.search.f66a7cf715', 'terminal'),
...translateSearchKeyword(
'auto.components.settings.terminal.search.cde233f5da',
'scrollback'
),
...translateSearchKeyword('auto.components.settings.terminal.search.rows', 'rows'),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep legacy search aliases during the bytes→rows rename.

This entry no longer matches old queries like size, mb, or bytes, so users following older docs or habit will stop finding the control after the rename. Keep those as aliases while the migration is still fresh.

💡 Suggested change
     keywords: [
       ...translateSearchKeyword('auto.components.settings.terminal.search.f66a7cf715', 'terminal'),
       ...translateSearchKeyword(
         'auto.components.settings.terminal.search.cde233f5da',
-        'scrollback'
+        'scrollback',
+        { aliases: ['size', 'mb', 'bytes'] }
       ),
       ...translateSearchKeyword('auto.components.settings.terminal.search.rows', 'rows'),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
keywords: [
...translateSearchKeyword('auto.components.settings.terminal.search.f66a7cf715', 'terminal'),
...translateSearchKeyword(
'auto.components.settings.terminal.search.cde233f5da',
'scrollback'
),
...translateSearchKeyword('auto.components.settings.terminal.search.rows', 'rows'),
keywords: [
...translateSearchKeyword('auto.components.settings.terminal.search.f66a7cf715', 'terminal'),
...translateSearchKeyword(
'auto.components.settings.terminal.search.cde233f5da',
'scrollback',
{ aliases: ['size', 'mb', 'bytes'] }
),
...translateSearchKeyword('auto.components.settings.terminal.search.rows', 'rows'),

Transition terminal scrollback configuration from a byte-based (MB)
limit to a row-based count to align with standard terminal emulator
behavior.

- Introduce a shared scrollback policy to handle normalization and
  safe migration of legacy byte presets to row equivalents.
- Update persistence logic to automatically convert and clean up legacy
  settings on startup and write-back.
- Refactor the advanced settings interface and localization strings
  to let users configure scrollback in terms of rows (up to 50k).
- Live-apply row limit changes directly to mounted xterm instances
  without recreating panes or restarting PTY sessions.
Avoid committing terminal scrollback row setting changes on every
keystroke, which can trigger rapid updates with incomplete or
invalid numbers. Instead, manage a local draft state and commit to
settings only when the input is blurred or the user presses Enter.
@AmethystLiang
AmethystLiang merged commit b6c0cb4 into main Jun 28, 2026
2 of 3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Migrate terminal scrollback setting from bytes to rows

Transition terminal scrollback configuration from a byte-based (MB)
limit to a row-based count to align with standard terminal emulator
behavior.

- Introduce a shared scrollback policy to handle normalization and
  safe migration of legacy byte presets to row equivalents.
- Update persistence logic to automatically convert and clean up legacy
  settings on startup and write-back.
- Refactor the advanced settings interface and localization strings
  to let users configure scrollback in terms of rows (up to 50k).
- Live-apply row limit changes directly to mounted xterm instances
  without recreating panes or restarting PTY sessions.

* Migrate terminal scrollback setting from bytes to rows

Transition terminal scrollback configuration from a byte-based (MB)
limit to a row-based count to align with standard terminal emulator
behavior.

- Introduce a shared scrollback policy to handle normalization and
  safe migration of legacy byte presets to row equivalents.
- Update persistence logic to automatically convert and clean up legacy
  settings on startup and write-back.
- Refactor the advanced settings interface and localization strings
  to let users configure scrollback in terms of rows (up to 50k).
- Live-apply row limit changes directly to mounted xterm instances
  without recreating panes or restarting PTY sessions.

* defer updating terminal scrollback rows until blur or Enter

Avoid committing terminal scrollback row setting changes on every
keystroke, which can trigger rapid updates with incomplete or
invalid numbers. Instead, manage a local draft state and commit to
settings only when the input is blurred or the user presses Enter.
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