Repository navigation
fix(browser): never resurrect cookies after a failed import clear (STA-4061) - #14132
Conversation
…A-4061)
removeAllCookiesExcept rolled a partial clear back by rebuilding each removed
cookie with cookies.set. Electron's cookies.get() omits partitionKey and
cookies.set() drops it, so a non-Google CHIPS cookie that had been removed came
back as an ordinary unpartitioned cookie — silent, restart-proof auth-state
corruption on a code path that reports failure.
The exclusion comment already stated the invariant ("Electron cannot round-trip
partition identity"); it was only applied to the Google family. Extend it to the
rollback: a failed clear now stays failed, which is retryable, instead of
reconstructing cookies whose identity cannot be reproduced.
|
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 (1)
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/browser/browser-cookie-import-policy.ts (1)
200-204: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the repeated CHIPS rationale comments.
Use one concise sentence at each site.
src/main/browser/browser-cookie-import-policy.ts#L200-L204: Reduce the five-line explanation to one sentence about Electron dropping CHIPS partition keys during reconstruction.src/main/browser/browser-cookie-import-policy.test.ts#L234-L235: Reduce the rationale to one sentence.src/main/browser/browser-cookie-import-google-exclusion.test.ts#L270-L271: Reduce the rationale to one sentence.As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f70aca6e-9262-4137-b66c-ed68827621ad
📒 Files selected for processing (4)
src/main/browser/browser-cookie-import-google-exclusion.test.tssrc/main/browser/browser-cookie-import-partition-rollback.electron.test.tssrc/main/browser/browser-cookie-import-policy.test.tssrc/main/browser/browser-cookie-import-policy.ts
Visual proof (macOS Electron)Environment: macOS 26.5.1 (Build 25F80) · Orca 1.4.178-rc.2 dev build from this worktree · Electron 43.1.0 · branch Identity check (before trusting any screenshot): Honesty: this PR has no happy-path UI delta. The change only removes a lossy rollback on an internal failure path the UI cannot trigger on demand. The screenshots below prove the cookie-import happy path still works on this branch. Failure-path evidence is the red/green Electron test, not a fabricated before/after screen. Images are hosted on scratch branch 1. Isolated worktree instance, landingFresh profile launched from this worktree. No project yet. This is the instance all later shots come from. 2. In-app browser tab — Import entry pointOpened a managed browser tab. Toolbar shows Import next to the address bar. Sidebar is 3. Import browser data popoverClicked Import. Detected Google Chrome, Safari. Same entry point also advertised under Settings > Browser. 4. Import menu — Chromium-family sourceImport… lists From Google Chrome / From Safari / From File…, plus the existing “Google logins aren't imported” disclosure (unchanged by this PR). 5. Chrome profile pickerSubmenu: stably.ai and Brennan. Imported from stably.ai (Chrome profile directory 6. Success summary (happy path, no UI regression)In-browser banner after the Chromium import:
Store result: 7. Settings > Browser — persisted sourceDefault profile is Active with source Google Chrome (stably.ai). Persistent success state after import. 8. Signed-in GitHub after importSame Orca browser, default profile ( Failure-path evidence (no dedicated UI)The rollback path has no screen. Same command both times: After the fix (this branch): PASS Before the fix (policy file only swapped to parent Policy file restored immediately after the red run. PR worktree source left clean. What I could not capture
|
…A-4061) (stablyai#14132) * fix(browser): never resurrect cookies after a failed import clear (STA-4061) removeAllCookiesExcept rolled a partial clear back by rebuilding each removed cookie with cookies.set. Electron's cookies.get() omits partitionKey and cookies.set() drops it, so a non-Google CHIPS cookie that had been removed came back as an ordinary unpartitioned cookie — silent, restart-proof auth-state corruption on a code path that reports failure. The exclusion comment already stated the invariant ("Electron cannot round-trip partition identity"); it was only applied to the Google family. Extend it to the rollback: a failed clear now stays failed, which is retryable, instead of reconstructing cookies whose identity cannot be reproduced. * test(browser): require partitioned cookie removal (STA-4061) (cherry picked from commit bc2e300)
…A-4061) (stablyai#14132) * fix(browser): never resurrect cookies after a failed import clear (STA-4061) removeAllCookiesExcept rolled a partial clear back by rebuilding each removed cookie with cookies.set. Electron's cookies.get() omits partitionKey and cookies.set() drops it, so a non-Google CHIPS cookie that had been removed came back as an ordinary unpartitioned cookie — silent, restart-proof auth-state corruption on a code path that reports failure. The exclusion comment already stated the invariant ("Electron cannot round-trip partition identity"); it was only applied to the Google family. Extend it to the rollback: a failed clear now stays failed, which is retryable, instead of reconstructing cookies whose identity cannot be reproduced. * test(browser): require partitioned cookie removal (STA-4061)








ELI5
When importing cookies from another browser, Orca first clears the existing cookie jar. If part of that clear failed, it tried to undo itself by putting the deleted cookies back. But Electron can't see or set a cookie's "partition key" (the CHIPS marker that binds a cookie to one top-level site), so putting a cookie back quietly stripped that marker. A partitioned login cookie came back as a plain one — broken auth state that a restart can't repair, on a path that already told the user the import failed. This PR stops the undo entirely: a failed clear now just stays failed, which the user can retry.
What Changed
removeAllCookiesExceptno longer rolls back a partial clear.restoreImportedDomainCookiescall and theremovedCookiesbookkeeping that fed it.storenarrowed fromPick<Cookies, 'get' | 'remove' | 'set'>toPick<Cookies, 'get' | 'remove'>, so the lossy reconstruction cannot be reintroduced here by accident.Could not clear existing cookies; the session was left partially cleared(it reaches the user viasummarizeCookieImportError).browser-cookie-import-partition-rollback.electron.test.ts: creates a non-Google CHIPS cookie over CDP, forces one removal to reject, and asserts no cookie is ever resurrected without its partition key.browser-cookie-import-policy.test.ts,browser-cookie-import-google-exclusion.test.ts).Deliberately not in scope: the
clearStorageDatabulk fast path (STA-4065, owned separately), andreplaceCookiesForImportedDomains— see Follow-up below.Why
Regression from #14086 (
fc7c2a1cd5a4), which replacedbulkClearCookiesExceptwith per-cookie removal plus a rollback.The comment above
removeAllCookiesExceptalready stated the governing invariant — "Electron cannot round-trip partition identity, so excluded cookies must never be removed" — but only thegoogle.comfamily (NON_TRANSPLANTABLE_DOMAINS) was excluded. Everything else was removed and, on any partial failure, rebuilt throughcookies.set.I probed Electron 43.1.0 against a real session jar to establish what is actually possible:
cookies.get({})partitionKey. Keys:domain, hostOnly, httpOnly, name, path, sameSite, secure, session, valuecookies.get({ url })cookies.get({ domain })cookies.remove(url, name)get({})returns 2 entries that are field-identical; oneremove()deletes bothcookies.set({ partitionKey })partitionKeyis silently ignored, not rejectedSo there is no per-cookie fix available: Electron exposes no way to tell a partitioned cookie from an unpartitioned one, and no way to recreate one. Every cookie in the snapshot is potentially partitioned, and every
cookies.setreconstruction is potentially a downgrade. Skipping "the cookies that can't be round-tripped" would mean skipping all of them.That leaves not reconstructing at all, which is also the better trade on the merits. The cookies being removed are stale cookies the import is about to replace; leaving them removed is a bounded, visible, retryable failure (
importCookiesFromBrowseralready returns{ok: false}and the user re-runs the import). Recreating them unpartitioned is unbounded silent corruption that survives restart and that neither Orca nor the user can detect or repair.Linked Issue
STA-4061 — https://linear.app/stably/issue/STA-4061/p0-cookie-import-rollback-destroys-non-google-partition-identity-after
Regression from #14086.
Fixes #
Visual Proof
No happy-path UI delta — this is a main-process failure-path change. Happy-path cookie-import screenshots (macOS Electron, no regression) plus red/green rollback-test output: #14132 (comment)
Testing
Platform tested: macOS (Electron 43.1.0, main process). This is a main-process cookie-store change with no renderer, mobile, Windows/WSL, or SSH-specific behavior — it runs identically wherever Electron does.
Red/green on the new regression test, same command both times:
Before the fix (at
9772da844a):The cookie survived the failed clear with its value intact and no
partitionKey— the corruption, reproduced end to end against a real Electron cookie jar.After the fix: passes.
Full suite for the touched area:
Also run clean:
pnpm run typecheck— passoxlint src/main/browser/— passpnpm run audit:code-quality:native— passpnpm run audit:code-quality:type-aware— passpnpm run check:max-lines-ratchet— pass (no new suppressions)oxfmt— cleanI manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
N/A — internal.
Review
xvfb-runhandling for Linux CI.cookies.setper removed cookie.Follow-up (not this PR)
replaceCookiesForImportedDomainsand theimportValidatedCookiesset-failure path (browser-cookie-import.ts:676) still roll back through the same lossyrestoreImportedDomainCookies, so they carry the same downgrade risk for cookies on imported domains. That is pre-existing behavior, not part of the #14086 regression, and it belongs in its own change — flagging it here so it isn't lost.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)