Repository navigation
refactor(runtime): preserve transport error codes over IPC - #12667
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe change updates remote runtime error classification to prioritize explicit error codes over legacy messages. Runtime calls now convert recognized remote transport and RPC queue overload errors into structured failed RPC responses containing the method, code, message, and runtime ID. Unrecognized errors continue to propagate through the existing IPC fallback path. Tests cover coded failures, uncoded failures, and classification precedence. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
…ent (#12676) Since #12667, a present error code short-circuits classification: a code that is genuinely transient but missing from `RECOVERABLE_CODES` classifies as FATAL. That is the shape that dead-ends terminal panes — #12650 fixed exactly that for a different error, where a transient failure misclassified as fatal unmounted the Reconnect banner and left recreating the session as the only escape. Today the code and fragment sets agree. Nothing prevented a future code from being added without a matching entry, and the failure would have been silent. This pins that agreement: for every reachable transport error, a code that classifies fatal must not carry a message that would have classified recoverable. 57 coded pairs plus 8 code-less ones, derived by invoking the producers where possible so a reworded message updates the corpus instead of leaving a stale copy silently passing. The failure message names the offending fragment and says what to do about it. Enumeration turned up producers beyond the obvious ones — notably the Tailscale-hinted variants, where `runtime-environment-transport-routing.ts` mutates the message on an already-coded error before it crosses IPC, making those distinct corpus members. Also documented (not asserted, because it is unreachable today): `runtime_rpc_queue_overloaded` is absent from both host passthrough allowlists, so if it ever crossed `mapRuntimeError` it would flatten to `runtime_error` while keeping its "queue is full" message — precisely the dangerous shape. The queue pool is never instantiated on the server dispatcher, so it cannot happen now. The known exception is pinned rather than silently exempted: a dedicated test records WHY the guard cannot see `remote_runtime_busy` (fatal by code, matching no fragment, so the two sides have nothing to disagree about). If someone rewords a busy message into connection wording, that test fails and points at STA-3479. Proven non-vacuous by four separate injections. The only production change is two `const` to `export const`.
…12667) Errors thrown across Electron's `ipcMain.handle` lose their structured error code — only the message survives. So the renderer classified transport failures by matching substrings of English message text. That is how a queue-overload rejection escaped classification during a remote outage and surfaced as a raw error wall: the code was stripped in transit and its message fragment was not in the recoverable list. This converts `RemoteRuntimeClientError` and `RuntimeRpcCallQueueOverloadError` rejections from `runtimeEnvironments:call` into the existing structured `{ok:false, error:{code,message}}` response, which the preload already passes through unchanged and `unwrapRuntimeRpcResult` already reconstructs with the code intact. Classification now treats a present code as authoritative and consults message fragments only when there is no code. The fragment list is deliberately RETAINED as a backstop, not deleted: untyped main-handler rejections, subscription-start failures, and older code-less paths still rely on it. Proven real rather than cosmetic: a test-only patch applied to unmodified main fails (4 failed / 66 passed) because the code does not survive the boundary today, and passes on this branch. Independent review specifically chased the risk that a present-but-unrecognized code would now short-circuit to fatal where a message fragment previously rescued it — the shape that dead-ends a pane. It enumerated all 34 reachable code/message pairs and confirmed no pair flips recoverable to fatal, that the newly-serialized code set is closed and client-local, and that host-forwarded codes preserve recoverable classification by design. A differential harness over that corpus was verified non-vacuous by injecting the bad shape. Nothing crosses the paired-runtime wire: desktop main -> IPC -> preload -> renderer only, reusing an existing response shape, no new fields or opcodes. The connection-level offline state with a single reconnect affordance remains as STA-3456 follow-up work.
…ent (stablyai#12676) Since stablyai#12667, a present error code short-circuits classification: a code that is genuinely transient but missing from `RECOVERABLE_CODES` classifies as FATAL. That is the shape that dead-ends terminal panes — stablyai#12650 fixed exactly that for a different error, where a transient failure misclassified as fatal unmounted the Reconnect banner and left recreating the session as the only escape. Today the code and fragment sets agree. Nothing prevented a future code from being added without a matching entry, and the failure would have been silent. This pins that agreement: for every reachable transport error, a code that classifies fatal must not carry a message that would have classified recoverable. 57 coded pairs plus 8 code-less ones, derived by invoking the producers where possible so a reworded message updates the corpus instead of leaving a stale copy silently passing. The failure message names the offending fragment and says what to do about it. Enumeration turned up producers beyond the obvious ones — notably the Tailscale-hinted variants, where `runtime-environment-transport-routing.ts` mutates the message on an already-coded error before it crosses IPC, making those distinct corpus members. Also documented (not asserted, because it is unreachable today): `runtime_rpc_queue_overloaded` is absent from both host passthrough allowlists, so if it ever crossed `mapRuntimeError` it would flatten to `runtime_error` while keeping its "queue is full" message — precisely the dangerous shape. The queue pool is never instantiated on the server dispatcher, so it cannot happen now. The known exception is pinned rather than silently exempted: a dedicated test records WHY the guard cannot see `remote_runtime_busy` (fatal by code, matching no fragment, so the two sides have nothing to disagree about). If someone rewords a busy message into connection wording, that test fails and points at STA-3479. Proven non-vacuous by four separate injections. The only production change is two `const` to `export const`.
Summary
RemoteRuntimeClientErrorandRuntimeRpcCallQueueOverloadErrorrejections fromruntimeEnvironments:callas the existing structuredRuntimeRpcFailureresponseunwrapRuntimeRpcResultpath reconstructRuntimeRpcCallErrorwith the original machine codeFixes STA-3456.
Why
Electron strips custom error properties when an
ipcMain.handlecallback rejects. The renderer therefore lost transport error codes and had to infer recoverability from English message fragments. That made classification fragile: a new or reworded upstream message could silently become an unrecoverable raw error surface.The main-process handler now catches the two established typed transport rejection classes and returns an
ok: falseresponse carrying{ code, message }. The preload already preserves this response unchanged, and the renderer's existingunwrapRuntimeRpcResultturns it intoRuntimeRpcCallError, restoring the code end to end.Untyped handler rejections still reject as before. Their renderer consumers, subscription-start rejections, direct Electron-style rejections from older paths, and code-less test/mixed-path errors continue to rely on the message-fragment fallback. The fallback is now consulted only when no structured code exists.
Compatibility
This change is entirely within one desktop app install: main process -> Electron IPC -> preload -> renderer. It does not add fields or opcodes to the paired client/server runtime protocol and does not cross the paired-runtime wire. Runtime RPC success/failure envelopes received from the paired host are unchanged.
The connection-level offline state and single reconnect affordance are intentionally out of scope for this PR and remain follow-up work for STA-3456.
Verification
Boundary proof
The new handler test uses deliberately non-matching messages for both:
remote_runtime_unavailableruntime_rpc_queue_overloadedApplied as test-only changes to unmodified
origin/main, the focused suites were red: 4 failed, 66 passed. Both boundary cases rejected instead of returning a coded response; the two code-precedence tests also exposed the previous message-first behavior.Mutation checks on this branch:
Regression matrix
221 passed across:
src/main/ipc/runtime-environments.test.tssrc/main/ipc/runtime-environment-transport-routing-tailscale-hint.test.tssrc/shared/remote-runtime-client-error-classification.test.tssrc/renderer/src/runtime/runtime-rpc-client.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-outage-toast-flood-and-stuck-reconnect.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-resubscribe-failure-recovery-routing.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-error-surface-dismissal.test.tsThis covers queue-overload backoff plus terminal-gone retirement, stale-handle re-resolution, SSH-session-expired recovery, oversized-snapshot suppression, outage toast deduplication, reconnect recovery, and dismissed-error resurfacing.
Additional checks:
pnpm run typecheck— passedoxlint --deny-warnings— passedoxlint --deny-warningson changed files after rebase — passedoxfmt --checkon changed files — passedoxfmt --check .— reports 19 pre-existing unchanged files; none are touched by this PR