Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/ipc/pty/ipc/spawn-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export async function commitPtyIpcSpawn(ctx: PtyIpcSpawnState): Promise<PtySpawn
typeof ctx.launchCommand === 'string' ? ctx.launchCommand : null
)
}
if (ctx.isClaudeLaunch && !ctx.stablePaneOwner) {
if (ctx.isClaudeLaunch && !ctx.stablePaneOwner && !ctx.result.agentResumeUnavailable) {
markClaudePtySpawned(ctx.result.id)
}
// Why: record the paneKey mapping so clearProviderPtyState can clear the agent-hooks server's per-paneKey caches on exit.
Expand Down Expand Up @@ -179,7 +179,8 @@ export async function commitPtyIpcSpawn(ctx: PtyIpcSpawnState): Promise<PtySpawn
})
}
// Why: telemetry-plan.md§Agent launch semantics — fire agent_started only after spawn resolved; safeParse each field so a spoofed IPC payload can't poison the event (missing required field skips it).
if (args.telemetry && !ctx.stablePaneOwner) {
// Why: a suppressed resume produced a plain shell, so there is no agent launch to report.
if (args.telemetry && !ctx.stablePaneOwner && !ctx.result.agentResumeUnavailable) {
const agentKindParse = agentKindSchema.safeParse(args.telemetry.agent_kind)
const launchSourceParse = launchSourceSchema.safeParse(args.telemetry.launch_source)
const requestKindParse = requestKindSchema.safeParse(args.telemetry.request_kind)
Expand Down
145 changes: 145 additions & 0 deletions src/main/ipc/pty/pane/relay-replacement-resume-suppression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import type { Store } from '../../../persistence'
import type { IPtyProvider, PtySpawnOptions, PtySpawnResult } from '../../../providers/types'
import { parseAppSshPtyId, toRelaySshPtyId } from '../../../providers/ssh-pty-id'

/** Bounded so a slow relay leaves the fallback spawn on today's timing, not blocked behind a probe. */
export const RELAY_AGE_STATUS_TIMEOUT_MS = 2_000

/**
* Slack between two independently measured elapsed times — the client's clock over the binding and
* the host's own uptime counter. Both are durations, so no clock-offset correction is possible or
* needed; this only absorbs jitter and the gap between daemon start and the first binding write.
*/
export const RELAY_AGE_CLOCK_SLACK_MS = 30_000

/**
* Startup intent replayed by the absence fallback. Mirrors the set `attachStablePaneOwner` already
* strips for an attach: everything that would run an agent, a resume argv, or a claim in the shell.
*/
export function stripStartupIntent(options: PtySpawnOptions): PtySpawnOptions {
return {
...options,
command: undefined,
commandDelivery: undefined,
startupCommandDelivery: undefined,
launchAgent: undefined,
startupIngress: undefined,
agentSessionEnsure: undefined,
agentSessionCreateOperationId: undefined
}
}

export function carriesStartupIntent(options: PtySpawnOptions): boolean {
return Boolean(
options.command ||
options.launchAgent ||
options.startupIngress ||
options.agentSessionEnsure ||
options.agentSessionCreateOperationId
)
}

/** Age of the lease that recorded this SSH binding, or null when nothing dates it. */
function bindingAgeMs(
store: Store | undefined,
connectionId: string,
ptyId: string,
now: number
): number | null {
if (!store || typeof store.getSshRemotePtyLeases !== 'function') {
return null
}
const parsed = parseAppSshPtyId(ptyId)
if (!parsed || parsed.connectionId !== connectionId) {
return null
}
let createdAt: number | null = null
for (const lease of store.getSshRemotePtyLeases(connectionId)) {
if (
toRelaySshPtyId(connectionId, lease.ptyId) !== parsed.relayPtyId ||
typeof lease.createdAt !== 'number' ||
!Number.isFinite(lease.createdAt)
) {
continue
}
createdAt = createdAt === null ? lease.createdAt : Math.min(createdAt, lease.createdAt)
}
if (createdAt === null) {
return null
}
const age = now - createdAt
return Number.isFinite(age) && age > 0 ? age : null
}

/**
* Does the relay that just answered "that PTY is absent" predate the binding it answered about?
*
* A daemon whose reported uptime is shorter than the binding's age cannot have owned the bound
* process, so its positive absence is `unverifiable` rather than `exited`
* (docs/reference/ssh-execution-boundary.md) — the shell it named may still be alive as an orphan
* of the daemon it replaced. Only an answer that ARRIVES and is demonstrably younger says so:
* a missing provider, a rejected or timed-out `relay.status`, an absent or unusable `uptimeMs`,
* and an undatable binding all return false, leaving the caller on today's behavior. Silence is
* never promoted to a verdict here.
*
* Reads only fields `relay.status` already publishes; adds no request field and no opcode.
*/
export async function answeringRelayPredatesBinding(args: {
provider: IPtyProvider
store?: Store | undefined
connectionId?: string | null
ptyId: string
now?: () => number
}): Promise<boolean> {
const { provider, connectionId, ptyId } = args
if (!connectionId) {
return false
}
const age = bindingAgeMs(args.store, connectionId, ptyId, (args.now ?? Date.now)())
if (age === null) {
return false
}
let status: unknown
try {
// Optional call: a provider with no host RPC yields undefined, which is not an answer.
status = await provider.requestHostRpc?.(
'relay.status',
{},
{
timeoutMs: RELAY_AGE_STATUS_TIMEOUT_MS
}
)
} catch {
return false
}
if (!status || typeof status !== 'object') {
return false
}
const uptimeMs = (status as { uptimeMs?: unknown }).uptimeMs
if (typeof uptimeMs !== 'number' || !Number.isFinite(uptimeMs) || uptimeMs < 0) {
return false
}
return age > uptimeMs + RELAY_AGE_CLOCK_SLACK_MS
}

/**
* The absence fallback's spawn, minus the startup intent a replacement relay never held.
*
* Returns null whenever nothing proves a replacement, leaving the caller on its unchanged path —
* the spawn itself is never gated here, only the intent replayed into it.
*/
export async function spawnWithoutReplayedIntent(args: {
provider: IPtyProvider
store?: Store | undefined
connectionId?: string | null
ptyId: string
spawnOptions: PtySpawnOptions
onFreshSpawn?: (result: PtySpawnResult) => void
}): Promise<PtySpawnResult | null> {
if (!carriesStartupIntent(args.spawnOptions) || !(await answeringRelayPredatesBinding(args))) {
return null
}
const result = await args.provider.spawn(stripStartupIntent(args.spawnOptions))
args.onFreshSpawn?.(result)
return { ...result, agentResumeUnavailable: true as const }
}
24 changes: 23 additions & 1 deletion src/main/ipc/pty/pane/stable-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from '../../../daemon/daemon-errors'
import { ptyIncarnationById, ptyOwnership } from '../provider/ownership-state'
import { isPtyAlreadyGoneError } from '../provider/liveness'
import { isSshPtyAbsentFromRelayError } from '../../../providers/ssh-pty-errors'
import { spawnWithoutReplayedIntent } from './relay-replacement-resume-suppression'
import { clearProviderPtyState } from '../provider/state-cleanup'

export type StablePaneOwner = {
Expand Down Expand Up @@ -166,6 +168,8 @@ export type StablePaneSpawnContext = {
connectionId?: string | null
resolveOwner?: () => StablePaneOwner | null
onFreshSpawn?: (result: PtySpawnResult) => void
/** Fired when a reachable relay positively answered this exact PTY id absent. */
onRelayPositiveAbsence?: () => void
}

export function stablePanePersistenceFence(
Expand Down Expand Up @@ -242,6 +246,9 @@ export async function attachStablePaneOwner(
if (!isPtyAlreadyGoneError(error)) {
throw error
}
if (isSshPtyAbsentFromRelayError(error)) {
args.onRelayPositiveAbsence?.()
}
Comment on lines +249 to +251

@coderabbitai coderabbitai Bot Aug 28, 2026 •

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 | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- applicable repository conventions ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -type f -name '*.md' -print
printf '%s\n' '--- SSH execution boundary ---'
cat -n docs/reference/ssh-execution-boundary.md
printf '%s\n' '--- stable-owner outline ---'
ast-grep outline src/main/ipc/pty/pane/stable-owner.ts
printf '%s\n' '--- changed path and direct flow ---'
sed -n '220,325p' src/main/ipc/pty/pane/stable-owner.ts
printf '%s\n' '--- onPtyExit definitions and callers ---'
rg -n -A8 -B8 'onPtyExit|isSshPtyAbsentFromRelayError|spawnForStablePane|attachStablePaneOwner' src/main

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- convention file headers ---'
find /tmp/coderabbit-repo-knowledge/stablyai/orca-89dc44e4 -type f -name '*.md' -print0 |
  while IFS= read -r -d '' f; do
    printf '\n### %s\n' "$f"
    head -5 "$f"
  done
printf '%s\n' '--- SSH execution boundary ---'
sed -n '1,220p' docs/reference/ssh-execution-boundary.md
printf '%s\n' '--- stable-owner imports and flow ---'
sed -n '1,90p' src/main/ipc/pty/pane/stable-owner.ts
sed -n '220,325p' src/main/ipc/pty/pane/stable-owner.ts
printf '%s\n' '--- focused definitions ---'
rg -n -A35 -B12 'class OrcaRuntimeService|onPtyExit\s*\(' src
printf '%s\n' '--- focused diff ---'
git diff -- src/main/ipc/pty/pane/stable-owner.ts
printf '%s\n' '--- stable-owner tests ---'
find src/main -type f \( -name '*stable-owner*.test.ts' -o -name '*pty*persisted*repair*.test.ts' \) -print

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- knowledge files ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -type f -name '*.md' -print
printf '%s\n' '--- SSH boundary terms ---'
rg -n -A4 -B4 'loss of contact|unverifiable|live|exited|relay' docs/reference/ssh-execution-boundary.md
printf '%s\n' '--- stable-owner exact source ---'
rg -n 'isSshPtyAbsentFromRelayError|onPtyExit|spawnForStablePane|attachStablePaneOwner|relay|unverif' src/main/ipc/pty/pane/stable-owner.ts
sed -n '1,80p' src/main/ipc/pty/pane/stable-owner.ts
sed -n '220,320p' src/main/ipc/pty/pane/stable-owner.ts
printf '%s\n' '--- runtime implementation location ---'
rg -l 'class OrcaRuntimeService' src/main
rg -n -A45 -B10 '^[[:space:]]*onPtyExit[[:space:]]*\(' src/main/runtime
printf '%s\n' '--- focused diff ---'
git diff --stat -- src/main/ipc/pty/pane/stable-owner.ts
git diff -U20 -- src/main/ipc/pty/pane/stable-owner.ts

Repository: stablyai/orca

Length of output: 24421


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- attachStablePaneOwner complete flow ---'
sed -n '185,285p' src/main/ipc/pty/pane/stable-owner.ts
printf '%s\n' '--- onPtyExit complete decision flow ---'
sed -n '15960,16090p' src/main/runtime/orca-runtime.ts
printf '%s\n' '--- liveness verdict implementation ---'
rg -n -A30 -B8 'getPtyLivenessVerdict|markPtyLivenessUnverifiable|SSH_EXIT_UNCONFIRMED_REASON' src/main/runtime/orca-runtime.ts
printf '%s\n' '--- relay absence error contract and provider path ---'
rg -n -A20 -B10 'isSshPtyAbsentFromRelayError|SshPtyAbsent|ABSENT_FROM_RELAY|absent from relay' src/main
printf '%s\n' '--- focused persisted-repair cases ---'
rg -n -A18 -B18 'owner_unverified|replacement relay|young|onPtyExit.*not|positive absence|relay' src/main/ipc/pty-persisted-incarnation-repair.test.ts

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- replacement-relay suppression implementation ---'
cat -n src/main/ipc/pty/pane/relay-replacement-resume-suppression.ts
printf '%s\n' '--- all relay age/replacement symbols ---'
rg -n -A12 -B12 'relayAge|relay age|replacement relay|relay replacement|replayed intent|spawnWithoutReplayedIntent|grace|young' src/main src/relay
printf '%s\n' '--- SSH provider lifecycle and relay identity ---'
sed -n '200,275p' src/main/providers/ssh-pty-session-reattach.ts
sed -n '1,130p' src/main/providers/ssh-pty-errors.ts
rg -n -A18 -B18 'restart|reconnect|generation|relay.*start|startedAt|createdAt|age' src/main/ssh src/main/providers src/relay | head -300
printf '%s\n' '--- relevant conventions and learnings ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/src.md
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-main-pty.md

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- suppression helper ---'
wc -l src/main/ipc/pty/pane/relay-replacement-resume-suppression.ts
cat -n src/main/ipc/pty/pane/relay-replacement-resume-suppression.ts
printf '%s\n' '--- stable pane spawn context and all age-related fields ---'
rg -n -A12 -B12 'StablePaneSpawnContext|relayAnsweredAbsent|spawnWithoutReplayedIntent|age|generation|replacement' src/main/ipc/pty/pane src/main/providers/ssh-pty-session-reattach.ts
printf '%s\n' '--- reattach error path ---'
sed -n '215,265p' src/main/providers/ssh-pty-session-reattach.ts
printf '%s\n' '--- focused persisted-repair tests ---'
sed -n '330,510p' src/main/ipc/pty-persisted-incarnation-repair.test.ts
printf '%s\n' '--- focused relay-absence tests ---'
sed -n '1,110p' src/main/providers/ssh-pty-relay-absence-verdict.test.ts

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- focused relay-absence test file ---'
wc -l src/main/ipc/pty/pane/stable-pane-relay-absence-respawn.test.ts
cat -n src/main/ipc/pty/pane/stable-pane-relay-absence-respawn.test.ts
printf '%s\n' '--- stable-owner context declaration ---'
rg -n -A35 -B8 'type StablePaneSpawnContext|interface StablePaneSpawnContext|onRelayPositiveAbsence' src/main/ipc/pty/pane/stable-owner.ts
printf '%s\n' '--- exact exit surface effects ---'
sed -n '16080,16180p' src/main/runtime/orca-runtime.ts

Repository: stablyai/orca

Length of output: 18101


Classify young replacement relays as unverifiable before exit handling. attachStablePaneOwner calls runtime.onPtyExit(..., 0, ...) before spawnWithoutReplayedIntent checks relay.status.uptimeMs. This treats a possibly live SSH PTY as exited. Add a test that asserts onPtyExit is not called.

Source: Coding guidelines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judged this from the code rather than the label, and I think it's real as a contract gap — but it is pre-existing, not introduced here, and the fix is bigger than the thread implies. Leaving it open for @brennanb2025 rather than resolving.

The ordering claim is accurate. At head 24614bd:

  • stable-owner.ts:249-251 — the new hook only records relayAnsweredAbsent.
  • stable-owner.ts:262 — runtime?.onPtyExit(owner.ptyId, 0, owner.incarnationId) fires immediately after, inside the same catch.
  • stable-owner.ts:305-307 — spawnWithoutReplayedIntent (and therefore answeringRelayPredatesBinding → relay.status.uptimeMs) runs only after attachStablePaneOwner has already returned null.

So the exit is published before anything has evaluated whether the answering relay could have owned the binding.

Why the exit code matters, and it isn't cosmetic. In orca-runtime.ts:

  • :15992 preservesAbnormalSshSurface requires exitCode < 0. The call site passes 0, so it is false.
  • :16002 is therefore skipped — markPtyLivenessUnverifiable(ptyId, SSH_EXIT_UNCONFIRMED_REASON) never runs.
  • :16012 processDeathCertified = exitCode >= 0 || … is true, so reconcileAgentStatusForEndedProcessFn runs and the agent status is reconciled as ended.

onPtyExit(ptyId, 0, …) is a certified clean death. That is exited.

Which is the one verdict this case is not allowed to be. docs/reference/ssh-execution-boundary.md, "Distinguishing unverifiable from exited": "A stale event, an event for a superseded incarnation, or one quiet terminal with no host evidence does not [establish exited]." A relay whose uptime is shorter than the binding's age is a superseded incarnation by construction — that is the PR's own premise, stated verbatim at relay-replacement-resume-suppression.ts:76-83 ("its positive absence is unverifiable rather than exited"). The code acts on that premise for the resume intent and not for the liveness verdict.

Two things the thread gets wrong, though.

  1. It isn't a regression from this PR. :262 is unchanged on main and fires for every isPtyAlreadyGoneError. This PR adds the knowledge that a subset of those absences is unverifiable; it does not make the verdict worse than it already was.

  2. "Add a test that asserts onPtyExit is not called" is not the right assertion, and the naive fix regresses something else. Skipping onPtyExit leaves the runtime holding a binding no relay will ever answer for. And unconditionally passing exitCode < 0 for every SshPtyAbsentFromRelayError would mark genuinely-exited SSH PTYs unverifiable, which feeds verifyUnstoppedPtys (unstopped-pty-verification.ts:17) and can block worktree removal. The correct shape is: still retire the surface, but choose exitCode 0 vs -1 based on the age probe — which means hoisting answeringRelayPredatesBinding above :262 and awaiting up to RELAY_AGE_STATUS_TIMEOUT_MS (2s) inside the teardown path. That is a real latency and design change, and it is why the "heavy lift" tag is the accurate part of this comment.

One thing worth acting on regardless of the above: every case in stable-pane-relay-age-resume-suppression.test.ts passes runtime: undefined (:63, :217), so runtime?.onPtyExit is a no-op in all 12 tests. Whatever this PR decides the verdict should be, nothing currently pins it.

Also unrelated to this thread but in the same file — answeringRelayPredatesBinding is named backwards. It returns true when age > uptimeMs + slack, i.e. when the relay started after the binding and therefore does not predate it. The behavior is correct and the test names use "predates" in the correct English sense (…test.ts:138 pairs "predates the binding" with olderRelay and expects a replay), so the identifier is the sole outlier. Worth renaming before someone inverts the gate reading it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@.wk-scratch/reply-16989-a.md

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.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

if [ -f .wk-scratch/reply-16989-a.md ]; then
  cat .wk-scratch/reply-16989-a.md
else
  printf '%s\n' 'Referenced draft does not exist in this checkout.'
  fd -a '^reply-16989-a\.md$' . || true
fi

Length of output: 415


@brennanb2025, .wk-scratch/reply-16989-a.md is not present in this checkout. Please paste the draft content or provide an accessible file path.

You are interacting with an AI system.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This describes #16989's tree only. Nothing here survives the PR's closure — and main's onPtyExit(…, 0, …) is correct as written. Recording the check so it is not rediscovered.

The reported ordering does not exist on main. At origin/main (94e7586665) stable-owner.ts is 293 lines, the exit is at :255, and spawnWithoutReplayedIntent / relay.status.uptimeMs appear nowhere in the repo — grep -rn answeringRelayPredatesBinding src/ returns zero hits. The "publishes before the gate" relationship is created by this PR, so it dies with it.

The ordering is real inside the PR. attachStablePaneOwner publishes the exit and then return nulls; the gate runs one frame later, in spawnForStablePane. So the PR suppresses the replayed startup intent but never retracts the exit it already published. Two aggravators, also PR-local: kill.ts:79-88 publishes -1 for the identical isPtyAlreadyGoneError predicate, and adopt-stable.ts:60 calls attachStablePaneOwner directly, so that caller never reaches the gate at all.

On main the 0 is not a coercion — it is a host-verified absence. By the time line 255 runs, the two non-evidence classes have already been diverted above it:

if (error instanceof TerminalSessionOwnerUnverifiedError) {   // :235
  throw new Error('terminal_pane_owner_unverified')
}
if (isDaemonEndpointGoneError(error)) {                        // :239
  throw new TerminalHostGoneError()
}
if (!isPtyAlreadyGoneError(error)) {                           // :242
  throw error
}

Each remaining arm of isPtyAlreadyGoneError (provider/liveness.ts:58-67) is positive evidence from the owning host on this path:

  • SshPtyAbsentFromRelayError — raised only at ssh-pty-session-reattach.ts:238, after :229 diverts identity mismatch ("the id names a LIVE PTY owned by another pane"). Pinned both directions by ssh-pty-relay-absence-verdict.test.ts.
  • /PTY ".+" not found/i — produced only by src/relay/pty-handler.ts, i.e. the relay answering. On the attach path it is converted to the class above before any caller sees it; the other four throw sites are closeStartupQueryAuthority, sendSignal, getCwd, getInitialCwd, none of which are on this path.
  • /Session not found/i — SessionNotFoundError, reachable here only from a received daemon response (decodeDaemonResponseError) or from resolution.kind === 'absent' in DaemonSessionOwnerResolver.spawnAttachOnly, which routes kind === 'unknown' to TerminalSessionOwnerUnverifiedError instead.

A transport failure cannot reach line 255: stable-pane-relay-absence-respawn.test.ts:98-107 pins that a lost link, a request timeout, and a bare SSH_SESSION_EXPIRED all rethrow and keep the binding.

So the downstream composition is right. resolveUnreportedExitCause(0) yields { kind: 'unknown', reason: 'cause_unreported' } — "the reporting host did not say why", which is exactly what a relay-confirmed absence with no status tells us. processDeathCertified (orca-runtime.ts:16012) becomes true, correct for a verified absence, and preservesAbnormalSshSurface (:15992) correctly does not mark the pane unverifiable. Switching main to -1 would be the regression, not the fix: it would publish stop_unverified and markPtyLivenessUnverifiable for a process the host positively reported gone.

Leaving this thread open per the reviewer's request. No main PR was opened, because there is nothing on main to change.

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.

@brennanb2025, agreed on the scope correction.

onPtyExit(..., 0, ...) is correct on main. On main, the attach path has only host-verified absence cases at that point. The replacement-relay age gate does not exist there.

The finding is limited to #16989. This PR adds a new fact that can change the absence verdict: a relay younger than the binding could not have owned that binding. The current flow publishes the certified exit before it evaluates that fact.

No main follow-up is needed. The open thread should remain scoped to the PR-local ordering and its direct callers, including adopt-stable.ts.

🐇🔍


✏️ Learnings added
Learnt from: brennanb2025
Repo: stablyai/orca PR: 16989
File: src/main/ipc/pty/pane/stable-owner.ts:249-251
Timestamp: 2026-08-28T14:53:40.394Z
Learning: In the Orca stable-pane attach path on main, `runtime.onPtyExit(ptyId, 0, incarnationId)` follows host-verified PTY absence and is correct. PR `#16989` adds replacement-relay age detection after `attachStablePaneOwner` returns; when the answering SSH relay is younger than the persisted binding, that PR-local ordering can publish a certified exit before the new relay-age evidence classifies the absence as unverifiable. Any fix must be scoped to the PR behavior, not main.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

const ownerBeforeRetire = args.resolveOwner?.()
if (
ownerBeforeRetire &&
Expand Down Expand Up @@ -282,10 +289,25 @@ export async function spawnForStablePane(
args: StablePaneSpawnContext
): Promise<{ result: PtySpawnResult; owner: StablePaneOwner | null }> {
if (args.owner) {
const attached = await attachStablePaneOwner({ ...args, owner: args.owner })
let relayAnsweredAbsent = false
const attached = await attachStablePaneOwner({
...args,
owner: args.owner,
onRelayPositiveAbsence: () => {
relayAnsweredAbsent = true
}
})
if (attached) {
return attached
}
// Why: the user still needs a terminal, so the spawn itself is never gated — only the startup
// intent is, and only when the answering relay proves it never held the binding it answered for.
const plain = relayAnsweredAbsent
? await spawnWithoutReplayedIntent({ ...args, ptyId: args.owner.ptyId })
: null
if (plain) {
return { result: plain, owner: null }
}
}
const result = await args.provider.spawn(args.spawnOptions)
args.onFreshSpawn?.(result)
Expand Down
Loading
Loading