Repository navigation
fix(pty): feed the runtime once for in-process panes behind a degraded daemon - #33119
Conversation
|
No actionable comments were generated in the recent review.
|
…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]>
1a38dfa to
576ee96
Compare
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
DegradedDaemonPtyProvidersends fresh spawns to its in-process fallback, the originalLocalPtyProvider. That provider was already set up throughconfigure().onData/onExit, which feed the runtime.bindProviderListenersdecided whether to feed the runtime a second time by checkinglocalProvider instanceof LocalPtyProvideron 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.onPtyDataran twice per chunk, which inflated the output sequence and doubled headless-emulator writes and the stream/tail buffers.runtime.onPtyExitran twice per exit.activateLocalPtySessionmarks each data or exit event withruntimeFed: truewhen its configuredonData/onExitalready reported it to the runtime.bindProviderListenersfeeds the runtime (and runs exit cleanup) only for events that are not marked, no matter which provider passes them along. Theinstanceof LocalPtyProvidercheck and its import are gone.LocalPtyProvider'sDataCallback/ExitCallbacktypes 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
bindProviderListenersmust feed, and fallback sessions, whichconfigure()already fed. Only a per-event flag can tell them apart. Moving the whole runtime feed out ofconfigure()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
acceptPtyDataForRenderersends 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
ptySpawnHealthwas 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.orca terminal read(stream)orca terminal read --screenTesting
New regression test:
src/main/ipc/pty-degraded-fallback-single-ingest.test.ts. It wraps the realLocalPtyProviderin a realDegradedDaemonPtyProvideraround an unhealthy daemon adapter, wired throughregisterPtyHandlers+rebindLocalProviderListenerswith a realOrcaRuntimeService. It checks that:seq/rawLength;Reproduced on
main: with the source files reverted, the test fails withexpected "vi.fn()" to be called 1 times, but got 2 times. A separate scratch probe printedonPtyData 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.tsnow expectsruntimeFed: trueon 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:
oxlintandoxfmt --checkare 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/exitListenerseach have a single emit site (local-pty-session-activation.ts), and it sets the flag exactly whenconfigure()installedonData/onExit. So no local event path can miss it.bindProviderListenersskipsclearProviderPtyState,ptyOwnership.delete, andruntime.onPtyExit, becauseconfigure().onExitalready ran them. This matches the plain-local path.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Original fix by @Muriano in #33119