Skip to content

feat(browser): auto-keep the embedded browser signed in via agentcookie (optional) - #4748

Open
mvanhorn wants to merge 14 commits into
stablyai:mainfrom
mvanhorn:feat/agentcookie-integration
Open

mvanhorn wants to merge 14 commits into
stablyai:mainfrom
mvanhorn:feat/agentcookie-integration

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

What

When the optional agentcookie CLI is installed, orca's embedded browser stays signed into your sites automatically. orca detects agentcookie on PATH and pulls your current session from agentcookie export through its own importer, on startup and on a 5-minute interval. If agentcookie is not installed, nothing here runs and orca behaves exactly as today.

Why

orca's cookie import is manual and one-shot today (the Settings file picker / import-from-browser). For anyone running agentcookie, this makes sign-in automatic and always fresh - the agent's browser does not silently log out mid-task - with no debug port and nothing to click. It is the "have the companion installed and the editor is better" pattern, fully opt-outable.

How

  • New src/main/browser/agentcookie-session-sync.ts: PATH-detects agentcookie, runs agentcookie export, and imports the result into persist:orca-browser through the existing validated pipeline. Guarded loop (one pull at a time): startup plus interval.
  • On by default (agentcookieSyncEnabled), and completely inert when agentcookie is not installed.
  • Detected / last-sync status is written to settings so a Settings UI row can show "agentcookie connected." The toggle and status fields are in place; the UI surface itself is a small follow-up I am happy to add to your styleguide.

Also: a __Host- import bug fix (separate commit)

