Skip to content

fix(pty): feed the runtime once for in-process panes behind a degraded daemon - #33119

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Muriano:fix/degraded-fallback-double-ingest
Oct 26, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Muriano:fix/degraded-fallback-double-ingest

Conversation

@Muriano

@Muriano Muriano commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Sometimes Orca's background terminal helper (the daemon) is "degraded": it can't start new terminals, but it still owns the ones that are already running. When that happens, new terminals run inside the app instead. For those in-app terminals, Orca saved every piece of output twice. So anything that reads that saved copy showed every line twice: orca terminal read, --screen, and the snapshot a pane is redrawn from when it comes back into view. TUIs like Claude Code and Codex also ghosted. With this change, each piece of output is saved once.

What Changed

  • Before: DegradedDaemonPtyProvider sends fresh spawns to its in-process fallback, the original LocalPtyProvider. That provider was already set up through configure().onData / onExit, which feed the runtime. bindProviderListeners decided whether to feed the runtime a second time by checking localProvider instanceof LocalPtyProvider on the installed provider. In degraded mode the installed provider is the wrapper, so every chunk and exit the wrapper passed along from its fallback was fed to the runtime twice. The result:
    • runtime.onPtyData ran twice per chunk, which inflated the output sequence and doubled headless-emulator writes and the stream/tail buffers.
    • runtime.onPtyExit ran twice per exit.
  • After: the check happens per event, not per provider type.
    • activateLocalPtySession marks each data or exit event with runtimeFed: true when its configured onData / onExit already reported it to the runtime.
    • bindProviderListeners feeds the runtime (and runs exit cleanup) only for events that are not marked, no matter which provider passes them along. The instanceof LocalPtyProvider check and its import are gone.
    • Renderer delivery is unchanged.
  • LocalPtyProvider's DataCallback / ExitCallback types now reuse the contract types (PtyDataEvent, IPtyProvider['onExit']), so the new flag is typed from start to end.

Why

This is the root cause of #31586. The degraded wrapper carries two kinds of sessions: daemon-owned sessions, which bindProviderListeners must feed, and fallback sessions, which configure() already fed. Only a per-event flag can tell them apart. Moving the whole runtime feed out of configure() would be a much larger change to the plain local path, and it isn't needed.

The flags are in-process only. The daemon adapter builds its events from an explicit field list, and acceptPtyDataForRenderer sends explicit fields to the renderer. So the flags never cross the daemon wire or IPC, and mixed client/server versions are not affected.

Linked Issue

Fixes #31586

Visual Proof

Before/after from the original PR (#33119), reproduced live in an isolated E2E profile on macOS: the daemon's ptySpawnHealth was forced to fail, then a pane was split so it ran in-process. Each screenshot shows the in-process pane (on the right) after its tab was hidden and shown again.

Before After
Before: every line of the re-shown in-process pane is repeated After: each line of the re-shown pane appears once
Measurement on the fresh in-process pane Before After
Marker line in orca terminal read (stream) 2 1
Marker line in orca terminal read --screen 2 1
Line printed while the tab was hidden, after re-showing it 2 1

Testing

  • New regression test: src/main/ipc/pty-degraded-fallback-single-ingest.test.ts. It wraps the real LocalPtyProvider in a real DegradedDaemonPtyProvider around an unhealthy daemon adapter, wired through registerPtyHandlers + rebindLocalProviderListeners with a real OrcaRuntimeService. It checks that:

    • each fallback chunk is fed to the runtime once, with the correct output sequence and renderer seq / rawLength;
    • a chunk from a daemon-owned session is still fed once;
    • each exit is fed once.
  • Reproduced on main: with the source files reverted, the test fails with expected "vi.fn()" to be called 1 times, but got 2 times. A separate scratch probe printed onPtyData calls 2 onPtyExit calls 2 renderer data 1 renderer exit 1. Both pass on this branch.

  • Unconfigured fallback probe: serve mode registers handlers after the daemon swap. With the fallback unconfigured, events are not marked and the runtime is still fed exactly once.

  • Updated test: local-pty-provider-io-events.test.ts now expects runtimeFed: true on data events from a configured provider.

  • Targeted vitest: the new test, local-pty-provider-io-events, src/main/ipc/pty/provider/*, degraded-daemon-pty-provider, pty-management, and the neighbouring local-pty suites all pass.

  • Lint/format: oxlint and oxfmt --check are clean on the touched files.

  • Platforms: tested on macOS. The change has no platform-specific code, so the same path runs on Linux and Windows. SSH providers never set the flag. Folder workspaces are not affected.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

  • dataListeners / exitListeners each have a single emit site (local-pty-session-activation.ts), and it sets the flag exactly when configure() installed onData / onExit. So no local event path can miss it.
  • For marked exits, bindProviderListeners skips clearProviderPtyState, ptyOwnership.delete, and runtime.onPtyExit, because configure().onExit already ran them. This matches the plain-local path.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Security: no new input surface. The flag is set in-process and can't be injected from the daemon socket.
  • Remote / mixed versions: no IPC or RPC shape change.
  • Mobile: reads terminal output through the runtime, which now receives each chunk once.
  • Performance: adds one boolean check per event. In degraded mode it removes a full duplicate runtime ingest per chunk.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Original fix by @Muriano in #33119

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ceec6c2a-3087-4a43-a7c3-5502b21ae198
Commits

Reviewing files that changed from the base of the PR and between 1a38dfa and 576ee96.

Files selected for processing: 7
  • src/main/ipc/pty-degraded-fallback-single-ingest.test.ts
  • src/main/ipc/pty/provider/bind-listeners.ts
  • src/main/providers/local-pty-provider-io-events.test.ts
  • src/main/providers/local-pty-provider-state.ts
  • src/main/providers/local-pty-session-activation.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/providers/pty-provider-events.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Walkthrough

Local PTY events now mark data and exits that have already reached the runtime through callbacks. Provider listeners use these markers to avoid duplicate runtime processing. Tests cover the event markers and verify runtime data and exit handling when a degraded daemon uses the local fallback.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 576ee

The reviewed change has no established issue requiring a fix before merge. The degraded daemon’s lack of automatic recovery remains separate follow-up work.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning For [#31586], the PR implements the duplicate-ingestion fix. activateLocalPtySession marks events already sent through configure().onData or configure().onExit, and bindProviderListeners skips… Implement and test degraded-daemon status visibility in the UI. Implement and test the agreed automatic-restart behavior for a severed daemon with no live sessions, or document and link a separate implementation only if the issue requiremen…
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title follows conventional-commit style and names the main change: the runtime is fed once for in-process panes when the daemon is degraded. The changeset matches this. The title is 77 characters,…
Description check Passed The description follows the repository template. It covers ELI5, What Changed, Why, Linked Issue (Fixes #31586), Visual Proof with before/after images and a measurement table, Testing with a new regre…
Out of Scope Changes check Passed The provider event flags, listener changes, type updates, expectation updates, and regression test directly support the duplicate PTY ingestion fix in [#31586]. The changes do not show unrelated behav…
Full details: Title check

Explanation

The title follows conventional-commit style and names the main change: the runtime is fed once for in-process panes when the daemon is degraded. The changeset matches this. The title is 77 characters, which is long but still descriptive.

Full details: Description check

Explanation

The description follows the repository template. It covers ELI5, What Changed, Why, Linked Issue (Fixes #31586), Visual Proof with before/after images and a measurement table, Testing with a new regression test, Review, Agent skill upstream boundary, Notes, and Checklist. The AI Disclosure section is absent, but the template marks it as optional for team members and it is not a required section for outside contributors. The description is detailed and matches the changes in the raw summary.

Full details: Out of Scope Changes check

Explanation

The provider event flags, listener changes, type updates, expectation updates, and regression test directly support the duplicate PTY ingestion fix in [#31586]. The changes do not show unrelated behavior or changes for other features.

Full details: Linked Issues check

Explanation

For [#31586], the PR implements the duplicate-ingestion fix. activateLocalPtySession marks events already sent through configure().onData or configure().onExit, and bindProviderListeners skips the second runtime feed. The regression test covers fallback data, daemon data, renderer sequencing, and exit delivery. However, the active issue also asks for degraded-daemon state in the UI and consideration of automatic daemon restart when no live sessions remain. The reviewed changes do not implement or test either behavior.

Resolution

Implement and test degraded-daemon status visibility in the UI. Implement and test the agreed automatic-restart behavior for a severed daemon with no live sessions, or document and link a separate implementation only if the issue requirements are formally split.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

❤️ Share

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

…d daemon

When the daemon's PTY spawn check fails, the DegradedDaemonPtyProvider
routes fresh terminals to the in-process LocalPtyProvider. bindProviderListeners
decided whether to feed the runtime via `instanceof LocalPtyProvider` on the
registered provider, so behind the degraded wrapper every in-process chunk and
exit was ingested twice (once through configure().onData/onExit, once here),
doubling output sequence numbers and exit handling.

Tag each data/exit event with `runtimeFed` when the emitting provider already
reported it through configure(), and gate the listener's runtime feed on that
per-event flag instead of the provider's class.

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/degraded-fallback-double-ingest branch from 1a38dfa to 576ee96 Compare October 26, 2026 16:13
@nwparker
nwparker merged commit d4500b4 into stablyai:main Oct 26, 2026
40 checks passed
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.

[Bug]: After an auto-update, new terminals silently fall back to in-process PTYs, and in-process PTYs deliver every byte twice (TUIs ghost one row off)

2 participants