Skip to content

Prefer Cursor app sessions in Automatic mode - #2598

Merged
steipete merged 5 commits into
mainfrom
codex/cursor-app-session
Aug 15, 2026
Merged

Prefer Cursor app sessions in Automatic mode#2598
steipete merged 5 commits into
mainfrom
codex/cursor-app-session

Conversation

@steipete

@steipete steipete commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Prefer a usable Cursor.app local session ahead of browser cookies in Automatic mode, while keeping Manual and explicit web source behavior authoritative.
  • Read Cursor's state database read-only with active-WAL support and the OpenCode Go immutable fallback for idle WAL databases without sidecars.
  • Persist validated derived sessions through the owner-only Cursor session store, without refreshing Cursor tokens.
  • Compare cheap local email/subject identities against cached browser sessions; warn on mismatch and keep the chosen app account identity visible on the card.
  • Credit @markmay's direction in the changelog and document the exact storage paths and live proof command.

Refs #2398

Proof

  • make check
  • swift test --filter CursorStatusProbeTests (46 tests)
  • swift test --filter CursorMenuCardModelTests (5 tests)
  • swift test --filter CursorImportedSessionScanningTests (13 tests)
  • swift test --filter CursorUsageEventsFetcherTests (26 tests)
  • swift test --filter CodexBackgroundRefreshCoalescingTests (23 tests after test-only scheduler stabilization)
  • Autoreview: Codex/Sol high, TruffleHog clean, no accepted/actionable findings.

make test was attempted repeatedly. Concurrent Swift test harnesses from other local worker checkouts caused unrelated timer/account suites to hit the harness timeout; the harness recovered many selections individually, and the affected coalescing suite passes in isolation. No Cursor suite failed.

Pending live gate

Cursor 3.14.7 is installed and its first-launch state database exists. Live authentication is intentionally pending Peter's login. After login, run:

/Users/steipete/Projects/CodexBar/.build/arm64-apple-macosx/debug/CodexBarCLI usage --provider cursor --source auto --verbose

Verbose output must include Using Cursor.app local auth, followed by a successful Cursor usage card for the chosen account.

@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

Proof before live login:

  • Cursor fixture matrix passes: app-only, cookies-only, both-same identity, both-different identity with warning/chosen card label, and expired-app fallback.
  • SQLite fixtures pass for both active uncheckpointed WAL state and idle WAL-mode databases without sidecars.
  • Cursor status, menu-card, imported-session, and usage-events suites pass.
  • make check passes.
  • Codex/Sol autoreview passes with no accepted/actionable findings; TruffleHog is clean.

Pending live gate: Peter must complete Cursor login. The reader consumes:

  • /Users/steipete/Library/Application Support/Cursor/User/globalStorage/state.vscdb
  • /Users/steipete/Library/Application Support/Cursor/User/globalStorage/state.vscdb-wal when active
  • /Users/steipete/Library/Application Support/Cursor/User/globalStorage/state.vscdb-shm when active

Then run:

/Users/steipete/Projects/CodexBar/.build/arm64-apple-macosx/debug/CodexBarCLI usage --provider cursor --source auto --verbose

The live gate passes when verbose output includes Using Cursor.app local auth and the usage card shows the logged-in Cursor account. Do not merge before that proof is recorded.

@steipete
steipete force-pushed the codex/cursor-app-session branch from 74d0434 to dea9085 Compare August 3, 2026 03:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74d0434f07

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

return Date(timeIntervalSince1970: expiration.doubleValue)
}

func makeCookie() throws -> HTTPCookie {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Import FoundationNetworking for Linux app-auth builds

When this file is compiled on Linux, HTTPCookie and HTTPCookiePropertyKey are provided by FoundationNetworking rather than Foundation; after moving app-auth code out of CursorStatusProbe.swift, the conditional import FoundationNetworking no longer covers this reference. The Linux CodexBarCore/CLI build will fail with cannot find type 'HTTPCookie' in scope, so add the same conditional import to this file.

Useful? React with 👍 / 👎.

cookies.filter { cookie in
guard CursorAppAuthSession.isPersistedCookie(cookie) else { return true }
let value = cookie.value.removingPercentEncoding ?? cookie.value
return value.components(separatedBy: "::").last != appSession.accessToken

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Drop stale persisted app auth after live token expiry

When Cursor's state DB returns an expired or invalid token but cursor-session.json still holds an older derived app-auth cookie for a different token, this predicate keeps the older cookie because only the matching access token is filtered. If no cached or browser session wins afterward, fetchStoredSession will authenticate with that stale app account instead of falling through away from app auth, so remove all persisted app-auth cookies whenever a live app session is unusable.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codex review: found issues before merge. Reviewed August 15, 2026, 12:32 AM ET / 04:32 UTC.

ClawSweeper review

What this changes

The PR makes Automatic Cursor usage resolution prefer a valid local Cursor.app session over cached or imported browser cookies, with fallback, identity display, tests, and documentation.

Merge readiness

Blocked by patch quality or review findings - 7 items remain

The branch needs a compatibility repair: saving a successful Cursor.app session replaces the legacy stored-session fallback. The owner-authored provider-auth and credential-storage policy also requires maintainer sign-off.

Priority: P1
Reviewed head: 3c4bc06c1e8a552f83491f4e3a8999c8e8b2d910
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The targeted coverage is substantial, but the source-proven stored-session overwrite is a merge-blocking compatibility defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This owner-authored PR is not subject to the external contributor proof gate, though its stated redacted post-login CLI verification remains useful before merge.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This owner-authored PR is not subject to the external contributor proof gate, though its stated redacted post-login CLI verification remains useful before merge.
Evidence reviewed 5 items Stored fallback is replaced: The new app-session persistence path writes a one-cookie array to the existing Cursor session store, replacing older non-app stored cookies.
Legacy fallback remains documented: The PR documentation still identifies stored session cookies from older CodexBar releases as a fallback, so overwriting them changes upgrade behavior.
Repository policy requires sign-off: VISION.md lists behavior changes affecting provider auth and data storage as requiring sign-off.
Findings 1 actionable finding [P1] Preserve legacy stored sessions when persisting app auth
Security None None.

How this fits together

CodexBar’s Cursor provider resolves local or browser authentication into a usage snapshot for the menu card and CLI. This change alters session selection before the existing Cursor usage request and persistence paths.

flowchart LR
A[Cursor settings] --> B[Session selection]
C[Cursor app database] --> B
D[Cached or browser cookies] --> B
B --> E[Cursor usage request]
E --> F[Usage snapshot]
F --> G[Menu card and CLI]
Loading

Decision needed

Question Recommendation
Should Automatic mode prioritize the locally signed-in Cursor.app account over an existing unselected browser session while preserving every legacy stored fallback? Keep app-first with fallback preservation: Retain the new Automatic-mode preference but repair persistence so pre-existing non-app stored sessions remain available if app auth is unavailable.

Why: VISION.md requires sign-off for provider-auth and credential-storage behavior changes, and this policy can change the account an existing user sees after upgrade.

Before merge

  • Preserve legacy stored sessions when persisting app auth (P1) - This line replaces the entire cursor-session.json cookie array after a successful app-auth fetch. Existing non-app stored sessions are the documented final fallback, so when the app token later expires, is removed, or is rejected, those users have already lost their fallback. Retain non-app records or store the derived app session separately, and add an upgrade regression. This was present at the prior reviewed head and is a late review finding.
  • Resolve merge risk (P2) - A successful app-auth refresh deletes legacy stored Cursor session cookies, so an existing user can lose their fallback when the app session later becomes unavailable.
  • Resolve merge risk (P1) - Automatic mode can switch an existing user from a cached browser account to a different local Cursor.app account; sign-off should confirm that policy.
  • Complete next step (P2) - Repair the stored-session overwrite, then obtain maintainer sign-off on the app-first account-selection policy.
  • Improve patch quality - Preserve legacy stored fallback data and add the upgrade regression.
  • Improve patch quality - Record the planned redacted Cursor.app local-auth CLI result after login.

Findings

  • [P1] Preserve legacy stored sessions when persisting app auth — Sources/CodexBarCore/Providers/Cursor/CursorStatusProbe.swift:680
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Implementation and tests production +623, docs +25, tests +402 The provider-auth change expands credential handling and regression coverage, so upgrade behavior needs focused review.

Merge-risk options

Maintainer options:

  1. Preserve the legacy fallback before merge (recommended)
    Store the derived app session separately or retain non-app stored cookies, then cover an upgrade sequence where app auth later disappears.
  2. Accept the fallback deletion
    Merge with the explicit decision that a successful local app session retires legacy stored Cursor sessions.

Technical review

Best possible solution:

Keep app-first Automatic mode only after retaining legacy non-app session data as a fallback and recording redacted local runtime evidence for the selected-account path.

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

Yes, from source: start with a legacy non-app cookie in the Cursor session store, complete one successful app-auth fetch, then make app auth unavailable; the changed write leaves no legacy stored fallback.

Is this the best way to solve the issue?

No: app-first resolution can be viable, but overwriting older stored credentials contradicts the documented fallback order; preserve them or store the derived app session independently.

Full review comments:

  • [P1] Preserve legacy stored sessions when persisting app auth — Sources/CodexBarCore/Providers/Cursor/CursorStatusProbe.swift:680
    This line replaces the entire cursor-session.json cookie array after a successful app-auth fetch. Existing non-app stored sessions are the documented final fallback, so when the app token later expires, is removed, or is rejected, those users have already lost their fallback. Retain non-app records or store the derived app session separately, and add an upgrade regression. This was present at the prior reviewed head and is a late review finding.
    Confidence: 0.96
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 71bbd263c902.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This owner-authored PR is not subject to the external contributor proof gate, though its stated redacted post-login CLI verification remains useful before merge.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: Existing Cursor users can lose a previously working stored authentication fallback after a successful automatic refresh.
  • merge-risk: 🚨 compatibility: The PR changes Automatic-mode account preference and overwrites stored fallback credentials.
  • merge-risk: 🚨 auth-provider: The PR reads Cursor.app authentication state and writes derived session credentials.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This owner-authored PR is not subject to the external contributor proof gate, though its stated redacted post-login CLI verification remains useful before merge.

Evidence

What I checked:

Likely related people:

  • steipete: The owner-authored branch and recent Cursor cache-ownership work establish direct responsibility for the proposed policy. (role: recent area contributor and decision owner; confidence: high; commits: 3c4bc06c1e8a, 29ebe6541174, 578653a8886b; files: Sources/CodexBarCore/Providers/Cursor/CursorStatusProbe.swift, Sources/CodexBarCore/Providers/Cursor/CursorStatusProbe+SessionResolution.swift)
  • anagnorisis2peripeteia: Commit d7bf947 routed CursorSessionStore through the shared private credential-file writer. (role: introduced secure session-store behavior; confidence: high; commits: d7bf94793dcd; files: Sources/CodexBarCore/Providers/Cursor/CursorStatusProbe.swift)
  • markmay: The PR credits their direction and partially overlaps the still-open Cursor-auth proposal. (role: related Cursor-auth contributor; confidence: medium; files: docs/cursor.md)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-03T11:46:20.617Z sha dea9085 :: needs changes before merge. :: [P1] Import FoundationNetworking for Linux cookie types | [P2] Clear every persisted app-auth cookie after invalid live auth
  • reviewed 2026-08-03T13:53:50.758Z sha dea9085 :: needs changes before merge. :: [P1] Import FoundationNetworking for Linux cookie types | [P2] Remove every persisted app-auth cookie after invalid live auth
  • reviewed 2026-08-03T15:56:04.202Z sha dea9085 :: found issues before merge. :: [P1] Import FoundationNetworking for Linux cookie types | [P2] Clear every persisted app-auth cookie after app-auth failure
  • reviewed 2026-08-03T19:00:35.577Z sha dea9085 :: found issues before merge. :: [P1] Import FoundationNetworking for Linux cookie types | [P2] Clear every persisted app-auth cookie after app-auth failure
  • reviewed 2026-08-11T05:56:42.555Z sha dea9085 :: found issues before merge. :: [P1] Import FoundationNetworking for Linux cookie types | [P2] Clear all derived app-auth cookies after app-auth failure
  • reviewed 2026-08-12T11:04:39.725Z sha dea9085 :: found issues before merge. :: [P1] Import FoundationNetworking for Linux cookie types | [P2] Clear every derived app-auth cookie after app-auth failure
  • reviewed 2026-08-15T03:14:46.403Z sha cdb9b37 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T04:04:00.918Z sha fd5d4f2 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 3, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 11, 2026
@clawsweeper clawsweeper Bot added the rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. label Aug 15, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@steipete
steipete merged commit 5a51837 into main Aug 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant