Skip to content

perf(browser): clear cookies in one bulk call that excludes the Google family (STA-4065) - #14131

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/sta-4065-cookie-bulk-clear-fastpath
Aug 13, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/sta-4065-cookie-bulk-clear-fastpath

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Wiping the browser jar before a cookie import used to be one phone call. Since #14086 it is one phone call per cookie — 3,000 calls for a 3,000-cookie jar — because a few Google cookies must be left alone and it looked like Electron could only skip them one at a time. It turns out the single call can be told which cookies to spare. This PR makes it one phone call again, always, and hands it the list to leave alone.

What Changed

removeAllCookiesExcept(store, isExcluded) becomes removeTransplantableCookies(session):

  • A non-empty jar is now always cleared with a single clearData({ dataTypes: ['cookies'], excludeOrigins }). There is no longer a gate that disables the bulk call when the jar holds cookies to preserve.
  • The caller-supplied exclusion predicate is gone. The preserved set now has exactly one source of truth — NON_TRANSPLANTABLE_DOMAINS — which both excludeOrigins and the fallback filter derive from. A predicate that disagreed with that constant would have deleted the very cookies the bulk call is meant to keep, and the type system now makes that unrepresentable rather than merely unlikely.
  • The per-cookie loop survives only as the fallback for a rejected bulk clear, carrying the same exclusion.
  • An empty jar still calls neither.
  • STA-4061's invariants are untouched: no rollback, and cookies.set remains unreachable from this path via Pick<Cookies, 'get' | 'remove'>.

One line at the call site in browser-cookie-import.ts now passes targetSession and no predicate.

Why

PR #14086 (fc7c2a1) replaced a bulk clear with a per-cookie clear so that partitioned Google cookies survive an import — Electron cannot round-trip partition identity, so a removed-and-restored cookie comes back without its partition key. That is correct and must stay whenever something is excluded. But it applies unconditionally, including when the exclusion predicate matches nothing, where a jar-wide clear removes exactly the same set.

Measured cost (STA-4065 notes latency was never measured, so it was)

Standalone Electron 43.1.0 / Chromium 150 main-process benchmark on macOS. Fresh persist: partition per trial, 3 trials each, 200 distinct eTLD+1 hosts, mixed secure/host-only/paths, jar size confirmed via cookies.get({}) before each timed run. Removal URLs and grouping replicate cookieRemovalUrl + mapSettledWithConcurrency(…, 8) exactly.

Cookies Per-cookie remove × N, conc=8 (current) Single clearData + excludeOrigins (shipped) Speedup
1,000 421 ms median (403–478) 7.6 ms median (7.0–8.5) ~56×
3,000 1,764 ms median (1,742–1,889) 23.8 ms median (20.9–25.6) ~74×

The exclusion costs essentially nothing: plain clearData({dataTypes:['cookies']}) measured 9.3 ms / 22.7 ms and clearStorageData({storages:['cookies']}) 7.9 ms / 21.3 ms over the same jars, so all three bulk calls are within noise of each other and all are two orders of magnitude below the per-cookie path.

The snapshot get({}) itself is noise (1.5 ms at 1k, 4.8 ms at 3k), so the fast path costs nothing extra to decide. The per-cookie path degrades worse than linearly — 3× the cookies costs 4.2× the time (throughput falls from 2,375 to 1,700 removals/s) — so the gap widens on larger jars. The bulk clear left the jar at 0 immediately after await in every one of 30 timed trials (and still 0 after 50 ms), so it is empty-when-resolved on this build.

Why the bulk call is safe with cookies to keep

The gate this PR removes was never what preserved Google cookies — excludeOrigins was. That was re-verified on real Electron 43.1.0 (Chrome 150) against a seeded persist: jar, reading the result back through CDP Network.getAllCookies:

Seeded cookie excludeOrigins: ['https://google.com']
google.com survived
accounts.google.com survived
.google.com (leading dot) survived
mail.google.com survived
partitioned CHIPS cookie on accounts.google.com survived
example.com deleted
notgoogle.com (lookalike) deleted
partitioned CHIPS cookie on a non-Google host deleted

A real-Electron fixture additionally proves an http-only, non-secure mail.google.com cookie and a domain-scoped .google.com cookie both survive a real import, so the exclusion is not limited to secure host-only cookies. Listing every subdomain origin explicitly produced an identical result, so origin matching is applied at the registrable-domain level — exactly isNonTransplantableCookieDomain's rule. The control run with excludeOrigins: [] wiped the entire jar including both Google and CHIPS cookies, which proves the exclusion is what did the work rather than the jar happening to survive.

This also closes the TOCTOU that review found in the first revision, and closes it better than the gate did. The target partition can be live during an import, so a Google/CHIPS cookie set by an in-flight response after the snapshot but before the clear was invisible to any gate — no snapshot can see it. excludeOrigins is evaluated by Chromium at clear time, so a cookie that arrives in that window is still protected.

Scope note: not a partition-identity or rollback fix. STA-4061 (#14132) owns those and is already on main; this PR is rebased on it and preserves its invariants.

Honest limitations

  • NON_TRANSPLANTABLE_DOMAINS entries must be lowercase-ASCII registrable domains, never bare subdomains or public suffixes: excludeOrigins derives one https://<entry> origin per entry and Chromium applies the exclusion at the registrable-domain boundary. That invariant is now recorded at the constant, because it is not obvious from the call site.
  • The fallback path is still per-cookie, so a rejected clearData on a 3,000-cookie jar still costs ~1.8 s. That is a degraded mode, not the normal one.

Linked Issue

Fixes STA-4065 — https://linear.app/stably/issue/STA-4065

Rebased onto #14132 (STA-4061), which is now on main.

Visual Proof

No UI change — this is a main-process clear-path speedup. Proof is from a live Orca Electron dev build of this branch (Orca: brennanb2025/sta-4065-cookie-bulk-clear-fastpath, CDP 9336), driven through the real Settings and browser-toolbar import surfaces.

Import surface (Settings → Browser → Session & Cookies)

Chrome was detected with two profiles. Import was triggered from stably.ai.

Settings import menu with Chrome profiles

Import completed

The Default profile flipped from “No cookies imported” to Google Chrome (stably.ai). Store summary: 949 source cookies → 878 imported, 71 skipped (Google / non-transplantable). 809 loaded in-memory; 69 need a restart (pre-existing fallback, not this PR).

Profile after import

Google-cookie skip toast after re-import

Fast-path evidence (honest: no HEAD~ before/after)

I did not disable the fast path or re-run HEAD~ in a second product build, so this is not a paired per-cookie vs clearData screenshot. What the running app did show:

A second import against the now-populated jar takes the session.clearData({ dataTypes: ['cookies'], excludeOrigins: ['https://google.com'] }) path. (These screenshots predate the change that made the bulk call unconditional; that widening only makes this path fire more often, never less, so the timing below remains representative.) In-app cookie-import-diag.log timestamps for the clear step only (staging complete → “cleared existing session cookies”):

Import Jar at clear Staging → cleared Wall time
1 (empty jar; neither path) 0 cookies 01:38:24.967Z → 01:38:24.969Z 2 ms
2 (fast-path candidate) ~809 cookies 01:40:23.768Z → 01:40:23.777Z 9 ms

9 ms to clear ~809 cookies matches the PR’s standalone clearData numbers (~7.6 ms median at 1,000) and is not the per-cookie path (~421 ms median at 1,000). The in-app log does not print clearData vs remove, so this is timing + predicate evidence, not a logged opcode.

Browser still works after import

https://example.com/ loads in the in-app browser. The toolbar Import hint is the other user-facing import surface.

Browser loads example.com after import

Browser toolbar Import popover

Imported cookies are live: https://github.com/ opened as the signed-in brennanb2025 dashboard (github.com was in the imported domain list).

GitHub session after cookie import

Testing

macOS. Windows / Linux / SSH are unaffected: this is Electron main-process session API usage with no platform-conditional code, no filesystem paths, and no wire format.

  • npx vitest run --config config/vitest.config.ts src/main/browser/ — 36 files, 614 tests passed
  • pnpm run typecheck:node — clean
  • npx oxlint src/main/browser/ — clean; npx oxfmt --check — clean
  • node config/scripts/check-changed-code-quality.mjs — 0 new findings across 5 changed files (native, type-aware, React Doctor)

Also fixed a test that my own change had quietly made vacuous: browser-cookie-import.test.ts mocked the session with clearStorageData, so its expect(...).not.toHaveBeenCalled() guard could no longer fail once the fast path moved to clearData. The mock now exposes clearData.

New/updated unit coverage in browser-cookie-import-policy.test.ts:

  • clears a jar holding Google cookies in one call that excludes them — the widening's core claim; pins the exact { dataTypes: ['cookies'], excludeOrigins: ['https://google.com'] } argument and asserts remove is never called

  • bulk clears in one call when the jar holds nothing to preserve

  • touches nothing when the jar is already empty

  • bulk clears cookies the per-cookie path could never address (undeliverable removal URL)

  • falls back to per-cookie removal when the bulk clear rejects

  • still preserves Google cookies on the per-cookie fallback — a rejected clearData must not become the path that finally deletes a live Google session

  • concurrency-bound, coordinate-serialization, and no-reconstruct tests retained, now driven through a rejecting bulk clear so they still reach the per-cookie path

  • re-reads the jar after a rejected bulk clear — clearData can empty part of the jar before rejecting, so the fallback must act on survivors rather than pre-attempt coordinates

I verified the central new test is not vacuous by mutation: reinstating the old gate makes exactly clears a jar holding Google cookies in one call that excludes them fail, and nothing else.

Two real bugs review caught in this revision

  1. Stale snapshot on the fallback. A rejected clearData may already have emptied part of the jar. The per-cookie fallback was iterating the snapshot taken before the attempt — retrying removals for cookies that were already gone, and blind to any cookie that arrived during the clear. It now re-reads, on rejection only.
  2. Three vacuous fixtures. browser-cookie-import-google-exclusion.test.ts and browser-cookie-import-replacement.test.ts mocked the session with clearStorageData after the implementation moved to clearData. The missing method threw a TypeError, the fallback's catch swallowed it, and those tests silently exercised the per-cookie path while asserting they covered exclusion. This predates the widening — it arrived with the clearData switch — and would have hidden a genuine regression in the bulk path.

Real-Electron coverage:

  • browser-cookie-import-partition.electron.test.ts — unfiltered cookies.get({}) returns a partitioned Google cookie

  • browser-cookie-import-partition-rollback.electron.test.ts (STA-4061's fixture, carried forward) — now forces clearData to reject so the fixture still reaches the per-cookie partial-failure path, seeds a live Google cookie, and asserts the bulk call was attempted exactly once. Without this it would have passed vacuously under the new bulk path while testing nothing.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

N/A — internal.

Review

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Security / data loss: the risk is an over-eager bulk clear wiping a cookie that must be preserved. Protection is excludeOrigins, evaluated by Chromium at clear time, measured on real Electron across host / leading-dot / subdomain / partitioned Google cookies plus a lookalike control. Removing the caller-supplied predicate leaves one source of truth for the preserved set.
  • Backwards compatibility: no wire, IPC, or persisted format change. removeAllCookiesExcept(store, isExcluded) is renamed to removeTransplantableCookies(session); it has exactly one non-test caller.
  • Performance: the point of the PR; numbers above.
  • Cross-platform / SSH / Mobile: main-process only, no platform branches; the browser cookie import is a desktop feature.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: bd7d506b-6167-4897-9330-bd4d106aae72

📥 Commits

Reviewing files that changed from the base of the PR and between e1be2e2 and 9cb2bac.

📒 Files selected for processing (3)
  • src/main/browser/browser-cookie-import-partition-rollback.electron.test.ts
  • src/main/browser/browser-cookie-import-policy.test.ts
  • src/main/browser/browser-cookie-import-policy.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/browser/browser-cookie-import-policy.ts
  • src/main/browser/browser-cookie-import-policy.test.ts

📝 Walkthrough

Walkthrough

Cookie cleanup now receives the target Electron session. When no cookies are excluded, it attempts bulk clearing with protected origins excluded. If bulk clearing fails, it uses per-cookie removal and rollback. Tests cover preservation, failures, rollback, empty jars, unaddressable cookies, concurrency, and removal ordering. Partition fixtures record unfiltered cookie names and verify partitioned, ordinary, and excluded cookies before cleanup.

🚥 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.
Description check ✅ Passed The description follows the required template and documents the change, rationale, linked issue, testing, visual proof, AI disclosure, review considerations, and checklist.
Title check ✅ Passed The title clearly and concisely identifies the browser performance change: bulk cookie clearing with Google-family exclusions.
✨ 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/main/browser/browser-cookie-import-policy.ts (1)

204-222: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Use session.clearData with excludeOrigins for the bulk path.

The only call site excludes google.com; use excludeOrigins: ['https://google.com'] with dataTypes: ['cookies']. This covers the registrable domain and its subdomains without relying on cookies.get({}) to expose every partitioned cookie.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84dc691d-fbc4-4b73-89ea-dd348143f3be

📥 Commits

Reviewing files that changed from the base of the PR and between 9772da8 and 59a3731.

📒 Files selected for processing (4)
  • 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.ts

@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: e4667756-83b0-41d6-86be-a3e77a512ffc

📥 Commits

Reviewing files that changed from the base of the PR and between 59a3731 and 31bcf14.

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

…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".
…rData switch

The mocked session still exposed clearStorageData, so asserting it was never
called could no longer fail once the fast path moved to clearData.
The per-cookie path's rollback is being removed by STA-4061; the comment only
needs to say the fallback re-removes what survived.
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.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4065-cookie-bulk-clear-fastpath branch from e1be2e2 to 9cb2bac Compare August 13, 2026 02:02
…cluded

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.
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.
@brennanb2025 brennanb2025 changed the title perf(browser): bulk clear cookies when an import excludes nothing (STA-4065) perf(browser): clear cookies in one bulk call that excludes the Google family (STA-4065) Aug 13, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Clean-provenance QA — Import Cookies Chrome submenu (no import)

Fresh CDP validation of this exact worktree on brennanb2025/sta-4065-cookie-bulk-clear-fastpath.

No cookie import was triggered. The native file picker was not opened. From File… was never clicked, and no Chrome profile item was selected. Default profile remained source: null / "No cookies imported" after the hover.

Identity via window.api.app.getIdentity():

  • devBranch: brennanb2025/sta-4065-cookie-bulk-clear-fastpath
  • devRepoRoot: /Users/brennanbenson/orca/workspaces/orca/sta-4065-cookie-bulk-clear-fastpath
  • CDP 127.0.0.1:9411, renderer 127.0.0.1:5281, unique ORCA_DEV_USER_DATA_PATH

What was exercised (Playwright/CDP only):

  1. Settings → Browser → Session & Cookies
  2. Opened Import Cookies
  3. Hovered From Google Chrome so the submenu appeared (stably.ai, Brennan are host Chrome profile labels only — no cookie values)

Renderer console: 0 errors; isolated profile logs had no cookie-import / file-picker activity.

1. Settings > Browser > Session & Cookies

01-settings-browser-session-cookies.png

2. Import Cookies menu open

02-import-cookies-menu-open.png

3. Chrome submenu hovered (import not clicked)

03-import-cookies-chrome-hovered.png

@brennanb2025
brennanb2025 merged commit e590683 into main Aug 13, 2026
86 of 88 checks passed
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
…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