Skip to content

fix(browser): keep cookie-import warnings readable from newer hosts - #15002

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/wirefix-toast-unknown-reason
Aug 17, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/wirefix-toast-unknown-reason

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​44

Problem

formatCookieImportWarning switches on warning.code, and inside cookies-undecryptable on warning.reason, with explicit cases only and no fallback. TypeScript believes both switches are exhaustive because each union is closed at compile time. They are not exhaustive at runtime.

The summary crosses the runtime RPC wire — store/slices/browser.ts → orca-runtime-browser.ts — and the response is cast, not decoded (runtime/runtime-rpc-client.ts:91, response as RuntimeRpcResponse<TResult>). A newer remote host that publishes a fourth reason (or a third code) therefore reaches an older client, nothing matches, the function returns undefined, and emitBrowserCookieImportToast renders toast.warning(undefined) — a blank warning toast on a partly-failed import.

This is a regression from #14683: the original code had a default: arm that absorbed unknown reasons, and it was replaced with case 'unknown': to satisfy switch-exhaustiveness-check.

Why not just restore default:

typescript/switch-exhaustiveness-check is configured with allowDefaultCaseForExhaustiveSwitch: false in both .oxlintrc.json and config/oxlint-code-quality-type-aware.json. Verified directly — adding a default: arm produces:

src/renderer/src/lib/browser-cookie-import-toast.ts:56:9: error typescript(switch-exhaustiveness-check):
  The switch statement is exhaustive, so the default case is unnecessary.

Fix

A runtime guard before each switch. The incoming value is widened to string, checked against the set of variants this build actually handles, and anything else routes to a generic message. The switches stay exhaustive over the narrowed union, so the lint gate stays satisfied.

The handled sets are Record<Union, true> keyed by the unions themselves, so this strengthens rather than weakens the compile-time guarantee. Adding a fourth reason to BrowserCookieImportSummary breaks the build here in two places:

browser-cookie-import-toast.ts(17,7): error TS2741: Property '"hardware-token-required"' is missing in type
  '{ 'app-bound-encryption': true; 'linux-keyring-unavailable': true; unknown: true; }'
  but required in type 'Record<...>'.
browser-cookie-import-toast.ts(31,67): error TS2366: Function lacks ending return statement
  and return type does not include 'undefined'.

Fallback copy

Neither message claims a cause it cannot know, and both give the user something to do:

  • Unknown reason (we do know the cookies failed to decrypt, and how many): "{{value0}} cookies could not be decrypted and were skipped for a reason this version of Orca does not recognize. Update Orca to see the details, then try the import again."
  • Unknown code (we know only that the import was degraded): "The cookie import finished with a warning this version of Orca does not recognize. Update Orca to see the details, then check this profile before relying on its cookies."

Both go through translate() like their neighbours; en.json synced via pnpm run sync:localization-catalog.

Test evidence — red before, green after

Four tests feed a reason and a code outside the declared unions, cast at the test boundary since the point is that the wire can carry them. Two cover unrecognized string values; two cover non-string values (for example ['unknown']), which an independent review found still slipped through — Object.hasOwn coerces its key, so an array whose toString() matches a handled variant passed the first version of the guard and fell straight back out of the switch.

Against unmodified main (b6d5972ec4):

 ❯ src/renderer/src/lib/browser-cookie-import-toast.test.ts (8 tests | 2 failed)
     × still warns when a newer host sends an undeclared undecryptable reason
     × still warns when a newer host sends an undeclared warning code

AssertionError: expected 'undefined' to be 'string' // Object.is equality
Expected: "string"
Received: "undefined"

 Test Files  1 failed (1)
      Tests  2 failed | 6 passed (8)

After the fix:

 Test Files  1 passed (1)
      Tests  8 passed (8)

Gates

Gate Result
node config/scripts/check-changed-code-quality.mjs Changed-code quality gate passed since b6d5972ec453. — 0 findings on all three scans
pnpm run typecheck clean
vitest (affected files, --config config/vitest.config.ts) 202 files / 1399 tests passed
verify:localization-catalog Verified 12231 localization key references against en.json.
verify:localization-extraction passed
verify:localization-coverage Localization coverage check passed with 12 allowlisted candidates.

All three oxlint scans were proven live, not silently dead, by injecting violations and confirming each caught them:

code quality:            no-else-return + no-unneeded-ternary  → 2 findings
type-aware code quality: switch-exhaustiveness-check           → 1 finding
React Doctor:            effect-needs-cleanup                  → 1 finding

Scope

Three files. No refactor of the toast module, no renames, no changes to the cookie-import main-process code.

The import summary is cast, not decoded, coming off the runtime RPC wire, so a
newer host can publish a warning code or undecryptable reason this build has
never seen. Both switches then matched nothing and returned undefined, which
rendered as a blank toast.warning(undefined).

#14683 replaced the absorbing default: arm with case 'unknown' to satisfy
switch-exhaustiveness-check, which forbids default: on an exhaustive switch.
Guard before each switch instead: narrow the wire value against the handled set
and route anything else to a generic message. The handled sets are keyed by the
unions themselves, so a fourth member still fails typecheck here.
@coderabbitai

coderabbitai Bot commented Aug 17, 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: aa18d7a2-442a-4140-8c61-007da93951da

📥 Commits

Reviewing files that changed from the base of the PR and between d3b3bfe and d713ce1.

📒 Files selected for processing (2)
  • src/renderer/src/lib/browser-cookie-import-toast.test.ts
  • src/renderer/src/lib/browser-cookie-import-toast.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/lib/browser-cookie-import-toast.test.ts
  • src/renderer/src/lib/browser-cookie-import-toast.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds localized fallback messages for unknown cookie-import warning codes and undecryptable-cookie reasons. Runtime validation now detects unsupported values before known-value handling. New tests verify that unknown and array-valued values produce non-empty warning toasts and preserve failed-cookie counts where applicable.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving readable cookie-import warnings from newer hosts.
Description check ✅ Passed The description clearly explains the problem, fix, fallback behavior, tests, validation results, and scope, but it omits several template headings and checklist entries.
✨ Finishing Touches 💡 1
📝 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.

@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.

🧹 Nitpick comments (1)
src/renderer/src/lib/browser-cookie-import-toast.test.ts (1)

104-124: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Optionally tighten both fallback tests to assert the exact translated message.

The current checks confirm that each fallback produces a non-empty string, but exact-message assertions would also catch selecting the wrong localization key while still returning plausible text.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f8665c3f-42ca-4381-ba9b-07ec6b10f910

📥 Commits

Reviewing files that changed from the base of the PR and between b6d5972 and d3b3bfe.

📒 Files selected for processing (3)
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/browser-cookie-import-toast.test.ts
  • src/renderer/src/lib/browser-cookie-import-toast.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 0 remain after this review.

Object.hasOwn coerces its key, so the membership guards admitted any value whose
toString() matched a handled variant. A host that widened reason to an array
sends ['unknown'], which passed the guard and then fell straight back out of the
switch -- the same undefined-to-toast.warning blank the guards exist to prevent.

Take unknown and check typeof first, matching isTopLevelView and isTuiAgent. The
Record membership sets still fail typecheck on a new union member.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review loop — CLEAN at d713ce14ab

Independent reviewer, fresh worktree off this branch, two passes. Pass 2 changed nothing, so the current head is the head a clean pass covers.

Pass 1 — P1 found and fixed

The fix for the blank toast still had a blank-toast hole.

Object.hasOwn coerces its key. The guards took code: string / reason: string, so a value the compiler never saw — say reason: ['unknown'], whose toString() is 'unknown' — passed the membership check, fell out of the switch, and rendered toast.warning(undefined): exactly the bug this PR exists to fix.

Object.hasOwn({ unknown: true }, ['unknown'])   // true

Fixed to take unknown and check typeof first, matching repo precedent (isTopLevelView, isTuiAgent both narrow from unknown):

function isHandledUndecryptableReason(reason: unknown): reason is UndecryptableReason {
  return typeof reason === 'string' && Object.hasOwn(HANDLED_UNDECRYPTABLE_REASONS, reason)
}

Two more tests added, proven red against this PR's own source before the fix. Pushed as d713ce14ab.

Claims verified rather than assumed

  • Both original holes close, checked across a hand-built 24-shape matrix over the two switches.
  • All 8 pre-existing warning shapes produce byte-identical output — no regression in the working paths.
  • The compile-time guarantee genuinely doubles: a 4th reason and a 3rd code each produce TS2741 on the Record and TS2366 on the switch. Re-verified after the P1 change, by adding a member and watching the build break.
  • The PR's original two tests are red against main's source file alone.

Gates

gate result
config/scripts/check-changed-code-quality.mjs exit 0 — 0/0/0, and all three scans proven live by injection (2/1/1 findings caught)
pnpm run typecheck exit 0
vitest 585 files, 5419 passed
localization ×3 exit 0
CI 44 pass, 0 fail

Same defect class found elsewhere — reported, not fixed here

src/renderer/src/lib/folder-workspace-path-status.ts:11 and :39 switch on status.reason off the same cast wire (repos.ts:1658, :2580). An unrecognized reason returns undefined, and FolderPathStatusIndicator.tsx:20 treats that as "nothing to show" — so the broken-folder marker disappears entirely and a broken folder workspace renders as healthy. Worse than the blank toast, since the warning is lost rather than merely empty. Two other same-shaped switches were checked and cleared: their discriminants are computed locally.

Deliberately left for a separate change — see below.

Structural note

src/shared/runtime-rpc-envelope.ts:26 declares result: z.unknown() inside the zod-validated success envelope, and unwrapRuntimeRpcResult returns it as TResult with no decode. So the envelope is validated and the payload is asserted — across 277 callRuntimeRpc<…> call sites in 72 files. There is also no assertNever/softAssertNever helper in the tree, which is why this guard sits before the switch instead of in a default arm — the shape that produced the P1 above.

This PR is the right local fix. The recurring class wants a decode at the transport boundary, which is a separate piece of work.

@brennanb2025
brennanb2025 merged commit d21f63e into main Aug 17, 2026
45 checks passed
brennanb2025 added a commit that referenced this pull request Aug 17, 2026
…ds a new reason

FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire --
runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands
back whatever the host sent. Both title and description switch on status.reason with
no runtime guard, so a newer host publishing a fifth reason matched nothing and
returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole
indicator, and a broken folder workspace rendered as healthy -- worse than the blank
toast #15002 fixed, because there the warning was empty and here it is gone.

Guard before each switch, the shape #15002 landed. A default: arm is not available:
the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one
with switch-exhaustiveness-check.

Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and
fourth copy, and move #15002's two bespoke guards onto it. It takes unknown and checks
typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field
to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops
it straight back out. That was the P1 found in review on #15002; one implementation
makes it structural instead of tribal.

An unrecognized reason gets its own copy rather than reusing 'unavailable'. The
unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false
lead here: the host did check and reported the folder unusable, so retrying and
inspecting a healthy connection wastes the user's time. Update Orca is the real remedy.

Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and
TS2366 plus switch-exhaustiveness-check on both switches.
brennanb2025 added a commit that referenced this pull request Aug 17, 2026
…ds a new reason (#15027)

FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire --
runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands
back whatever the host sent. Both title and description switch on status.reason with
no runtime guard, so a newer host publishing a fifth reason matched nothing and
returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole
indicator, and a broken folder workspace rendered as healthy -- worse than the blank
toast #15002 fixed, because there the warning was empty and here it is gone.

Guard before each switch, the shape #15002 landed. A default: arm is not available:
the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one
with switch-exhaustiveness-check.

Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and
fourth copy, and move #15002's two bespoke guards onto it. It takes unknown and checks
typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field
to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops
it straight back out. That was the P1 found in review on #15002; one implementation
makes it structural instead of tribal.

An unrecognized reason gets its own copy rather than reusing 'unavailable'. The
unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false
lead here: the host did check and reported the folder unusable, so retrying and
inspecting a healthy connection wastes the user's time. Update Orca is the real remedy.

Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and
TS2366 plus switch-exhaustiveness-check on both switches.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…tablyai#15002)

* fix(browser): keep cookie-import warnings readable from newer hosts

The import summary is cast, not decoded, coming off the runtime RPC wire, so a
newer host can publish a warning code or undecryptable reason this build has
never seen. Both switches then matched nothing and returned undefined, which
rendered as a blank toast.warning(undefined).

stablyai#14683 replaced the absorbing default: arm with case 'unknown' to satisfy
switch-exhaustiveness-check, which forbids default: on an exhaustive switch.
Guard before each switch instead: narrow the wire value against the handled set
and route anything else to a generic message. The handled sets are keyed by the
unions themselves, so a fourth member still fails typecheck here.

* fix(browser): reject non-string cookie-import warning discriminants

Object.hasOwn coerces its key, so the membership guards admitted any value whose
toString() matched a handled variant. A host that widened reason to an array
sends ['unknown'], which passed the guard and then fell straight back out of the
switch -- the same undefined-to-toast.warning blank the guards exist to prevent.

Take unknown and check typeof first, matching isTopLevelView and isTuiAgent. The
Record membership sets still fail typecheck on a new union member.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…ds a new reason (stablyai#15027)

FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire --
runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands
back whatever the host sent. Both title and description switch on status.reason with
no runtime guard, so a newer host publishing a fifth reason matched nothing and
returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole
indicator, and a broken folder workspace rendered as healthy -- worse than the blank
toast stablyai#15002 fixed, because there the warning was empty and here it is gone.

Guard before each switch, the shape stablyai#15002 landed. A default: arm is not available:
the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one
with switch-exhaustiveness-check.

Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and
fourth copy, and move stablyai#15002's two bespoke guards onto it. It takes unknown and checks
typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field
to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops
it straight back out. That was the P1 found in review on stablyai#15002; one implementation
makes it structural instead of tribal.

An unrecognized reason gets its own copy rather than reusing 'unavailable'. The
unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false
lead here: the host did check and reported the folder unusable, so retrying and
inspecting a healthy connection wastes the user's time. Update Orca is the real remedy.

Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and
TS2366 plus switch-exhaustiveness-check on both switches.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#15002)

* fix(browser): keep cookie-import warnings readable from newer hosts

The import summary is cast, not decoded, coming off the runtime RPC wire, so a
newer host can publish a warning code or undecryptable reason this build has
never seen. Both switches then matched nothing and returned undefined, which
rendered as a blank toast.warning(undefined).

stablyai#14683 replaced the absorbing default: arm with case 'unknown' to satisfy
switch-exhaustiveness-check, which forbids default: on an exhaustive switch.
Guard before each switch instead: narrow the wire value against the handled set
and route anything else to a generic message. The handled sets are keyed by the
unions themselves, so a fourth member still fails typecheck here.

* fix(browser): reject non-string cookie-import warning discriminants

Object.hasOwn coerces its key, so the membership guards admitted any value whose
toString() matched a handled variant. A host that widened reason to an array
sends ['unknown'], which passed the guard and then fell straight back out of the
switch -- the same undefined-to-toast.warning blank the guards exist to prevent.

Take unknown and check typeof first, matching isTopLevelView and isTuiAgent. The
Record membership sets still fail typecheck on a new union member.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ds a new reason (stablyai#15027)

FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire --
runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands
back whatever the host sent. Both title and description switch on status.reason with
no runtime guard, so a newer host publishing a fifth reason matched nothing and
returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole
indicator, and a broken folder workspace rendered as healthy -- worse than the blank
toast stablyai#15002 fixed, because there the warning was empty and here it is gone.

Guard before each switch, the shape stablyai#15002 landed. A default: arm is not available:
the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one
with switch-exhaustiveness-check.

Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and
fourth copy, and move stablyai#15002's two bespoke guards onto it. It takes unknown and checks
typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field
to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops
it straight back out. That was the P1 found in review on stablyai#15002; one implementation
makes it structural instead of tribal.

An unrecognized reason gets its own copy rather than reusing 'unavailable'. The
unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false
lead here: the host did check and reported the folder unusable, so retrying and
inspecting a healthy connection wastes the user's time. Update Orca is the real remedy.

Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and
TS2366 plus switch-exhaustiveness-check on both switches.
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