Skip to content

fix(terminal): make remote agent sessions host-authoritative - #9687

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/bug-remote-client-resumes-live-host-agent-sessio
Jul 22, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/bug-remote-client-resumes-live-host-agent-sessio

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Make the remote Orca host authoritative for agent-session ownership and terminal membership.

  • prevent two clients from waking the same live remote agent into duplicate PTYs
  • retire exited terminal surfaces durably so stale client snapshots cannot resurrect ghost tabs
  • negotiate the structured authority path only when the client, runtime, daemon, and relay support it
  • preserve the exact legacy launch behavior at safe pre-side-effect mixed-version boundaries
  • integrate fix(terminal): prevent reconnect from killing live daemon sessions #9804's non-destructive reconnect lifecycle contract without weakening old-client user closes
  • add a deterministic real remote-server reproduction harness and document the compatibility contract
  • register the experimental reliability class agent-session.remote-host-authority

Fixes #8878.
Related to #9352 and #9804.

Screenshots

No visual change.

Testing

  • pnpm lint — repository-wide baseline failures remain in untouched skill-freshness and generated skill-manifest files; task-owned oxlint, reliability, and max-lines checks pass
  • pnpm typecheck
  • pnpm test — 3,213 files passed; 33,949 tests passed in the pre-review full-root validation
  • Build-backed remote reproduction — pnpm test:repro:remote-agent-session
  • Added or updated high-quality regression tests

Final post-rebase validation:

  • remote host-authority gate: 10 files, 325 tests
  • fix(terminal): prevent reconnect from killing live daemon sessions #9804 reconnect/daemon-generation gate: 9 files, 1,010 tests
  • real headless orca serve harness over encrypted WebSocket pairing: one physical spawn across two racing clients, canonical retry adoption, durable exit retirement, stale-publication rejection, and no resurrection after server restart
  • all three TypeScript typechecks
  • reliability manifest validation for 46 gates
  • touched-file oxlint and targeted oxfmt checks
  • git diff --check

The Windows daemon harness now derives explicit v24 clean-disconnect, v25 startup-ingress, and v26 agent-authority boundaries and covers v21–v26. Recorded native Windows evidence remains v21–v25; the six-generation v26 native rerun has not been collected locally.

AI Review Report

The final combined diff was independently re-reviewed for lifecycle, protocol compatibility, and topology after rebasing onto #9804. All three specialist reviews returned clean.

The review/fix rounds covered multi-client races, old/new client-runtime-daemon-relay combinations, SSH reconnect identity, daemon and relay exit-before-reply ordering, PTY ID reuse, stale renderer writes, provisional-tab retirement, deletion boundaries, bounded operation state, and reconnect lifecycle safety.

The final #9804 integration review found and fixed:

  • a fresh daemon inventory could prove a persisted PTY live before pane metadata rebound; lifecycle retirement now treats that exact observed PTY as live
  • reasonless closes from authenticated legacy runtime clients were accidentally refused; old runtime and mobile clients retain their historical explicit-user close behavior
  • an immediate close before snapshot confirmation could address a provisional tab ID; exact structured handoff now resolves the canonical host ID
  • the post-create confirmation inventory could share an older in-flight list; it now waits out pre-existing work and coalesces only the causally fresh request
  • the Windows generation fixture now keeps the explicit v24, v25, and v26 compatibility boundaries

Cross-platform review considered macOS, Linux, Windows, native, WSL, SSH, daemon, relay, and remote-runtime execution. This PR adds no keyboard shortcut or UI-label behavior, uses platform path APIs in the harness, and does not add production shell assumptions or Git-version-dependent commands.

Security Audit

  • structured requests accept only supported agents and normalized provider identities
  • host-only claim identities omit raw provider session IDs and bind execution/worktree scope
  • unknown, conflicting, disconnected, malformed, or unproven ownership fails closed after dispatch
  • legacy fallback is allowed only before authority side effects, or after method_not_found proves an old host did not recognize the request
  • successful spawns require exact PTY incarnation proof; late exits cannot retire a reused PTY
  • host-private topology revisions are omitted from renderer hydration and writes, preventing cross-host authority collisions
  • no dependency, authentication, secret-storage, or permission model changes

No follow-up security action is required for the v1 scope.

Compatibility

Mixed-version combinations preserve workflows that existed before upgrading. New hosts continue accepting old clients. Authenticated old runtime and mobile clients that omit a close reason retain the historical explicit-user close behavior. New clients use the evidence-bearing lifecycle method and never fall back from an unsupported lifecycle call to a destructive legacy close.

New clients use structured agent-session authority only when every authority layer for that route advertises support; otherwise they select the unchanged legacy request before trust, claim, spawn, replay fencing, or execution-owner-local filesystem access. Partially upgraded routes may retain the original duplicate-resume/ghost-tab behavior until the route is fully capable, but upgrading any subset does not remove previously working launch, resume, or explicit-close behavior.

Reliability Contract

Experimental gate: agent-session.remote-host-authority

The invariant requires one live PTY owner and one canonical host surface per provider-session identity on every claim-capable route. Exact physical exit retires that incarnation durably, while mixed-version routes choose legacy behavior before authority side effects. Causally fresh inventory fencing prevents a pre-operation snapshot from confirming a post-operation handoff.

Documented future extensions remain intentionally outside this PR:

  • durable fresh-operation journaling across runtime restarts
  • host-owned automatic sleep checkpoints
  • verified nested-SSH execution namespaces
  • multi-process profile coordination

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change introduces remote agent-session host authority with explicit resume and fresh-create RPCs, signed claims, ownership reconciliation, operation replay fencing, and legacy compatibility paths. PTY incarnation identifiers now flow through local, daemon, relay, SSH, runtime, persistence, and renderer layers to reject stale exits and prevent resurrection. Terminal retirement and topology revision state is persisted and reconciled across workspace transfers, host partitions, and restarts. Renderer launch flows now support structured host creation, provisional handoffs, session options, localized outcomes, and legacy fallback. A deterministic Electron-based reproduction harness and extensive regression coverage are added.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.67% 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
Linked Issues check ✅ Passed The PR implements host-authoritative remote session ownership, duplicate-resume prevention, and durable exit retirement, matching #8878's core goals.
Out of Scope Changes check ✅ Passed The changes stay within the agent-session and terminal authority lifecycle scope; the added docs, tests, and launch updates support the same feature set.
Title check ✅ Passed The title clearly and accurately summarizes the main change: making remote agent sessions host-authoritative.
Description check ✅ Passed The description covers the required template sections and is mostly complete; only the Notes section is missing.

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.

@OrcaWin
OrcaWin force-pushed the OrcaWin/bug-remote-client-resumes-live-host-agent-sessio branch 2 times, most recently from 64196d9 to af2e0a7 Compare July 21, 2026 21:38

@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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/daemon/daemon-server.ts (1)

758-772: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Guard the post-await streamClientIdBySessionId.set(...). If the PTY exits before createOrAttach returns, the exit handler removes the entry and this write adds it back for a dead session, leaving a stale map entry until restart.

Source: Linters/SAST tools

🧹 Nitpick comments (7)
config/scripts/remote-agent-session-repro-client.mjs (1)

20-29: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unhandled request rejection yields opaque harness errors.

If connection.request rejects (timeout/transport error), nothing is written to stdout, so the parent script's JSON.parse(stdout.trim()) fails with a generic "invalid JSON" message instead of surfacing the actual RPC error.

🔧 Optional: surface the underlying error
 try {
-  const response = await connection.request(method, JSON.parse(rawParams), 20_000)
-  process.stdout.write(`${JSON.stringify(response)}\n`)
-  if (!response.ok) {
-    process.exitCode = 1
-  }
+  const response = await connection
+    .request(method, JSON.parse(rawParams), 20_000)
+    .catch((error) => ({ ok: false, error: String(error?.message ?? error) }))
+  process.stdout.write(`${JSON.stringify(response)}\n`)
+  if (!response.ok) {
+    process.exitCode = 1
+  }
 } finally {
   connection.close()
 }
src/main/daemon/pty-session-id.test.ts (1)

31-56: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing collision coverage for realistic clientOperationId shapes.

These tests only use synthetic operationIds ('a'.repeat(43), etc.), never the real ${timestamp}-${hex} shape used elsewhere in the RPC layer (agent-session.test.ts). See the consolidated comment on src/main/daemon/pty-session-id.ts for the root-cause collision risk this masks.

src/main/daemon/session.ts (1)

99-101: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a "why" comment on the new incarnationId field.

Its purpose (letting clients distinguish exits from a superseded PTY incarnation for stale-exit rejection) isn't obvious from the field alone, and the rest of the file consistently documents non-obvious state with "Why:" comments.

As per path instructions, **/*.{ts,tsx}: "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

Source: Path instructions

src/main/daemon/types.ts (1)

82-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a "why" comment for agentSessionEnsure, matching sibling fields.

Every other optional field in this payload (shellOverride, terminalWindowsWslDistro, terminalWindowsPowerShellImplementation) carries a comment explaining why it exists. agentSessionEnsure — arguably the most non-obvious addition here, gating structured host-authority negotiation — has none.

📝 Suggested comment
+    /** Why: presence signals a structured host-authority resume/create request;
+     *  claim + surface let the daemon verify ownership before admitting the session. */
     agentSessionEnsure?: {
       claim: AgentSessionExecutionClaim
       surface: AgentSessionSurfaceBinding
     }
As per coding guidelines, "`**/*.{ts,tsx}`: For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

Source: Coding guidelines

src/main/providers/ssh-agent-session-claim-validation.ts (1)

80-85: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Undocumented asymmetry: surface binding isn't validated for adopted dispositions.

surfacesEqual is only enforced when disposition === 'created'; an 'adopted' owner's surface is never compared against expected.surface. This file otherwise documents non-obvious constraints with "Why:" comments (Lines 69-71), but this asymmetric check has none. Please confirm this is intentional (e.g., resumed/adopted sessions may legitimately reconnect from a different tab/leaf, so only claim identity matters) and add a short comment explaining the rationale, so a future refactor doesn't silently add or remove the check.

📝 Suggested clarifying comment
   if (
     claimed.disposition === 'created' &&
     !surfacesEqual(claimed.owner.surface, expected.surface)
   ) {
+    // Why: only newly created owners must bind exactly to the requested
+    // surface; adopted owners may legitimately resume under a different
+    // tab/leaf, so surface binding is not re-verified here.
     return { valid: false, cleanup, error: 'agent_session_ownership_unknown' }
   }

Based on coding guidelines: "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

Source: Coding guidelines

src/main/providers/ssh-pty-session-reattach.ts (1)

46-72: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider demoting the happy-path console.warn debug logging.

The three console.warn calls (including the success-path pty.attach succeeded log at Line 61-62) fire on every reattach and read as leftover debug instrumentation. Consider routing them through the project debug logger or removing the success log. Static analysis also flags these as sensitive-data logging (CWE-532); sessionId here is a PTY id rather than a credential, so that specific concern is largely a false positive.

Source: Linters/SAST tools

src/main/runtime/orca-runtime.test.ts (1)

10586-10612: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the shared canonical-owner fixture invariant.

canonicalOwner intentionally persists across mock spawns to prove retry adoption retains the original execution surface; add a brief why-comment so this state is not simplified away later.

Proposed clarification
+    // Preserve the first host owner so retries must adopt its canonical surface.
     let canonicalOwner:

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: eb8048ce-dd43-48fc-a880-1128ac4f7c89

📥 Commits

Reviewing files that changed from the base of the PR and between 903112a and 64196d977a8a60e414c1f3045a68c3d5b35d25c4.

📒 Files selected for processing (150)
  • config/localization-coverage-allowlist.json
  • config/scripts/remote-agent-session-authority-repro.mjs
  • config/scripts/remote-agent-session-repro-client.mjs
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • docs/reference/remote-agent-session-host-authority.md
  • package.json
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/daemon-pty-provider.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • src/main/daemon/terminal-host.ts
  • src/main/daemon/types.ts
  • src/main/index.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-session-reattach.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/main/providers/types.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.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/agent-background-session-test-state.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/shared/agent-session-host-authority.ts
  • src/shared/claimed-agent-pty-owner-snapshot.ts
  • src/shared/claimed-agent-pty-owner.test.ts
  • src/shared/claimed-agent-pty-owner.ts
  • src/shared/protocol-version.ts
  • src/shared/pty-incarnation.ts
  • src/shared/runtime-types.ts
  • src/shared/types.ts
  • src/shared/workspace-session-schema.ts

Comment thread src/main/daemon/pty-session-id.ts Resolved
Comment thread src/main/daemon/terminal-host.ts Resolved
Comment thread src/main/ipc/pty.ts Resolved
Comment on lines +51 to +81
function canonicalPathForPlatform(value: string): string {
const canonical = normalize(realpathSync(value))
return process.platform === 'win32' ? canonical.toLocaleLowerCase('en-US') : canonical
}

export function canonicalizeAgentSessionIdentity(
agent: unknown,
rawProviderSession: unknown
): CanonicalAgentSessionIdentity {
if (!isResumableTuiAgent(agent)) {
throw new Error('agent_session_identity_required')
}
const providerSession = normalizeAgentProviderSession(rawProviderSession)
if (!providerSession || !getAgentResumeArgv(agent, providerSession)) {
throw new Error('agent_session_identity_required')
}
if (agent !== 'pi') {
return { agent, providerSession }
}
const transcriptPath = providerSession.transcriptPath
if (
!transcriptPath ||
!isAbsolute(transcriptPath) ||
Buffer.byteLength(transcriptPath, 'utf8') > TRANSCRIPT_PATH_MAX_BYTES
) {
throw new Error('agent_session_identity_required')
}
const canonicalTranscriptPath = canonicalPathForPlatform(transcriptPath)
if (!statSync(canonicalTranscriptPath).isFile()) {
throw new Error('agent_session_identity_required')
}

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

Normalize filesystem errors to the identity rejection.

realpathSync (Line 52) and statSync (Line 79) throw raw ENOENT/permission errors when the pi transcript path is missing or removed mid-flight, bypassing the explicit agent_session_identity_required rejection used elsewhere in this function. A deleted/relocated transcript is an invalid identity, not an internal fault, so it should reject consistently.

🛡️ Proposed fix to normalize the rejection
-function canonicalPathForPlatform(value: string): string {
-  const canonical = normalize(realpathSync(value))
-  return process.platform === 'win32' ? canonical.toLocaleLowerCase('en-US') : canonical
-}
+function canonicalPathForPlatform(value: string): string {
+  let canonical: string
+  try {
+    canonical = normalize(realpathSync(value))
+  } catch {
+    throw new Error('agent_session_identity_required')
+  }
+  return process.platform === 'win32' ? canonical.toLocaleLowerCase('en-US') : canonical
+}

And guard the statSync call similarly:

-  const canonicalTranscriptPath = canonicalPathForPlatform(transcriptPath)
-  if (!statSync(canonicalTranscriptPath).isFile()) {
-    throw new Error('agent_session_identity_required')
-  }
+  const canonicalTranscriptPath = canonicalPathForPlatform(transcriptPath)
+  let isFile = false
+  try {
+    isFile = statSync(canonicalTranscriptPath).isFile()
+  } catch {
+    throw new Error('agent_session_identity_required')
+  }
+  if (!isFile) {
+    throw new Error('agent_session_identity_required')
+  }
📝 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
function canonicalPathForPlatform(value: string): string {
const canonical = normalize(realpathSync(value))
return process.platform === 'win32' ? canonical.toLocaleLowerCase('en-US') : canonical
}
export function canonicalizeAgentSessionIdentity(
agent: unknown,
rawProviderSession: unknown
): CanonicalAgentSessionIdentity {
if (!isResumableTuiAgent(agent)) {
throw new Error('agent_session_identity_required')
}
const providerSession = normalizeAgentProviderSession(rawProviderSession)
if (!providerSession || !getAgentResumeArgv(agent, providerSession)) {
throw new Error('agent_session_identity_required')
}
if (agent !== 'pi') {
return { agent, providerSession }
}
const transcriptPath = providerSession.transcriptPath
if (
!transcriptPath ||
!isAbsolute(transcriptPath) ||
Buffer.byteLength(transcriptPath, 'utf8') > TRANSCRIPT_PATH_MAX_BYTES
) {
throw new Error('agent_session_identity_required')
}
const canonicalTranscriptPath = canonicalPathForPlatform(transcriptPath)
if (!statSync(canonicalTranscriptPath).isFile()) {
throw new Error('agent_session_identity_required')
}
function canonicalPathForPlatform(value: string): string {
let canonical: string
try {
canonical = normalize(realpathSync(value))
} catch {
throw new Error('agent_session_identity_required')
}
return process.platform === 'win32' ? canonical.toLocaleLowerCase('en-US') : canonical
}
export function canonicalizeAgentSessionIdentity(
agent: unknown,
rawProviderSession: unknown
): CanonicalAgentSessionIdentity {
if (!isResumableTuiAgent(agent)) {
throw new Error('agent_session_identity_required')
}
const providerSession = normalizeAgentProviderSession(rawProviderSession)
if (!providerSession || !getAgentResumeArgv(agent, providerSession)) {
throw new Error('agent_session_identity_required')
}
if (agent !== 'pi') {
return { agent, providerSession }
}
const transcriptPath = providerSession.transcriptPath
if (
!transcriptPath ||
!isAbsolute(transcriptPath) ||
Buffer.byteLength(transcriptPath, 'utf8') > TRANSCRIPT_PATH_MAX_BYTES
) {
throw new Error('agent_session_identity_required')
}
const canonicalTranscriptPath = canonicalPathForPlatform(transcriptPath)
let isFile = false
try {
isFile = statSync(canonicalTranscriptPath).isFile()
} catch {
throw new Error('agent_session_identity_required')
}
if (!isFile) {
throw new Error('agent_session_identity_required')
}

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

🧹 Nitpick comments (1)
src/main/providers/ssh-pty-provider.ts (1)

184-199: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Dead sessionExpired branch in the fresh-create return.

opts.sessionId truthy is already fully handled by the early reattachSshPtySessionWithExitFence return at Line 126, so this return path is only reached when opts.sessionId is falsy. The ...(opts.sessionId ? { sessionExpired: true } : {}) therefore always spreads {}. Drop it (or confirm whether a fresh create was ever meant to surface sessionExpired).

♻️ Suggested cleanup
-        ...(opts.sessionId ? { sessionExpired: true } : {})
       }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f8b2741b-b933-4464-a696-52870914e2a0

📥 Commits

Reviewing files that changed from the base of the PR and between 64196d977a8a60e414c1f3045a68c3d5b35d25c4 and af2e0a7.

📒 Files selected for processing (153)
  • config/localization-coverage-allowlist.json
  • config/scripts/remote-agent-session-authority-repro.mjs
  • config/scripts/remote-agent-session-repro-client.mjs
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • docs/reference/remote-agent-session-host-authority.md
  • package.json
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/daemon-pty-provider.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • src/main/daemon/terminal-host.ts
  • src/main/daemon/types.ts
  • src/main/index.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-capabilities.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-session-reattach.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/main/providers/types.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.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/agent-background-session-test-state.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-web-runtime.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/shared/agent-session-host-authority.ts
  • src/shared/claimed-agent-pty-owner-snapshot.ts
  • src/shared/claimed-agent-pty-owner.test.ts
  • src/shared/claimed-agent-pty-owner.ts
  • src/shared/protocol-version.ts
  • src/shared/pty-incarnation.ts
  • src/shared/runtime-types.ts
  • src/shared/types.ts
  • src/shared/workspace-session-schema.ts
🚧 Files skipped from review as they are similar to previous changes (139)
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/runtime/rpc/methods/index.ts
  • config/localization-coverage-allowlist.json
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/terminal-host-options.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/shared/pty-incarnation.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • src/main/providers/pty-spawn-result.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/shared/protocol-version.ts
  • package.json
  • src/main/ipc/ssh.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/main/daemon/session.test.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • config/scripts/remote-agent-session-repro-client.mjs
  • src/main/runtime/orca-runtime.test.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/shared/types.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/runtime/rpc/errors.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/shared/workspace-session-schema.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/ipc/ssh.test.ts
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/i18n/locales/es.json
  • config/scripts/remote-agent-session-authority-repro.mjs
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/main/runtime/runtime-rpc.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/i18n/locales/en.json
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/main/daemon/daemon-pty-provider.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/index.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/renderer/src/i18n/locales/ja.json
  • src/main/runtime/agent-session-claim-identity.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/shared/claimed-agent-pty-owner.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/main/daemon/session.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/types.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/shared/claimed-agent-pty-owner-snapshot.ts
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/renderer/src/i18n/locales/ko.json
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/types.ts
  • src/renderer/src/lib/agent-background-session-test-state.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/relay/pty-handler.test.ts
  • src/main/daemon/terminal-host.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/shared/claimed-agent-pty-owner.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/main/ssh/ssh-relay-session.ts

@OrcaWin
OrcaWin force-pushed the OrcaWin/bug-remote-client-resumes-live-host-agent-sessio branch 2 times, most recently from 4517536 to 180d3cf Compare July 22, 2026 01:40

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/daemon/daemon-server.ts (1)

721-786: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject an attach/create whose PTY exited before its response.

onExit queues the exit but does not fence the pending RPC. If the PTY exits during host.createOrAttach, Lines 762-786 still register and return it as a successful live session, allowing a stale binding/ghost surface race.

Proposed fix
+        let exitedBeforeResponse = false
         try {
           ...
           streamClient: {
             ...
             onExit: (code, incarnationId) => {
+              exitedBeforeResponse = true
               ...
             }
           }
         } finally {
           ...
         }
         routedSessionId = result.agentSessionEnsure?.owner.ptyId ?? p.sessionId
+        if (exitedBeforeResponse) {
+          throw new Error('agent_session_exited_during_start')
+        }
         this.streamClientIdBySessionId.set(routedSessionId, clientId)

Based on PR objectives, an exit must retire the surface rather than permit a successful stale attachment.

src/main/persistence.ts (1)

4821-4831: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Prune workspaceSessionsByHostId here too

removeWorktreeMeta only clears the local workspaceSession; remote/runtime partitions in workspaceSessionsByHostId can still retain the removed worktree’s tabs and topology fence. That leaves stale PTY state behind after worktree deletion.

🧹 Nitpick comments (3)
src/main/index.ts (1)

1989-1992: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the shared profile-path authority domain.

Using the profile path as both key directory and authority-domain ID is intentional but non-obvious; add a rationale comment so future path changes do not silently invalidate durable claims.

Suggested clarification
+    // Why: the authority domain must remain profile-scoped and stable across restarts,
+    // matching the location of the durable coordination key.
     agentSessionClaimSigner: loadAgentSessionClaimSigner(
       getProfileUserDataPath(),
       getProfileUserDataPath()

As per coding guidelines, “For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works.”

Source: Coding guidelines

src/main/daemon/daemon-server.ts (1)

689-695: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document why malformed claims must fail before PTY admission.

This validation is security-sensitive and non-obvious enough to warrant a brief rationale comment.

As per coding guidelines, “For non-obvious TypeScript code, add a concise comment explaining why the constraint exists.”

Source: Coding guidelines

src/main/providers/ssh-pty-session-reattach.ts (1)

88-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Explain the attach/exit race fence.

Add a short rationale before the match check; this prevents future changes from removing a necessary dead-binding guard.

As per coding guidelines, “For non-obvious TypeScript code, add a concise comment explaining why the constraint exists.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 74e63cc0-efa3-48e6-af4d-52cb89c54a1a

📥 Commits

Reviewing files that changed from the base of the PR and between af2e0a7 and 180d3cf.

📒 Files selected for processing (143)
  • config/localization-coverage-allowlist.json
  • config/scripts/remote-agent-session-authority-repro.mjs
  • config/scripts/remote-agent-session-repro-client.mjs
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • docs/reference/remote-agent-session-host-authority.md
  • package.json
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/daemon-pty-provider.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • src/main/daemon/terminal-host.ts
  • src/main/daemon/types.ts
  • src/main/index.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-capabilities.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-session-reattach.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/main/providers/types.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.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/agent-background-session-test-state.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-cwd.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-web-runtime.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
🚧 Files skipped from review as they are similar to previous changes (124)
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • config/localization-coverage-allowlist.json
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • config/scripts/remote-agent-session-repro-client.mjs
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/daemon/types.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • package.json
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/providers/ssh-agent-session-capabilities.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/main/daemon/daemon-pty-provider.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/session.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • config/scripts/remote-agent-session-authority-repro.mjs
  • src/main/ipc/ssh.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/renderer/src/i18n/locales/zh.json
  • src/main/daemon/daemon-protocol-version.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-web-runtime.test.ts
  • src/main/daemon/session.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/main/daemon/terminal-host.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/renderer/src/i18n/locales/ja.json
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/ipc/ssh.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/lib/agent-background-session-test-state.ts
  • src/main/providers/types.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/relay/pty-handler.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/main/persistence.test.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/relay/pty-handler.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
👮 Files not reviewed due to content moderation or server errors (1)
  • src/renderer/src/i18n/locales/ko.json

Comment on lines +45 to +77
const relaySessionId = toRelaySshPtyId(args.connectionId, args.sessionId)
console.warn(`[ssh-pty] spawn() called with sessionId=${args.sessionId}, attempting pty.attach`)
try {
// Why: expected pane identity prevents a reused relay id from attaching the wrong shell.
const expectedPaneKey = args.options.paneKey ?? args.options.env?.ORCA_PANE_KEY
const expectedTabId = args.options.tabId ?? args.options.env?.ORCA_TAB_ID
const attachResult = parseSshPtyAttachResult(
await args.mux.request('pty.attach', {
id: relaySessionId,
cols: args.options.cols,
rows: args.options.rows,
suppressReplayNotification: true,
...(expectedPaneKey ? { expectedPaneKey } : {}),
...(expectedTabId ? { expectedTabId } : {})
})
)
console.warn(
`[ssh-pty] pty.attach succeeded for ${args.sessionId}, replay=${!!attachResult.replay}`
)
return {
id: toAppSshPtyId(args.connectionId, relaySessionId),
isReattach: true,
...(attachResult.replay ? { replay: attachResult.replay } : {}),
...(attachResult.incarnationId ? { incarnationId: attachResult.incarnationId } : {})
}
} catch (error) {
// Why: an expired relay lease must be surfaced distinctly so the renderer clears its binding.
console.warn(`[ssh-pty] pty.attach FAILED for ${args.sessionId}:`, error)
if (isSshPtyNotFoundError(error)) {
const mismatchMarker = isSshPtyIdentityMismatchError(error)
? ` ${SSH_PTY_IDENTITY_MISMATCH_ERROR}`
: ''
throw new Error(`${SSH_SESSION_EXPIRED_ERROR}: ${relaySessionId}${mismatchMarker}`)

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.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Do not log raw relay errors or session identifiers.

The failure path writes the full remote error object, and all paths expose session IDs. Log a stable error class/code instead.

Proposed fix
-    console.warn(`[ssh-pty] spawn() called with sessionId=${args.sessionId}, attempting pty.attach`)
+    console.warn('[ssh-pty] attempting pty.attach')
...
-    console.warn(
-      `[ssh-pty] pty.attach succeeded for ${args.sessionId}, replay=${!!attachResult.replay}`
-    )
+    console.warn('[ssh-pty] pty.attach succeeded', { replay: Boolean(attachResult.replay) })
...
-    console.warn(`[ssh-pty] pty.attach FAILED for ${args.sessionId}:`, error)
+    console.warn('[ssh-pty] pty.attach failed', {
+      reason: isSshPtyNotFoundError(error) ? 'not-found' : 'request-error'
+    })
📝 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
const relaySessionId = toRelaySshPtyId(args.connectionId, args.sessionId)
console.warn(`[ssh-pty] spawn() called with sessionId=${args.sessionId}, attempting pty.attach`)
try {
// Why: expected pane identity prevents a reused relay id from attaching the wrong shell.
const expectedPaneKey = args.options.paneKey ?? args.options.env?.ORCA_PANE_KEY
const expectedTabId = args.options.tabId ?? args.options.env?.ORCA_TAB_ID
const attachResult = parseSshPtyAttachResult(
await args.mux.request('pty.attach', {
id: relaySessionId,
cols: args.options.cols,
rows: args.options.rows,
suppressReplayNotification: true,
...(expectedPaneKey ? { expectedPaneKey } : {}),
...(expectedTabId ? { expectedTabId } : {})
})
)
console.warn(
`[ssh-pty] pty.attach succeeded for ${args.sessionId}, replay=${!!attachResult.replay}`
)
return {
id: toAppSshPtyId(args.connectionId, relaySessionId),
isReattach: true,
...(attachResult.replay ? { replay: attachResult.replay } : {}),
...(attachResult.incarnationId ? { incarnationId: attachResult.incarnationId } : {})
}
} catch (error) {
// Why: an expired relay lease must be surfaced distinctly so the renderer clears its binding.
console.warn(`[ssh-pty] pty.attach FAILED for ${args.sessionId}:`, error)
if (isSshPtyNotFoundError(error)) {
const mismatchMarker = isSshPtyIdentityMismatchError(error)
? ` ${SSH_PTY_IDENTITY_MISMATCH_ERROR}`
: ''
throw new Error(`${SSH_SESSION_EXPIRED_ERROR}: ${relaySessionId}${mismatchMarker}`)
const relaySessionId = toRelaySshPtyId(args.connectionId, args.sessionId)
console.warn('[ssh-pty] attempting pty.attach')
try {
// Why: expected pane identity prevents a reused relay id from attaching the wrong shell.
const expectedPaneKey = args.options.paneKey ?? args.options.env?.ORCA_PANE_KEY
const expectedTabId = args.options.tabId ?? args.options.env?.ORCA_TAB_ID
const attachResult = parseSshPtyAttachResult(
await args.mux.request('pty.attach', {
id: relaySessionId,
cols: args.options.cols,
rows: args.options.rows,
suppressReplayNotification: true,
...(expectedPaneKey ? { expectedPaneKey } : {}),
...(expectedTabId ? { expectedTabId } : {})
})
)
console.warn('[ssh-pty] pty.attach succeeded', { replay: Boolean(attachResult.replay) })
return {
id: toAppSshPtyId(args.connectionId, relaySessionId),
isReattach: true,
...(attachResult.replay ? { replay: attachResult.replay } : {}),
...(attachResult.incarnationId ? { incarnationId: attachResult.incarnationId } : {})
}
} catch (error) {
// Why: an expired relay lease must be surfaced distinctly so the renderer clears its binding.
console.warn('[ssh-pty] pty.attach failed', {
reason: isSshPtyNotFoundError(error) ? 'not-found' : 'request-error'
})
if (isSshPtyNotFoundError(error)) {
const mismatchMarker = isSshPtyIdentityMismatchError(error)
? ` ${SSH_PTY_IDENTITY_MISMATCH_ERROR}`
: ''
throw new Error(`${SSH_SESSION_EXPIRED_ERROR}: ${relaySessionId}${mismatchMarker}`)
🧰 Tools
🪛 ast-grep (0.44.1)

[warning] 45-45: Avoid logging sensitive data
Context: console.warn([ssh-pty] spawn() called with sessionId=${args.sessionId}, attempting pty.attach)
Note: [CWE-532] Insertion of Sensitive Information into Log File.

(log-sensitive-data-typescript)


[warning] 60-62: Avoid logging sensitive data
Context: console.warn(
[ssh-pty] pty.attach succeeded for ${args.sessionId}, replay=${!!attachResult.replay}
)
Note: [CWE-532] Insertion of Sensitive Information into Log File.

(log-sensitive-data-typescript)


[warning] 71-71: Avoid logging sensitive data
Context: console.warn([ssh-pty] pty.attach FAILED for ${args.sessionId}:, error)
Note: [CWE-532] Insertion of Sensitive Information into Log File.

(log-sensitive-data-typescript)

Source: Linters/SAST tools

@Jinwoo-H
Jinwoo-H force-pushed the OrcaWin/bug-remote-client-resumes-live-host-agent-sessio branch from 180d3cf to 60c9881 Compare July 22, 2026 02:10

@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: 1

🧹 Nitpick comments (2)
src/main/runtime/orca-runtime-agent-session-operation.test.ts (1)

42-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the intentional type escapes.

as never and unknown as bypass the runtime’s dependency/internal contracts. Add a concise why-comment so future contract drift is not silently hidden by this fixture.

Proposed clarification
+  // Keep ledger tests isolated from unrelated store/provider setup while
+  // explicitly exposing the runtime seams exercised below.
   const runtime = new OrcaRuntimeService(

Source: Coding guidelines

src/shared/claimed-agent-pty-owner.ts (1)

68-84: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a "why" comment distinguishing the two equality checks.

agentSessionClaimsEqual (identity-scope) is checked first, then worktreeScopeDigest is compared separately, while find()/the fresh-owner path elsewhere use scopedAgentSessionClaimsEqual (identity + worktree). This split is intentional — it's what lets same-identity/different-worktree claims fall through to agent_session_conflict instead of agent_session_ownership_unknown — but nothing here signals that distinction, making it easy to mistake for redundant/dead code.

As per coding guidelines, **/*.{ts,tsx}: "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

📝 Proposed comment
     const live = this.live.get(key)
     if (live) {
+      // Why: this is identity-only equality (worktree-agnostic); a same-identity,
+      // different-worktree claim must fall through to the conflict check below
+      // rather than being rejected as an unrelated/unknown claim.
       if (!agentSessionClaimsEqual(live.claim, requestedClaim)) {
         throw new Error('agent_session_ownership_unknown')
       }
+      // Why: worktree scope is checked separately from identity so a same-identity
+      // claim from a different worktree is reported as a conflict, not "unknown".
       if (live.claim.worktreeScopeDigest !== requestedClaim.worktreeScopeDigest) {
         throw new Error('agent_session_conflict')
       }

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 37e265ee-ed81-4aca-81e6-4f29d4a6f843

📥 Commits

Reviewing files that changed from the base of the PR and between 180d3cf and 60c9881020e39717bc206f9ecbac76217e730b41.

📒 Files selected for processing (155)
  • config/localization-coverage-allowlist.json
  • config/reliability-gates.jsonc
  • config/scripts/remote-agent-session-authority-repro.mjs
  • config/scripts/remote-agent-session-repro-client.mjs
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • docs/reference/remote-agent-session-host-authority.md
  • package.json
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/daemon-pty-provider.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • src/main/daemon/terminal-host.ts
  • src/main/daemon/types.ts
  • src/main/index.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-capabilities.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-session-reattach.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/main/providers/types.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.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/agent-background-session-test-state.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-cwd.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-web-runtime.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/shared/agent-session-host-authority.ts
  • src/shared/claimed-agent-pty-owner-snapshot.ts
  • src/shared/claimed-agent-pty-owner.test.ts
  • src/shared/claimed-agent-pty-owner.ts
  • src/shared/protocol-version.ts
  • src/shared/pty-incarnation.ts
  • src/shared/runtime-types.ts
  • src/shared/types.ts
  • src/shared/workspace-session-schema.ts
🚧 Files skipped from review as they are similar to previous changes (138)
  • config/localization-coverage-allowlist.json
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • config/scripts/remote-agent-session-repro-client.mjs
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/renderer/src/i18n/locales/es.json
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ipc/ssh.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/shared/runtime-types.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/main/daemon/pty-session-id.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/shared/pty-incarnation.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/shared/protocol-version.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-cwd.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/shared/types.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • package.json
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/shared/workspace-session-schema.ts
  • src/main/index.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/main/daemon/session.test.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-web-runtime.test.ts
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/renderer/src/i18n/locales/en.json
  • src/main/daemon/daemon-pty-provider.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • config/scripts/remote-agent-session-authority-repro.mjs
  • src/main/daemon/session.ts
  • src/main/providers/ssh-agent-session-capabilities.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/agent-background-session-test-state.ts
  • src/renderer/src/i18n/locales/ko.json
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/renderer/src/i18n/locales/ja.json
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/main/daemon/terminal-host.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/main/providers/types.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/shared/claimed-agent-pty-owner-snapshot.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/persistence.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/main/ipc/pty.ts
  • src/relay/pty-handler.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/persistence.test.ts
  • src/main/ipc/pty.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/relay/pty-handler.test.ts
  • src/main/daemon/types.ts

Comment on lines +1384 to +1387
"runtimeBudget": {
"p95Seconds": 30,
"scope": "focused ownership, compatibility, lifecycle, and renderer handoff tests; build-backed repro tracked separately"
},

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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Align the runtime budget with the configured repro command.

The gate runs pnpm test:repro:remote-agent-session, but its recorded duration is 48.47s (Lines 1378-1381), exceeding this 30s budget. Raise the budget or split the repro into a separately budgeted gate.

@Jinwoo-H
Jinwoo-H force-pushed the OrcaWin/bug-remote-client-resumes-live-host-agent-sessio branch from 60c9881 to 66e495a Compare July 22, 2026 02:41

@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: 1

🧹 Nitpick comments (3)
src/main/daemon/daemon-server.ts (1)

718-720: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document canonical PTY routing.

Explain why an adopted agent session must reroute all stream lifecycle state from the provisional request ID to the execution owner’s canonical PTY ID.

Suggested clarification
+            // Why: adoption replaces the provisional request ID with the canonical owner PTY;
+            // stream data and exit cleanup must use that owner to avoid stale lifecycle state.
             onSessionResolved: (sessionId) => {
               routedSessionId = sessionId
             },

As per coding guidelines, “For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works.”

Also applies to: 762-763

Source: Coding guidelines

src/main/providers/ssh-pty-session-reattach.ts (1)

88-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the attach/exit race fence.

Add a why-comment at the operation boundary: an exact exit can arrive while pty.attach is in flight, and this check prevents reviving a dead or reused relay PTY.

As per coding guidelines, “For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works.”

Source: Coding guidelines

src/renderer/src/runtime/remote-runtime-session-tabs-inflight.ts (1)

11-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a short "why" comment for the \u0000 key separator.

Not obvious why a null byte was chosen over another delimiter; a brief note (e.g., prevents ambiguous key collisions between differing id boundaries) would help future readers.

As per path instructions, "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 976a208e-5820-4c24-b0fe-b6e6bdb2e67e

📥 Commits

Reviewing files that changed from the base of the PR and between 60c9881020e39717bc206f9ecbac76217e730b41 and 66e495aa777b0737d557e0d514cee17d2a269c8a.

📒 Files selected for processing (163)
  • config/localization-coverage-allowlist.json
  • config/reliability-gates.jsonc
  • config/scripts/remote-agent-session-authority-repro.mjs
  • config/scripts/remote-agent-session-repro-client.mjs
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • docs/reference/plans/2026-07-21-windows-daemon-generation-safety-investigation.md
  • docs/reference/remote-agent-session-host-authority.md
  • package.json
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/daemon-pty-provider.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • src/main/daemon/terminal-host.ts
  • src/main/daemon/types.ts
  • src/main/index.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-capabilities.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-session-reattach.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/main/providers/types.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/session-tab-close-methods.ts
  • src/main/runtime/rpc/methods/session-tabs-schemas.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.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/agent-background-session-test-state.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-cwd.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-web-runtime.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/renderer/src/runtime/remote-runtime-session-tabs-inflight.test.ts
  • src/renderer/src/runtime/remote-runtime-session-tabs-inflight.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/shared/agent-session-host-authority.ts
  • src/shared/claimed-agent-pty-owner-snapshot.ts
  • src/shared/claimed-agent-pty-owner.test.ts
  • src/shared/claimed-agent-pty-owner.ts
  • src/shared/protocol-version.ts
  • src/shared/pty-incarnation.ts
  • src/shared/runtime-types.ts
  • src/shared/types.ts
  • src/shared/workspace-session-schema.ts
  • tests/e2e/daemon-generation-reconnect-safety.spec.ts
🚧 Files skipped from review as they are similar to previous changes (142)
  • src/main/daemon/daemon-protocol-version.test.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/terminal-host-session-cwd.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/main/providers/ssh-capability-probe-waiter.ts
  • src/main/ipc/ssh.ts
  • config/localization-coverage-allowlist.json
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • src/shared/pty-incarnation.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/terminal-host-agent-session-generations.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/daemon/daemon-pty-provider.test.ts
  • src/main/daemon/terminal-host-tombstones.ts
  • src/main/daemon/daemon-create-or-attach-result.ts
  • src/shared/runtime-types.ts
  • src/main/providers/ssh-pty-provider-claim-incarnation.test.ts
  • config/scripts/remote-agent-session-repro-client.mjs
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/renderer/src/runtime/agent-session-operation-id.test.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/main/providers/ssh-agent-session-process-list.ts
  • src/shared/types.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/runtime/agent-session-operation-id.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-remote-compat.test.ts
  • src/main/providers/ssh-pty-errors.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/main/daemon/terminal-host-agent-session.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/daemon/terminal-host-create-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/index.ts
  • src/main/runtime/remote-agent-session-host-authority.integration.test.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/providers/ssh-pty-spawn-request.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/main/runtime/rpc/errors.ts
  • package.json
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/main/runtime/orca-runtime.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/i18n/locales/es.json
  • src/main/orca-profiles/profile-project-session-state.test.ts
  • src/main/daemon/types.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/main/providers/ssh-pty-spawn-exit-race.ts
  • src/renderer/src/runtime/runtime-client-target.ts
  • src/renderer/src/i18n/locales/en.json
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/main/providers/ssh-agent-session-capabilities.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/runtime/remote-agent-session-launch.ts
  • src/renderer/src/lib/runtime-agent-background-create.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/shared/protocol-version.ts
  • src/renderer/src/lib/workspace-session-host-records.ts
  • src/shared/workspace-session-schema.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-cwd.test.ts
  • src/main/daemon/pty-session-id.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/renderer/src/runtime/agent-session-create-operation.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/main/orca-profiles/profile-project-transfer-payload.ts
  • src/main/runtime/agent-session-claim-identity.test.ts
  • src/main/orca-profiles/profile-project-session-transfer.ts
  • src/main/ipc/ssh.test.ts
  • src/renderer/src/lib/workspace-session-host-field-ownership.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/renderer/src/runtime/remote-agent-session-launch.test.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-agent-session-claim-validation.ts
  • src/main/daemon/session.test.ts
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/main/runtime/agent-session-claim-identity.ts
  • src/renderer/src/lib/workspace-session-host-split.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/runtime/mobile-session-terminal-persistence-retirement.test.ts
  • src/main/orca-profiles/profile-project-session-state.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/terminal-host.ts
  • src/main/providers/types.ts
  • src/main/daemon/session.ts
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/i18n/locales/ko.json
  • src/main/runtime/workspace-session-terminal-membership-authority.ts
  • config/scripts/remote-agent-session-authority-repro.mjs
  • src/main/runtime/mobile-session-terminal-persistence-retirement.ts
  • src/main/runtime/mobile-session-terminal-retirement.test.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/renderer/src/lib/agent-background-session-test-state.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/renderer/src/lib/workspace-session-host-split.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/shared/claimed-agent-pty-owner.test.ts
  • src/relay/pty-handler.test.ts
  • src/shared/claimed-agent-pty-owner-snapshot.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-agent-session-handoff.ts
  • src/main/persistence.ts
  • src/main/runtime/mobile-session-terminal-retirement.ts
  • src/renderer/src/lib/launch-agent-background-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/shared/claimed-agent-pty-owner.ts
  • src/relay/pty-handler.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/main/ipc/pty.test.ts
  • src/main/persistence.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-web-runtime.test.ts
  • src/main/ipc/pty.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts

@OrcaWin
OrcaWin force-pushed the OrcaWin/bug-remote-client-resumes-live-host-agent-sessio branch from 66e495a to 25c017a Compare July 22, 2026 03:33
@OrcaWin

OrcaWin commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto current main at 2a32c5c9a and resolved the new conflicts.

Upstream integration audit:

Post-rebase validation:

  • remote host-authority gate: 10 files / 325 tests passed
  • reconnect plus mirrored-close gate: 10 files / 1,014 tests passed
  • all TypeScript typechecks passed
  • reliability manifest: 46 gates passed
  • build-backed two-client remote harness passed: one spawn, retry adoption, durable exit retirement, no restart resurrection
  • git diff --check passed

The branch remains one squashed commit authored and committed by OrcaWin.

@OrcaWin
OrcaWin merged commit b232df7 into main Jul 22, 2026
11 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/bug-remote-client-resumes-live-host-agent-sessio branch July 22, 2026 03:51
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
@AmethystLiang

Copy link
Copy Markdown
Contributor

Related to #8871.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Remote client resumes live host agent sessions, spawning duplicate TUIs on the same provider session

2 participants