Skip to content

fix(profile): prevent cookie sync from clobbering headless session cookies#607

Merged
shaun0927 merged 1 commit intodevelopfrom
fix/needsync-guard-headless-cookies
Apr 9, 2026
Merged

fix(profile): prevent cookie sync from clobbering headless session cookies#607
shaun0927 merged 1 commit intodevelopfrom
fix/needsync-guard-headless-cookies

Conversation

@shaun0927
Copy link
Copy Markdown
Owner

Summary

Fixes #606 (Root Cause B): when a headless session acquires Google login cookies and writes them to ~/.openchrome/profile/Default/Cookies, the next launch incorrectly overwrites those cookies by syncing from the real Chrome profile.

Root cause: needsSync() returns true when the last sync is older than 30 minutes or the source Cookies file has changed — with no awareness that a headless session may have written newer cookies into the persistent profile in the meantime.

Fix: Before returning true for staleness or source-hash mismatch, check whether the persistent profile's Cookies file has a newer mtime than the lastSyncTimestamp. If so, a headless session wrote cookies after the last sync — skip the overwrite.

Changes

  • src/chrome/profile-manager.ts: Added guard in needsSync() that compares persistent profile Cookies mtime against lastSyncTimestamp. Returns false (skip sync) when persistent cookies are newer, preserving headless-acquired session.
  • tests/chrome/persistent-profile.test.ts: Added test case should return false when persistent profile Cookies were modified after last sync (headless guard) covering the new guard path. All 48 tests pass.

Test plan

  • New test: persistent Cookies written after last sync → needsSync() returns false
  • Existing tests: source changed → true, stale → true, fresh+unchanged → false, no metadata → true, no source Cookies → false
  • npm run build passes with zero errors
  • npx jest tests/chrome/persistent-profile.test.ts — 48/48 passed

🤖 Generated with Claude Code

…ookies

When a headless session acquires Google login cookies and writes them to
the persistent profile, needsSync() was returning true after 30 minutes
(or when the real Chrome Cookies file changed), causing syncProfileData()
to overwrite those cookies with the real Chrome profile's cookies.

Add a guard that checks the persistent profile's Cookies mtime against
the last sync timestamp. If the persistent Cookies were modified after
the last sync, a headless session must have written them — skip the
overwrite to preserve the acquired session (Root Cause B, issue #606).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shaun0927 shaun0927 merged commit 06f1561 into develop Apr 9, 2026
9 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