Skip to content

refactor(runtime): preserve transport error codes over IPC - #12667

Merged
Jinwoo-H merged 1 commit into
mainfrom
sta-3456/typed-runtime-ipc-errors
Aug 5, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
sta-3456/typed-runtime-ipc-errors

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

Summary

  • return typed RemoteRuntimeClientError and RuntimeRpcCallQueueOverloadError rejections from runtimeEnvironments:call as the existing structured RuntimeRpcFailure response
  • let the existing renderer unwrapRuntimeRpcResult path reconstruct RuntimeRpcCallError with the original machine code
  • classify a present structured code authoritatively, while retaining English message fragments only as a fallback for code-less errors

Fixes STA-3456.

Why

Electron strips custom error properties when an ipcMain.handle callback 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: false response carrying { code, message }. The preload already preserves this response unchanged, and the renderer's existing unwrapRuntimeRpcResult turns it into RuntimeRpcCallError, 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_unavailable
  • runtime_rpc_queue_overloaded

Applied 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:

  • disabling typed IPC serialization: 2 failed, 68 passed
  • restoring old message-first classification: 2 failed, 68 passed
  • restored implementation: 70 passed

Regression matrix

221 passed across:

  • src/main/ipc/runtime-environments.test.ts
  • src/main/ipc/runtime-environment-transport-routing-tailscale-hint.test.ts
  • src/shared/remote-runtime-client-error-classification.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-outage-toast-flood-and-stuck-reconnect.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-resubscribe-failure-recovery-routing.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-error-surface-dismissal.test.ts

This 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 — passed
  • repository-wide oxlint --deny-warnings — passed
  • oxlint --deny-warnings on changed files after rebase — passed
  • oxfmt --check on changed files — passed
  • repository-wide oxfmt --check . — reports 19 pre-existing unchanged files; none are touched by this PR

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c45d0d83-4a89-4d33-84cd-d576e4466593

📥 Commits

Reviewing files that changed from the base of the PR and between e233d6a and 7552917.

📒 Files selected for processing (4)
  • src/main/ipc/runtime-environment-connectivity-handlers.ts
  • src/main/ipc/runtime-environments.test.ts
  • src/shared/remote-runtime-client-error-classification.test.ts
  • src/shared/remote-runtime-client-error-classification.ts

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and testing well, but it omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all missing template sections, state whether there is visual change, document AI cross-platform review, summarize the security audit, and record platform risks or follow-up work.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes preserving transport error codes over IPC, which is the primary change in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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
Jinwoo-H merged commit 15ef69a into main Aug 5, 2026
43 checks passed
Jinwoo-H added a commit that referenced this pull request Aug 5, 2026
…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`.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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`.
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.

1 participant