Skip to content

fix(browser): preserve partitioned Google cookies on import - #14086

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-4013-preserve-google-cookie-partitions
Aug 12, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-4013-preserve-google-cookie-partitions

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • replace native Chromium bulk cookie clearing with bounded selective removal
  • skip Google-family destination cookies before any destructive operation, so excluded cookies are never cleared or reconstructed
  • preserve file, Firefox, Safari, Google exclusion/accounting, and toast behavior

Electron coverage

A real Electron 43 process creates a partitioned accounts.google.com cookie through Chromium CDP, runs the production selective-removal implementation, and verifies the complete CDP cookie remains unchanged while a stale non-Google cookie is removed. The test also pins the public API gap: Electron Cookies.get exposes the cookie but omits partitionKey, so snapshot/restore cannot preserve partition identity. Linux runs the same fixture through Xvfb with the required sandbox override.

Performance

This intentionally restores the O(N) bounded-concurrency removal path. The real-Electron measurements recorded for #13966 were 3.6 ms at 100 cookies, 195.2 ms at 1,000, and 2,226.6 ms at 3,300 versus 1.0 ms, 8.8 ms, and 35.8 ms for bulk clear (3.5x to 62.1x slower); correctness takes priority because the bulk path can invalidate active Google sessions.

Validation

  • 60 focused tests across five files, including the real Electron partition test
  • node typecheck
  • standard, native-plugin, and type-aware focused oxlint
  • changed-code quality and React Doctor gate
  • max-lines ratchet and git diff checks

Fixes STA-4013.

@coderabbitai

coderabbitai Bot commented Aug 12, 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: dfb46645-bc6f-4b57-ae15-91b3d79d7455

📥 Commits

Reviewing files that changed from the base of the PR and between 33c74f6 and a901260.

📒 Files selected for processing (1)
  • src/main/browser/browser-cookie-import-partition.electron.test.ts

📝 Walkthrough

Walkthrough

The cookie import flow now removes existing cookies individually through removeAllCookiesExcept. It skips excluded cookies, groups removals by URL and name, limits concurrency, preserves group order, and restores removed cookies when a failure occurs. Bulk storage clearing and related restoration logic were removed. Tests cover exclusion, rollback, concurrency, partitioned cookies, and failure behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, rationale, testing, performance impact, and linked issue, but omits most required template sections and checklist details. Use the repository template headings and add ELI5, What Changed, Why, Visual Proof or N/A, Testing checkboxes and platforms, AI Disclosure, Review, Checklist, and Author sections.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes preserving partitioned Google cookies during browser cookie import.
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 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/browser/browser-cookie-import-policy.test.ts (1)

234-257: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the rollback-failure branch.

This test covers the successful rollback path. removeAllCookiesExcept has a second failure branch: when restoreImportedDomainCookies also fails, it throws AggregateError with the message Cookie clearing and rollback failed. That branch stays untested. Add a case where set rejects after a remove rejection.

♻️ Proposed additional test
+  it('reports clearing and rollback failure when restoration also fails', async () => {
+    const get = vi
+      .fn()
+      .mockResolvedValue([
+        cookie('.example.com', 'first', '/one'),
+        cookie('.example.com', 'second', '/two')
+      ])
+    const remove = vi.fn().mockImplementation(async (_url: string, name: string) => {
+      if (name === 'second') {
+        throw new Error('store unavailable')
+      }
+    })
+    const set = vi.fn().mockRejectedValue(new Error('set unavailable'))
+
+    await expect(
+      removeAllCookiesExcept({ get, remove, set }, () => false)
+    ).rejects.toThrow('Cookie clearing and rollback failed')
+  })
src/main/browser/browser-cookie-import-partition.electron.test.ts (1)

112-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Do not derive the policy entry path from process.cwd().

process.cwd() depends on how Vitest starts. If a project config sets a different root, the Vite build resolves a wrong entry and the fixture fails. Derive the path from the test file location instead.

♻️ Proposed fix
+import { fileURLToPath } from 'node:url'
...
-      lib: {
-        entry: join(process.cwd(), 'src/main/browser/browser-cookie-import-policy.ts'),
+      lib: {
+        entry: fileURLToPath(new URL('./browser-cookie-import-policy.ts', import.meta.url)),

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 74a34b89-d206-40cc-807c-6c43f59d6009

📥 Commits

Reviewing files that changed from the base of the PR and between 09ec516 and 60c8127.

📒 Files selected for processing (6)
  • src/main/browser/browser-cookie-import-google-exclusion.test.ts
  • src/main/browser/browser-cookie-import-partition.electron.test.ts
  • src/main/browser/browser-cookie-import-policy.test.ts
  • src/main/browser/browser-cookie-import-policy.ts
  • src/main/browser/browser-cookie-import.test.ts
  • src/main/browser/browser-cookie-import.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA (STA-4013) — partitioned Google cookie survives native import

Result: PASS. A real partitioned Google-family cookie was present before a native Chromium import, the import was run through the app UI, and the same cookie was still present afterward with the same partition identity. Import still succeeded and the stale non-excluded cookie was replaced, so the fix did not disable importing.

Evidence lives on scratch branch qa-evidence/sta-4013-14086 (not this PR branch). orca artifacts share returned artifact_sharing_disabled (not retried).

CDP owner verification

Isolated dev instance launched from this worktree via config/scripts/run-electron-vite-dev.mjs on CDP 9336 / renderer 5176 (9333–9335 and 5173–5175 were already taken). Not the user live app.

window.api.app.getIdentity():

  • name: Orca: a901260fef
  • devLabel: qa-14086-sta4013 @ a901260fef
  • devBranch: a901260fef
  • devWorktreeName: qa-14086-sta4013
  • devRepoRoot: /Users/brennanbenson/orca/workspaces/orca/qa-14086-sta4013

window.__store.getState().worktreesByRepo contained this folder workspace:

  • ed0fe930-...::/Users/brennanbenson/orca/workspaces/orca/qa-14086-sta4013

HEAD confirmed: a901260fef (test(browser): cover partition preservation through native import).

What each screenshot proves

1. Before import — partitioned cookie present

Seeded partitioned-google=.google.com value sta4013-live-value, sameSite=None, secure, httpOnly, partitionKey={ topLevelSite: https://example.com, hasCrossSiteAncestor: true }, plus stale [email protected]=remove-me. Overlay is a QA injection of Chromium Network.getAllCookies on the live persist:orca-browser webview, shown on the real app chrome (example.com tab + Import).

Before import

2. Native Chromium import menu (not file import)

Import browser data detected Google Chrome and Safari. Menu shows From Google Chrome.

Import menu

3. UI path used: From Google Chrome → stably.ai

Clicked the real Import control through to Chrome profile stably.ai.

Chrome profiles

4. After import — same cookie, same partition key; stale gone; import not a no-op

CDP re-read: partitioned-google still sta4013-live-value with identical partitionKey. [email protected] removed. Source had 941 cookies; import wrote 869 cookies / 196 domains (4 Google integrity + 68 non-transplantable skipped). Visible jar after: 611 cookies.

After import

5. Import succeeded in product UI

Settings → Browser → Session & Cookies shows Default Active with source Google Chrome (stably.ai).

Settings source

Gaps

  • 69 imported cookies failed in-memory cookies.set and were staged for restart (existing fallback). Import still succeeded (800 loaded).
  • Success toast disappeared before a dedicated screenshot; Settings source + diag log + cookie counts cover that.
  • Partition identity is not a first-class product field. The overlay is QA-only, populated from Chromium CDP on the live webview (the same API the Electron 43 fixture uses). Electron cookies.get still omits partitionKey; that is the bug this PR avoids by not reconstructing excluded cookies.

Full notes: https://github.com/stablyai/orca/raw/qa-evidence/sta-4013-14086/qa-evidence/sta-4013-14086/REPORT.md

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Independent Electron QA (Grok / Playwright CDP)

HEAD: a901260fef917ccf5f0f91839b813f12dd24163f
Verdict: PASS — no PR-introduced defect; no code changes.

Identity: window.api.app.getIdentity() attached to this worktree (sta-4013-preserve-partitioned-google-cookies @ brennanb2025/sta-4013-preserve-google-cookie-partitions). Isolated ORCA_DEV_USER_DATA_PATH + CDP :9335.

Action

Prepared isolated profile qa-partition with a synthetic partitioned accounts.google.com cookie (partitioned-google, partitionKey={topLevelSite:https://example.com, hasCrossSiteAncestor:true}) and a stale non-Google cookie (stale). Exercised the production native Chromium import through Settings → Browser → Session & Cookies → Import Cookies → From Helium against an isolated fixture source (imported=new-value on .example.com). Store/API/CDP only prepared and inspected state.

CDP assertions (Network.getAllCookies)

  • Google cookie identity-equal after import: name, domain, value, path, secure, httpOnly, sameSite, and partitionKey unchanged
  • Stale non-Google cookie removed
  • Imported cookie present (imported / .example.com)
  • Remaining names: imported, partitioned-google
  • Import summary: importedCookies=1, domains=["example.com"]
  • Logs: selective clear + in-memory load of 1 cookie, 0 failures; no restart fallback

Cleanup

Removed the planted Helium fixture, isolated user-data profile, and only the Electron process group started for this run. Worktree left clean. Not merged.

Screenshots

Import surface (qa-partition, no cookies imported):

01-import-surface.png

Import menu with From Helium (Google logins disclosure visible):

02-import-menu.png

Result: qa-partition sourced from Helium (Default):

03-import-result.png

Completion toast after production import:

04-import-toast.png

@brennanb2025
brennanb2025 merged commit fc7c2a1 into main Aug 12, 2026
80 of 88 checks passed
brennanb2025 added a commit that referenced this pull request Aug 13, 2026
…A-4065)

PR #14086 replaced the bulk clear with one Electron cookies.remove() per
removable cookie so partitioned excluded cookies survive an import. That is
required whenever something must be preserved, but it also runs when nothing
is excluded, where a single clearStorageData is equivalent and far cheaper:
421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43.

The fast path is gated on the same unfiltered cookies.get() the exclusion
predicate already reads, which an Electron fixture now proves returns
partitioned cookies, so "no exclusions in the snapshot" means "nothing in the
jar to preserve".
brennanb2025 added a commit that referenced this pull request Aug 13, 2026
…e family (STA-4065) (#14131)

* perf(browser): bulk clear cookies when an import excludes nothing (STA-4065)

PR #14086 replaced the bulk clear with one Electron cookies.remove() per
removable cookie so partitioned excluded cookies survive an import. That is
required whenever something must be preserved, but it also runs when nothing
is excluded, where a single clearStorageData is equivalent and far cheaper:
421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43.

The fast path is gated on the same unfiltered cookies.get() the exclusion
predicate already reads, which an Electron fixture now proves returns
partitioned cookies, so "no exclusions in the snapshot" means "nothing in the
jar to preserve".

* fix(browser): protect cookie clear fast-path race (STA-4065)

* test(browser): keep the no-bulk-clear assertion honest after the clearData switch

The mocked session still exposed clearStorageData, so asserting it was never
called could no longer fail once the fast path moved to clearData.

* docs(browser): stop the fallback comment from asserting a rollback

The per-cookie path's rollback is being removed by STA-4061; the comment only
needs to say the fallback re-removes what survived.

* test(browser): keep the STA-4061 rollback fixture on the per-cookie path

The bulk fast path clears a jar with no excluded cookie in one call, which
would have made every assertion in the partition-rollback fixture vacuous.
Give it a live Google cookie so the partial-failure clear still runs, and
assert the bulk call count is zero so a future widening fails loudly.

* perf(browser): always bulk clear cookies, not only when nothing is excluded

The fast path only fired when the jar held no Google cookie, but this import
exists for Google, so a Google cookie is normally present and the common case
still paid one native remove per cookie. Measured on Electron 43, clearData
excludeOrigins preserves the whole google.com registrable family -- host,
leading-dot, subdomain and partitioned cookies -- so the bulk call is safe with
cookies to keep, and the gate was never load-bearing for preservation.

Drop the caller-supplied exclusion predicate so the preserved set has exactly
one source of truth: a predicate that disagreed with NON_TRANSPLANTABLE_DOMAINS
would have deleted cookies the bulk call is meant to keep. The per-cookie loop
stays as the fallback for a rejected bulk clear, carrying the same exclusion.

* fix(browser): re-read the cookie jar after a rejected bulk clear

clearData can empty part of the jar before rejecting, so the per-cookie
fallback was working from a snapshot taken before the attempt: it retried
removals for cookies that were already gone and could not see cookies that
arrived during the clear. Re-read on rejection only.

Also repairs three fixtures that mocked the session with clearStorageData
after the call moved to clearData. The missing method threw, the catch
swallowed it, and every one of those tests silently asserted per-cookie
behaviour while believing it covered exclusion. Records the registrable-domain
invariant at NON_TRANSPLANTABLE_DOMAINS, since excludeOrigins derives one
origin per entry, and extends the real-Electron fixture to prove http-only and
domain-scoped Google cookies survive alongside the partitioned one.
hyoteis pushed a commit to hyoteis/orca that referenced this pull request Aug 15, 2026
hyoteis pushed a commit to hyoteis/orca that referenced this pull request Aug 15, 2026
…e family (STA-4065) (stablyai#14131)

* perf(browser): bulk clear cookies when an import excludes nothing (STA-4065)

PR stablyai#14086 replaced the bulk clear with one Electron cookies.remove() per
removable cookie so partitioned excluded cookies survive an import. That is
required whenever something must be preserved, but it also runs when nothing
is excluded, where a single clearStorageData is equivalent and far cheaper:
421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43.

The fast path is gated on the same unfiltered cookies.get() the exclusion
predicate already reads, which an Electron fixture now proves returns
partitioned cookies, so "no exclusions in the snapshot" means "nothing in the
jar to preserve".

* fix(browser): protect cookie clear fast-path race (STA-4065)

* test(browser): keep the no-bulk-clear assertion honest after the clearData switch

The mocked session still exposed clearStorageData, so asserting it was never
called could no longer fail once the fast path moved to clearData.

* docs(browser): stop the fallback comment from asserting a rollback

The per-cookie path's rollback is being removed by STA-4061; the comment only
needs to say the fallback re-removes what survived.

* test(browser): keep the STA-4061 rollback fixture on the per-cookie path

The bulk fast path clears a jar with no excluded cookie in one call, which
would have made every assertion in the partition-rollback fixture vacuous.
Give it a live Google cookie so the partial-failure clear still runs, and
assert the bulk call count is zero so a future widening fails loudly.

* perf(browser): always bulk clear cookies, not only when nothing is excluded

The fast path only fired when the jar held no Google cookie, but this import
exists for Google, so a Google cookie is normally present and the common case
still paid one native remove per cookie. Measured on Electron 43, clearData
excludeOrigins preserves the whole google.com registrable family -- host,
leading-dot, subdomain and partitioned cookies -- so the bulk call is safe with
cookies to keep, and the gate was never load-bearing for preservation.

Drop the caller-supplied exclusion predicate so the preserved set has exactly
one source of truth: a predicate that disagreed with NON_TRANSPLANTABLE_DOMAINS
would have deleted cookies the bulk call is meant to keep. The per-cookie loop
stays as the fallback for a rejected bulk clear, carrying the same exclusion.

* fix(browser): re-read the cookie jar after a rejected bulk clear

clearData can empty part of the jar before rejecting, so the per-cookie
fallback was working from a snapshot taken before the attempt: it retried
removals for cookies that were already gone and could not see cookies that
arrived during the clear. Re-read on rejection only.

Also repairs three fixtures that mocked the session with clearStorageData
after the call moved to clearData. The missing method threw, the catch
swallowed it, and every one of those tests silently asserted per-cookie
behaviour while believing it covered exclusion. Records the registrable-domain
invariant at NON_TRANSPLANTABLE_DOMAINS, since excludeOrigins derives one
origin per entry, and extends the real-Electron fixture to prove http-only and
domain-scoped Google cookies survive alongside the partitioned one.

(cherry picked from commit e590683)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…e family (STA-4065) (stablyai#14131)

* perf(browser): bulk clear cookies when an import excludes nothing (STA-4065)

PR stablyai#14086 replaced the bulk clear with one Electron cookies.remove() per
removable cookie so partitioned excluded cookies survive an import. That is
required whenever something must be preserved, but it also runs when nothing
is excluded, where a single clearStorageData is equivalent and far cheaper:
421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43.

The fast path is gated on the same unfiltered cookies.get() the exclusion
predicate already reads, which an Electron fixture now proves returns
partitioned cookies, so "no exclusions in the snapshot" means "nothing in the
jar to preserve".

* fix(browser): protect cookie clear fast-path race (STA-4065)

* test(browser): keep the no-bulk-clear assertion honest after the clearData switch

The mocked session still exposed clearStorageData, so asserting it was never
called could no longer fail once the fast path moved to clearData.

* docs(browser): stop the fallback comment from asserting a rollback

The per-cookie path's rollback is being removed by STA-4061; the comment only
needs to say the fallback re-removes what survived.

* test(browser): keep the STA-4061 rollback fixture on the per-cookie path

The bulk fast path clears a jar with no excluded cookie in one call, which
would have made every assertion in the partition-rollback fixture vacuous.
Give it a live Google cookie so the partial-failure clear still runs, and
assert the bulk call count is zero so a future widening fails loudly.

* perf(browser): always bulk clear cookies, not only when nothing is excluded

The fast path only fired when the jar held no Google cookie, but this import
exists for Google, so a Google cookie is normally present and the common case
still paid one native remove per cookie. Measured on Electron 43, clearData
excludeOrigins preserves the whole google.com registrable family -- host,
leading-dot, subdomain and partitioned cookies -- so the bulk call is safe with
cookies to keep, and the gate was never load-bearing for preservation.

Drop the caller-supplied exclusion predicate so the preserved set has exactly
one source of truth: a predicate that disagreed with NON_TRANSPLANTABLE_DOMAINS
would have deleted cookies the bulk call is meant to keep. The per-cookie loop
stays as the fallback for a rejected bulk clear, carrying the same exclusion.

* fix(browser): re-read the cookie jar after a rejected bulk clear

clearData can empty part of the jar before rejecting, so the per-cookie
fallback was working from a snapshot taken before the attempt: it retried
removals for cookies that were already gone and could not see cookies that
arrived during the clear. Re-read on rejection only.

Also repairs three fixtures that mocked the session with clearStorageData
after the call moved to clearData. The missing method threw, the catch
swallowed it, and every one of those tests silently asserted per-cookie
behaviour while believing it covered exclusion. Records the registrable-domain
invariant at NON_TRANSPLANTABLE_DOMAINS, since excludeOrigins derives one
origin per entry, and extends the real-Electron fixture to prove http-only and
domain-scoped Google cookies survive alongside the partitioned one.
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