While wiring this I found importValidatedCookies always passed a domain to cookies.set(). Chromium rejects a __Host--prefixed cookie that carries a Domain, so those cookies (for example GitHub's __Host- session pair) were silently dropped - by the existing Settings file import too. They are now imported host-only (no domain, path /, Secure).

Tests

  • agentcookie PATH detection, and the sync loop's enabled/detected gating.
  • importCookiesFromJson plus a __Host- host-only-shaping regression.
  • Node typecheck clean; existing cookie import tests pass.

Notes

agentcookie is optional and external. orca depends on nothing new and behaves identically without it. Happy to flip the default (on vs opt-in) or shape the UI however you prefer.

ELI5

If you install the optional agentcookie CLI, Orca’s embedded browser can auto-import your signed-in site sessions on a timer so you stay logged in without manual cookie import.

mvanhorn and others added 2 commits June 6, 2026 07:08
…t dropped

importValidatedCookies always passed `domain` to cookies.set(). Chromium
rejects a __Host--prefixed cookie that carries a Domain attribute, so the most
important session cookies (e.g. GitHub's __Host- pair) silently failed and the
imported session could read as logged out. Omit the domain and force path '/'
+ Secure for __Host- names. Also extracts importCookiesFromJson from
importCookiesFromFile so the same validated pipeline can take an in-memory
array. Fixes both the Settings file import and any programmatic import.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When the optional agentcookie CLI (github.com/mvanhorn/agentcookie) is on PATH,
orca pulls the user's current browser session from `agentcookie export` and
loads it through its own validated importer, on startup and on a 5-minute
interval. This turns orca's manual one-shot cookie import into automatic,
always-fresh sign-in for the embedded browser, with no debug port and no change
to behavior when agentcookie is not installed.

- src/main/browser/agentcookie-session-sync.ts: PATH detection + pull loop
- on by default (agentcookieSyncEnabled), inert when agentcookie is absent
- detected/last-sync status surfaced in settings for a future Settings UI row

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes — integrates an optional external agentcookie CLI to keep the embedded browser signed in automatically, plus a __Host- cookie import fix that also applies to the existing Settings file-import path.

  • Add AgentcookieSessionSync — PATH-detects agentcookie, runs agentcookie export, and imports the result through the existing importValidatedCookies pipeline on startup and a 5-minute interval. Inert when agentcookie is absent or the setting is off.
  • Extract importCookiesFromJson — shared by the Settings file import and the agentcookie pull so both get identical validation and __Host- host-only shaping.
  • Fix __Host- cookie import — previously importValidatedCookies always passed a domain to cookies.set(), causing Chromium to silently reject __Host--prefixed cookies (e.g. GitHub's session pair). Now omits domain, forces path='/', and forces secure=true for those cookies.
  • Wire into app lifecycle — startAgentcookieSessionSync() at app ready, agentcookieSync.stop() at will-quit.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Resolved conflicts, preserving this PR's change on top of upstream's
restructuring.
@greptile-apps

greptile-apps Bot commented Aug 2, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds optional automatic cookie sync from the agentcookie CLI into Orca's embedded browser partition, and fixes a pre-existing bug where __Host--prefixed cookies were silently dropped during import because Chromium rejects them when a Domain attribute is present.

  • New AgentcookieSessionSync class (agentcookie-session-sync.ts): PATH-scans for the agentcookie binary on startup and every 5 minutes, runs agentcookie export, and feeds the result through the existing validated cookie pipeline. Completely inert when the binary is absent.
  • __Host- cookie fix (browser-cookie-import.ts): importValidatedCookies now omits the domain field and forces path='/' and secure=true for __Host--prefixed cookies; importCookiesFromFile is refactored into the new shared importCookiesFromJson so both import paths get identical shaping.
  • Settings fields added for agentcookieSyncEnabled, agentcookieDetected, agentcookieLastSyncAt, and agentcookieLastImported; the sync loop writes status back on each cycle for a planned Settings UI row.

Confidence Score: 3/5

Safe to merge for the __Host- bug fix; the agentcookie sync path needs the lastImported naming resolved before the Settings UI is built on top of it.

The __Host- fix and the refactor of importCookiesFromFile into importCookiesFromJson are clean and well-tested. The sync loop is inert when agentcookie is absent. The main concern is agentcookieLastImported: it stores an imported cookie count but is named and typed identically to a timestamp field, creating a high likelihood of the wrong rendering when the planned Settings UI row is added.

Files Needing Attention: src/main/browser/agentcookie-session-sync.ts and src/shared/types.ts — the lastImported/agentcookieLastImported field semantics need to be settled before the UI layer consumes them.

Important Files Changed

Filename Overview
src/main/browser/agentcookie-session-sync.ts New sync loop: PATH-detects agentcookie, runs agentcookie export, and imports the result. Has a naming bug where lastImported stores a cookie count rather than a timestamp, a missing idempotency guard in start(), and silent stderr discard.
src/main/browser/browser-cookie-import.ts Extracts importCookiesFromJson from importCookiesFromFile and fixes __Host- prefix cookies being silently dropped by omitting the domain field when Chromium requires host-only cookies. Fix is correct and well-tested.
src/main/index.ts Wires AgentcookieSessionSync into the app lifecycle: starts after app.whenReady() and stops on will-quit. Guard against double-init is correct; status is persisted to settings with safe conditional spreading.
src/shared/types.ts Adds four optional agentcookie* fields to GlobalSettings. All are optional for backward compatibility. agentcookieLastImported is ambiguously named — it stores a count, but the `number
src/shared/constants.ts Adds defaults for the four new agentcookie settings fields; defaults are sensible (enabled=true, detected=false, sync timestamps null).
src/main/browser/agentcookie-session-sync.test.ts Tests PATH detection, no-op when absent, and enabled/disabled state. Does not cover the successful sync path with a real (mocked) export, or the lastImported count semantics.
src/main/browser/browser-cookie-import.test.ts Adds tests for importCookiesFromJson including the __Host- host-only regression case; coverage is thorough for the new exported function.

Sequence Diagram

sequenceDiagram
    participant App as Electron App
    participant Sync as AgentcookieSessionSync
    participant FS as PATH / fs.accessSync
    participant AC as agentcookie CLI
    participant CI as importCookiesFromJson
    participant Session as persist:orca-browser
    participant Store as SettingsStore

    App->>Sync: new AgentcookieSessionSync(options)
    App->>Sync: start()
    Sync->>FS: detectAgentcookie()
    FS-->>Sync: "binary path | null"
    Sync->>Store: "onStatus({ detected, lastSyncAt: null, lastImported: null })"

    alt agentcookie installed and enabled
        Sync->>Sync: syncNow() [immediate]
        Sync->>FS: detectAgentcookie()
        FS-->>Sync: binary path
        Sync->>AC: execFile(binary, ['export'])
        AC-->>Sync: JSON cookie array stdout
        Sync->>CI: importCookiesFromJson(stdout, partition)
        CI->>Session: cookies.set() per cookie
        Session-->>CI: ok or skipped
        CI-->>Sync: BrowserCookieImportResult
        Sync->>Store: "onStatus({ detected:true, lastSyncAt: Date.now(), lastImported: count })"

        loop Every 5 minutes
            Sync->>Sync: syncNow() [interval]
            Note over Sync: concurrency guard: skip if already running
        end
    end

    App->>Sync: stop() on will-quit
    Sync->>Sync: clearInterval(timer)
Loading

Reviews (1): Last reviewed commit: "Merge upstream/main into feat/agentcooki..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The change adds optional agentcookie session synchronization. It resolves an approved executable, exports session data, and imports cookie JSON into the browser partition. The synchronizer reports detection and import status, uses a five-minute default interval, and can stop during shutdown. Desktop startup initializes the synchronizer and stores its status in global settings. The change also adds settings defaults and tests for executable detection, synchronization lifecycle, and JSON cookie importing.

Merge Risk: Moderate · previous review 45ed8

Optional sync can replace newer browser cookies and may report misleading status or finish after approval is withdrawn. These issues should be addressed before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title names the main change: an optional feature that keeps the embedded browser signed in through the agentcookie CLI. The changeset adds an agentcookie session sync module, settings fields, star…
Description check Passed The description follows the repository template. It includes What Changed, Why, a Linked Issue section, Testing, Notes, and an ELI5 section. The Linked Issue section reads 'Fixes #' with no issue numb…
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.
Full details: Title check

Explanation

The title names the main change: an optional feature that keeps the embedded browser signed in through the agentcookie CLI. The changeset adds an agentcookie session sync module, settings fields, startup wiring, and a JSON import path that matches this. The title does not cover the timer, PATH detection, or the __Host- fix, which is expected for a short title. The title follows the conventional commit form.

Full details: Description check

Explanation

The description follows the repository template. It includes What Changed, Why, a Linked Issue section, Testing, Notes, and an ELI5 section. The Linked Issue section reads 'Fixes #' with no issue number, and the Visual Proof section is not filled in. The description does not state the AI disclosure, and the Review and Checklist sections are missing or unchecked. The description still covers the mechanism, the reasons, and the test coverage, so the check passes. The description also says the UI surface is a follow-up, so the Visual Proof section should state that this change has no visual change or explain the reason.

Resolution

Consider these fixes before merge: (1) add the linked issue number in the 'Fixes #' line, or confirm the PR has one; (2) state the visual proof status, either attach before and after media or write N/A with the reason that the UI row is a follow-up; (3) complete the AI Disclosure section if an AI tool was used, and check the Testing and Checklist items that apply; (4) note the Review section's Agent skill upstream boundary item.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 12 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6af93a31-6601-4656-bbf9-0a5013623518
Commits

Reviewing files that changed from the base of the PR and between 37262cb and 45ed8e8.

Files selected for processing: 2

  • src/main/browser/agentcookie-session-sync.test.ts
  • src/main/browser/agentcookie-session-sync.ts

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

@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: 2

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)

568-586: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Force secure before deriving the URL for __Host- cookies.

deriveUrl only forces https when secure is already true, but importValidatedCookies overrides secure to true during cookies.set(). A __Host-* entry with secure missing or false gets an http:// URL, then cookies.set() rejects it with the per-cookie catch silently counting it as skipped. Force the secure flag in validateCookieEntry when name.startsWith('__Host-') so the derived URL scheme matches the host-prefixed cookie.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b76905c-8002-42cc-aa91-a6985983428b

📥 Commits

Reviewing files that changed from the base of the PR and between 99b94a3 and 6d38a94.

📒 Files selected for processing (7)
  • src/main/browser/agentcookie-session-sync.test.ts
  • src/main/browser/agentcookie-session-sync.ts
  • src/main/browser/browser-cookie-import.test.ts
  • src/main/browser/browser-cookie-import.ts
  • src/main/index.ts
  • src/shared/constants.ts
  • src/shared/types.ts

@mvanhorn

mvanhorn commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

No rush on the review, just clearing the way. Merged main into the branch (6d38a94). It was a long way behind and conflicted in src/main/index.ts; resolved, and the PR is mergeable again.

The agentcookie integration itself is unchanged.

@brennanb2025

Copy link
Copy Markdown
Contributor

Compatibility note before this lands: the startup/five-minute sync drives the shared JSON/file import pipeline. On current main, that pipeline does not filter Google's source-bound integrity cookies, so a periodic export can re-import source-bound values every five minutes. In testing, raw Google imports containing those cookies went stale in roughly nine minutes.

#12601 documents the divergence and #12607 centralizes the filter plus explicit import modes. Please rebase onto/adopt #12607's shared policy before merge, and have the periodic caller deliberately select merge semantics. The manual file importer uses imported-domain replacement; applying that replacement mode every five minutes would overwrite cookies that the live embedded session rotates between syncs. Conversely, inheriting native Chromium's full-jar clear would also destroy unrelated live state.

#12166's __Host- shaping remains useful, but it does not address these Google source-bound cookies or the timer's merge/replacement choice.

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

@brennanb2025

Copy link
Copy Markdown
Contributor

Apologies for the two months — this sat far longer than it should have.

The __Host- fix in your first commit deserves particular credit. That was a real bug and you found it in June: Chromium silently drops __Host- cookies when a Domain attribute is present. We hit it independently and shipped our own fix in #12166, which means you identified it two months ahead of us and then watched us land it elsewhere while this waited. That's on us.

Status: #12607 landed today. The Google source-bound filter now lives in a shared policy module applied to file, Firefox, Safari, and native Chromium imports, and importValidatedCookies takes an explicit CookieImportMode. That closes the divergence I flagged earlier.

On the agentcookie integration: to be clear, this isn't a knock on the implementation — it's cleanly built and does what it says. My hesitation is about the approach, and I'd genuinely welcome you pushing back if you see it differently or think I've got something wrong.

The main thing is the execution surface. detectAgentcookie resolves a binary by scanning PATH, and the sync runs it at startup and every five minutes, treating its stdout as cookie material. There's no pinning or provenance check, so whatever is first on PATH under that name gets executed automatically — and the payload is session cookies. On Windows especially that's a PATH-order hijack with a high-value target. That's a design concern rather than a bug in your code, but it's a hard bar for something that runs by default once enabled.

Secondarily, it overlaps what we already have: browser-cookie-import.ts already does Chrome v10 AES decryption, Firefox, and Safari across all three platforms. The genuinely new idea here isn't reading cookies — it's not making the user re-import by hand, which is the real complaint in #11518 and #10890, and it's a good idea. That part we'd rather solve natively, using the importer we already own, without an external binary in the loop.

Two things we ran into that are worth sharing either way, in case they're useful for agentcookie on your side:

  • A fixed short interval may fight the thing it's trying to fix. In our testing, repeated re-transplants of the same account started getting rejected, where a single import didn't. We can't yet cleanly separate "transplants are one-shot" from "that cadence tripped an abuse signal" — but it points toward syncing on a detected signed-out state rather than a timer. Worth saying plainly: we haven't actually cracked the underlying Google staleness problem yet, and I'm not convinced more frequent copying is the lever.
  • Import mode matters for a periodic caller. After fix(browser): align cookie import safeguards #12607, a re-sync should use merge semantics rather than replacing cookies in the imported domains — otherwise Google's reissued rotating cookies (SIDCC, the PSIDCCs, __Secure-1PSIDTS) can get clobbered between rotations. This is a note about our new code, not yours; flagging it because it'd bite any periodic importer.

The __Host- half of your work is already in the product, and the problem you were solving is one we're going to keep working on. Sorry again for the delay, and thank you for filing it — please do say if any of the above looks off to you.

@mvanhorn

mvanhorn commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

No pushback on the PATH point. Resolving an unpinned binary from PATH on a timer and treating its stdout as session cookies is a hijack surface I shouldn't have shipped as a default-on loop; pinning would narrow it but not close it, and you already own an importer that does the decryption natively. I agree the durable part of this PR is the "stop making users re-import by hand" loop, and that belongs on your importer, not an external binary.

Want me to rework this PR down to that: the startup/five-minute keep-alive calling browser-cookie-import through #12607's shared policy with explicit merge semantics, no agentcookie in the loop? If you'd rather build it fresh internally, happy to close this instead.

The interval finding is genuinely useful, thank you. I'll take the fixed-cadence lesson back to agentcookie (backoff plus change detection rather than a flat five minutes). And the credit on the __Host- fix is appreciated.

A second start() overwrote this.timer without clearing the first
interval, so stop() left the original timer firing. Return early when a
timer is already running. stop() clears the handle, so restart still works.

@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

Caution

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

⚠️ Outside diff range comments (2)

Major · Preserve host-only scope for agentcookie cookies. · browser-cookie-import.ts:575-580

src/main/browser/browser-cookie-import.ts:575-580
Major · Security & Privacy · Quick win

Preserve host-only scope for agentcookie cookies.

agentcookie export represents a host-only cookie as domain: "example.com". The importer passes that value to Electron as domain, which converts it into a cookie valid for subdomains. A session cookie can therefore be sent to sub.example.com even though the source cookie was host-only.

Omit domain when the exported host key has no leading dot. Keep it for domain cookies.

Suggested fix
       const isHostPrefixed = cookie.name.startsWith('__Host-')
+      const isHostOnly = !cookie.domain.startsWith('.')
       await targetSession.cookies.set({
         url: cookie.url,
         name: cookie.name,
         value: stripNonPrintable(cookie.value),
-        ...(isHostPrefixed ? {} : { domain: cookie.domain }),
+        ...(isHostPrefixed || isHostOnly ? {} : { domain: cookie.domain }),
         path: isHostPrefixed ? '/' : cookie.path,
Minor · Join or cancel the active session sync before quit… · agentcookie-session-sync.ts:116-121

src/main/browser/agentcookie-session-sync.ts:116-121
Minor · Stability & Availability · Quick win

Join or cancel the active session sync before quit teardown.

stop() only clears the interval. If agentcookie export is already running, syncNow() continues after stop(), calls importCookiesFromJson(...), and writes cookies through targetSession.cookies.set(...). The quit path can destroy browser backends while this work is still pending. The continuation can also call settingsStore.updateSettings(...) after the final settings flush has started.

Make stop() cancel or await the active pull, include that completion in the quit teardown barrier, and suppress the importer and status callback after cancellation. This prevents partial cookie writes and late settings mutations during shutdown.


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7df30541-129f-4dba-bd5b-ef3090d2f48d
Commits

Reviewing files that changed from the base of the PR and between 6d38a94 and cec2fc8.

Files selected for processing: 2
  • src/main/browser/agentcookie-session-sync.test.ts
  • src/main/browser/agentcookie-session-sync.ts

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

Main moved the cookie importer under src/main/browser/cookies, dropped the
shared types barrel and split main process startup into src/main/startup. Port
the agentcookie sync onto that layout:

- importCookiesFromJson now lives in the import pipeline. Failure copy for the
  file import is unchanged.
- The sync starts from main-process-runtime-launch and stops from the quit
  handler, through a slot on the main process state.
- The __Host- shaping from this branch is dropped because main already has it,
  along with its test.

Also rename lastImported to lastImportedCount and agentcookieLastImported to
agentcookieLastImportedCount, since the value is a cookie count and sits next to
the lastSyncAt timestamp.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Merged main in 840cf75. This took more than a plain merge because main moved the cookie importer under src/main/browser/cookies, dropped the shared types barrel and split startup into src/main/startup.

  • importCookiesFromJson now lives in the import pipeline, and the file import's failure copy is unchanged.
  • The sync starts from main-process-runtime-launch and stops from the quit handler.
  • The settings moved to agentcookie-settings-types.ts, because the main settings file is at its line limit.
  • I dropped this branch's __Host- change, since main already has it.

This does not change the design. The PATH lookup and timer are still here, and the question above about reworking this or closing it is still open.

Ran oxfmt, oxlint, tc:node, tc:web, tc:cli, the changed-code quality check and 918 tests covering the sync, cookie import and startup, all on Node 24.

@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: 4


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 57e5dd9c-bba9-42ec-8fd1-55722d2f3ec5
Commits

Reviewing files that changed from the base of the PR and between cec2fc8 and 840cf75.

Files selected for processing: 12
  • src/main/browser/agentcookie-session-sync.test.ts
  • src/main/browser/agentcookie-session-sync.ts
  • src/main/browser/cookies/browser-cookie-import-pipeline.ts
  • src/main/browser/cookies/browser-cookie-import.test.ts
  • src/main/browser/cookies/browser-cookie-import.ts
  • src/main/startup/main-process-agentcookie-sync.ts
  • src/main/startup/main-process-quit.ts
  • src/main/startup/main-process-runtime-launch.ts
  • src/main/startup/main-process-state.ts
  • src/shared/agentcookie-settings-types.ts
  • src/shared/default-global-settings.ts
  • src/shared/global-settings-base.ts

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

if (!stdout.trim()) {
return null
}
return importCookiesFromJson(stdout, targetPartition)

@coderabbitai coderabbitai Bot Oct 31, 2026 •

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.

Major · Data Integrity & Integration · Heavy lift

Do not overwrite a newer destination cookie with a stale export.

The periodic pull writes every exported cookie identity again. If the source export lags a cookie rotation in Orca’s browser, a write to the same identity replaces the working destination value and can sign the user out. The importer preserves unrelated cookies, but that merge behavior does not protect matching identities. Compare source and destination freshness, or skip unchanged and older source values before periodic writes. (raw.githubusercontent.com)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still holds at 37262cb. importCookiesFromJson passes every exported cookie to importValidatedCookies, and the write step sets each one without reading what the partition already has. An export that lags a rotation in Orca's browser would overwrite the newer value. That comes from reading the code; I have not reproduced it.

I have not changed this. What a periodic pull should do here (skip older values, or sync on a signed-out signal instead of a timer) depends on the rework-or-close question above, so I am leaving this thread open for that answer.

A correction to my 20:24Z comment: the design did change, in 37262cb, and that comment no longer holds. It said the design was unchanged and the PATH lookup was still here. Since 37262cb the sync is off by default and there is no PATH lookup: it runs only the absolute path in agentcookieBinaryPath, and only when agentcookieSyncEnabled is true. The timer is still here, and it now always runs and checks those settings on each tick.

That commit went in while the rework-or-close question was open, and the question is still open. The PR description is also out of date: it still says on by default and PATH detected.

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.

@mvanhorn Thanks for the correction. At 37262cba4, sync is off by default and uses the configured absolute agentcookieBinaryPath, not a PATH lookup. Those changes address the earlier default-enablement and PATH-lookup concerns. They do not address same-identity cookie replacement.

This finding remains open. The overwrite risk follows from the write path you describe; a resulting sign-out has not been reproduced.

The rework-or-close decision still needs a maintainer answer. If periodic sync remains, the key regression check is to rotate a destination cookie, import a stale source value for the same identity, and verify that the destination value survives. A signed-out trigger would reduce repeated imports, but would not itself establish cookie freshness.

The PR description should also reflect the disabled default and configured executable path.

You are interacting with an AI system.

Comment on lines +141 to +142
lastSyncAt: Date.now(),
lastImportedCount: imported

@coderabbitai coderabbitai Bot Oct 31, 2026 •

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.

Minor · Functional Correctness · Quick win

Do not stamp a failed pull as a completed sync.

When the export fails or the importer returns ok: false, this branch still sets lastSyncAt to the current time. The settings callback retains the previous imported count when lastImportedCount is null. The persisted time can thus describe a failed attempt while the count describes an older success. Update the success fields together, or store a separate last-attempt time and failure status. (raw.githubusercontent.com)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This holds at 45ed8e8. syncNow() sets lastSyncAt to Date.now() whatever pullAgentcookieSession returns, including null from a failed export and ok: false from the importer. The onStatus callback in startAgentcookieSessionSync then saves the new time but keeps the old agentcookieLastImportedCount, so settings can pair a failed attempt's time with an older success's count. That comes from reading the code; I have not reproduced it.

I have not changed this. It waits on the answer to the rework-or-close question above, so I am leaving this thread open.

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.

@mvanhorn Understood. The supplied code supports the finding, but the failure path has not been reproduced at runtime. The finding remains unresolved while the rework-or-close decision is pending.

You are interacting with an AI system.

Running whichever agentcookie came first on PATH at startup let an earlier
PATH entry supply the session cookies. Turn the sync off by default and only
execute the absolute path in agentcookieBinaryPath, with no PATH search.

The timer now always runs and checks the settings on each tick, so turning
the sync on takes effect without a restart. Export failures log their stderr
through the cookie import diagnostics instead of disappearing.

@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


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bde8aada-cfb6-4881-bcb6-19bdb711b120
Commits

Reviewing files that changed from the base of the PR and between 840cf75 and 37262cb.

Files selected for processing: 5
  • src/main/browser/agentcookie-session-sync.test.ts
  • src/main/browser/agentcookie-session-sync.ts
  • src/main/startup/main-process-agentcookie-sync.ts
  • src/shared/agentcookie-settings-types.ts
  • src/shared/default-global-settings.ts

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


// syncNow pulls once. Concurrency-guarded so the interval can't stack pulls.
async syncNow(): Promise<AgentcookieSyncStatus> {
const binary = resolveApprovedAgentcookie(this.options.getApprovedBinaryPath())

@coderabbitai coderabbitai Bot Oct 31, 2026 •

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.

Minor · Security & Privacy · Quick win

Recheck approval before importing an in-flight export.

If agentcookieSyncEnabled becomes false or agentcookieBinaryPath is cleared while agentcookie export runs, syncNow() retains the previously approved path. pullAgentcookieSession() then imports the output without checking either setting again. One export can therefore write session cookies after approval is revoked. Recheck the live settings before passing the output to importCookiesFromJson, and test a settings change during a pending export. (raw.githubusercontent.com)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This holds at 45ed8e8. syncNow() reads the approved path once, before the export, and isEnabled is only checked by the startup and interval callers before they call it. Nothing rechecks either setting after agentcookie export returns, so pullAgentcookieSession imports the output even if sync was turned off or the path was cleared during the export. The export timeout is 30 seconds, and no test covers a settings change while one is pending. That comes from reading the code; I have not reproduced it.

I have not changed this. It waits on the answer to the rework-or-close question above, so I am leaving this thread open.

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.

@mvanhorn Understood. The finding remains valid based on code inspection, but it has not been reproduced. No fix is confirmed. This thread should remain open pending the rework-or-close decision.

You are interacting with an AI system.

The startup and interval pulls discarded the syncNow promise, so a failure
in the import or the status callback became an unhandled rejection. Catch
it at those call sites and write it to the cookie import diagnostics.
Resolve the global-settings-base import conflict: keep the AgentcookieSettings
import and take main's moved browser-extension-settings path.
Resolve the conflict in browser-cookie-import.test.ts: keep main's
trimmed test file and re-add the importCookiesFromJson tests this PR
introduces.
Resolve conflict in src/shared/global-settings-base.ts by keeping
AgentcookieSettings alongside the new AntigravityChatAuthSettings,
EmulatorOpeningSettings and SshRemoteControlSettings groups.
Main moved the file import into src/main/browser/cookies/imports, split
startup into runtime-startup and quit, and moved shared settings under
src/shared/settings. importCookiesFromJson now lives next to
importCookiesFromFile in import-cookie-file.ts, the sync moved to
browser/cookies/sync, and the startup hook and settings types follow
main's new layout.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Merged main again in f2d9f0b. There was a conflict, resolved by hand; the agentcookie files follow main's new layout.

Main moved runtime services onto DesktopCore and quit teardown into
desktop-core-shutdown. The agentcookie sync slot now lives on core and
stops next to automations.
…integration

# Conflicts:
#	src/main/browser/cookies/browser-cookie-import.test.ts
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Merged main again in d77aa53. The two conflicts were resolved by keeping main's team-policy stop calls in desktop-core-shutdown.ts and its lazy serve imports in main-process-runtime-launch.ts, next to the agentcookie sync start and stop.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants