Skip to content

fix(browser): never resurrect cookies after a failed import clear (STA-4061) - #14132

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-4061-cookie-partition-rollback
Aug 13, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-4061-cookie-partition-rollback

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

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

removeAllCookiesExcept no longer rolls back a partial clear.

  • Dropped the restoreImportedDomainCookies call and the removedCookies bookkeeping that fed it.
  • store narrowed from Pick<Cookies, 'get' | 'remove' | 'set'> to Pick<Cookies, 'get' | 'remove'>, so the lossy reconstruction cannot be reintroduced here by accident.
  • Failure message is now truthful about the resulting state: Could not clear existing cookies; the session was left partially cleared (it reaches the user via summarizeCookieImportError).
  • New real-Electron regression test 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.
  • Updated the two existing tests that codified the old rollback (browser-cookie-import-policy.test.ts, browser-cookie-import-google-exclusion.test.ts).

Deliberately not in scope: the clearStorageData bulk fast path (STA-4065, owned separately), and replaceCookiesForImportedDomains — see Follow-up below.

Why

Regression from #14086 (fc7c2a1cd5a4), which replaced bulkClearCookiesExcept with per-cookie removal plus a rollback.

The comment above removeAllCookiesExcept already stated the governing invariant — "Electron cannot round-trip partition identity, so excluded cookies must never be removed" — but only the google.com family (NON_TRANSPLANTABLE_DOMAINS) was excluded. Everything else was removed and, on any partial failure, rebuilt through cookies.set.

I probed Electron 43.1.0 against a real session jar to establish what is actually possible:

Probe Result
cookies.get({}) Returns partitioned cookies, stripped of partitionKey. Keys: domain, hostOnly, httpOnly, name, path, sameSite, secure, session, value
cookies.get({ url }) Returns partitioned cookies too — no unpartitioned-only view
cookies.get({ domain }) Same — no discrimination
cookies.remove(url, name) Does delete partitioned cookies
partitioned + unpartitioned twin at same url+name get({}) returns 2 entries that are field-identical; one remove() deletes both
cookies.set({ partitionKey }) partitionKey is silently ignored, not rejected

So 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.set reconstruction 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 (importCookiesFromBrowser already 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:

pnpm exec vitest run --config config/vitest.config.ts src/main/browser/browser-cookie-import-partition-rollback.electron.test.ts

Before the fix (at 9772da844a):

AssertionError: chips-auth was downgraded to unpartitioned: [{"name":"chips-auth","value":"keep-me"}]
- Expected: []
+ Received: [ { "name": "chips-auth", "value": "keep-me" } ]

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:

pnpm exec vitest run --config config/vitest.config.ts src/main/browser/
  Test Files  36 passed (36)
       Tests  608 passed (608)

Also run clean:

  • pnpm run typecheck — pass

  • oxlint src/main/browser/ — pass

  • pnpm run audit:code-quality:native — pass

  • pnpm run audit:code-quality:type-aware — pass

  • pnpm run check:max-lines-ratchet — pass (no new suppressions)

  • oxfmt — clean

  • I manually tested these changes locally

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

AI Disclosure

N/A — internal.

Review

  • Security: strictly reduces writes to the cookie jar; no new cookie is ever created by the failure path. Removes a path that could silently weaken a cookie's isolation from partitioned to global.
  • Cross-platform: no platform-conditional code; Electron cookie APIs behave the same on macOS/Linux/Windows. The new test follows the existing rig's xvfb-run handling for Linux CI.
  • Remote SSH / folder workspaces: cookie import is a local main-process operation against an Electron session; unaffected.
  • Mobile: unaffected — desktop main process only.
  • Backwards compatibility: no wire, IPC, or persisted-format change. The only observable difference is on the already-failing path: the jar is left partially cleared rather than partially (and lossily) restored, and the failure string is more specific.
  • Performance: strictly less work — the failure path no longer issues a cookies.set per removed cookie.

Follow-up (not this PR)

replaceCookiesForImportedDomains and the importValidatedCookies set-failure path (browser-cookie-import.ts:676) still roll back through the same lossy restoreImportedDomainCookies, 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

  • 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)

…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.
@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: 5fd5da01-4f26-4c9e-ab3d-357542d7767b

📥 Commits

Reviewing files that changed from the base of the PR and between dcc03fd and 950d220.

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

📝 Walkthrough

Walkthrough

removeAllCookiesExcept no longer requires Cookies.set and does not restore removed cookies after failures. It preserves grouped, bounded, and ordered removal, then reports a partially cleared session through AggregateError. Unit tests cover the updated failure behavior. A new Electron integration test covers failed removal of partitioned cookies and verifies partition metadata and cookie state.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 identifies the browser cookie import fix and the key behavior: cookies are not resurrected after a failed clear.
Description check ✅ Passed The description is detailed and covers the change, rationale, linked issue, testing, scope, compatibility, and checklist requirements.
✨ Finishing Touches
📝 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: 1

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

200-204: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Condense 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

📥 Commits

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

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

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 brennanb2025/sta-4061-cookie-partition-rollback · isolated user-data + CDP 9335.

Identity check (before trusting any screenshot): window.api.app.getIdentity() returned name: Orca: brennanb2025/sta-4061-cookie-partition-rollback, devRepoRoot: /Users/brennanbenson/orca/workspaces/orca/sta-4061-cookie-partition-rollback.

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 orca-visual-proof/sta-4061-macos-electron (not for merge). orca artifacts share is disabled on this device (artifact_sharing_disabled).


1. Isolated worktree instance, landing

Fresh profile launched from this worktree. No project yet. This is the instance all later shots come from.

Landing

2. In-app browser tab — Import entry point

Opened a managed browser tab. Toolbar shows Import next to the address bar. Sidebar is sta-4061-cookie-partition-rollback.

Browser tab

3. Import browser data popover

Clicked Import. Detected Google Chrome, Safari. Same entry point also advertised under Settings > Browser.

Import popover

4. Import menu — Chromium-family source

Import… lists From Google Chrome / From Safari / From File…, plus the existing “Google logins aren't imported” disclosure (unchanged by this PR).

Import menu

5. Chrome profile picker

Submenu: stably.ai and Brennan. Imported from stably.ai (Chrome profile directory Default).

Chrome profiles

6. Success summary (happy path, no UI regression)

In-browser banner after the Chromium import:

Imported 878 cookies for 360yield.com, 3lift.com, 6sc.co +194 more. Reload the page to use them.

Store result: totalCookies=949, importedCookies=878, skippedCookies=71 (all Google / non-transplantable). This banner is existing UI; this PR does not change it.

Import success

7. Settings > Browser — persisted source

Default profile is Active with source Google Chrome (stably.ai). Persistent success state after import.

Settings Browser

8. Signed-in GitHub after import

Same Orca browser, default profile (persist:orca-browser), navigated to https://github.com/. Dashboard is signed in as brennanb2025 with stablyai repos. Imported session cookies work. Identity re-checked immediately before this shot.

GitHub signed in


Failure-path evidence (no dedicated UI)

The rollback path has no screen. Same command both times:

pnpm exec vitest run --config config/vitest.config.ts src/main/browser/browser-cookie-import-partition-rollback.electron.test.ts

After the fix (this branch): PASS

 ✓ src/main/browser/browser-cookie-import-partition-rollback.electron.test.ts (1 test) 731ms
     ✓ never resurrects a removed partitioned cookie  724ms

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

Before the fix (policy file only swapped to parent 9772da844a, then restored): FAIL — chips-auth survived with value keep-me and no partitionKey.

AssertionError: chips-auth survived: [{"name":"chips-auth","value":"keep-me"}]: expected [ { name: 'chips-auth', …(1) } ] to deeply equal []

- Expected
+ Received

- []
+ [
+   {
+     "name": "chips-auth",
+     "value": "keep-me",
+   },
+ ]

Policy file restored immediately after the red run. PR worktree source left clean.

What I could not capture

  • No before/after UI pair — there is no user-visible change on the happy path, and the failure path cannot be triggered from the UI.
  • Ephemeral sonner toast — Playwright's next command often outlived the toast. The persistent in-browser banner in shot 6 is the actual imported-cookie summary.
  • orca artifacts share — disabled on this device; used the scratch-branch fallback instead.
  • Did not use the mobile emulator, a Windows remote host, SSH, or computer-use.

Full logs: after · before

@brennanb2025
brennanb2025 merged commit bc2e300 into main Aug 13, 2026
85 of 88 checks passed
hyoteis pushed a commit to hyoteis/orca that referenced this pull request Aug 15, 2026
…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)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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)
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