Skip to content

fix(terminal): attach never-activated daemon sessions on remote subscribe and provider-read fallback - #12589

Merged
Jinwoo-H merged 2 commits into
mainfrom
subscriber-driven-daemon-attach
Aug 5, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
subscriber-driven-daemon-attach

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Stacked on #12574 (sibling of #12578/#12579).

Summary

Fixes the remote-server blank-pane class (v1.4.169-rc.0 handoff): on a host, a daemon terminal whose tab was never activated in the host UI was never attached, so its output was never ingested — paired clients rendered blank/frozen panes and terminal read returned an empty tail while the PTY ran fine, and the recovery gate could never fire for desktop clients (their synthetic pty:-form handles always carry a ptyId, so the !leaf?.ptyId blank-detector at the multiplex subscribe site is unreachable; the correct never-attached detector was wired to mobile only).

A remote subscriber now counts as a viewer — with zero host-UI impact:

  • First subscriber acquire in the already-ref-counted registerRemoteTerminalViewSubscriber (covers both the multiplex and subscribe RPC paths) triggers a main-side headless attach of known-but-unattached local daemon sessions: attach-only (absent session ⇒ SessionNotFoundError, never a create; a pre-v31 daemon that ignores attachOnly and spawns gets the accidental session killed), at the session's own applied dimensions (the dormant attach() primitive hardcoded 80×24 — now reads getAppliedSize first), with in-flight dedupe, sticky success, and retry allowed only on a later subscriber event. Ingestion is already renderer-free, so this works identically on headed hosts and headless orca serve; no focus, selection, mount request, or navigation is ever touched — N clients share one attachment by construction.
  • withVisibleSnapshotFallback gains a strictly-scoped never-attached fallback so CLI terminal read of a live unattached session returns the provider tail instead of []. Unknown liveness keeps today's empty result, never an error.
  • Spawns published through this app are excluded (spawnPublishedPtys) — a respawned/reused id must not be treated as never-attached (caught by an existing pinned legacy-worker test during development).

Test plan

  • New terminal-subscriber-driven-daemon-attach.test.ts (8): real OrcaRuntimeService + real TERMINAL_METHODS multiplex dispatcher + injected daemon-model controller with attach-gated data delivery, handle minted via the same issuePtyHandle path session.tabs.list uses, no window ever attached (headless-equivalent). Byte-identical oracle on base: 7 failed; with fix: green. Oracle covers: attach exactly once across concurrent subscribers; release keeps ingesting; zero resize calls; no renderer mount/focus spy hits; snapshot-capable (frozen→live) and snapshot-null v19-style (blank→live) daemons; never-attached read returns provider tail; SSH-scoped and inventory-absent ids never attach; unrelated ptys untouched.
  • daemon-pty-adapter.test.ts +3 real-socket attach tests (dims preserved 137×41, no subprocess resize, absent session refuses); pty.test.ts +1 controller routing test.
  • Suites green: orca-runtime (1022), pty (435), daemon-pty-adapter (160), terminal-multiplex ×4, daemon-server-attach-only, upgrade-adoption, local-pty-provider, runtime-rpc, and more; tsc node ✅; oxlint ✅. Independently re-verified by the coordinating session (1187/1188).

Review notes

  • Pre-v18 daemons (no getSize) refuse attach — conservative degrade (blank stays blank, nothing destructive).
  • Release never detaches (daemon detach is stubbed/last-attach-wins); continued ingestion is intentional and cheap.
  • No reliability-gate registration yet: no existing family covers this invariant; recommend a future terminal-session.subscriber-driven-daemon-attach family seeded from the new test file after soak.
  • Explicit remaining gap: no live headed/headless paired-server E2E in this change — the deterministic harness models the controller seam and the real-socket adapter tests cover the daemon protocol half.

@Jinwoo-H
Jinwoo-H changed the base branch from terminal-session-restore-upgrade-repro to main August 5, 2026 00:20
OrcaWin added 2 commits August 4, 2026 20:24
…ribe and provider-read fallback

A daemon-backed terminal whose tab was never activated in the host UI was
never attached, so the daemon emitted no bytes: paired clients rendered
blank/frozen panes and `terminal read` returned an empty tail while the PTY
was alive.

- Runtime: first remote view subscriber of a known-but-unattached local
  daemon session triggers an attach through the pty controller — attach-only,
  no resize, no renderer mount/focus, headless-safe, deduped across
  concurrent subscribers, and never detached on release. Excludes SSH-scoped
  ids and sessions a local spawn already published this generation.
- Read path: withVisibleSnapshotFallback now falls back to the provider tail
  for an empty-tail never-attached live local session; unprovable state stays
  empty, never an error.
- pty controller: expose attach with getProviderForPty-style routing,
  answering false on doubt; local daemon provider only.
- Daemon adapter: attach rides the session's applied size instead of a
  hardcoded 80x24, sends attachOnly, and retires a pre-v31 daemon's
  accidental spawn instead of publishing it.

Deterministic harness drives the real terminal.multiplex handler against a
real OrcaRuntimeService with an injected daemon-model controller whose data
events are gated on attach; covers snapshot-capable and snapshot-null
daemons, concurrency, release, replacement-spawn exclusion, and negative
safety. Red on base, green with the fix, red again with the fix reverted.
…ailed legacy-spawn retire

Verifier follow-ups on subscriber-driven daemon attach:

- DegradedDaemonPtyProvider.attach routed unknown ids to the in-process
  fallback, whose no-op attach resolves — the runtime then pinned a
  subscriber-driven attach as succeeded while the stream stayed blank.
  Attach now refuses any route that resolves to the fallback (a fallback pty
  cannot own a daemon-surviving session), so the controller answers false,
  no sticky success is recorded, and a later subscriber attaches once a
  daemon adapter proves the id. Session-probe adoption moved to
  degraded-daemon-session-routing alongside the new refusal.
- The pre-v31 attach-only TOCTOU retire (accidental legacy spawn kill) now
  logs a warning with the sessionId on kill failure instead of swallowing
  it, so an orphaned replacement shell is diagnosable.

Regressions: degraded provider refuses unowned/fallback-owned attach and
routes to a daemon once it proves the id (red on previous commit); runtime
harness pins refused-attach retry for a later subscriber; adapter test pins
the surfaced kill failure.
@Jinwoo-H
Jinwoo-H force-pushed the subscriber-driven-daemon-attach branch from c962bdf to ea05e53 Compare August 5, 2026 00:25
@Jinwoo-H
Jinwoo-H merged commit 7224591 into main Aug 5, 2026
46 checks passed
@Jinwoo-H
Jinwoo-H deleted the subscriber-driven-daemon-attach branch August 5, 2026 00:25
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fcf8111-a98b-4ebe-be39-b0938476eb28

📥 Commits

Reviewing files that changed from the base of the PR and between 51ca82d and ea05e53.

📒 Files selected for processing (9)
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/degraded-daemon-session-routing.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/terminal-subscriber-driven-daemon-attach.test.ts

📝 Walkthrough

Walkthrough

The change adds attach-only handling for local daemon PTYs. The adapter preserves daemon-reported dimensions and retires accidental sessions from legacy daemons. Provider routing now identifies session ownership and rejects fallback attachment. IPC exposes attach results for eligible local sessions. Runtime subscriptions trigger deduplicated attachment, retry failures, reset lifecycle state, and use provider snapshots when terminal tails are empty. Tests cover adapter, routing, IPC, and end-to-end subscriber behavior.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Jinwoo-H added a commit that referenced this pull request Aug 5, 2026
With a desktop client paired to a remote Orca runtime, terminal panes could report connected, writable, and `terminal.send` returning accepted — yet keystrokes never reached the agent. No error, no banner, no recovery; input silently vanished.

The ticket was really two bugs. The attach half was already fixed by #12589 (subscriber-driven daemon attach), confirmed by reproducing against current main. This fixes the remaining half: a write the host refuses had no way to tell anyone.

A capability-negotiated `WriteUnavailable` opcode carries that refusal back to the client, where it feeds the pane's pre-existing recovery hook. Capability gating matters because decoders reject unknown opcodes on desktop — and, worse, silently drop them on mobile — so the signal is negotiated in the subscribe handshake. Verified per direction: an old host strips the unknown Subscribe key, an old client omits it so the host never emits, and capability cannot be inherited across resubscribe.

Independent review then found the signal was being delivered and discarded: recovery demanded an authoritative liveness answer, and `pty:hasPty` had no `remote:` guard, so a paired pane's id fell through to the LOCAL provider, which returned false, and recovery bailed before remounting. Every test stopped at the transport boundary, so all of them passed while the pane stayed just as stuck. `pty:kill` already had exactly that guard.

The fix makes main answer LESS rather than claim more: `pty:hasPty` now returns unknown for a `remote:` id instead of a fabricated false, because main cannot speak for another host's PTY. The remount is then authorized by positive evidence — the process that owns the PTY stating it refused this specific write over a live negotiated connection — not by inference from silence. Local and app-SSH ids keep the probe, where a false genuinely means the shell died. Nothing is destroyed on this path; the remount rebuilds the renderer over the session it already had.

An end-to-end test now carries a rejected write from the host through to an actual remount, which no prior test did. A surviving mutant was also killed: the legacy-binary capability gate could previously be deleted with nothing turning red.

The reliability gate stays experimental — live paired journeys and mixed installed-release evidence remain uncollected. Fixes STA-2830.
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ribe and provider-read fallback (stablyai#12589)

* fix(terminal): attach never-activated daemon sessions on remote subscribe and provider-read fallback

A daemon-backed terminal whose tab was never activated in the host UI was
never attached, so the daemon emitted no bytes: paired clients rendered
blank/frozen panes and `terminal read` returned an empty tail while the PTY
was alive.

- Runtime: first remote view subscriber of a known-but-unattached local
  daemon session triggers an attach through the pty controller — attach-only,
  no resize, no renderer mount/focus, headless-safe, deduped across
  concurrent subscribers, and never detached on release. Excludes SSH-scoped
  ids and sessions a local spawn already published this generation.
- Read path: withVisibleSnapshotFallback now falls back to the provider tail
  for an empty-tail never-attached live local session; unprovable state stays
  empty, never an error.
- pty controller: expose attach with getProviderForPty-style routing,
  answering false on doubt; local daemon provider only.
- Daemon adapter: attach rides the session's applied size instead of a
  hardcoded 80x24, sends attachOnly, and retires a pre-v31 daemon's
  accidental spawn instead of publishing it.

Deterministic harness drives the real terminal.multiplex handler against a
real OrcaRuntimeService with an injected daemon-model controller whose data
events are gated on attach; covers snapshot-capable and snapshot-null
daemons, concurrency, release, replacement-spawn exclusion, and negative
safety. Red on base, green with the fix, red again with the fix reverted.

* fix(terminal): refuse degraded-provider attach fallback and surface failed legacy-spawn retire

Verifier follow-ups on subscriber-driven daemon attach:

- DegradedDaemonPtyProvider.attach routed unknown ids to the in-process
  fallback, whose no-op attach resolves — the runtime then pinned a
  subscriber-driven attach as succeeded while the stream stayed blank.
  Attach now refuses any route that resolves to the fallback (a fallback pty
  cannot own a daemon-surviving session), so the controller answers false,
  no sticky success is recorded, and a later subscriber attaches once a
  daemon adapter proves the id. Session-probe adoption moved to
  degraded-daemon-session-routing alongside the new refusal.
- The pre-v31 attach-only TOCTOU retire (accidental legacy spawn kill) now
  logs a warning with the sessionId on kill failure instead of swallowing
  it, so an orphaned replacement shell is diagnosable.

Regressions: degraded provider refuses unowned/fallback-owned attach and
routes to a daemon once it proves the id (red on previous commit); runtime
harness pins refused-attach retry for a later subscriber; adapter test pins
the surfaced kill failure.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#12675)

With a desktop client paired to a remote Orca runtime, terminal panes could report connected, writable, and `terminal.send` returning accepted — yet keystrokes never reached the agent. No error, no banner, no recovery; input silently vanished.

The ticket was really two bugs. The attach half was already fixed by stablyai#12589 (subscriber-driven daemon attach), confirmed by reproducing against current main. This fixes the remaining half: a write the host refuses had no way to tell anyone.

A capability-negotiated `WriteUnavailable` opcode carries that refusal back to the client, where it feeds the pane's pre-existing recovery hook. Capability gating matters because decoders reject unknown opcodes on desktop — and, worse, silently drop them on mobile — so the signal is negotiated in the subscribe handshake. Verified per direction: an old host strips the unknown Subscribe key, an old client omits it so the host never emits, and capability cannot be inherited across resubscribe.

Independent review then found the signal was being delivered and discarded: recovery demanded an authoritative liveness answer, and `pty:hasPty` had no `remote:` guard, so a paired pane's id fell through to the LOCAL provider, which returned false, and recovery bailed before remounting. Every test stopped at the transport boundary, so all of them passed while the pane stayed just as stuck. `pty:kill` already had exactly that guard.

The fix makes main answer LESS rather than claim more: `pty:hasPty` now returns unknown for a `remote:` id instead of a fabricated false, because main cannot speak for another host's PTY. The remount is then authorized by positive evidence — the process that owns the PTY stating it refused this specific write over a live negotiated connection — not by inference from silence. Local and app-SSH ids keep the probe, where a false genuinely means the shell died. Nothing is destroyed on this path; the remount rebuilds the renderer over the session it already had.

An end-to-end test now carries a rejected write from the host through to an actual remount, which no prior test did. A surviving mutant was also killed: the legacy-binary capability gate could previously be deleted with nothing turning red.

The reliability gate stays experimental — live paired journeys and mixed installed-release evidence remain uncollected. Fixes STA-2830.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants