Skip to content

Release cookie snapshots when import preparation fails - #26218

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-cookie-import-preparation-cleanup
Oct 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-cookie-import-preparation-cleanup

Conversation

@nwparker

@nwparker nwparker commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A failed browser-cookie import left a private copy of the browser’s cookie database on disk. Every retry could leave another copy. Orca now removes the copies owned by an import that stops during preparation.

What Changed

Preparation owns its source snapshot and staging database until it returns a successful import context. A finally block closes both private databases and removes their files on empty-source, unreadable-partition, denied-key, and preparation-error exits. Successful preparation transfers ownership to the existing importer, including a staged database needed for restart replay.

Why

The importer could clean up only after preparation returned a context. Earlier exits lost the source snapshot’s cleanup callback. Keeping cleanup with its current owner fixes that gap without a directory sweeper, new cache, or changes to cookie selection and retry policy.

The actual Chromium importer with a generated 1,000-cookie SQLite database and live WAL left 12,583,080 bytes in three private snapshot directories after three denied-key attempts. The fix leaves zero. The single-cookie control went from 49,208 bytes to zero. Measurements use generated cookie values and a mocked denied credential response; they measure persistent files, not typing latency or CPU.

Linked Issue

No existing issue; maintainer performance audit.

Visual Proof

N/A — private temporary-file cleanup; the import result and browser interaction remain the same.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Six regression tests exercise real SQLite databases and private snapshot copies through the existing importer seams. Four fail on the original source and all six pass with the fix. They cover empty and denied-key imports, an unreadable cookie partition, a thrown schema error, ordinary completion, and retained restart replay. The error case observes both private database handles closed before snapshot removal.

  • Full browser suite: 209 files, 1,907 passing tests; two skipped.
  • pnpm tc:node, focused oxlint, formatting, and changed-code quality gate pass.
  • Combined branch with all 28 audit changes: 3,799 passing tests across 472 files, plus two skipped tests in one skipped file; full pnpm tc passes and the 93-file changed-code quality gate reports no new findings.
  • Seven before/after importer cases preserve results, writes, clear operations, pending replay contents, and the source and target database bytes. An import requiring restart retains the same usable 20,480-byte staged database.
  • Local validation ran on macOS with Node 24 and mocked Electron Session/credential seams, with ORCA_BACKGROUND_LAUNCH=1. No native credential prompt or app window was opened. Hosted macOS/Windows packaging, static analysis/typecheck, relay integration and all five Node24 test shards passed. One Ubuntu ARM shard initially lost communication with GitHub’s server; the failed jobs passed on retry without a source change.

Review

Independent source review confirmed cleanup order and successful-context ownership, including restart replay. Only preparation and its new regression test change. Paths and cleanup retries reuse the existing cross-platform implementation. This host-local browser import adds no SSH execution or wire-protocol behavior.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Successful imports retain their existing cleanup and restart fallback. Failed preparation removes only its own private copies.

Checklist

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

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d7aa6fff-05a2-4c44-b4d5-e9e7d35d5d28
📥 Commits

Reviewing files that changed from the base of the PR and between 0d82899 and 0ec39ae.

📒 Files selected for processing (2)
  • src/main/browser/browser-cookie-chromium-prepare.ts
  • src/main/browser/browser-cookie-import-snapshot-ownership.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Chromium cookie-import preparation now uses shared cleanup for unsuccessful exits. It closes open databases, removes staged database files and sidecars, and cleans up the source snapshot. Successful preparation transfers resource ownership to the returned context. New tests cover refusal and error cleanup, successful imports, and staged-database retention during replay.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 0ec39

The change appears ready to merge after normal checks; no remaining cleanup failure has been established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: releasing cookie snapshots when import preparation fails.
Description check ✅ Passed The description follows the repository template and explains the user impact, implementation, rationale, testing, compatibility considerations, and checklist status. The missing issue link is explicit…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker
nwparker merged commit 7e60664 into main Oct 8, 2026
51 of 53 checks passed
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