Skip to content

fix: persist Command Code browser sessions - #2564

Merged
steipete merged 4 commits into
mainfrom
codex/commandcode-session-save
Aug 2, 2026
Merged

fix: persist Command Code browser sessions#2564
steipete merged 4 commits into
mainfrom
codex/commandcode-session-save

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • reuse validated Command Code sessions from the shared cookie cache
  • cache the browser session that successfully returns usage
  • cover refresh-suppression staging, persistence, and subsequent cache reuse with an isolated test store
  • document the fix in the 0.46.1 changelog

Root cause

The Command Code automatic strategy imported and validated browser cookies directly, but never participated in CookieHeaderCache. The CLI cookie-refresh transaction hides the existing cache while validation runs and requires exactly one staged cache replacement before it reports success. Command Code therefore validated successfully but always committed zero staged mutations, producing the reported "could not be saved" result and leaving CLI/service consumers without credentials.

Fix

The automatic strategy now checks the shared cache before browser import, evicts a cached entry only after an explicit invalid-credentials response, and stores the first browser session that successfully validates. During explicit cookie refresh, that store is staged by the existing suppression gate and committed only after provider validation succeeds.

Proof

  • swift test --filter CommandCodeProviderTests — passed, 6 tests
  • swift test --filter CLICookieRefreshTests — passed, 12 tests
  • make check — passed
  • make test — all completed groups passed except the documented loaded-machine wall-clock flake in KiroStatusProbeTests; an isolated rerun reproduced only accepted pipe output cannot overrun the usage deadline
  • autoreview — clean, no accepted/actionable findings

Closes #2541

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

Exact test proof for commit 5e303b80e:

  • swift test --filter CommandCodeProviderTests: passed — 6 tests, 0 issues.
  • swift test --filter CLICookieRefreshTests: passed — 12 tests, 0 issues.
  • make check: passed — SwiftFormat reported 0 files requiring formatting; SwiftLint reported 0 violations in 1,668 files; repository checks passed.
  • make test: discovered 763 selections across 64 groups. The harness reported 34 first-pass successful groups and one failed/retried group; the only failure was the documented loaded-machine wall-clock flake in KiroStatusProbeTests (4 issues). No non-Kiro suite failed before the harness stopped.
  • swift test --filter KiroStatusProbeTests: isolated reproduction confirmed the same known flake; 54 of 55 tests passed, and only accepted pipe output cannot overrun the usage deadline failed (2 timing-related assertions).
  • /Users/steipete/Projects/agent-skills/skills/autoreview/scripts/autoreview --mode local: clean — no accepted/actionable findings.

All credential persistence coverage used KeychainCacheStore.withImplicitTestStoreForTesting; no live browser, provider, network, or real Keychain probe was run.

@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: 5e303b80e4

ℹ️ 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".

Comment on lines +45 to +46
try await KeychainCacheStore.withServiceOverrideForTesting(service) {
try await KeychainCacheStore.withImplicitTestStoreForTesting {

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 Isolate the legacy cookie cache in cache tests

When these new cache-aware tests run on a machine that already has a legacy commandcode-cookie.json, overriding only the Keychain service is not enough: CookieHeaderCache.load(provider:) falls back to the default Application Support legacy file before sessionLoader is used, then migrates/removes that real entry. That makes the recorder expectations depend on developer machine state and can touch real credentials; wrap these blocks in CookieHeaderCache.withLegacyBaseURLOverrideForTesting with a temp directory as well.

AGENTS.md reference: AGENTS.md:L26-L26

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge. Reviewed August 2, 2026, 8:21 AM ET / 12:21 UTC.

ClawSweeper review

What this changes

This PR makes Command Code reuse a validated cached browser session and persist a newly validated browser session so CLI refreshes and later local-service usage can authenticate.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep this owner-authored PR open for explicit maintainer handling. The provider fix is focused, but the existing P2 blocker remains: its new cache-aware tests isolate the Keychain store but not the legacy cookie-file fallback, so they can read, migrate, or remove a developer’s real Command Code credential state.

Priority: P2
Reviewed head: dccbcaed341f940b05c3969c2d0ddb3a587501e4

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The provider fix is focused and covered by targeted tests, but the repeated P2 credential-test isolation defect blocks a higher readiness rating.
Proof confidence 🌊 off-meta tidepool Not applicable: This is an owner-authored PR, so external-contributor real-behavior proof is not a merge gate; the provided focused test evidence remains useful supplemental validation.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is an owner-authored PR, so external-contributor real-behavior proof is not a merge gate; the provided focused test evidence remains useful supplemental validation.
Evidence reviewed 5 items PR cache behavior: The branch first validates a saved Command Code cookie, clears it only after an invalid-credentials response, and stores a browser session only after usage validation succeeds.
Unisolated test setup: The new tests override the Keychain service and enable an implicit test store, but do not override the legacy cookie-file base URL before exercising CookieHeaderCache.load.
Legacy fallback can mutate real state: On a Keychain cache miss, the shared cache migrates a legacy entry; migration writes the Keychain entry and removes the legacy file, so test isolation must cover both stores.
Findings 1 actionable finding [P2] Isolate the legacy cookie cache in these tests
Security Needs attention Tests can migrate a real legacy Command Code cookie: Overriding only the Keychain service leaves the default legacy-file fallback active; a cache miss can load, migrate, and remove a developer’s real saved cookie during the test run.

How this fits together

Command Code’s web fetch strategy receives either a manual cookie, a shared cached cookie, or an imported browser session, then validates it against the usage endpoint. A successful browser session is written through the shared cookie cache so CLI refresh and subsequent provider requests can reuse it.

flowchart LR
  A[Manual cookie or browser session] --> B[Command Code fetch]
  C[Shared cookie cache] --> B
  B --> D[Usage validation]
  D -->|valid browser session| E[Stage or persist cache entry]
  E --> C
  D --> F[CLI and local service usage]
Loading

Before merge

  • Isolate the legacy cookie cache in these tests (P2) - These new paths call CookieHeaderCache.load, which migrates the default legacy Application Support cookie file after the isolated Keychain lookup misses. A developer’s Command Code cookie can therefore bypass sessionLoader and be migrated or removed; wrap each cache-aware test in withLegacyBaseURLOverrideForTesting with a unique temporary base, as the existing cache tests do.
  • Resolve security concern: Tests can migrate a real legacy Command Code cookie - Overriding only the Keychain service leaves the default legacy-file fallback active; a cache miss can load, migrate, and remove a developer’s real saved cookie during the test run.
  • Resolve merge risk (P1) - The changed credential-cache tests can still consume, migrate, or delete a real legacy Command Code cookie file on a developer machine, making outcomes machine-dependent and crossing the intended credential-test boundary.
  • Resolve merge risk (P1) - Merging changes the provider’s cached credential selection and invalid-credential eviction path; the focused tests should remain fully isolated before relying on them as authentication regression coverage.
  • Complete next step (P2) - The remaining blocker is a narrow, mechanical test-isolation repair that can be made without changing the provider’s runtime behavior.

Findings

  • [P2] Isolate the legacy cookie cache in these tests — Tests/CodexBarTests/CommandCodeProviderTests.swift:45-46
  • [low] Tests can migrate a real legacy Command Code cookie — Tests/CodexBarTests/CommandCodeProviderTests.swift:45
Agent review details

Security

Needs attention: The runtime change has no new supply-chain path, but its new credential-cache tests can access and mutate real legacy browser-session material without full test isolation.

Review metrics

Metric Value Why it matters
Patch scope 3 files affected; 107 added, 35 removed The runtime change is small and concentrated, while most of the patch expands provider cache regression coverage.
Cache-aware tests 3 new affected test paths All newly cache-aware paths need the same legacy-file isolation boundary.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #2541
Summary: This PR is the candidate repair for the linked Command Code cookie-refresh persistence defect.

Members:

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

Merge-risk options

Maintainer options:

  1. Isolate both credential-cache backends (recommended)
    Add a unique temporary legacy-cache override around the three cache-aware tests so they cannot read or migrate a developer’s real legacy Command Code cookie.
  2. Pause the branch until test isolation is repaired
    Do not merge while the regression tests can mutate developer credential state and produce machine-dependent results.

Technical review

Best possible solution:

Keep the runtime persistence design, but wrap every new cache-aware Command Code test in a unique temporary legacy-cache base as well as the existing isolated Keychain store, then rerun the focused provider and CLI refresh suites.

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

Yes, at source level: a Keychain test-store miss reaches the legacy-file migration path, while the new tests omit the available legacy-base override. The linked report also provides a concrete real-user CLI refresh and subsequent usage/service reproduction path.

Is this the best way to solve the issue?

No, not yet. The provider persistence approach matches existing shared-cache patterns, but the tests must isolate the legacy cookie cache before they safely prove the repair.

Full review comments:

  • [P2] Isolate the legacy cookie cache in these tests — Tests/CodexBarTests/CommandCodeProviderTests.swift:45-46
    These new paths call CookieHeaderCache.load, which migrates the default legacy Application Support cookie file after the isolated Keychain lookup misses. A developer’s Command Code cookie can therefore bypass sessionLoader and be migrated or removed; wrap each cache-aware test in withLegacyBaseURLOverrideForTesting with a unique temporary base, as the existing cache tests do.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 41bc0141e5f1.

Labels

Label justifications:

  • P2: The reported Command Code authentication persistence failure is a bounded but real provider workflow regression.
  • merge-risk: 🚨 auth-provider: The patch changes how Command Code session credentials are reused, invalidated, and persisted.
  • merge-risk: 🚨 security-boundary: The new tests can reach legacy cookie-file credentials outside their intended test store unless both cache backends are isolated.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is an owner-authored PR, so external-contributor real-behavior proof is not a merge gate; the provided focused test evidence remains useful supplemental validation.

Evidence

Security concerns:

  • [low] Tests can migrate a real legacy Command Code cookie — Tests/CodexBarTests/CommandCodeProviderTests.swift:45
    Overriding only the Keychain service leaves the default legacy-file fallback active; a cache miss can load, migrate, and remove a developer’s real saved cookie during the test run.
    Confidence: 0.99

Acceptance criteria:

  • [P1] swift test --filter CommandCodeProviderTests.
  • [P1] swift test --filter CLICookieRefreshTests.
  • [P1] make check.

What I checked:

Likely related people:

  • steipete: Current Command Code history shows Peter Steinberger authored the preceding browser-session retry work and the substantive persistence commit; the GitHub context identifies the corresponding repository owner handle as steipete. (role: feature owner and recent area contributor; confidence: high; commits: f2dc5ab431a4, 5e303b80e43d; files: Sources/CodexBarCore/Providers/CommandCode/CommandCodeProviderDescriptor.swift, Tests/CodexBarTests/CommandCodeProviderTests.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wrap the cache-aware tests with a unique withLegacyBaseURLOverrideForTesting base.
  • Rerun swift test --filter CommandCodeProviderTests, swift test --filter CLICookieRefreshTests, and make check after the isolation fix.

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 (5 earlier review cycles)
  • reviewed 2026-08-02T01:04:33.861Z sha 5e303b8 :: needs changes before merge. :: [P2] Isolate the legacy cookie cache in cache tests
  • reviewed 2026-08-02T01:46:14.142Z sha 5e303b8 :: needs changes before merge. :: [P2] Isolate the legacy cookie cache in cache tests
  • reviewed 2026-08-02T05:00:32.359Z sha ade9dee :: needs changes before merge. :: [P2] Isolate the legacy cookie cache in cache tests
  • reviewed 2026-08-02T07:08:49.587Z sha 55f1309 :: needs changes before merge. :: [P2] Isolate the legacy cookie cache in cache tests
  • reviewed 2026-08-02T09:56:20.840Z sha dccbcae :: needs changes before merge. :: [P2] Isolate the legacy cookie cache in these tests

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. label Aug 2, 2026
@steipete
steipete merged commit 4ec9b16 into main Aug 2, 2026
9 checks passed
Finesssee added a commit to nesszer/Win-CodexBar that referenced this pull request Aug 4, 2026
* Port upstream 0.47.0: Low Power Mode (steipete#2518)

* Port upstream 0.47.0: Notion AI provider (steipete#2552)

* Port upstream 0.47.0: codexbar hooks watch (steipete#2536)

* Port upstream 0.47.0: Cursor optional on-demand usage (steipete#2338)

* Port upstream 0.47.0: Command Code persist browser sessions (steipete#2564)

* Port upstream 0.47.0: OpenCode Go idle WAL read (steipete#2544)

* Port upstream 0.47.0: real-calendar monthly pace (steipete#2552)

* Port upstream 0.47.0: XAI provider

* Port upstream 0.47.0: verified z.ai/Kimi/Grok window durations (steipete#2431)

* Document upstream port procedure

* Simplify port helpers: drop bespoke trait, unused param, duplicated aggregation
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: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

Command Code: cookie refresh validates but session "could not be saved"; provider never authenticates

1 participant