Skip to content

fix(remote): preserve terminal recovery across control refresh - #11513

Merged
OrcaWin merged 17 commits into
mainfrom
remote-orca-servers-load-issue
Jul 30, 2026
Merged

OrcaWin merged 17 commits into
mainfrom
remote-orca-servers-load-issue

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve ready waiters and pending shared-control RPCs when a successful reachability probe refreshes a pre-ready socket.
  • Keep original RPC deadlines and normal close/error/manual-disconnect rejection semantics.
  • Require paired-terminal recovery to succeed while all target terminal managers remain unmounted in the host renderer.
  • Keep CI fixtures aligned with Jira's verified source-context contract and current main line budgets.

Deterministic reproduction

The encrypted-WebSocket oracle reproduces the screenshot error exactly:

Refreshing remote runtime control transport.

It withholds the first ready frame, starts one RPC, then lets a successful one-shot status.get call reconnectNow(). Before the fix, replacing the pre-ready socket rejects that RPC. After the fix, the original call survives the refresh and completes through the replacement socket under its original deadline.

The oracle requires exactly two connections, one authoritative host RPC, one successful response, zero pending calls, and zero retained request bytes. Ordinary close, error, and manual disconnect paths still reject rather than migrate calls.

Field evidence and lifecycle coverage

On v1.4.162-rc.1, opening the affected parked terminal on the Windows host over RDP caused the existing client terminal to recover. This shows the PTY could remain alive while client recovery depended on mounting the host renderer.

The headed oracle now converts mirrored web tab IDs back to raw host tab IDs and pins the host's actual pre-pairing active workspace. It requires zero matching host pane managers before and after client recovery while the client restores row 4,000, parked-time output, the same PTY, and live input/output. The same parking contract runs against isolated headed desktop-server and headless orca serve topologies.

Release ancestry

v1.4.162-rc.1 commit 62c51e77b2 predates merged PR #11416 and does not contain terminal.paired-parking.v1. It contains neither #11416's paired-terminal parking design nor this control-refresh follow-up.

Validation

  • pnpm run typecheck
  • full pnpm run lint, reliability manifest, and max-lines ratchet
  • shared-control transport: 27/27
  • focused RPC/admission/runtime review suite: 74/74
  • daemon router/history handoff: 31/31
  • headed + headless paired parking: 2/2
  • Jira project-switch source-context journey: 2/2
  • the two other previously red E2E cases pass unchanged
  • fresh Electron E2E build
  • git diff --check

Screenshots

No visual change.

AI Review Report

  • Greptile: 5/5 confidence, no correctness findings.
  • CodeRabbit: both actionable findings addressed—explicit Vitest config and explicit host-page poll timeout.
  • Focused independent review found one merge blocker in the initial host oracle: client-prefixed tab IDs could make the zero-mount assertion vacuous. The oracle now checks raw host IDs and the actual seeded active workspace; headed/headless E2E passed after the correction.
  • CodeRabbit's generic docstring warning was not applied because it conflicts with this repository's concise TypeScript comment conventions and did not identify undocumented public behavior.

Security Audit

  • No endpoint, token, pairing material, key, or terminal command text is logged or committed.
  • Request preservation is limited to an already-authorized reachability-triggered socket refresh and retains the original deadline.
  • Manual disconnect and ordinary close/error paths continue to reject and clean pending work.
  • No local fallback, dependency, or executable-download changes.

Notes

The Jira E2E failure was a stale fixture: current Orca correctly rejects Jira linked items without matching source identity. The fixture now supplies the active project/host and matching Jira site/project identity; product behavior was not weakened.

OrcaWin added 10 commits July 29, 2026 15:28
…oad-issue

# Conflicts:
#	config/reliability-gates.jsonc
#	src/main/runtime/rpc/methods/terminal.ts
#	src/main/runtime/rpc/terminal-multiplex.test.ts
#	src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts
…oad-issue

# Conflicts:
#	config/reliability-gates.jsonc
#	tests/e2e/helpers/paired-terminal-parking-oracle.ts
#	tests/e2e/paired-remote-terminal-retention-memory.spec.ts
@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a regression where a successful one-shot reachability probe calling reconnectNow() on a pre-ready shared-control socket would reject any RPCs that were waiting for that socket to become ready. The fix threads a preserveReadyWaitersAndPendingRequests flag through the close path so those waiters and pending requests migrate to the replacement socket under their original deadlines.

  • Core transport fix: closeSocket gains a boolean flag; when reconnectNow() sets it, ready waiters and pending requests are kept alive while the old socket is torn down and a new one is opened — ordinary close(), error, and manual-disconnect paths continue to reject as before.
  • New deterministic oracle: A real encrypted-WebSocket test withholds the first ready frame, starts one RPC, triggers reconnectNow(), and asserts exactly two connections, one host delivery, a successful response, and zero retained request bytes.
  • E2E oracle hardening: The paired-terminal parking oracle now verifies host-renderer zero-mount state using raw host tab IDs (toHostSessionTabId), and the Jira project-switch fixture supplies the actual active project identity to satisfy the current source-context contract.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to the pre-ready socket-refresh path and all ordinary close/error/disconnect paths are unaffected.

The transport fix is logically sound: ready waiters and pending requests are arrays/maps on the connection object that survive the socket swap, the original deadline timers are untouched, and the socket-generation fence ensures the discarded socket's close event is a no-op. The new unit oracle exercises the exact failure scenario with a real WebSocket server and verifies zero retained bytes after completion. E2E corrections tighten previously vacuous assertions without weakening product behavior.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/shared/remote-runtime-shared-control-connection.ts Core fix: adds preserveReadyWaitersAndPendingRequests flag to closeSocket so reconnectNow() keeps in-flight RPCs alive across a pre-ready socket refresh; inlines the single-use scheduleReconnectAttemptReset helper with no behavior change.
src/shared/remote-runtime-shared-control-state.ts Adds preserveReadyWaitersAndPendingRequests guard in closeSharedControlSocketState; when true, skips rejecting ready waiters and pending requests so they can migrate to the replacement socket.
src/shared/remote-runtime-shared-control-socket-close.ts Threads the new preserveReadyWaitersAndPendingRequests flag through closeSharedControlSocket to closeSharedControlSocketState; minimal pass-through change.
src/shared/remote-runtime-shared-control-connection.test.ts Adds a real encrypted-WebSocket test that withholds the first ready frame, triggers a reconnectNow(), and verifies the RPC completes on the second connection with zero retained bytes; adds suppressReadyFrameCount to the server factory.
tests/e2e/helpers/paired-terminal-parking-oracle.ts Adds options.hostPage parameter and expectHostTerminalsUnmounted helper that asserts zero host pane managers for the remote tabs using raw host tab IDs (via toHostSessionTabId), correcting the earlier vacuous assertion issue with client-prefixed IDs.
tests/e2e/paired-remote-terminal-retention-memory.spec.ts Uses the active worktree's own ID (instead of worktreeIds[0]) as fallbackWorktreeId for the parking oracle, and passes orcaPage as hostPage to enable the new unmounted-terminals assertion.
tests/e2e/new-workspace-linked-item-project-switch.spec.ts Adds getJiraSourceContext to read the actual active project host setup and Jira identity from the store, supplying a valid taskSourceContext that satisfies the current source-identity contract.
tests/e2e/terminal-long-table-fixtures.ts Consolidates the emoji table completion marker and width marker into a single output line; the old marker string remains a prefix of the new combined line, so existing toContain(marker) checks in specs continue to work.
config/reliability-gates.jsonc Updates invariant/oracle descriptions and coverage notes to reflect the new socket-refresh preservation guarantee and the host-renderer unmount assertion; adds the new unit-test command and its passing run result.

Sequence Diagram

sequenceDiagram
    participant C as Client (request caller)
    participant Conn as SharedControlConnection
    participant S1 as Socket 1 (pre-ready)
    participant S2 as Socket 2 (replacement)
    participant H as Host

    C->>Conn: request('worktree.ps', 1000ms)
    Note over Conn: pendingRequests.set(id, ...)<br/>readyWaiters.push(waiter)
    Conn->>S1: open() - awaiting_ready
    Note over S1: ready frame suppressed

    Note over Conn: status probe succeeds, reconnectNow()
    Conn->>Conn: "closeSocket(error, preserveWaiters=true)"
    Note over Conn: readyWaiters and pendingRequests PRESERVED<br/>subscriptions marked unsent
    S1--xConn: ws.close() stale generation ignored

    Conn->>S2: open() new generation
    S2-->>Conn: e2ee_ready frame
    Note over Conn: resolveSharedControlReadyWaiters()<br/>waiter resolved, send(requestId)
    Conn->>H: encrypted RPC (worktree.ps)
    H-->>Conn: response
    Conn-->>C: resolve ok true result
    Note over Conn: pendingRequests.delete(id)<br/>retainedBytes = 0
Loading

Reviews (5): Last reviewed commit: "test(terminal): keep restore sentinel on..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 30, 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: Pro Plus

Run ID: c287d9ba-a3a3-4741-bd8c-0385df09139b

📥 Commits

Reviewing files that changed from the base of the PR and between a70235e and 7ec69f4.

📒 Files selected for processing (1)
  • tests/e2e/terminal-long-table-fixtures.ts

📝 Walkthrough

Walkthrough

Shared-control reconnects now preserve pending requests and ready waiters during transport replacement while resetting readiness state. New tests cover pre-ready socket replacement and request resolution. E2E retention checks verify host terminals remain unmounted during recovery, and reliability gates include the updated contracts. The workspace project-switching test now derives and passes Jira task source context to the composer. Terminal table fixtures now use a derived width marker and omit the standalone restore marker.

🚥 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 matches the main change: preserving recovery across shared-control refreshes.
Description check ✅ Passed The description covers summary, reproduction, validation, screenshots, AI review, security, and notes, with only minor template-specific polish missing.
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 💡 1
📝 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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b59b52c-0b25-410d-a540-d70eb20fba03

📥 Commits

Reviewing files that changed from the base of the PR and between 561e2d3 and 846fb8b.

📒 Files selected for processing (9)
  • config/reliability-gates.jsonc
  • src/main/daemon/daemon-pty-router-events.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/shared/remote-runtime-shared-control-connection.test.ts
  • src/shared/remote-runtime-shared-control-connection.ts
  • src/shared/remote-runtime-shared-control-socket-close.ts
  • src/shared/remote-runtime-shared-control-state.ts
  • tests/e2e/helpers/paired-terminal-parking-oracle.ts
  • tests/e2e/paired-remote-terminal-retention-memory.spec.ts

Comment thread config/reliability-gates.jsonc Resolved
@raquelpn1979-tech

Copy link
Copy Markdown

@thekvn

@OrcaWin
OrcaWin merged commit ab665a3 into main Jul 30, 2026
104 of 106 checks passed
@raquelpn1979-tech

Copy link
Copy Markdown

the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@raquelpn1979-tech

Copy link
Copy Markdown

Svelte específicamente en este proyecto

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#11513)

* fix(remote): recover stalled terminal streams

* fix(i18n): localize manual disconnect error

* fix(remote): park paired terminals with host snapshots

* test(remote): mock authoritative resync snapshots

* fix(terminal): defer startup mounts until hydration

* fix(remote): raise paired terminal stream capacity

* fix(remote): harden terminal recovery lifecycle

* fix(remote): preserve calls across control refresh

* test(remote): harden paired recovery oracle

* test(workspace): seed Jira source context

* test(remote): assert raw host terminal identities

* test(terminal): keep restore sentinels atomic

* test(terminal): keep restore sentinel on one row

---------

Co-authored-by: OrcaWin <[email protected]>
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.

2 participants