Skip to content

[Bug]: Managed browser cookies never persist to disk (in-memory only) — login sessions lost on every browser/gateway restart (reproduces on 2026.6.10; refile of #15645) #96704

Closed

Description

@TurboTheTurtle

Summary

The managed openclaw browser profile loses all cookies / login sessions whenever the browser process, or the parent gateway that owns the Chrome child, restarts. This was reported and root-caused in #15645, which was auto-closed as stale, not fixed. It still reproduces on the latest release, so filing fresh per the closing note's request.

Root cause

Chrome driven over CDP does not flush cookies to its on-disk SQLite store; cookies live only in memory. Network.getAllCookies returns them in-session, but user-data/Default/Cookies stays at 0 rows and Default/Network/Cookies is never created. This is documented Chrome-via-CDP behavior; see chromedp/chromedp#818.

Reproduction (minimal)

  1. openclaw browser start
  2. Over CDP, set a persistent cookie with Storage.setCookies and a future expires, or log into any site in the managed profile.
  3. Inspect ~/.openclaw/browser/openclaw/user-data/Default/Cookies -> 0 rows; no Default/Network/Cookies exists.
  4. Even after a graceful Browser.close with Preferences exit_type: Normal and a 45s in-flight wait, the cookie is absent from disk.
  5. Relaunch the profile -> the cookie / login session is gone.

Evidence / scope

Impact

Any browser-SSO automation cold-starts every run and hits the SSO/MFA wall, so it cannot complete unattended.

Proposed fix

Implement CDP cookie save/restore as #15645 specified: on graceful stop and on a periodic flush, Network.getAllCookies -> a per-profile sidecar; on start, Network.setCookies to restore. The sidecar should be treated as sensitive profile state.

A working local patch already does this in the browser plugin's launch/stop lifecycle and survives both browser restarts and gateway restarts. Happy to open a PR if the maintainers want this upstream.

Refile of #15645.

Activity

  1. clawsweeper commented on Jun 25, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 30, 2026, 5:43 PM ET / 21:43 UTC.

    Summary
    Keep open: current main and the latest release still launch a persistent managed Chrome user-data-dir but have no durable cookie snapshot/restore path, and the fresh live repro now shows the same cookie loss after managed browser restart on current main.

    Reproducibility: yes. The issue discussion now includes an isolated current-main live repro with Storage.setCookies before restart and Storage.getCookies empty after relaunch, and current source confirms there is no durable cookie restore path.

    Root-cause cluster
    Relationship: canonical
    Canonical: #96704
    Summary: This issue is the canonical fresh current-main report for managed-browser cookie/session loss; the older issue is stale-closed and the prior implementation PR is closed unmerged as the wrong shape.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    The issue is credible and well scoped, but existing labels and the prior PR review show the remaining blocker is maintainer/security product direction rather than a safe autonomous fix lane.

    Security
    Needs attention: This issue is security-sensitive because any durable fix may store or restore browser login cookies outside Chrome's normal profile database.

    Review details

    Best possible solution:

    Keep this open for maintainer/security selection of a current-path managed-browser persistence design that preserves login cookies without default plaintext duplicate storage, then prove browser and gateway restart behavior.

    Do we have a high-confidence way to reproduce the issue?

    Yes. The issue discussion now includes an isolated current-main live repro with Storage.setCookies before restart and Storage.getCookies empty after relaunch, and current source confirms there is no durable cookie restore path.

    Is this the best way to solve the issue?

    Unclear. CDP Storage.getCookies/Storage.setCookies is a plausible mechanism, but the prior default plaintext sidecar approach was rejected; the best fix needs a maintainer-approved sensitive-storage and lifecycle design.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Any durable cookie fix handles login cookies, so a default plaintext sidecar would be a security regression unless maintainers explicitly approve storage, encryption/permissions, redaction, and opt-in semantics.
    • This review did not run Chrome locally, but the discussion now contains a concrete current-main live repro and current source inspection confirms there is no restore path.

    Codex review notes: model internal, reasoning high; reviewed against 3811001d2783.

    Label changes

    Label changes:

    • add issue-rating: 🦀 challenger crab: Current issue advisory state selects this label.
    • add clawsweeper:current-main-repro: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.
    • remove clawsweeper:needs-live-repro: Current issue advisory state no longer selects this label.
    • remove issue-rating: 🐚 platinum hermit: Current issue advisory state no longer selects this label.

    Label justifications:

    • P1: Managed browser SSO workflows can lose login state on every browser or gateway restart, blocking real unattended browser automation.
    • impact:data-loss: The report is about persistent browser cookies and login state disappearing across restarts.
    • impact:session-state: The affected state is the managed browser session continuity that automation depends on.
    • impact:security: A fix must handle browser login cookies, which are sensitive credential-like state.
    Evidence reviewed

    Security concerns:

    • [medium] Avoid default plaintext cookie duplication
      A CDP cookie snapshot can duplicate SSO cookies into OpenClaw-managed storage; prior review rejected a default plaintext sidecar, so a fix needs explicit sensitive-storage handling and maintainer/security approval.
      Confidence: 0.91

    What I checked:

    • Current managed launch path: Current main resolves the managed profile to CONFIG_DIR/browser//user-data and passes it as Chrome's --user-data-dir, but launch has no cookie restore step before or after Chrome starts. (extensions/browser/src/browser/chrome.ts:718, 3811001d2783)
    • Current stop path: Current main stop handling sends SIGTERM, waits for CDP to disappear, and escalates to SIGKILL; it does not call a cookie flush/snapshot routine or Browser.close. (extensions/browser/src/browser/chrome.ts:1132, 3811001d2783)
    • Current cookie commands are context-only: The browser cookie routes delegate to Playwright page.context().cookies(), addCookies(), and clearCookies(), with no OpenClaw persistence layer around cookie state. (extensions/browser/src/browser/pw-tools-core.storage.ts:7, 3811001d2783)
    • No current persistence implementation found: A targeted search found no current browser implementation for Storage.getCookies/Storage.setCookies, Network.getAllCookies/Network.setCookies, openclaw-saved-state, sessionPersistence, cookies.json, or cookie snapshot/restore terms. (3811001d2783)
    • Latest release still lacks the fix: v2026.6.11 points at e085fa1, and the release copy of chrome.ts has the same user-data-dir launch and stopOpenClawChrome shape with no cookie persistence hits. (extensions/browser/src/browser/chrome.ts:720, e085fa1a3ffd)
    • Live current-main repro in discussion: The reporter added a current-origin/main live repro using an isolated temp profile: Storage.setCookies succeeds in memory, the on-disk cookie DB remains empty, and Storage.getCookies returns no matching cookies after browser stop and relaunch.

    Likely related people:

    • steipete: Peter Steinberger authored the original browser control path, the server-context split, the Playwright storage helper split, and the bundled browser plugin move; the same handle also closed the prior cookie persistence PR with the sensitive-storage/product-direction concern. (role: browser runtime owner and prior reviewer; confidence: high; commits: 208ba02a4a65, 663c1858b80e, 2b60ee96f219; files: extensions/browser/src/browser/chrome.ts, extensions/browser/src/browser/server-context.availability.ts, extensions/browser/src/browser/pw-tools-core.storage.ts)
    • John-Rood: Authored the closed PR that prototyped CDP cookie snapshot/restore for the same managed-browser login-session loss, making them useful context for a future maintainer-sponsored fix. (role: prior implementation author; confidence: medium; commits: 040aa5f64a87, 6d46c867d685; files: src/browser/session-persistence.ts, src/browser/chrome.ts, src/browser/server-context.availability.ts)
    • TurboTheTurtle: Provided the fresh current-main live repro and corrected the proposed CDP API family to Storage.getCookies/Storage.setCookies, though they do not appear as a current-main code owner in the inspected history. (role: current reporter and live repro provider; confidence: medium; files: extensions/browser/src/browser/chrome.ts, extensions/browser/src/browser/pw-tools-core.storage.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:data-lossCan lose, corrupt, or silently drop user/session/config data.
    impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    on Jun 25, 2026
  3. TurboTheTurtle commented on Jun 25, 2026

    @TurboTheTurtle
    ContributorAuthor

    Correction to the proposed-fix note: the browser-level CDP cookie methods are Storage.getCookies / Storage.setCookies, not Network.getAllCookies / Network.setCookies. The Network.* variants are page-session only and return 'Network.getAllCookies' wasn't found on the browser-target WebSocket endpoint.

    A local implementation using Storage.* has been validated end-to-end: snapshot on graceful stop plus a periodic flush, restore on launch, and a real multi-cookie SSO session survived a hard browser kill and relaunch.

  4. TurboTheTurtle commented on Jun 25, 2026

    @TurboTheTurtle
    ContributorAuthor

    Correction to the proposed-fix note above: the browser-level CDP cookie methods are Storage.getCookies / Storage.setCookies, not Network.getAllCookies / Network.setCookies. The Network.* variants are page-session only and return 'Network.getAllCookies' wasn't found on the browser-target WebSocket endpoint.

    A local implementation using Storage.* (snapshot on graceful stop plus a periodic flush, restore on launch) has been validated end-to-end — a real multi-cookie SSO session survived a hard browser kill and relaunch.

  5. TurboTheTurtle commented on Jun 30, 2026

    @TurboTheTurtle
    ContributorAuthor

    Live repro on current origin/main:

    • OpenClaw: 2026.6.11 (44ec7580e2f) built locally from a clean temp worktree
    • Browser: Google Chrome headless via the managed openclaw profile
    • Isolation: explicit temp OPENCLAW_CONFIG_PATH / OPENCLAW_STATE_DIR, browser plugin only, profile at /private/tmp/openclaw-96704-home/state/browser/openclaw/user-data

    Steps/results:

    1. Started the isolated gateway and ran openclaw browser start --headless.
      Status reported running: true, cdpReady: true, cdpPort: 19978, and the temp user data dir above.
    2. Sent browser-level CDP Storage.setCookies for a persistent synthetic cookie:
      name=oc96704_live_repro, domain=example.com, value value-96704-live-20260630, future expires.
    3. Immediate browser-level Storage.getCookies confirmed the cookie was live in memory:
    {
      "totalCookies": 1,
      "matchingCookies": 1,
      "matchingValues": ["value-96704-live-20260630"],
      "matchingDomains": ["example.com"]
    }
    1. While the browser was still running, Chrome's on-disk cookie DB already had zero rows:
    /private/tmp/openclaw-96704-home/state/browser/openclaw/user-data/Default/Cookies
    select count(*) from cookies; -> 0
    

    No Default/Network/Cookies file existed, and no OpenClaw cookie sidecar existed.

    1. Stopped the managed browser through openclaw browser stop; the same DB still had 0 cookie rows after shutdown.
    2. Relaunched the same profile with openclaw browser start --headless.
    3. Browser-level Storage.getCookies after relaunch returned no cookies:
    {
      "totalCookies": 0,
      "matchingCookies": 0,
      "matchingValues": []
    }

    So the live behavior matches the report: the managed Chrome profile accepts the persistent cookie in-session, but current OpenClaw/Chrome does not write it to durable profile storage, and the session is lost on browser restart.

  6. TurboTheTurtle commented on Jun 30, 2026

    @TurboTheTurtle
    ContributorAuthor

    @clawsweeper re-review

  7. clawsweeper commented on Jun 30, 2026

    @clawsweeper
    Contributor

    🦞🧹
    ClawSweeper re-review requested.

    I asked ClawSweeper to review this item again.
    Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
    Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

  8. added
    issue-rating: 🦀 challenger crabExceptional issue quality: high-confidence current-main reproduction and actionable evidence.
    clawsweeper:current-main-reproClawSweeper found a high-confidence current-main issue reproduction.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    and removed
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    on Jun 30, 2026
  9. locked as resolved and limited conversation to collaborators on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:current-main-reproClawSweeper found a high-confidence current-main issue reproduction.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦀 challenger crabExceptional issue quality: high-confidence current-main reproduction and actionable evidence.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions