Skip to content

fix(cloud): name the transport failure sign-in and Relay swallow - #13736

Open
Jaeyoung22 wants to merge 1 commit into
stablyai:mainfrom
Jaeyoung22:fix/surface-relay-mint-network-cause
Open

Jaeyoung22 wants to merge 1 commit into
stablyai:mainfrom
Jaeyoung22:fix/surface-relay-mint-network-cause

Conversation

@Jaeyoung22

Copy link
Copy Markdown
Contributor

Related to #13735

Scope

Diagnostics only. No transport, TLS policy, or trust store changes here, and nothing that fails today starts succeeding. #13735 describes the underlying trust-store split and asks which direction you want for the transport half; this PR only stops the reason from being thrown away, so triage does not require reading the source.

Problem

A request that fails in transport rejects with the message fetch failed for every cause — an untrusted TLS chain, DNS, a refused connection — and the reason that tells them apart is only on the nested cause.

  • profile-cloud-service.ts returned that bare message as its failure string, and the renderer already shows it as a toast description, so a user behind a TLS-inspecting network saw Failed to connect profile / fetch failed.
  • mobileRelayMintFailureFromUnknown keeps a code only when it matches /^relay_[a-z0-9_]{1,74}$/, so an uppercase transport code like SELF_SIGNED_CERT_IN_CHAIN was replaced by the relay_mint_failed fallback and did not reach the Copy diagnostics payload or the warn line.

Change

networkTransportErrorCode(error) walks up to four cause levels and returns a code only on exact match against a fixed uppercase vocabulary of certificate-validation, reachability, and undici timeout codes. Anything else yields null. That code is appended to the sign-in failure string and carried on MobileRelayMintFailure as an optional networkCode, which reaches the existing diagnostics payload and log line with no UI change.

The sign-in toast now reads fetch failed (SELF_SIGNED_CERT_IN_CHAIN).

Why the vocabulary is an exact-match set

runtime-rpc.ts:881 deliberately refuses to log raw provider errors because they can carry request metadata or credentials. That constraint is preserved by construction: only a member of the fixed set is ever returned, so a URL, token, or free-form message cannot travel through the new field. A test asserts a cause.code of https://relay.example/v1/assign?token=secret produces no networkCode.

Why the property reads look paranoid

errorOwnDataProperty reads an own data descriptor rather than using in, indexed access, or instanceof. All of this runs inside catch blocks, where an accessor or Proxy trap that throws would replace the failure being reported with a second one — sign-in would throw out of its own handler, and Relay pairing would skip its structured failure response. Reading a data descriptor also ignores inherited properties, so a polluted prototype cannot invent a code. A Proxy still observes the descriptor lookup; no standard reflective inspection avoids that, and the doc comment says so rather than claiming otherwise.

This also covers the pre-existing unguarded reads in mobileRelayMintFailureFromUnknown. Its instanceof Error plus .message branch became a message descriptor read, which widens provenance from Error instances to any own string message — the unchanged relay_* pattern is still what decides admission, and there is a test for the widened case.

Compatibility

networkCode is optional and crosses only local Electron IPC as part of the pairing-offer result; it does not cross the remote runtime wire. Older preload/renderer code ignores it. No RPC method, required parameter, stream opcode, payload shape, Git command, dependency, or persisted state changes.

Evidence

  • New network-transport-error-code.test.ts: extraction from a nested cause, a code carried directly, cause-depth bounding, cyclic causes, a throwing getter, a getter asserted never to run, a Proxy whose traps all throw, prototype-supplied codes, and rejection of lowercase, URL-shaped, non-string, and message-only values.
  • Extended mobile-relay-mint-failure.test.ts: the transport code is attached, a URL cannot become one, a hostile Proxy still yields the structured fallback, and a non-Error own message is admitted under the existing pattern.
  • Extended profile-cloud-service.test.ts: a token exchange rejecting with TypeError: fetch failed and cause.code = SELF_SIGNED_CERT_IN_CHAIN produces fetch failed (SELF_SIGNED_CERT_IN_CHAIN).
  • Full suite: 4489 passed, 16 skipped, across 458 files. Typecheck, oxlint (plain and type-aware), oxfmt, and the max-lines ratchet all pass.

Unproved gaps

Behaviour on Windows and Linux under TLS interception was reasoned about but not run; the vocabulary is platform-independent Node/undici/OpenSSL codes, so I expect no difference, but I have not observed it. The reproduction itself was done on macOS against one inline-inspection vendor.

A request that fails in transport rejects with the message "fetch failed" for
every cause, and the reason that tells them apart is only on the nested
`cause`. Sign-in returned that bare message as its failure string, so the toast
read "fetch failed"; Relay mint kept a code only when it matched relay_*, so a
transport reason was replaced by the fallback constant. On a network that
terminates TLS with a root the OS trusts but Node does not, both flows fail
with nothing to act on.

Extract the reason as an allow-listed code and carry it into the sign-in
failure string and the Relay mint failure, which already reaches the existing
diagnostics payload and warn line. The vocabulary is an exact-match set, so no
request URL, token, or free-form error text can travel with it.

Read every property off the caught value through an own data descriptor. This
runs inside catch blocks, where an accessor or Proxy trap that throws would
replace the failure being reported with a second one, and where an inherited
property would let a polluted prototype invent a reason.

Diagnostic only: no transport, TLS policy, or trust store changes here, and no
request that fails today starts succeeding.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds safe own-property inspection and bounded extraction of allow-listed transport error codes from nested causes. Relay mint failures now include an optional networkCode while preserving validated Relay codes and fallback messages. Profile connection failures append detected transport codes. Relay pairing logs include validated network codes without raw provider errors. Tests cover nested causes, hostile objects, invalid values, and connection failure reporting.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and testing well but omits the required AI Review Report, Security Audit, Screenshots, and Notes sections. Add the missing template sections, state whether there is visual change, document the AI review and security audit, confirm cross-platform checks, and complete the testing checklist.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main diagnostics change for cloud sign-in and Relay transport failures.
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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 906ca1fa-ec13-41e3-ae21-49728bb101c4

📥 Commits

Reviewing files that changed from the base of the PR and between 34c721f and c0b7943.

📒 Files selected for processing (8)
  • src/main/orca-profiles/profile-cloud-service.test.ts
  • src/main/orca-profiles/profile-cloud-service.ts
  • src/main/runtime/runtime-rpc.ts
  • src/shared/error-own-data-property.ts
  • src/shared/mobile-relay-mint-failure.test.ts
  • src/shared/mobile-relay-mint-failure.ts
  • src/shared/network-transport-error-code.test.ts
  • src/shared/network-transport-error-code.ts

Comment on lines +42 to +52
// Why: undici nests cause chains, and a bound stops a self-referential chain from looping.
const MAX_CAUSE_DEPTH = 4

export function networkTransportErrorCode(error: unknown): string | null {
let current: unknown = error
for (let depth = 0; depth < MAX_CAUSE_DEPTH && current != null; depth += 1) {
const code = errorOwnDataProperty(current, 'code')
if (typeof code === 'string' && TRANSPORT_ERROR_CODES.has(code)) {
return code
}
current = errorOwnDataProperty(current, 'cause')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Inspect four nested cause levels.

Line 47 counts the root error as one of four iterations. A code on the fourth nested cause is not inspected. This conflicts with the PR objective to inspect up to four nested cause levels.

  • src/shared/network-transport-error-code.ts#L42-L52: permit the root error plus four nested cause values.
  • src/shared/network-transport-error-code.test.ts#L32-L37: expect ETIMEDOUT at the fourth nested cause, and move the null assertion to a fifth nested cause.
📍 Affects 2 files
  • src/shared/network-transport-error-code.ts#L42-L52 (this comment)
  • src/shared/network-transport-error-code.test.ts#L32-L37

This branch has not been deployed

No deployments
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.

4 participants