You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(terminal): judge live-agent reattach modes by the image's own title - #35920
After restarting a remote Orca server whose terminals kept running, a paired or browser client sometimes stopped sending mouse and focus events to a still-running agent such as Claude Code. Scrolling and clicking in the agent quietly broke. The client decided "is this an agent?" from a pane title that, for a moment after the restart, still read "Terminal 1". It now decides from the title the server attaches to the screen image it sends.
What Changed
Before: after an orca serve restart that kept its terminal daemon, a live agent pane could come back with mouse tracking and focus reporting turned off, depending on timing. Instrumented runs showed the host publishing the pane with its tab-default title, then seeding the daemon's live title about 180 ms later. If the client replayed the reattach snapshot inside that window, the post-replay reset saw no agent. It then applied the reset meant for plain normal-buffer programs, which disarms ?1003/?1004, even though the snapshot itself had just re-armed them.
After: the host adds the title it tracked when it took the image to the snapshot info. This is an additive lastTitle field, and it is sent only with the image's seq. The client uses that title for every decision about whether this image belongs to a live agent:
the post-replay reset;
the focus-in that follows it;
the hidden-restore reset;
the model-snapshot reattach.
The decision and the bytes now describe the same moment. Local Electron model snapshots already carried this title and now use it the same way.
The reattach policy itself is unchanged. Non-agent normal-buffer panes still drop modes a dead child may have left behind (#7329, #7893). terminal-reattach-mouse-mode-leak.spec.ts still pins that.
Why
The bug was a race between two channels: the terminal stream and the session-tabs title publication. Keeping modes on any same-process reattach was considered and rejected. The incarnation is the shell's, so it can't prove a mode-arming child is still alive, and that would bring back #7329. Making the reset judge by a title that travels with the image removes the race without changing the policy.
Compatibility:
Older hosts omit the field, so clients fall back to the published title (today's behavior).
Older clients and the mobile app ignore unknown meta keys.
The mobile byte budget counts the new field.
Follows #35889, whose e2e same-process step is this PR's regression guard.
N/A. This changes terminal input modes, not visuals. The tests below read xterm mode state directly.
Testing
New unit test pty-connection-remote-snapshot-image-title.test.ts:
A live-agent image still keeps its modes while the store title shows the tab default.
An image titled vim is disarmed even though the store title names an agent.
An older host without the field falls back to the store title.
The first two cases fail on the parent commit.
terminal-snapshot-scrollback-rows.test.ts: the host sends lastTitle only together with the image's seq.
paired-serve-respawn-process-state.spec.ts: during the same-process serve restart, the test pins the client's published title to the tab default and clears pane status. This forces the window deterministically. The test then requires mouse, focus and cursor-key modes to survive.
Fails 3/3 on the parent commit (mouse none, focus false).
Passes 6/6 with this change.
Related e2e specs pass:
terminal-reattach-mouse-mode-leak (warm reattach still disarms);
terminal-reattach-tui-mouse-mode;
paired-remote-terminal-serve-restart-binding (one serve-shutdown timeout under load passed on rerun);
paired-mobile-desktop-mirror.
All 154 unit test files that import the changed modules pass.
check:changed static checks pass (29/29). Its unit step doesn't finish under current machine load.
Tested on macOS only. There is no platform-specific code.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Codex: no findings.
Independent review: one P2 (the focus-in still used the store title), fixed. Re-review clean.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Security: no change.
Cross-platform: nothing platform-specific.
SSH relays: no change (they send no snapshot meta).
Mobile: ignores the field; its byte budget counts it.
Folder workspaces: unaffected.
Backwards compatibility: an additive optional field, no new opcode.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
After a serve restart where the daemon survives, a paired client could
drop mouse and focus reporting for a still-live agent. The host publishes
the pane with its tab-default title until it seeds the daemon's live title
about 180 ms later. A reattach image replayed inside that window was judged
against the default title, read as a plain normal-buffer program, and got
the reset that disarms its modes, though the image itself carried them.
The snapshot now carries the host's tracked title when the image was taken,
as an additive `lastTitle` field in the snapshot info, gated on the image's
seq. Every reset that judges a replayed image as a live agent's (the
post-replay reset, the focus-in that follows it, the hidden-restore reset,
and the model-snapshot reattach) uses that title when present, so the
decision describes the same moment as the replayed bytes. Local Electron
model snapshots already carried this title and now use it the same way. The reattach policy itself is
unchanged: non-agent normal-buffer panes still shed modes a dead child may
have left (#7329, #7893).
Older hosts omit the field and clients fall back to the published title.
Older clients ignore it.
Refs #35559
This PR carries lastTitle with terminal snapshots and uses it when choosing reattach resets and sending focus-in.
Reattach mode decisions use the title captured with each terminal image.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Host snapshot and lastTitle] --> B[Snapshot metadata]
B --> C[Remote replay or hidden restore]
C --> D[Choose reset using image title]
C --> E[Check focused-agent focus-in]
F[Published pane title] -->|Fallback when title absent| D
F -->|Fallback when title absent| E
The reason will be displayed to describe this comment to others. Learn more.
Focus-in behavior stays untested
These tests never exercise the changed focus-in decision. createPane starts with sendFocusMode: false, and the replacement terminal.write only records bytes, so replay never enables it. The tests would still pass if the focus-in checks stopped using imageTitle.
Add a focused-pane case with focus reporting enabled. Assert that sendInput receives TERMINAL_FOCUS_IN_SEQUENCE when the image names an agent but the store does not.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Snapshot publication now carries the host-tracked lastTitle through renderer snapshot and replay metadata. Reattach checks use the replay image title when evaluating live-agent signals, terminal-mode preservation, focus behavior, and reset selection. Added tests cover image-title and missing-title cases. The end-to-end test checks mouse tracking, focus reporting, and application cursor mode after reattachment.
Priority: Normal
Merge Risk: Low · up to f9bfd
Rare title transitions can leave reattached terminals with incorrect mouse or focus modes. Merge with owner awareness and follow-up.
Pre-merge checks: 3 · 2
Failed checks: 2 warnings
Check name
Status
Explanation
Resolution
Description check
The description covers the change, motivation, compatibility, testing, review, and checklist sections. However, the Linked Issue section uses "Refs #35559" even though the template requires an actual …
Replace "Refs #35559" with the required issue-closing format, such as "Fixes #35559", or provide the repository-approved linked issue format.
Docstring Coverage
Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title is concise, specific, and accurately describes the main change: using the image's own title to judge live-agent reattach modes.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description covers the change, motivation, compatibility, testing, review, and checklist sections. However, the Linked Issue section uses "Refs #35559" even though the template requires an actual issue link and states that Refs is insufficient.
Resolution
Replace "Refs #35559" with the required issue-closing format, such as "Fixes #35559", or provide the repository-approved linked issue format.
Full details: Docstring Coverage
Explanation
Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 22 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 1
📝 Generate docstrings: 💡
Commit to this branch
Create a new PR
Autofix · 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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Supported by static analysis
Script executed:
#!/bin/bash# Inspect the snapshot producers and their treatment of cleared or empty titles.
rg -n -C 4 'preferTrackedLastTitle|serializeAuthoritativeTerminalBuffer|serializeRendererTerminalBuffer|lastTitle:' src/main/runtime
Repository: stablyai/orca
Length of output: 41760
Script executed:
# Inspect the title tracker's normalization and getter, then every producer and consumer of lastTitle.
ast-grep outline src/main/runtime/terminal/output/terminal-title-tracker.ts --view expanded
rg -n -F -e 'getLastNormalizedTitle' -e 'getTrackedDisplayTitleForPty' -e 'normalizeTitle' -e 'normalizedTitle' src/main/runtime ||test"$?" -eq 1
rg -n -F -e 'lastTitle' src/renderer ||test"$?" -eq 1
sed -n '1,40p' src/main/runtime/rpc/methods/terminal/terminal-snapshot-payload.ts
Repository: stablyai/orca
Length of output: 16330
Script executed:
# Read the renderer serializer result construction, then locate the headless snapshot producer and its lastTitle source.
sed -n '100,160p' src/renderer/src/components/terminal-pane/pty-buffer-serializer.ts
rg -n -F -e 'getSnapshot(' -e 'lastTitle' src/main/runtime/terminal src/renderer/src/components/terminal-pane/pty-buffer-serializer.ts ||test"$?" -eq 1
rg -n -F 'getSnapshot(' src/main src/shared ||test"$?" -eq 1
Repository: stablyai/orca
Length of output: 41072
Script executed:
# Locate the emulator's getSnapshot declaration and every non-test lastTitle producer in the daemon and terminal-pane trees.
ast-grep outline src/main/daemon/headless-emulator.ts --view expanded ||test"$?" -eq 1
rg -n -F --glob '!*.test.ts' --glob '!*.spec.ts' -e 'lastTitle' src/main/daemon src/renderer/src/components/terminal-pane ||test"$?" -eq 1
Repository: stablyai/orca
Length of output: 10243
Script executed:
# Locate extractLastOscTitle and read its definition and the scanner's assignment site.
rg -n -F -e 'extractLastOscTitle' src/main src/shared ||test"$?" -eq 1
ast-grep outline src/main/daemon/terminal-osc-cwd-title-scanner.ts --view expanded ||test"$?" -eq 1
sed -n '1,60p' src/main/daemon/terminal-osc-cwd-title-scanner.ts
Repository: stablyai/orca
Length of output: 4412
Script executed:
# Read the extractLastOscTitle implementation and its helper boundaries.
ast-grep outline src/shared/osc-title-extraction.ts --view expanded ||test"$?" -eq 1
sed -n '60,100p' src/shared/osc-title-extraction.ts
Repository: stablyai/orca
Length of output: 2188
Compare a sequenced image title with undefined, not truthiness.
The truthiness check drops a known empty title. An image title of '' leaves lastTitle absent from the frame. Clients treat absence as "use the published title", so the reattach decision can use a title that is not the image's own. Consumers test presence with !== undefined, and the payload comment says absence means unknown. The check should match that contract.
--- "a/src/main/runtime/rpc/methods/terminal/terminal-snapshot-payload.ts"+++ "b/src/main/runtime/rpc/methods/terminal/terminal-snapshot-payload.ts"@@ -24,7 +24,7 @@
? { terminalOwner: options.terminalOwner }
: {}),
// Clients judge live-agent reattach modes by this image's own title, not a separately published one.
- ...(typeof options.seq === 'number' && options.lastTitle+ ...(typeof options.seq === 'number' && options.lastTitle !== undefined
? { lastTitle: options.lastTitle }
: {}),
// Consumers do not recheck terminalOwner; ungated alternateScreen changes mouse-reset selection on live TUI reattach.
The empty-title path is real. An OSC title with an empty payload parses to '', and the scanner stores it. The impact is narrow. It applies only when the latest image title is empty and the published title differs.
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.
…ck (#35936)
The same-process serve restart step relied on timing to land the reattach
replay inside the window where the host still publishes the tab-default
title, which happened about one run in five. Pin the client's published
pane title to the tab default and clear its pane status for the duration
of the restart, so the replayed image's own title alone must prove the
live agent. The check fails 3/3 without #35920 and passes with it.
Refs #35559
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
After restarting a remote Orca server whose terminals kept running, a paired or browser client sometimes stopped sending mouse and focus events to a still-running agent such as Claude Code. Scrolling and clicking in the agent quietly broke. The client decided "is this an agent?" from a pane title that, for a moment after the restart, still read "Terminal 1". It now decides from the title the server attaches to the screen image it sends.
What Changed
Before: after an
orca serverestart that kept its terminal daemon, a live agent pane could come back with mouse tracking and focus reporting turned off, depending on timing. Instrumented runs showed the host publishing the pane with its tab-default title, then seeding the daemon's live title about 180 ms later. If the client replayed the reattach snapshot inside that window, the post-replay reset saw no agent. It then applied the reset meant for plain normal-buffer programs, which disarms?1003/?1004, even though the snapshot itself had just re-armed them.After: the host adds the title it tracked when it took the image to the snapshot info. This is an additive
lastTitlefield, and it is sent only with the image'sseq. The client uses that title for every decision about whether this image belongs to a live agent:The decision and the bytes now describe the same moment. Local Electron model snapshots already carried this title and now use it the same way.
The reattach policy itself is unchanged. Non-agent normal-buffer panes still drop modes a dead child may have left behind (#7329, #7893).
terminal-reattach-mouse-mode-leak.spec.tsstill pins that.Why
The bug was a race between two channels: the terminal stream and the session-tabs title publication. Keeping modes on any same-process reattach was considered and rejected. The incarnation is the shell's, so it can't prove a mode-arming child is still alive, and that would bring back #7329. Making the reset judge by a title that travels with the image removes the race without changing the policy.
Compatibility:
Follows #35889, whose e2e same-process step is this PR's regression guard.
Linked Issue
Refs #35559
Visual Proof
N/A. This changes terminal input modes, not visuals. The tests below read xterm mode state directly.
Testing
New unit test
pty-connection-remote-snapshot-image-title.test.ts:vimis disarmed even though the store title names an agent.terminal-snapshot-scrollback-rows.test.ts: the host sendslastTitleonly together with the image's seq.paired-serve-respawn-process-state.spec.ts: during the same-process serve restart, the test pins the client's published title to the tab default and clears pane status. This forces the window deterministically. The test then requires mouse, focus and cursor-key modes to survive.none, focusfalse).Related e2e specs pass:
terminal-reattach-mouse-mode-leak(warm reattach still disarms);terminal-reattach-tui-mouse-mode;paired-remote-terminal-serve-restart-binding(one serve-shutdown timeout under load passed on rerun);paired-mobile-desktop-mirror.All 154 unit test files that import the changed modules pass.
check:changedstatic checks pass (29/29). Its unit step doesn't finish under current machine load.Tested on macOS only. There is no platform-specific code.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)