Skip to content

fix(terminal): keep restored OSC-8 ranges across a no-op resize - #17759

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-restored-osc-links-resize
Sep 1, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-restored-osc-links-resize

Conversation

@nwparker

@nwparker nwparker commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

Fixes #17756.

ELI5

Terminals can contain clickable links. When Orca restores a terminal's history after a restart, it recovers those links along with the text.

It was throwing them away. Restored links are remembered by which row they're on, so if the terminal gets resized the remembered positions are wrong and Orca clears them — correct. But it also cleared them when the terminal was "resized" to the size it already was, which isn't a resize at all. That happens routinely: every time you reattach to a terminal, Orca re-asserts its dimensions.

So the common case — restore a session, reattach to it — silently lost every clickable link in the restored scrollback. Now a resize only clears them when the size actually changed.

The bug

HeadlessEmulator.resize() cleared restoredOscLinks unconditionally:

resize(cols, rows) {
  if (this.disposed) return
  this.restoredOscLinks = []      // fires even when dimensions are unchanged
  this.terminal.resize(cols, rows)
}

The cold-restore path seeds the ranges and then replays records that resize:

  • history-reader.ts:298 — setRestoredOscLinks(checkpoint.oscLinks) → :313 — replay.resize(record.cols, record.rows)
  • daemon-durable-history-snapshot.ts:91 (set) → :180 (resize, via replayPendingRecords)

And same-size resize records genuinely reach the durable log: session-output-plane.ts:109-111 records every resize with no same-size dedupe, while every attach re-asserts the pane's dimensions.

Net effect: cold-restore a session whose post-checkpoint log holds any resize record — including a no-op one from an ordinary reattach — and the checkpoint's OSC-8 ranges are dropped. Restored hyperlinks lose clickability. Cosmetic fidelity loss, not corruption.

Where it was introduced

