Repository navigation
fix(browser): route every cookie-import write through CDP identities (STA-4300) - #14729
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughCookie imports preserve readable Chromium, JSON, and Firefox partition identities. Unreadable partition metadata is skipped, counted, staged for replay when applicable, and reported in the import summary. Cookie writes use a shared CDP identity store with rollback support and failure handling. Chromium storage paths come from the target session. Unit and Electron tests cover partition parsing, CHIPS preservation, host-prefixed cookies, legacy schemas, and renderer warnings. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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: 2
🧹 Nitpick comments (2)
src/main/browser/browser-cookie-import-validated-partition.electron.test.ts (1)
156-231: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated Electron fixture harness across both partition regression tests. Both files build a temp root, bundle
browser-cookie-import.tswith Vite incjslib mode, stripELECTRON_RUN_AS_NODE, selectxvfb-runon Linux, spawn Electron, and readresult.jsonwith the same status assertions. The shared root cause is a missing helper module for that harness.
src/main/browser/browser-cookie-import-validated-partition.electron.test.ts#L156-L231: replace the inline harness with a shared helper that takes the exported symbol name, bundle file name, and fixture main source.src/main/browser/browser-cookie-import-partition-success.electron.test.ts#L155-L223: call the same helper, and keep only the Chromium source-database setup local to this file.src/renderer/src/lib/browser-cookie-import-toast.test.ts (1)
88-96: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the duplicate negative test.
This test uses the same summary as
does not infer a Google warning from generic skipped cookieson lines 98-107 and asserts the samewarningToastMockexpectation. The existing test already proves that a genericskippedCookiesvalue emits no warning. Delete one of the two, or give this one a distinct input such aspartitionSkippedCookies: 0.♻️ Proposed change to make the new test distinct
- it('does not infer a partition warning from generic skipped cookies', () => { + it('does not warn when the partition-skipped count is zero', () => { emitBrowserCookieImportToast( - { ...summary, importedCookies: 2, skippedCookies: 1 }, + { ...summary, importedCookies: 2, skippedCookies: 1, partitionSkippedCookies: 0 }, 'Imported 2 cookies.', 'Local Mac' ) expect(warningToastMock).not.toHaveBeenCalled() })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f3c3b473-2e4a-4298-962d-dbcca5f6cf2e
📒 Files selected for processing (19)
src/main/browser/browser-cookie-clear-store.test.tssrc/main/browser/browser-cookie-clear-store.tssrc/main/browser/browser-cookie-import-clear.tssrc/main/browser/browser-cookie-import-google-exclusion.test.tssrc/main/browser/browser-cookie-import-partition-fidelity.test.tssrc/main/browser/browser-cookie-import-partition-success.electron.test.tssrc/main/browser/browser-cookie-import-replacement.test.tssrc/main/browser/browser-cookie-import-test-database.tssrc/main/browser/browser-cookie-import-validated-partition.electron.test.tssrc/main/browser/browser-cookie-import-write.test.tssrc/main/browser/browser-cookie-import-write.tssrc/main/browser/browser-cookie-import.test.tssrc/main/browser/browser-cookie-import.tssrc/main/browser/browser-cookie-source-partition.test.tssrc/main/browser/browser-cookie-source-partition.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/lib/browser-cookie-import-toast.test.tssrc/renderer/src/lib/browser-cookie-import-toast.tssrc/shared/browser-workspace-types.ts
| "restartFallbackUnavailablePartial": "Imported {{value0}} of {{value1}} cookies. The rest could not be loaded, and the restart fallback was unavailable. Try the import again.", | ||
| "googleCookiesSkipped": "Google cookies were not imported. Open a browser in Orca on {{value0}} with this profile, then sign into Google." | ||
| "googleCookiesSkipped": "Google cookies were not imported. Open a browser in Orca on {{value0}} with this profile, then sign into Google.", | ||
| "partitionSkipped": "{{value0}} cookies were not imported because their site-partition could not be read. Sign in to those sites again in Orca." |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
i18next 26 pluralization suffixes _one _other with count option
💡 Result:
In i18next v26, pluralization relies entirely on the Intl.PluralRules API [1][2]. This system uses CLDR (Common Locale Data Repository) plural categories as suffixes to determine which translation string to use based on the provided count [3]. When using the count option in your translation function, i18next automatically selects the appropriate key based on the plural rules of the current language [3]. Key aspects of pluralization in i18next v26: 1. The count option: You must pass the count variable to the translation function (e.g., i18next.t('key', { count: 1 })) [4][5]. The variable name must be exactly count [4][5]. If it is not provided, i18next cannot resolve the correct plural form and will not fall back to a base key [4][5]. 2. Plural suffixes: The _one and _other suffixes are standard for English and many other languages [4][3]. The _other suffix acts as the mandatory fallback; omitting it may result in the raw key name being returned [3]. 3. Additional categories: Depending on the language's specific grammar, you may also use other categories such as _zero, _two, _few, or _many [4][6][3]. 4. Intl.PluralRules requirement: As of v24 and continuing into v26, the Intl.PluralRules API is mandatory [4][7][1]. In environments where this API is not supported (such as older React Native environments using Hermes), you must install an Intl polyfill to ensure pluralization works correctly [4][7]. Without the polyfill, i18next will degrade and may only resolve basic English-style _one/_other forms [4][7]. Example structure: { "key_one": "item", "key_other": "items" } Usage: i18next.t('key', { count: 1 }); // Returns "item" i18next.t('key', { count: 5 }); // Returns "items"
Citations:
- 1: https://www.i18next.com/misc/migration-guide
- 2: https://github.com/i18next/i18next/releases/tag/v26.0.0
- 3: https://localepack.app/guides/i18next-json-format-namespaces-plurals
- 4: https://www.i18next.com/translation-function/plurals
- 5: https://www.i18next.com/translation-function/plurals.md
- 6: https://i18next.github.io/i18next/pages/doc_features.html
- 7: https://www.i18next.com/how-to/faq
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- relevant source and test references ---'
rg -n -C 5 'partitionSkipped|browser-cookie-import-toast|found_theme_(one|other)|RESERVED_PLACEHOLDER_NAMES|I18NEXT_OPTION_NAMES' \
src/renderer/src config/scripts 2>/dev/null | head -n 240
printf '%s\n' '--- translation call sites ---'
rg -n -C 6 'partitionSkipped' src/renderer/srcRepository: stablyai/orca
Length of output: 22091
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- toast test assertion ---'
sed -n '80,95p' src/renderer/src/lib/browser-cookie-import-toast.test.ts
printf '%s\n' '--- translation implementation and option handling ---'
rg -n -C 8 'function translate|const translate|export .*translate|I18NEXT_OPTION_NAMES|RESERVED_PLACEHOLDER_NAMES|count' \
src/renderer/src/i18n config/scripts | head -n 320
printf '%s\n' '--- plural call patterns ---'
rg -n -C 5 'translate\([^,]+_(one|other)|\{ count:|count:' src/renderer/src config/scripts | head -n 260Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- localization placeholder contract ---'
rg -n -C 12 'RESERVED_PLACEHOLDER_NAMES|I18NEXT_OPTION_NAMES' config/scripts/localization-source-references.mjs
printf '%s\n' '--- explicit plural call-site patterns ---'
rg -n -C 8 "found_theme_one|found_theme_other|translate\(.*_one|translate\(.*_other" \
src/renderer/src/components src/renderer/src/lib | head -n 180
printf '%s\n' '--- partitionSkipped across catalogs ---'
rg -n -C 2 '"partitionSkipped(_one|_other)?"' src/renderer/src/i18n/localesRepository: stablyai/orca
Length of output: 364
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- locate localization reference scripts ---'
fd -i 'localization-source-references' . || true
fd -i 'localization' config src/renderer/src/i18n 2>/dev/null | head -n 120
printf '%s\n' '--- candidate reserved-option declarations ---'
rg -n -C 10 'RESERVED_PLACEHOLDER_NAMES|I18NEXT_OPTION_NAMES|reserved.*placeholder|placeholder.*reserved' \
. --glob '*.mjs' --glob '*.js' --glob '*.ts' --glob '*.tsx' | head -n 180
printf '%s\n' '--- explicit partition key and call-site context ---'
rg -n -C 8 'partitionSkipped|found_theme_one|found_theme_other' \
src/renderer/src/i18n/locales src/renderer/src/lib src/renderer/src/components/settings/WarpThemeImportModal.tsxRepository: stablyai/orca
Length of output: 21699
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
import json
from pathlib import Path
catalog = json.loads(Path("src/renderer/src/i18n/locales/en.json").read_text())
toast = catalog["auto"]["lib"]["browser"]["cookie"]["import"]["toast"]
source = Path("src/renderer/src/lib/browser-cookie-import-toast.ts").read_text()
test = Path("src/renderer/src/lib/browser-cookie-import-toast.test.ts").read_text()
warp = Path("src/renderer/src/components/settings/WarpThemeImportModal.tsx").read_text()
assert "partitionSkipped" in toast
assert toast["partitionSkipped"] == (
"{{value0}} cookies were not imported because their site-partition could not be read. "
"Sign in to those sites again in Orca."
)
assert "'auto.lib.browser.cookie.import.toast.partitionSkipped'" in source
assert "{ value0: summary.partitionSkippedCookies }" in source
assert "'1 cookies were not imported" in test
assert "preview.themes.length === 1" in warp
assert "found_theme_one" in warp and "found_theme_other" in warp
assert "{ value0: preview.themes.length }" in warp
print("partitionSkipped uses one base key and value0 interpolation")
print("singleton test currently expects the ungrammatical plural message")
print("existing found_theme plural forms are selected explicitly by call-site branching")
PYRepository: stablyai/orca
Length of output: 358
Fix the singular warning text. Use explicit singular/plural keys selected in browser-cookie-import-toast.ts, with value0 interpolation. Do not use count or i18next plural resolution. Update the toast assertion to expect “1 cookie was not imported…”.
Visual QA — warning toast (macOS, real Electron, playwright-cli + CDP)Driven end to end in the running app: Settings → Browser → Session & Cookies → Import Cookies → From File… with a cookie JSON containing one ordinary cookie plus one CHIPS cookie whose Both toasts shown below with the sonner stack hover-expanded (the real UI behavior for revealing stacked toasts — the warning persists 12s, the success toast 4s). BEFORE —
|
Independent verification of the review-loop fixes (
|
| Mutation applied | Result |
|---|---|
Restore the over-wide replace scope (importableCookies.map(...) with no filter) |
does not replace existing cookies for a domain whose only source cookie is skipped fails — and only that test |
Remove the unreadable guard so those rows reach the staging DB again |
never stages a partitioned row whose ancestor bit is unreadable fails — and only that test |
Both reverted; suite green.
The staging finding is the more important one. My original reasoning — "skip the in-memory write but let the staged cold-start replay carry it, since staging copies the source's own partition columns verbatim" — was wrong. When the source schema lacks has_cross_site_ancestor, buildChromiumCookieInsertParams fills the target's column with the target's default. That is a guessed ancestor bit: the same silent misfile the write path refuses to make, arriving one restart later through a channel I had argued was more faithful. The failure-mode table in the PR body has been corrected; it previously claimed the staged replay covered this cell.
I also proved the suite's structural guard is live rather than silently clean. unreachableCookieSet throws if cookies.set is called for any user cookie (only the __init probe is allowed). Injecting a single targetSession.cookies.set into the native write path fails 6 tests with Error: cookies.set was called for user cookie probe; removing it returns the suite to green. The guard is not a no-op.
Local gates after the merge: src/main/browser 45 files / 671 tests pass, both typechecks clean, oxlint clean, max-lines ratchet clean, no max-lines disable added.
There was a problem hiding this comment.
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.ts (1)
1736-1752: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winExclude unreadable partition cookies from the write set.
decryptedCookiesis later passed towriteImportedCookiesat Lines 1838-1852. Thecontinueat Line 1752 runs after the cookie was pushed at Line 1736. The memory phase therefore still receives the unreadable cookie. This can cause a partitionless CDP write or classify the cookie as a memory-write failure instead of a partition skip.Move
decryptedCookies.push(...)below the unreadable-partition guard. The PR objective requires unreadable partition cookies to be skipped instead of written with downgraded identity.Proposed fix
const value = decryptedValue.toString('latin1') - decryptedCookies.push({ - decryptedValue, - value, - domain, - name, - path, - secure, - httpOnly, - sameSite, - expirationDate: expiresUtc > 0 ? expiresUtc : undefined, - partition - }) - if (partition.status === 'unreadable') { partitionSkipped++ skipped++ continue } + decryptedCookies.push({ + decryptedValue, + value, + domain, + name, + path, + secure, + httpOnly, + sameSite, + expirationDate: expiresUtc > 0 ? expiresUtc : undefined, + partition + }) + const cleanDomain = domain.startsWith('.') ? domain.slice(1) : domain
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 21733426-bf6a-4e2e-9c9e-35f9bcc6d9b3
📒 Files selected for processing (7)
src/main/browser/browser-cookie-import-partition-fidelity.test.tssrc/main/browser/browser-cookie-import.tssrc/main/runtime/orca-runtime-browser.tssrc/main/runtime/rpc/methods/browser-schemas.tssrc/main/runtime/rpc/methods/browser.test.tssrc/renderer/src/store/slices/browser.test.tssrc/renderer/src/store/slices/browser.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/browser/browser-cookie-import-partition-fidelity.test.ts
…ot be rebuilt (STA-4300)
Review-loop verdict, stated honestlyThe codex review loop is NOT a clean pass. Its final same-model round stalled waiting on its own subagents after surfacing the Firefox boundary, so no post-fix clean verification completed and I interrupted it rather than let it hang. Concerns it had not yet re-verified are unverified, not clean. I am recording that rather than implying a green review. What the loop did deliver, all merged and each independently mutation-verified by me:
On the Firefox boundary specificallyI asked the reviewer to challenge my claim rather than accept it, and it was right to. Firefox packs two different things into Safari stands as originally argued: ITP is browser-imposed and absent from What a human reviewer should still look atBecause the loop did not converge, these are the places I would spend review attention:
Local gates on |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 17329183-283d-4164-875c-483016a0d04e
📒 Files selected for processing (3)
src/main/browser/browser-cookie-import.tssrc/main/browser/browser-cookie-source-partition.test.tssrc/main/browser/browser-cookie-source-partition.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/browser/browser-cookie-import.ts
…-cdp-cookie-writes # Conflicts: # src/renderer/src/store/slices/browser.test.ts
Electron CDP visual proof (STA-4300)Validated on an isolated dev instance of this worktree via Playwright CDP. No product code was edited and screenshots were not committed. Identity (
Live user path: Settings → Browser → Session & Cookies → Import Cookies → From Google Chrome → Live import result: Console: 0 renderer errors. Unrelated warnings only (Radix tooltip control, React Grab outdated). Isolated Browser settings (empty profile)Import Cookies menuChrome profile pickerAfter live Chrome importLive summary toasts (same helper, re-fired after the 12s toasts expired)Success + Google-skip copy from the live summary ( Partition-skip warning copy (helper demo)This Chrome profile had 0 unreadable partitions, so the STA-4300 toast did not fire from the live import. The same Not verified: a live source cookie whose partition is unreadable; native |
|
@brennanb2025 we reverted #14729 in #14942 because importing a Chromium profile can remove working site sessions for cookies the import then skips. Please reland with a fix that never clears a destination session unless that cookie will actually be written or staged. |
…(STA-4300) (#14729) * test(browser): repro STA-4300 CHIPS partition downgrade on native cookie import success path * fix(browser): route every cookie-import write through CDP identities (STA-4300) * test(browser): cover partition fidelity on both import write paths (STA-4300) * fix(browser): never stage unreadable cookie partitions (STA-4300) * fix(browser): gate partition skips on client support (STA-4300) * test(browser): anchor the client partition-skip capability assertion (STA-4300) * fix(browser): skip Firefox CHIPS cookies whose Chromium identity cannot be rebuilt (STA-4300) * fix(browser): tolerate a Firefox schema without originAttributes (STA-4300) * docs(browser): correct a comment that still named the removed cookies.set write * fix(browser): block lossy Firefox cookie import on old clients * fix(browser): read Firefox CHIPS from schema flag
…es, and never clear what it will not write back (#15030) * reland(browser): restore CDP-identity cookie-import writes (#14729) Reverts the revert 3c8410d (#14942) to restore the reviewed bf6dc6f tree. The defect that caused that revert is NOT fixed by this commit — it is fixed in the commits that follow, so the delta a reviewer must scrutinise stays small instead of hiding inside a 2000-line re-add. Conflict resolutions, all keep-both: - browser-cookie-import.ts: two hunks around the zero-import early return. #14683's undecryptable warning and decryptedCookies.length === 0 condition are kept alongside the reland's old-client gate and partitionSkippedCookies. The old-client gate stays above the early return, and so above any mutation. - en.json: both string sets (#14683's undecryptable copy and partitionSkipped). - crashpad-capture.test.ts: took HEAD wholesale; unrelated to this ticket. getStoragePath, and its positive-write assertion moves from cookies.set to the CDP identity store — adapted, not weakened, and now strictly stronger because it also asserts cookies.set carries no imported user data. Every decryption assertion is untouched. * fix(browser): add registrableFamily, one definition of a cookie family STA-4300, change 1 of the reland fixes. No behaviour change yet — this only adds the helper the later commits derive every skip scope from. Deriving "family" inline in several places is what let the removal scope and the write set disagree in STA-4090 and STA-4170, so there is exactly one. The IP check runs on normalizeCookieDomain's OUTPUT, never the raw string. psl treats an IPv4 literal as a dotted DNS name — psl.parse('127.0.0.1').domain is '0.1' — and Chromium accepts many spellings of one address. new URL() inside normalizeCookieDomain canonicalises 127.1 / 2130706433 / 0x7f.1 / 010.0.0.1 and a trailing dot to a dotted quad first, so isIP() then catches all of them. Mutation-proved: moving the check ahead of normalisation reddens the five alternate-spelling cases and nothing else. Bracketed IPv6 needs its own branch because isIP('[::1]') is 0; without it the value falls through to psl, which throws, which returns the host — the right answer for the wrong reason. Returns null for a bare public suffix: naming `com` as a family would preserve an entire TLD from removal and silently turn an import into a no-op. * fix(browser): plan every cookie's fate before any jar mutation STA-4300, change 2. Adds planImportWrites — pure, no I/O — so the write set and every removal scope can derive from one value instead of being computed twice. Not yet wired into the import paths; that is the next commits. TWO passes, and the second is not optional. Family-atomic skip is a property of the whole input: with a readable mixed.example row BEFORE an unreadable sub.mixed.example row, a per-row guard emits the readable one before anything knows the family will be skipped. Pass 1 classifies and collects the skipped families; pass 2 re-filters the provisional writes. Mutation-proved with a faithful one-pass guard (consult skippedFamilies as you go): the readable-before-unreadable case goes red and the unreadable-before- readable case still passes. That asymmetry is why both orders are tested and why only the first is the named detector. Family closure is at the registrable boundary because that is the boundary the removal scope actually expands to: importedDomainScopes turns an imported mixed.example into descendant roots, so a readable apex cookie drags a skipped subdomain's live session into the removal scope (STA-4300 §2b). hasUnrepresentableSkip surfaces a skip whose family cannot be named. A family we cannot name is one we cannot exclude from the removal plan, and clearing a family we cannot protect is the P0 this ticket exists to stop — so the caller refuses before mutating rather than proceeding and hoping. * fix(browser): derive path A's removal scope from the write plan (STA-4300 §2b) Change 3. importValidatedCookies now plans before it opens the jar, and the replacement scope and the write set are the SAME array. bf6dc6f filtered replacementDomains per exact cookie (partition.status !== 'unreadable'). That is not sufficient: replaceCookiesForImportedDomains expands each imported domain into its descendant roots, so a readable cookie on mixed.example pulls sub.mixed.example into the removal scope — and a skipped cookie living there has its session removed with nothing written back. Same erasure as the P0, different path. plan.writes is family-closed, and because path A passes the very same array to replaceCookiesForImportedDomains and to writeImportedCookies, the two sets cannot drift apart. That is stronger than keeping them in sync: there is only one set. Also here, both before any mutation: - an unrepresentable skip (registrableFamily → null) refuses the import, because a family we cannot name is one we cannot exclude from the removal scope; - the old-client gate now keys off plan.skips rather than re-deriving the condition. Counters: partitionSkippedCookies is a BREAKDOWN of skippedCookies — the unreadable rows plus their family-suppressed siblings — added in exactly once, so totalCookies === importedCookies + skippedCookies keeps holding. Counting it separately is how a summary silently stops adding up. Full src/main/browser suite: 69 files, 729 tests, green. * fix(browser): split path B into scan and emit, and never stage a skip (STA-4300) Change 4 — this is the commit that fixes the shipped P0. bf6dc6f did: decryptedCookies.push({ ..., partition }) // write set built HERE if (partition.status === 'unreadable') { ... continue } // guard AFTER so an unreadable row discovered late could not retract a sibling already emitted, while removeTransplantableCookies cleared the ENTIRE jar. The mutation set was the whole jar and the write set a strict subset of it, which is how a mixed readable/unreadable source emptied a populated jar and repopulated only part of it. Now the row loop SCANS only. Nothing is emitted inside it — not decryptedCookies, not domainSet, not a staging row, not the imported count. Between scan and emit, planImportWrites closes the skip over whole registrable families, and emit walks the plan. Each scanned candidate carries its raw source row because buildChromiumCookieInsertParams needs it; a record holding only the derived fields compiles and then silently cannot stage. Also between scan and emit, both before any mutation: - an unrepresentable skip refuses the import; - any skipped family calls disableStaging. A staged image is a whole-database replacement on the next start, so it cannot express "preserve this family"; main's existing memoryFailed arm then reports restart-fallback-unavailable. Test contract change, deliberately stronger: "never stages a partitioned row whose ancestor bit is unreadable" asserted that an image WAS registered and merely omitted the row. That image would still have erased the preserved family on replay. It now asserts no image is registered at all — plus a new paired case proving a no-skip import still stages, so "disable on skip" cannot be implemented as "disable always" unnoticed. Honest note on detection: reverting the emit filter currently reddens only the staging assertion, because every end-to-end fixture in this module still starts with an EMPTY jar — where clear-then-write-all and clear-then-write-some are indistinguishable. That is the blind spot that let this ship. The populated-jar suite in the next commit is what actually detects the erasure. Full src/main/browser: 69 files, 730 tests, green. * fix(browser): never remove a family the import declined to write (STA-4300 I2) Change 5, and the one that makes preservation observable. removeTransplantableCookies takes preserveFamilies. removableCookieEntries filters those families out, which keeps them out of the removal plan AND — since the CDP snapshot is taken from that same list — out of the restore set, so a preserved coordinate is never submitted to any mutation at all. When anything is preserved, the bulk clearData path is not used. clearData removes everything outside excludeOrigins, and its own comment concedes a rejection may already have emptied part of the jar; a preserved family is deliberately absent from the snapshot, so a partial delete followed by a rejection would destroy it with no identity able to restore it. Handing a dynamically derived preserve list to that primitive cannot be made safe, so a skip-bearing clear runs the frozen per-coordinate plan — which already excludes those families — as its primary path instead. Nothing is preserved on an ordinary import, so that path keeps today's single clearData call unchanged. New populated-jar suite. Every end-to-end fixture in this module starts with cookies.get returning [], and against an empty jar "clear then write all" and "clear then write some" are indistinguishable — which is why four independent gates missed the P0. These fixtures start populated. Mutation-proved, and this is the first detector in the change set that catches the actual erasure rather than a proxy: - drop the preserved-family filter → 6 of 8 red - use bulk clearData while preserving → 6 of 8 red, including "leaves a preserved family untouched", which is the erasure itself IPv4-literal and single-label host families are covered explicitly: psl reads 127.0.0.1 as the dotted DNS name '0.1', so a wrong family here would fail to match the preserve set and erase the live loopback session. Full src/main/browser: 70 files, 738 tests, green. * test(browser): pin STA-4300 end to end in real Electron, both write paths Ports the pre-implementation reproduction into the PR. Verified RED against main's product code and GREEN with the fix, on both paths — I re-ran it both ways rather than assuming. Two assertions are INVERTED rather than deleted, and both are now stronger. The repro proved the defect by showing cookies.set was called WITHOUT a partitionKey; after the reland the import write path does not touch cookies.set for user data at all, so seeing the imported cookie there is itself the regression. The fixture's internal guard is inverted the same way. Non-vacuity, asserted in-run rather than in a report: ok:true with a nonzero importedCookies, the importer reaching its terminal step, the source really carrying its partition fields, and a CONTROL cookie written via CDP *with* a partitionKey and read back with it — so "partitionKey absent" cannot be confused with "the oracle cannot see partitions". electronVersion proves Electron ran. Fixture correction worth recording, because the original reproduction was invalid on this path and I did not catch it on first read: readJsonCookiePartition reads a NESTED partitionKey object, but the fixture wrote topLevelSite and hasCrossSiteAncestor at the entry's top level, where the importer never looks. The file/paste case therefore failed on main for a fixture-shape reason rather than for the defect — and its own non-vacuity check validated what the fixture wrote instead of what the parser reads, which is exactly how a check that looks rigorous proves nothing. Only the native half was ever a real reproduction. Partition keys use a schemeful SITE, not an origin: Chromium canonicalises https://app.example.com to https://example.com, measured via CDP. * fix(browser): fail closed on lossy cookie identity recovery * fix(browser): preserve unreadable families before decrypt * fix(browser): reject malformed cookie partition sites * fix(browser): validate recovered cookie partition sites * fix(browser): reject empty JSON partition identities * fix(browser): fail closed and serialize cookie imports * fix(browser): reject malformed CDP opaque flags * fix(browser): roll back outcome-unknown cookie writes * revert(browser): move import serialization out to STA-4601 Reverts only the concurrency-serialization half of f7c27b7 so #15030 stays scoped to the STA-4300 reland. That commit mixed two concerns; this removes one of them and keeps the other. REMOVED (moves to STA-4601, a separate pre-existing P1): - acquireCookieMutationLock / withCookieMutationLock and the mutationLocks map; clear.ts goes back to withCookieClearLock - the import-wide lock in path A (mutationOwner on the target, acquire/release around replace + writes + rollback) - the widened lock around path B's clear + memory writes - browser-cookie-import-concurrency.test.ts KEPT (genuinely STA-4300 scope, not concurrency): - partitionKeyOpaque handling in readJsonCookiePartition and the CDP snapshot. An opaque partition key cannot be represented faithfully, so it reads as unreadable and its family is preserved — exactly the rule this ticket adds. 194e57a's refinement of that shape stays too. The concurrent-import interleaving is real and reachable (nothing serialises imports per partition, and the clear lock is released before the memory writes), but it predates this change and is not caused or worsened by it. It gets its own PR and its own review rather than riding a P0 reland whose history is that every additional fix introduced a new defect. src/main/browser: 71 files, 772 tests, green. Electron oracle still passes on both write paths and still goes red against main's product code.
…es, and never clear what it will not write back (stablyai#15030) * reland(browser): restore CDP-identity cookie-import writes (stablyai#14729) Reverts the revert 3c8410d (stablyai#14942) to restore the reviewed bf6dc6f tree. The defect that caused that revert is NOT fixed by this commit — it is fixed in the commits that follow, so the delta a reviewer must scrutinise stays small instead of hiding inside a 2000-line re-add. Conflict resolutions, all keep-both: - browser-cookie-import.ts: two hunks around the zero-import early return. stablyai#14683's undecryptable warning and decryptedCookies.length === 0 condition are kept alongside the reland's old-client gate and partitionSkippedCookies. The old-client gate stays above the early return, and so above any mutation. - en.json: both string sets (stablyai#14683's undecryptable copy and partitionSkipped). - crashpad-capture.test.ts: took HEAD wholesale; unrelated to this ticket. getStoragePath, and its positive-write assertion moves from cookies.set to the CDP identity store — adapted, not weakened, and now strictly stronger because it also asserts cookies.set carries no imported user data. Every decryption assertion is untouched. * fix(browser): add registrableFamily, one definition of a cookie family STA-4300, change 1 of the reland fixes. No behaviour change yet — this only adds the helper the later commits derive every skip scope from. Deriving "family" inline in several places is what let the removal scope and the write set disagree in STA-4090 and STA-4170, so there is exactly one. The IP check runs on normalizeCookieDomain's OUTPUT, never the raw string. psl treats an IPv4 literal as a dotted DNS name — psl.parse('127.0.0.1').domain is '0.1' — and Chromium accepts many spellings of one address. new URL() inside normalizeCookieDomain canonicalises 127.1 / 2130706433 / 0x7f.1 / 010.0.0.1 and a trailing dot to a dotted quad first, so isIP() then catches all of them. Mutation-proved: moving the check ahead of normalisation reddens the five alternate-spelling cases and nothing else. Bracketed IPv6 needs its own branch because isIP('[::1]') is 0; without it the value falls through to psl, which throws, which returns the host — the right answer for the wrong reason. Returns null for a bare public suffix: naming `com` as a family would preserve an entire TLD from removal and silently turn an import into a no-op. * fix(browser): plan every cookie's fate before any jar mutation STA-4300, change 2. Adds planImportWrites — pure, no I/O — so the write set and every removal scope can derive from one value instead of being computed twice. Not yet wired into the import paths; that is the next commits. TWO passes, and the second is not optional. Family-atomic skip is a property of the whole input: with a readable mixed.example row BEFORE an unreadable sub.mixed.example row, a per-row guard emits the readable one before anything knows the family will be skipped. Pass 1 classifies and collects the skipped families; pass 2 re-filters the provisional writes. Mutation-proved with a faithful one-pass guard (consult skippedFamilies as you go): the readable-before-unreadable case goes red and the unreadable-before- readable case still passes. That asymmetry is why both orders are tested and why only the first is the named detector. Family closure is at the registrable boundary because that is the boundary the removal scope actually expands to: importedDomainScopes turns an imported mixed.example into descendant roots, so a readable apex cookie drags a skipped subdomain's live session into the removal scope (STA-4300 §2b). hasUnrepresentableSkip surfaces a skip whose family cannot be named. A family we cannot name is one we cannot exclude from the removal plan, and clearing a family we cannot protect is the P0 this ticket exists to stop — so the caller refuses before mutating rather than proceeding and hoping. * fix(browser): derive path A's removal scope from the write plan (STA-4300 §2b) Change 3. importValidatedCookies now plans before it opens the jar, and the replacement scope and the write set are the SAME array. bf6dc6f filtered replacementDomains per exact cookie (partition.status !== 'unreadable'). That is not sufficient: replaceCookiesForImportedDomains expands each imported domain into its descendant roots, so a readable cookie on mixed.example pulls sub.mixed.example into the removal scope — and a skipped cookie living there has its session removed with nothing written back. Same erasure as the P0, different path. plan.writes is family-closed, and because path A passes the very same array to replaceCookiesForImportedDomains and to writeImportedCookies, the two sets cannot drift apart. That is stronger than keeping them in sync: there is only one set. Also here, both before any mutation: - an unrepresentable skip (registrableFamily → null) refuses the import, because a family we cannot name is one we cannot exclude from the removal scope; - the old-client gate now keys off plan.skips rather than re-deriving the condition. Counters: partitionSkippedCookies is a BREAKDOWN of skippedCookies — the unreadable rows plus their family-suppressed siblings — added in exactly once, so totalCookies === importedCookies + skippedCookies keeps holding. Counting it separately is how a summary silently stops adding up. Full src/main/browser suite: 69 files, 729 tests, green. * fix(browser): split path B into scan and emit, and never stage a skip (STA-4300) Change 4 — this is the commit that fixes the shipped P0. bf6dc6f did: decryptedCookies.push({ ..., partition }) // write set built HERE if (partition.status === 'unreadable') { ... continue } // guard AFTER so an unreadable row discovered late could not retract a sibling already emitted, while removeTransplantableCookies cleared the ENTIRE jar. The mutation set was the whole jar and the write set a strict subset of it, which is how a mixed readable/unreadable source emptied a populated jar and repopulated only part of it. Now the row loop SCANS only. Nothing is emitted inside it — not decryptedCookies, not domainSet, not a staging row, not the imported count. Between scan and emit, planImportWrites closes the skip over whole registrable families, and emit walks the plan. Each scanned candidate carries its raw source row because buildChromiumCookieInsertParams needs it; a record holding only the derived fields compiles and then silently cannot stage. Also between scan and emit, both before any mutation: - an unrepresentable skip refuses the import; - any skipped family calls disableStaging. A staged image is a whole-database replacement on the next start, so it cannot express "preserve this family"; main's existing memoryFailed arm then reports restart-fallback-unavailable. Test contract change, deliberately stronger: "never stages a partitioned row whose ancestor bit is unreadable" asserted that an image WAS registered and merely omitted the row. That image would still have erased the preserved family on replay. It now asserts no image is registered at all — plus a new paired case proving a no-skip import still stages, so "disable on skip" cannot be implemented as "disable always" unnoticed. Honest note on detection: reverting the emit filter currently reddens only the staging assertion, because every end-to-end fixture in this module still starts with an EMPTY jar — where clear-then-write-all and clear-then-write-some are indistinguishable. That is the blind spot that let this ship. The populated-jar suite in the next commit is what actually detects the erasure. Full src/main/browser: 69 files, 730 tests, green. * fix(browser): never remove a family the import declined to write (STA-4300 I2) Change 5, and the one that makes preservation observable. removeTransplantableCookies takes preserveFamilies. removableCookieEntries filters those families out, which keeps them out of the removal plan AND — since the CDP snapshot is taken from that same list — out of the restore set, so a preserved coordinate is never submitted to any mutation at all. When anything is preserved, the bulk clearData path is not used. clearData removes everything outside excludeOrigins, and its own comment concedes a rejection may already have emptied part of the jar; a preserved family is deliberately absent from the snapshot, so a partial delete followed by a rejection would destroy it with no identity able to restore it. Handing a dynamically derived preserve list to that primitive cannot be made safe, so a skip-bearing clear runs the frozen per-coordinate plan — which already excludes those families — as its primary path instead. Nothing is preserved on an ordinary import, so that path keeps today's single clearData call unchanged. New populated-jar suite. Every end-to-end fixture in this module starts with cookies.get returning [], and against an empty jar "clear then write all" and "clear then write some" are indistinguishable — which is why four independent gates missed the P0. These fixtures start populated. Mutation-proved, and this is the first detector in the change set that catches the actual erasure rather than a proxy: - drop the preserved-family filter → 6 of 8 red - use bulk clearData while preserving → 6 of 8 red, including "leaves a preserved family untouched", which is the erasure itself IPv4-literal and single-label host families are covered explicitly: psl reads 127.0.0.1 as the dotted DNS name '0.1', so a wrong family here would fail to match the preserve set and erase the live loopback session. Full src/main/browser: 70 files, 738 tests, green. * test(browser): pin STA-4300 end to end in real Electron, both write paths Ports the pre-implementation reproduction into the PR. Verified RED against main's product code and GREEN with the fix, on both paths — I re-ran it both ways rather than assuming. Two assertions are INVERTED rather than deleted, and both are now stronger. The repro proved the defect by showing cookies.set was called WITHOUT a partitionKey; after the reland the import write path does not touch cookies.set for user data at all, so seeing the imported cookie there is itself the regression. The fixture's internal guard is inverted the same way. Non-vacuity, asserted in-run rather than in a report: ok:true with a nonzero importedCookies, the importer reaching its terminal step, the source really carrying its partition fields, and a CONTROL cookie written via CDP *with* a partitionKey and read back with it — so "partitionKey absent" cannot be confused with "the oracle cannot see partitions". electronVersion proves Electron ran. Fixture correction worth recording, because the original reproduction was invalid on this path and I did not catch it on first read: readJsonCookiePartition reads a NESTED partitionKey object, but the fixture wrote topLevelSite and hasCrossSiteAncestor at the entry's top level, where the importer never looks. The file/paste case therefore failed on main for a fixture-shape reason rather than for the defect — and its own non-vacuity check validated what the fixture wrote instead of what the parser reads, which is exactly how a check that looks rigorous proves nothing. Only the native half was ever a real reproduction. Partition keys use a schemeful SITE, not an origin: Chromium canonicalises https://app.example.com to https://example.com, measured via CDP. * fix(browser): fail closed on lossy cookie identity recovery * fix(browser): preserve unreadable families before decrypt * fix(browser): reject malformed cookie partition sites * fix(browser): validate recovered cookie partition sites * fix(browser): reject empty JSON partition identities * fix(browser): fail closed and serialize cookie imports * fix(browser): reject malformed CDP opaque flags * fix(browser): roll back outcome-unknown cookie writes * revert(browser): move import serialization out to STA-4601 Reverts only the concurrency-serialization half of f7c27b7 so stablyai#15030 stays scoped to the STA-4300 reland. That commit mixed two concerns; this removes one of them and keeps the other. REMOVED (moves to STA-4601, a separate pre-existing P1): - acquireCookieMutationLock / withCookieMutationLock and the mutationLocks map; clear.ts goes back to withCookieClearLock - the import-wide lock in path A (mutationOwner on the target, acquire/release around replace + writes + rollback) - the widened lock around path B's clear + memory writes - browser-cookie-import-concurrency.test.ts KEPT (genuinely STA-4300 scope, not concurrency): - partitionKeyOpaque handling in readJsonCookiePartition and the CDP snapshot. An opaque partition key cannot be represented faithfully, so it reads as unreadable and its family is preserved — exactly the rule this ticket adds. 194e57a's refinement of that shape stays too. The concurrent-import interleaving is real and reachable (nothing serialises imports per partition, and the clear lock is released before the memory writes), but it predates this change and is not caused or worsened by it. It gets its own PR and its own review rather than riding a P0 reland whose history is that every additional fix introduced a new defect. src/main/browser: 71 files, 772 tests, green. Electron oracle still passes on both write paths and still goes red against main's product code.
…(STA-4300) (stablyai#14729) * test(browser): repro STA-4300 CHIPS partition downgrade on native cookie import success path * fix(browser): route every cookie-import write through CDP identities (STA-4300) * test(browser): cover partition fidelity on both import write paths (STA-4300) * fix(browser): never stage unreadable cookie partitions (STA-4300) * fix(browser): gate partition skips on client support (STA-4300) * test(browser): anchor the client partition-skip capability assertion (STA-4300) * fix(browser): skip Firefox CHIPS cookies whose Chromium identity cannot be rebuilt (STA-4300) * fix(browser): tolerate a Firefox schema without originAttributes (STA-4300) * docs(browser): correct a comment that still named the removed cookies.set write * fix(browser): block lossy Firefox cookie import on old clients * fix(browser): read Firefox CHIPS from schema flag
…es, and never clear what it will not write back (stablyai#15030) * reland(browser): restore CDP-identity cookie-import writes (stablyai#14729) Reverts the revert 23fe91e (stablyai#14942) to restore the reviewed 210f961 tree. The defect that caused that revert is NOT fixed by this commit — it is fixed in the commits that follow, so the delta a reviewer must scrutinise stays small instead of hiding inside a 2000-line re-add. Conflict resolutions, all keep-both: - browser-cookie-import.ts: two hunks around the zero-import early return. stablyai#14683's undecryptable warning and decryptedCookies.length === 0 condition are kept alongside the reland's old-client gate and partitionSkippedCookies. The old-client gate stays above the early return, and so above any mutation. - en.json: both string sets (stablyai#14683's undecryptable copy and partitionSkipped). - crashpad-capture.test.ts: took HEAD wholesale; unrelated to this ticket. getStoragePath, and its positive-write assertion moves from cookies.set to the CDP identity store — adapted, not weakened, and now strictly stronger because it also asserts cookies.set carries no imported user data. Every decryption assertion is untouched. * fix(browser): add registrableFamily, one definition of a cookie family STA-4300, change 1 of the reland fixes. No behaviour change yet — this only adds the helper the later commits derive every skip scope from. Deriving "family" inline in several places is what let the removal scope and the write set disagree in STA-4090 and STA-4170, so there is exactly one. The IP check runs on normalizeCookieDomain's OUTPUT, never the raw string. psl treats an IPv4 literal as a dotted DNS name — psl.parse('127.0.0.1').domain is '0.1' — and Chromium accepts many spellings of one address. new URL() inside normalizeCookieDomain canonicalises 127.1 / 2130706433 / 0x7f.1 / 010.0.0.1 and a trailing dot to a dotted quad first, so isIP() then catches all of them. Mutation-proved: moving the check ahead of normalisation reddens the five alternate-spelling cases and nothing else. Bracketed IPv6 needs its own branch because isIP('[::1]') is 0; without it the value falls through to psl, which throws, which returns the host — the right answer for the wrong reason. Returns null for a bare public suffix: naming `com` as a family would preserve an entire TLD from removal and silently turn an import into a no-op. * fix(browser): plan every cookie's fate before any jar mutation STA-4300, change 2. Adds planImportWrites — pure, no I/O — so the write set and every removal scope can derive from one value instead of being computed twice. Not yet wired into the import paths; that is the next commits. TWO passes, and the second is not optional. Family-atomic skip is a property of the whole input: with a readable mixed.example row BEFORE an unreadable sub.mixed.example row, a per-row guard emits the readable one before anything knows the family will be skipped. Pass 1 classifies and collects the skipped families; pass 2 re-filters the provisional writes. Mutation-proved with a faithful one-pass guard (consult skippedFamilies as you go): the readable-before-unreadable case goes red and the unreadable-before- readable case still passes. That asymmetry is why both orders are tested and why only the first is the named detector. Family closure is at the registrable boundary because that is the boundary the removal scope actually expands to: importedDomainScopes turns an imported mixed.example into descendant roots, so a readable apex cookie drags a skipped subdomain's live session into the removal scope (STA-4300 §2b). hasUnrepresentableSkip surfaces a skip whose family cannot be named. A family we cannot name is one we cannot exclude from the removal plan, and clearing a family we cannot protect is the P0 this ticket exists to stop — so the caller refuses before mutating rather than proceeding and hoping. * fix(browser): derive path A's removal scope from the write plan (STA-4300 §2b) Change 3. importValidatedCookies now plans before it opens the jar, and the replacement scope and the write set are the SAME array. 210f961 filtered replacementDomains per exact cookie (partition.status !== 'unreadable'). That is not sufficient: replaceCookiesForImportedDomains expands each imported domain into its descendant roots, so a readable cookie on mixed.example pulls sub.mixed.example into the removal scope — and a skipped cookie living there has its session removed with nothing written back. Same erasure as the P0, different path. plan.writes is family-closed, and because path A passes the very same array to replaceCookiesForImportedDomains and to writeImportedCookies, the two sets cannot drift apart. That is stronger than keeping them in sync: there is only one set. Also here, both before any mutation: - an unrepresentable skip (registrableFamily → null) refuses the import, because a family we cannot name is one we cannot exclude from the removal scope; - the old-client gate now keys off plan.skips rather than re-deriving the condition. Counters: partitionSkippedCookies is a BREAKDOWN of skippedCookies — the unreadable rows plus their family-suppressed siblings — added in exactly once, so totalCookies === importedCookies + skippedCookies keeps holding. Counting it separately is how a summary silently stops adding up. Full src/main/browser suite: 69 files, 729 tests, green. * fix(browser): split path B into scan and emit, and never stage a skip (STA-4300) Change 4 — this is the commit that fixes the shipped P0. 210f961 did: decryptedCookies.push({ ..., partition }) // write set built HERE if (partition.status === 'unreadable') { ... continue } // guard AFTER so an unreadable row discovered late could not retract a sibling already emitted, while removeTransplantableCookies cleared the ENTIRE jar. The mutation set was the whole jar and the write set a strict subset of it, which is how a mixed readable/unreadable source emptied a populated jar and repopulated only part of it. Now the row loop SCANS only. Nothing is emitted inside it — not decryptedCookies, not domainSet, not a staging row, not the imported count. Between scan and emit, planImportWrites closes the skip over whole registrable families, and emit walks the plan. Each scanned candidate carries its raw source row because buildChromiumCookieInsertParams needs it; a record holding only the derived fields compiles and then silently cannot stage. Also between scan and emit, both before any mutation: - an unrepresentable skip refuses the import; - any skipped family calls disableStaging. A staged image is a whole-database replacement on the next start, so it cannot express "preserve this family"; main's existing memoryFailed arm then reports restart-fallback-unavailable. Test contract change, deliberately stronger: "never stages a partitioned row whose ancestor bit is unreadable" asserted that an image WAS registered and merely omitted the row. That image would still have erased the preserved family on replay. It now asserts no image is registered at all — plus a new paired case proving a no-skip import still stages, so "disable on skip" cannot be implemented as "disable always" unnoticed. Honest note on detection: reverting the emit filter currently reddens only the staging assertion, because every end-to-end fixture in this module still starts with an EMPTY jar — where clear-then-write-all and clear-then-write-some are indistinguishable. That is the blind spot that let this ship. The populated-jar suite in the next commit is what actually detects the erasure. Full src/main/browser: 69 files, 730 tests, green. * fix(browser): never remove a family the import declined to write (STA-4300 I2) Change 5, and the one that makes preservation observable. removeTransplantableCookies takes preserveFamilies. removableCookieEntries filters those families out, which keeps them out of the removal plan AND — since the CDP snapshot is taken from that same list — out of the restore set, so a preserved coordinate is never submitted to any mutation at all. When anything is preserved, the bulk clearData path is not used. clearData removes everything outside excludeOrigins, and its own comment concedes a rejection may already have emptied part of the jar; a preserved family is deliberately absent from the snapshot, so a partial delete followed by a rejection would destroy it with no identity able to restore it. Handing a dynamically derived preserve list to that primitive cannot be made safe, so a skip-bearing clear runs the frozen per-coordinate plan — which already excludes those families — as its primary path instead. Nothing is preserved on an ordinary import, so that path keeps today's single clearData call unchanged. New populated-jar suite. Every end-to-end fixture in this module starts with cookies.get returning [], and against an empty jar "clear then write all" and "clear then write some" are indistinguishable — which is why four independent gates missed the P0. These fixtures start populated. Mutation-proved, and this is the first detector in the change set that catches the actual erasure rather than a proxy: - drop the preserved-family filter → 6 of 8 red - use bulk clearData while preserving → 6 of 8 red, including "leaves a preserved family untouched", which is the erasure itself IPv4-literal and single-label host families are covered explicitly: psl reads 127.0.0.1 as the dotted DNS name '0.1', so a wrong family here would fail to match the preserve set and erase the live loopback session. Full src/main/browser: 70 files, 738 tests, green. * test(browser): pin STA-4300 end to end in real Electron, both write paths Ports the pre-implementation reproduction into the PR. Verified RED against main's product code and GREEN with the fix, on both paths — I re-ran it both ways rather than assuming. Two assertions are INVERTED rather than deleted, and both are now stronger. The repro proved the defect by showing cookies.set was called WITHOUT a partitionKey; after the reland the import write path does not touch cookies.set for user data at all, so seeing the imported cookie there is itself the regression. The fixture's internal guard is inverted the same way. Non-vacuity, asserted in-run rather than in a report: ok:true with a nonzero importedCookies, the importer reaching its terminal step, the source really carrying its partition fields, and a CONTROL cookie written via CDP *with* a partitionKey and read back with it — so "partitionKey absent" cannot be confused with "the oracle cannot see partitions". electronVersion proves Electron ran. Fixture correction worth recording, because the original reproduction was invalid on this path and I did not catch it on first read: readJsonCookiePartition reads a NESTED partitionKey object, but the fixture wrote topLevelSite and hasCrossSiteAncestor at the entry's top level, where the importer never looks. The file/paste case therefore failed on main for a fixture-shape reason rather than for the defect — and its own non-vacuity check validated what the fixture wrote instead of what the parser reads, which is exactly how a check that looks rigorous proves nothing. Only the native half was ever a real reproduction. Partition keys use a schemeful SITE, not an origin: Chromium canonicalises https://app.example.com to https://example.com, measured via CDP. * fix(browser): fail closed on lossy cookie identity recovery * fix(browser): preserve unreadable families before decrypt * fix(browser): reject malformed cookie partition sites * fix(browser): validate recovered cookie partition sites * fix(browser): reject empty JSON partition identities * fix(browser): fail closed and serialize cookie imports * fix(browser): reject malformed CDP opaque flags * fix(browser): roll back outcome-unknown cookie writes * revert(browser): move import serialization out to STA-4601 Reverts only the concurrency-serialization half of f7c27b7 so stablyai#15030 stays scoped to the STA-4300 reland. That commit mixed two concerns; this removes one of them and keeps the other. REMOVED (moves to STA-4601, a separate pre-existing P1): - acquireCookieMutationLock / withCookieMutationLock and the mutationLocks map; clear.ts goes back to withCookieClearLock - the import-wide lock in path A (mutationOwner on the target, acquire/release around replace + writes + rollback) - the widened lock around path B's clear + memory writes - browser-cookie-import-concurrency.test.ts KEPT (genuinely STA-4300 scope, not concurrency): - partitionKeyOpaque handling in readJsonCookiePartition and the CDP snapshot. An opaque partition key cannot be represented faithfully, so it reads as unreadable and its family is preserved — exactly the rule this ticket adds. 194e57a's refinement of that shape stays too. The concurrent-import interleaving is real and reachable (nothing serialises imports per partition, and the clear lock is released before the memory writes), but it predates this change and is not caused or worsened by it. It gets its own PR and its own review rather than riding a P0 reland whose history is that every additional fix introduced a new defect. src/main/browser: 71 files, 772 tests, green. Electron oracle still passes on both write paths and still goes red against main's product code.









ELI5
Some sites store a cookie that only works inside one specific parent site — a "partitioned" (CHIPS) cookie. When Orca imported cookies from Chrome, it wrote them through an Electron API that cannot express that "only inside this parent site" part, so the attribute was quietly dropped. The import said "success", the cookie was there, and the site still could not see it.
This routes every cookie-import write through CDP, which can express it. If we cannot read a cookie's partition faithfully from the source, we now skip that cookie and tell you — we never write a downgraded copy.
What Changed
Both remaining user-data writes moved from
session.cookies.set()to CDPNetwork.setCookie, through the identity machinery PR #14383 already built for the rollback path:browser-cookie-import.ts—importValidatedCookies(file / paste / Safari / Firefox) and the native Chromium import's in-memory load.importValidatedCookiesno longer receives aSessionat all. It takes aCookieImportWriteStore, which has noseton it, so the lossy write is not merely unused — it cannot be named. Same guard fix(browser): restore replaced cookies through CDP identities #14383 applied to the clear path.browser-cookie-source-partition.tsreads partition identity from the source: Chromium'stop_frame_site_key+has_cross_site_ancestorfor the native path, and apartitionKeyobject for JSON exports.browser-cookie-import-write.tsowns the write phase: plan → identity → write, with the skip decision in one place.targetPartitionhardening: the native path's partition directory now comes fromtargetSession.getStoragePath()instead ofjoin(userData, 'Partitions', partitionString).partitionSkippedCookieson the import summary, plus a warning toast.The one attach change:
attachCookieClearSessionfalls back to its own hidden window if it cannot lease the debugger of an existing tab.Why
Four P0s in this module came from one API boundary that cannot express cookie identity — STA-4013 → STA-4061 → STA-4090 → STA-4170. Each fix was correct and each spawned the next, because the lossy write stayed available. #14383 removed it from the clear path; this removes it from the import path, which is the last one that touches user data.
Named user-visible harm for each behavior change (nothing here changes without one):
partitionKeyfrom JSON exportspartitionKey. The reader discarded it at parse time, so pasted exports lost CHIPS cookies the same silent way.getStoragePath()targetPartitionarrives from IPC and was pasted into a filesystem path unsanitized, sopersist:../..resolved aCookiesDB outsidePartitions/and staged a replacement over it. It also drifts if Chromium changes how a partition name maps to a directory.No
max-linesdisable was added.browser-cookie-import.test.tscrossed the cap, so the new cases were split intobrowser-cookie-import-partition-fidelity.test.tsinstead of suppressing it.Failure-mode table
Both write paths × cookie kind × outcome. Every cell either preserves the cookie or reports it. No cell silently downgrades or silently loses a cookie.
Path A — validated import (
importValidatedCookies: file, paste, Safari, Firefox)Sources feed this path with a partition read each: JSON
partitionKey, Firefoxmoz_cookies.isPartitionedAttributeSet, and Safari (no partition field exists in its format).Network.setCookie. Nothing to lose.ok:false.ok:false. Jar untouched.__Host-hostOnlyat path/, which is what Chromium requires. Verified on real Electron.partitionKeycarried toNetwork.setCookieand stored. Verified on real Electron.partitionSkippedCookies, logged by domain only, surfaced as a warning toast.CookieImportModeisreplace-imported-domainsat every call site, so a rejection always has the CDP restore behind it. Mutation set = restore set by construction: the removal plan and its identities are fixed together inreplaceCookiesForImportedDomains(STA-4170's invariant), and this change does not re-read the jar anywhere.Path B — native Chromium import (
importCookiesFromBrowser)Network.setCookie.memoryFailed; the staged DB is registered so the cookie lands on the next cold start. If staging is unavailable,restart-fallback-unavailablewarning. (Pre-existing behavior, unchanged.)ok:falseand the staging file is discarded. On an empty jar the clear does not attach, so the first write throws instead — every cookie is then counted failed and the staged replay covers them.__Host-hostOnlyat path/.partitionKeyread fromtop_frame_site_key+has_cross_site_ancestorand stored. Verified on real Electron.domainSet, and fromimported. Counted inpartitionSkippedCookies.Two cells deserve calling out as deliberate rather than incidental:
partitionKeyon a JSON cookie is read as unpartitioned, not as unreadable. Every mainstream exporter omits the field for ordinary cookies; treating absence as unreadable would reject whole exports. Absence is a faithful read.top_frame_site_keycolumn at all is read as unpartitioned. That schema predates cookie partitioning, so it genuinely has no partitioned rows.Three defects the review loop found in this PR, and their fixes
All three were introduced by the skip logic in this change, and all three are recorded here rather than quietly amended, because each is the same shape as the bug this PR is meant to end.
A skipped cookie erased the session it never replaced (validated path).
replaceCookiesForImportedDomainsreceived every importable domain, including domains whose only source cookie was skipped for an unreadable partition. So the import cleared the user's working cookies for that domain and then wrote nothing in their place — a strictly worse outcome than the downgrade this PR removes. Fixed by excluding unreadable-partition cookies from the replace scope. This is the mutation-set-wider-than-the-write-set failure STA-4170 was, in a new place.The staged cold-start replay re-introduced the downgrade (native path). The first draft folded skipped cookies into
memoryFailedso the staging DB would carry them, on the reasoning that staging copies the source's own partition columns verbatim. That reasoning was wrong: when the source schema has nohas_cross_site_ancestorcolumn,buildChromiumCookieInsertParamsfills the target's column with the target's default, which is a guessed ancestor bit — exactly the silent misfile the write path refuses to make, arriving by the back door one restart later. Fixed by excluding unreadable rows from staging entirely, so the cookie is skipped in every channel and reported once.An older remote client would have rendered a skip as a plain success (wire compatibility).
partitionSkippedCookiesis a new field on the import summary, and a client predating it ignores the field — so the host would skip cookies, the old client would show "Imported N cookies", and the loss would be silent again, over the wire this time. Remedied with capability negotiation:browser.profileImportFromBrowsertakes an optionalsupportsPartitionSkippedCookies: true, current clients send it, and a host that would have to skip a cookie for a client that did not declare support fails the import before touching the jar — no clear, no removal, no write — with a reason telling the user to update Orca, rather than publishing a loss the client would render as success. The local Electron IPC path sends no flag and stays permissive, because main and renderer are always the same build.importCookiesFromFilehas no remote RPC, so it carries no wire exposure.Every fix is mutation-proved: reverting any one of them fails its test and only its test. I re-ran each mutation myself rather than taking the reviewer's word for it.
Firefox source-model correction from final review
Firefox records two independent facts:
originAttributes.partitionKeyis dFPI / Total Cookie Protection storage isolation that Firefox imposed on an ordinary cookie. Its components can include port or ancestor context, so component count is not a CHIPS discriminator. Chromium re-derives its own third-party isolation after import; writing this cookie unpartitioned is faithful.moz_cookies.isPartitionedAttributeSetrecords whether the server sentPartitioned. That is the real CHIPS signal. Firefox records no Chromium cross-site-ancestor bit, so this identity cannot be rebuilt and the cookie must be skipped and reported.Final readiness caught that the earlier implementation inferred CHIPS from
originAttributescomponent count. That could skip ordinary dFPI cookies and silently downgrade real Firefox CHIPS cookies. Fixed inadf4e62b32: the importer schema-probes and selectsisPartitionedAttributeSet, ignoresoriginAttributesshape for CHIPS classification, imports flag-zero dFPI rows, and skips flag-one CHIPS rows. The regression contains both row types.f2d8b46a08also carries the old-client reporting capability into this Firefox path, so an older remote client fails before the target jar is read, cleared, or written.Safari stands as originally argued. ITP is browser-imposed and is not recorded in
Cookies.binarycookiesat all, so there is no server-declared partition identity to drop and nothing to guess.The one cell this change does not improve, stated plainly:
importValidatedCookiesstill strips non-printable bytes from cookie values before writing. That is pre-existing, orthogonal to partition identity, and changing it risks turning a currently-imported cookie into a rejected one (STA-4240 territory). Left exactly as it was.Linked Issue
Fixes STA-4300 — https://linear.app/stably/issue/STA-4300/p1-route-all-cookie-import-writes-through-cdp-identities-ends-the
Visual Proof
Before/after captured end to end on real Electron (macOS): #14729 (comment)
Driven through the real UI — Settings → Browser → Session & Cookies → Import Cookies → From File… — with a cookie JSON containing one ordinary cookie plus one CHIPS cookie whose
partitionKeyhastopLevelSitebut nohasCrossSiteAncestor.main) — only the success toast: "Imported 2 cookies from file into Default." The partial-partition cookie is silently downgraded and lands in the jar unpartitioned. No warning of any kind.importedCookies: 1, partitionSkippedCookies: 1.Jar contents were verified on both instances, so the screenshots are backed by the actual cookie store, not just the toast text. The only automation seam was the native file-open dialog; no product code was modified to capture this.
Known cosmetic nit, deliberately left: the string reads "1 cookies" for a singular count. That matches the convention of every pre-existing toast in this module ("Imported {n} of {m} cookies", "None of the {n} cookies"), and fixing only this one string would make it the odd one out while touching four locale catalogs. Worth a separate sweep across the module's strings if wanted.
Testing
Desktop main-process change. Not mobile, not Windows/WSL, not SSH. Tested on macOS.
The defect was reproduced first, on real Electron, by a separate agent before any fix was written (
3983fcd5d5, first commit on this branch). Onmainthe import returnsok:truewithimportedCookies: 2and no warning, while the partitioned cookie comes back throughNetwork.getAllCookieswithpartitionKey: null.Real-Electron regression tests (spawn the electron binary, write through the real import, read the jar back through CDP —
session.cookies.get()stripspartitionKey, so it cannot observe this either way and any test asserting through it would be vacuous):browser-cookie-import-partition-success.electron.test.ts— native path, full import end to end, CHIPS partition intact.browser-cookie-import-validated-partition.electron.test.ts— validated path, full import end to end: CHIPS and__Host-CHIPS both stored partitioned, ordinary cookie unchanged, unreadable partition skipped and counted.Mutation-proved — each mutation was applied, the test run confirmed failing, then reverted:
partitionKeyfrom the built identitypartition-success.electronfails:expected null to deeply equal { … }supportsPartitionSkippedCookiesoriginAttributescomponent count instead ofisPartitionedAttributeSetpartition-success.electronfails, same signaturevalidated-partition.electronfailsVacuous-test trap (this module has been bitten three times): a store mock missing
writeCookieIdentitythrows aTypeErrorthe per-cookiecatchswallows, routing every write down the rejected path while the suite still looks green. Guards against it here:toHaveBeenCalledTimes(n)and the identity argument — not just the end state.browser-cookie-import.test.tsandbrowser-cookie-import-partition-fidelity.test.tsinstallunreachableCookieSet, which throws ifcookies.setis called for any user cookie. Only the__initprobe (no user data) is allowed through. If the lossy write ever returns, those suites fail rather than pass quietly.Also covered: the skip log line contains only the domain, never the cookie name or value.
Commands:
All green.
Review
targetPartitionno longer reaches a filesystem path from a caller-supplied string. Cookie values are never logged; the skip line carries only the domain.getStoragePath(), which is more correct on Windows, not less. The Electron fixtures use the existingxvfb-runwrapper on Linux.browser.profileImportFromBrowsergains one optional request field,supportsPartitionSkippedCookies: true. Additive and back-compatible perdocs/reference/remote-wire-compatibility.md: an old host ignores an unknown key, an old client simply omits it, and no stream opcode was added. What the host publishes also changed — the summary carries a new optional counter — which is precisely why the host refuses to skip a cookie for a client that has not declared it can report one.partitionSkippedCookiesis a new optional field onBrowserCookieImportSummary. Older renderers ignore it.Notes on adjacent tickets
Author