Repository navigation
fix(cloud): name the transport failure sign-in and Relay swallow - #13736
Jaeyoung22 wants to merge 1 commit into
Conversation
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]>
📝 WalkthroughWalkthroughThe 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 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
src/main/orca-profiles/profile-cloud-service.test.tssrc/main/orca-profiles/profile-cloud-service.tssrc/main/runtime/runtime-rpc.tssrc/shared/error-own-data-property.tssrc/shared/mobile-relay-mint-failure.test.tssrc/shared/mobile-relay-mint-failure.tssrc/shared/network-transport-error-code.test.tssrc/shared/network-transport-error-code.ts
| // 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') |
There was a problem hiding this comment.
🎯 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 nestedcausevalues.src/shared/network-transport-error-code.test.ts#L32-L37: expectETIMEDOUTat the fourth nested cause, and move thenullassertion 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
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 failedfor every cause — an untrusted TLS chain, DNS, a refused connection — and the reason that tells them apart is only on the nestedcause.profile-cloud-service.tsreturned 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 sawFailed to connect profile / fetch failed.mobileRelayMintFailureFromUnknownkeeps a code only when it matches/^relay_[a-z0-9_]{1,74}$/, so an uppercase transport code likeSELF_SIGNED_CERT_IN_CHAINwas replaced by therelay_mint_failedfallback and did not reach theCopy diagnosticspayload or the warn line.Change
networkTransportErrorCode(error)walks up to fourcauselevels and returns a code only on exact match against a fixed uppercase vocabulary of certificate-validation, reachability, and undici timeout codes. Anything else yieldsnull. That code is appended to the sign-in failure string and carried onMobileRelayMintFailureas an optionalnetworkCode, 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:881deliberately 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 acause.codeofhttps://relay.example/v1/assign?token=secretproduces nonetworkCode.Why the property reads look paranoid
errorOwnDataPropertyreads an own data descriptor rather than usingin, indexed access, orinstanceof. All of this runs insidecatchblocks, 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. Itsinstanceof Errorplus.messagebranch became amessagedescriptor read, which widens provenance fromErrorinstances to any own stringmessage— the unchangedrelay_*pattern is still what decides admission, and there is a test for the widened case.Compatibility
networkCodeis 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
network-transport-error-code.test.ts: extraction from a nestedcause, 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.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-Errorownmessageis admitted under the existing pattern.profile-cloud-service.test.ts: a token exchange rejecting withTypeError: fetch failedandcause.code = SELF_SIGNED_CERT_IN_CHAINproducesfetch failed (SELF_SIGNED_CERT_IN_CHAIN).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.