Skip to content

fix(browser): fail-closed cookie clear after a partial import wipe (STA-4090) - #14191

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/sta-4090-cookie-clear-atomicity
Aug 13, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/sta-4090-cookie-clear-atomicity

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Failed native cookie import could permanently delete cookies that were already removed during a concurrent/partial full clear (STA-4090, follow-up to #14132). The import reported failure, but existing non-Google session cookies stayed gone.

This keeps the STA-4065 bulk clearData path, but snapshots partition-complete cookie identities before any mutation. If the bulk clear rejects and a later per-cookie removal also rejects, the clear restores from that snapshot through CDP Network.setCookie (including CHIPS partitionKey). Electron cookies.set() is never used for restore. If identities cannot be snapshotted, the import fails closed and leaves the jar unchanged.

Fixes STA-4090. Follow-up to #14132.

Reproduction (current main)

A deterministic unit regression and a real Electron fixture both failed on origin/main:

  • removed-first was deleted, stale then rejected, and removed-first stayed gone.
  • In Electron, a CHIPS cookie and an ordinary cookie were both absent after the failed clear.

Design

  • Snapshot removable cookies with CDP identities before clearData.
  • Keep one bulk clear that excludes the google.com family.
  • On bulk rejection, fall back to bounded per-cookie removal of survivors.
  • On any fallback failure, restore all snapshotted identities (covers cookies the bulk call already deleted).
  • Concurrent clears on the same session serialize.

No remote-wire shape change.

Tests

  • Unit: failed fallback restores the earlier cookie; incomplete snapshot does not mutate; restore failure reports a partial clear; partitioned identities never go through cookies.set(); concurrent clears serialize.
  • Electron: after a forced bulk failure plus a later victim removal rejection, chips-auth is still partitioned and plain is still present. Google SID stays excluded.

Validation

  • Focused vitest cookie-import unit tests: pass
  • browser-cookie-import-partition-rollback.electron.test.ts: pass
  • browser-cookie-import-partition.electron.test.ts: pass
  • pnpm tc:node: pass
  • oxlint + oxfmt + max-lines ratchet: pass

Residual risk

If restore itself fails after a partial clear, the session can still be left partial and the error says so. Headless hosts without an existing partition webContents create a hidden window to attach CDP; if that attach fails, the import fails closed without deleting cookies.

…TA-4090)

A rejected bulk clear plus a later per-cookie removal could permanently
delete cookies that were already gone. Snapshot partition-complete
identities before mutating, keep the bulk clear, and restore through CDP
so a failed import never silently drops existing cookies.
@coderabbitai

coderabbitai Bot commented Aug 13, 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: 3ba23b4b-061c-4ef8-8832-383764bd871d

📥 Commits

Reviewing files that changed from the base of the PR and between 6e8ae17 and 154051e.

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

📝 Walkthrough

Walkthrough

The PR separates cookie clearing from policy logic. It adds serialized clear operations, cookie identity capture, rollback handling, and CDP-based restoration with partition-key support. Cookie imports create and dispose a clear store around cleanup. Tests cover snapshot failures, removal failures, partial restoration, concurrent clears, Google exclusions, and Electron partitioned-cookie rollback.

Mergeability Score: ⚪ Minimal · up to 15405

The PR adds fail-closed cookie clearing with rollback for partial failures; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.03% 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
Title check ✅ Passed The title clearly identifies the fail-closed cookie-clear fix after a partial import wipe.
Description check ✅ Passed The description clearly explains the problem, solution, testing, linked issue, design, and residual risk.
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 💡 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.

Actionable comments posted: 3

🧹 Nitpick comments (4)
src/main/browser/browser-cookie-clear-store.ts (1)

110-149: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Network.enable stays on for a reused tab.

When findPartitionWebContents returns an existing tab, dispose() releases the debugger lease but does not send Network.disable. If another owner holds the lease, or if DevTools is attached, the Network domain remains enabled on a user-visible tab after the import. That changes network instrumentation for that tab for the rest of its life.

Consider sending Network.disable in dispose() when the store enabled the domain on a pre-existing tab.

src/main/browser/browser-cookie-import-google-exclusion.test.ts (1)

88-100: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

The mock reverses an already reversed list.

removeTransplantableCookies calls restoreClearIdentities(identities.toReversed()) in src/main/browser/browser-cookie-import-clear.ts (Line 134). This mock then applies toReversed() again, so it writes cookies back in the original snapshot order. The real store in src/main/browser/browser-cookie-clear-store.ts restores in the order it receives. Drop toReversed() here so the mock matches the production contract.

♻️ Proposed fix
-      for (const identity of identities.toReversed()) {
+      for (const identity of identities) {
src/main/browser/browser-cookie-import-policy.test.ts (1)

4-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Move the clear-module cases out of the policy test file.

removeTransplantableCookies now lives in src/main/browser/browser-cookie-import-clear.ts. This file is named for the policy module, and src/main/browser/browser-cookie-import-clear-atomicity.test.ts already covers the clear workflow. Move the clearSession fixture and the clear tests into a clear-module test file so each test file matches its subject.

Also applies to: 357-384

src/main/browser/browser-cookie-import.test.ts (1)

47-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Three copies of the openCookieClearStore mock. Each import test file redeclares the same fake clear store with its own inline types. A contract change in CookieClearStore requires three edits.

  • src/main/browser/browser-cookie-import.test.ts#L47-L61: replace the inline factory with a shared factory imported from a new module such as browser-cookie-clear-store-test-double.ts, typed against CookieClearStore.
  • src/main/browser/browser-cookie-import-replacement.test.ts#L29-L43: use the same shared factory.
  • src/main/browser/browser-cookie-import-google-exclusion.test.ts#L33-L104: use the shared factory with a restore callback option so this file keeps its cookies.set behavior. Do not name the new module helpers, utils, common, or shared. As per coding guidelines: "Do not use vague names such as helpers, utils, common, misc, or shared-stuff for files, folders, or modules; use concrete domain-oriented names instead."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c25cbb93-c3c2-4196-a85f-6c9dc33cd69a

📥 Commits

Reviewing files that changed from the base of the PR and between d3a2bf3 and a035486.

📒 Files selected for processing (11)
  • src/main/browser/browser-cookie-clear-store.test.ts
  • src/main/browser/browser-cookie-clear-store.ts
  • src/main/browser/browser-cookie-import-clear-atomicity.test.ts
  • src/main/browser/browser-cookie-import-clear.ts
  • src/main/browser/browser-cookie-import-google-exclusion.test.ts
  • 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
  • src/main/browser/browser-cookie-import-replacement.test.ts
  • src/main/browser/browser-cookie-import.test.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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/browser/browser-cookie-import-partition-rollback.electron.test.ts (1)

90-94: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert that a cookie removal succeeds before testing rollback.

mapSettledWithConcurrency starts all groups concurrently, so cookie enumeration order does not guarantee that victim fails after another removal. Record successful cookies.remove calls and assert that at least one succeeds before asserting restored cookies.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c6659275-5a23-456e-b2a2-4f3a2fc1530a

📥 Commits

Reviewing files that changed from the base of the PR and between a035486 and 4f9b612.

📒 Files selected for processing (5)
  • src/main/browser/browser-cookie-clear-store-lifecycle.test.ts
  • src/main/browser/browser-cookie-clear-store.test.ts
  • src/main/browser/browser-cookie-clear-store.ts
  • src/main/browser/browser-cookie-import-clear-atomicity.test.ts
  • src/main/browser/browser-cookie-import-partition-rollback.electron.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/browser-cookie-import-clear-atomicity.test.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Attachments

sta-4090-cookie-clear-proof-google-only.png
sta-4090-cookie-clear-proof-google-only.png

@brennanb2025

Copy link
Copy Markdown
Contributor Author

STA-4090 visual proof @ 154051efd1d3b7c82bc2336ea333cf129e6e0be3

Read-only Electron CDP run against the production openCookieClearStore + removeTransplantableCookies path on this exact pushed head. Cookie import is not a user-visible Orca chrome surface, so this is an isolated Electron proof window whose table values come from live assertions (the process fails if any assertion is false). All 24 production-path assertions passed.

1. Failed partial clear restores ordinary + CHIPS

Forced clearData rejection, then a later victim remove() rejection. After restore:

  • chips-auth=keep-me still partitioned { topLevelSite: "https://top.example", hasCrossSiteAncestor: true }
  • ordinary plain=stale still present
  • excluded Google SID=live untouched
  • error: Could not clear existing cookies; existing cookies were restored

2. Unrepresentable initial cookie fails before mutation

A transplantable jar plus an unaddressable domain: '' cookie failed closed with the session was left unchanged. snapshot / clearData / remove / restore were not called. Real cookie keep-real=before was unchanged.

3. Excluded-only Google jar does no clear/debugger/window work

Jar with only SID=live on accounts.google.com returned immediately: snapshot/clear/remove/restore = 0, windows/webContents before=after=0, SID still live.

full-page proof table

viewport with branch/HEAD

rollback before/failure/after

unrepresentable cookie

excluded-only Google jar

Gap: this is a production-path fixture window, not the full Orca app chrome. Electron cookies.get() still reports CHIPS partitionKey: null; CDP Network.getAllCookies is what preserves the partition identity (same as the PR Electron test).

@brennanb2025
brennanb2025 merged commit 93334dc into main Aug 13, 2026
44 checks passed
hyoteis pushed a commit to hyoteis/orca that referenced this pull request Aug 15, 2026
…TA-4090) (stablyai#14191)

* fix(browser): fail-closed cookie clear after a partial import wipe (STA-4090)

A rejected bulk clear plus a later per-cookie removal could permanently
delete cookies that were already gone. Snapshot partition-complete
identities before mutating, keep the bulk clear, and restore through CDP
so a failed import never silently drops existing cookies.

* fix(browser): preserve exact cookie clear identities

* fix(browser): abort unrepresentable cookie clears

* fix(browser): skip excluded-only cookie clears

(cherry picked from commit 93334dc)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…TA-4090) (stablyai#14191)

* fix(browser): fail-closed cookie clear after a partial import wipe (STA-4090)

A rejected bulk clear plus a later per-cookie removal could permanently
delete cookies that were already gone. Snapshot partition-complete
identities before mutating, keep the bulk clear, and restore through CDP
so a failed import never silently drops existing cookies.

* fix(browser): preserve exact cookie clear identities

* fix(browser): abort unrepresentable cookie clears

* fix(browser): skip excluded-only cookie clears
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