d46349c — fix: improve mobile link modifier handling (#5597), 19 Jun 2026.

That commit added setRestoredOscLinks and, in the same change, unconditional clearing in both resize() and clearScrollback():

     if (this.disposed) {
       return
     }
+    this.restoredOscLinks = []
     this.terminal.resize(cols, rows)

The intent was right — row-indexed ranges don't survive a reflow — but the guard was missing, so it also fired on same-size resizes. clearScrollback()'s clearing from that commit is correct and is left alone (with a test pinning it).

Not a regression from the recent perf work

#17667 incidentally masked this by gating no-op resizes to protect a snapshot cache; #17752 removed that cache and with it the gate, restoring the pre-existing behavior byte-for-byte. So the bug was latent from June, briefly hidden, and is now fixed on its own terms — as a correctness change with tests, rather than as a side effect of a cache.

Fix

Return early when cols/rows already match. Chosen over deduping resize records in session-output-plane.ts because it fixes the root cause for every caller — live sessions, replay emulators, and runtime mirrors — not just the durable-log path.

Verification

New headless-emulator-restored-osc-links.test.ts, 5 cases. Confirmed the two same-size cases fail before the fix and pass after; the three real-invalidation cases (col change, row change, clearScrollback) pass throughout, so the fix doesn't over-correct.

pnpm tc clean; 2956 tests pass across src/main/daemon and the runtime suites; changed-code quality gate clean.

Risk

Daemon-only; no renderer, wire, or persisted-format change.

Cold restore seeded a checkpoint's OSC-8 link ranges and then replayed records
that resize, so any resize record after the checkpoint dropped them and
restored hyperlinks in scrollback lost clickability. Same-size resize records
reach the durable log routinely, because every attach re-asserts the pane's
dimensions and session-output-plane records each one without a same-size
dedupe — so an ordinary reattach was enough to lose the links.

Restored ranges are row-indexed, so clearing them on a reflow is right; a
resize to the size already applied is not a reflow. Gate on the dimensions
actually changing.

Introduced in d46349c ("fix: improve mobile link modifier handling",
#5597), which added setRestoredOscLinks along with unconditional clearing in
both resize() and clearScrollback(). clearScrollback's clearing is correct and
is unchanged, with a test pinning it.

Found during adversarial review of #17752 and filed as #17756. Not a
regression from that PR: #17667 had incidentally masked it by gating no-op
resizes to protect a snapshot cache, and removing the cache removed the gate.
The same gate returns here on its own terms — as a correctness fix with tests,
rather than as a side effect of a cache.
@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR preserves restored OSC-8 hyperlink ranges when a terminal receives a no-op resize while continuing to invalidate them after actual dimension changes or scrollback clearing.

  • Adds a same-dimension guard to HeadlessEmulator.resize.
  • Adds focused coverage for no-op resize replay and genuine invalidation paths.

Confidence Score: 5/5

The PR appears safe to merge, with focused behavior and regression coverage for both preservation and invalidation paths.

The new guard suppresses only resize calls whose requested dimensions already match the terminal, while real dimension changes still clear restored hyperlink ranges and reach the underlying terminal resize.

Important Files Changed

Filename Overview
src/main/daemon/headless-emulator.ts Adds an early return for unchanged dimensions so restored row-indexed OSC-8 ranges survive no-op resize records.
src/main/daemon/headless-emulator-restored-osc-links.test.ts Verifies preservation across same-size resizes and invalidation after column changes, row changes, and scrollback clearing.

Reviews (1): Last reviewed commit: "fix(terminal): keep restored OSC-8 range..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: bc19beed-29e6-44bb-a41e-0dbbc7703544

📥 Commits

Reviewing files that changed from the base of the PR and between 8ac1c6e and 22666e1.

📒 Files selected for processing (2)
  • src/main/daemon/headless-emulator-restored-osc-links.test.ts
  • src/main/daemon/headless-emulator.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

HeadlessEmulator.resize now returns early when the requested dimensions match the current terminal dimensions. Same-size resizes no longer clear restored OSC-8 links or call terminal.resize. New Vitest cases cover same-size resize retention, replayed resize records, dimension and row-count changes, scrollback clearing, and emulator cleanup.

Merge Risk: ⚪ Minimal · up to 22666

This change preserves clickable links in restored terminal history during no-op resizes while still clearing link ranges when dimensions actually change. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes preserving restored OSC-8 ranges across no-op terminal resizes.
Description check ✅ Passed The description explains the problem, cause, fix, scope, linked issue, and verification. It is sufficiently complete despite omitting several optional template headings and checklist items.
Linked Issues check ✅ Passed The implementation directly satisfies issue #17756 by preserving restored OSC-8 links across same-size resizes while still clearing them after dimension changes and scrollback clearing.
Out of Scope Changes check ✅ Passed The changes are limited to the required daemon fix and focused regression tests. No unrelated code, protocol, persistence, or renderer changes are included.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ 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.

@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

  • Early return on same-size resize — HeadlessEmulator.resize() now returns before clearing restoredOscLinks when this.terminal.cols/rows already match the requested dims, so restored OSC-8 ranges survive the same-size resize records that cold restore replays on every reattach.
  • Focused regression suite — five exact-toEqual cases pinning same-size keep, col/row-change drop, repeated same-size replay, and the (unchanged) clearScrollback drop.

The guard is sound: terminal.cols/rows are only ever mutated by resize() itself, so the equality check exactly matches "no reflow happened". The fix corrects the root cause for every caller (live, replay, runtime mirrors) rather than deduping records at the durable-log layer, and clearScrollback()'s clearing is correctly left intact. Tests are exact and the two same-size cases fail against the pre-fix behavior; I verified the suite passes (5/5). Daemon-only, no wire or persisted-format change.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit ae35e04 into main Sep 1, 2026
35 checks passed
Jinwoo-H added a commit that referenced this pull request Sep 2, 2026
Hosted iOS security e2e (three branch-only harness bugs):
- `simctl privacy grant` terminates the app; the relaunch cold-resumes
  straight onto the session route, so skip workspace-row activation when
  the hybrid handoff already landed on /session/. Activation failures now
  name the document href.
- Uploaded-path regex fused two abutting orca-paste-*.png paths; use a
  lazy segment quantifier.
- Photos orders by capture date, which addmedia takes from file birth
  time; stage a freshly written fixture copy (copyFile clones birth time
  on APFS) so "last Photo" is the fixture.

Root tests:
- Allowlist walker skips -test-fakes / -test-fixture(s) / .test-support
  sources, which are not mobile call sites.
- Drop the height-only OSC-8 test: main's #17759 clears restored ranges
  on any dimension change and pins it.
- Drop serve-update-handoff-startup-order.test.ts: main pins the same
  order against main-process-preflight.ts.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#17759)

Cold restore seeded a checkpoint's OSC-8 link ranges and then replayed records
that resize, so any resize record after the checkpoint dropped them and
restored hyperlinks in scrollback lost clickability. Same-size resize records
reach the durable log routinely, because every attach re-asserts the pane's
dimensions and session-output-plane records each one without a same-size
dedupe — so an ordinary reattach was enough to lose the links.

Restored ranges are row-indexed, so clearing them on a reflow is right; a
resize to the size already applied is not a reflow. Gate on the dimensions
actually changing.

Introduced in 10fe9a0 ("fix: improve mobile link modifier handling",
stablyai#5597), which added setRestoredOscLinks along with unconditional clearing in
both resize() and clearScrollback(). clearScrollback's clearing is correct and
is unchanged, with a test pinning it.

Found during adversarial review of stablyai#17752 and filed as stablyai#17756. Not a
regression from that PR: stablyai#17667 had incidentally masked it by gating no-op
resizes to protect a snapshot cache, and removing the cache removed the gate.
The same gate returns here on its own terms — as a correctness fix with tests,
rather than as a side effect of a cache.
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.

Cold restore drops OSC-8 link ranges when a no-op resize record follows the checkpoint

1 participant