Skip to content

fix(ollama): try every browser before giving up on cookie import - #430

Open
leoarayas wants to merge 1 commit into
nesszer:mainfrom
leoarayas:fix/ollama-cookie-browser-priority
Open

fix(ollama): try every browser before giving up on cookie import#430
leoarayas wants to merge 1 commit into
nesszer:mainfrom
leoarayas:fix/ollama-cookie-browser-priority

Conversation

@leoarayas

@leoarayas leoarayas commented Sep 6, 2026

Copy link
Copy Markdown

Summary

Fixes #426.

Auto/Web cookie import for Ollama used browser_cookies_for_domain, which stops at the first installed browser that returns any cookies for ollama.com — even when those cookies are stale/irrelevant (e.g. an analytics or consent cookie left over from a one-off visit in Chrome/Edge) and carry no recognized session cookie. That starves out a later browser (often the one actually signed in, e.g. Brave) and the fetch fails with No cookies available for web API, even though a valid, logged-in session is sitting right there on disk.

Fix

resolve_browser_cookie_header now walks every detected browser and keeps going until one yields a header containing a recognized Ollama session cookie, instead of stopping at the first non-empty result. The selection logic is extracted into a small pure helper (first_recognized_cookie_header) so it's testable without real browser I/O.

Verified

  • Reproduced the exact bug against a real multi-browser Windows machine: Chrome/Edge held only unrelated ollama.com cookies, Brave held the real __Secure-session, and the old code returned NoCookies while stopping at Chrome.
  • With the fix, codexbar diagnose -p ollama returns real, cookie-scraped usage data end-to-end.
  • Added a focused unit test reproducing the regression (first cookie set irrelevant-only, second set has the real session → header comes from the second set).

Test plan

cargo test --manifest-path rust/Cargo.toml providers::ollama
cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
cargo fmt --manifest-path rust/Cargo.toml -- --check

All pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L23pzyCfMvfbMQwnHXmKCp

Summary by CodeRabbit

  • Bug Fixes
    • Improved Ollama browser cookie detection by checking all available browsers and selecting a valid session cookie when present.
    • Prevents irrelevant cookie sets from stopping cookie resolution prematurely.
    • Returns no result when no recognized session cookie is found.

Auto/Web cookie import stopped at the first installed browser that
returned any cookies for ollama.com, even when those cookies were
stale/irrelevant (e.g. a consent or analytics cookie left over from a
one-off visit) and carried no recognized session cookie. That starved
out a later browser (often the one actually signed in) and surfaced
"No cookies available for web API" even with a valid, logged-in
session sitting on disk.

Walk every detected browser and keep going until one yields a header
containing a recognized Ollama session cookie, instead of stopping at
the first non-empty result. Extracted the selection logic into a small
pure helper with a focused regression test reproducing the exact
scenario (irrelevant-only cookies on one browser, real session on the
next).

Fixes nesszer#426

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L23pzyCfMvfbMQwnHXmKCp
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: ef4180c1-1375-46ba-8e7a-9b22968e091e

📥 Commits

Reviewing files that changed from the base of the PR and between 1e3d04c and 82ff2d7.

📒 Files selected for processing (1)
  • rust/src/providers/ollama/cookies.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Ollama browser cookie resolution now scans all detected browsers and selects the first cookie set with a recognized session cookie. Tests cover skipping irrelevant cookie sets and returning no header when no session cookie is found.

Changes

Ollama cookie resolution

Layer / File(s) Summary
Select recognized Ollama session cookies
rust/src/providers/ollama/cookies.rs
The resolver checks each detected browser and returns the first recognized session-cookie header. Tests cover fallback to a later browser and the no-session-cookie case.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 82ff2

Ollama Web cookie import now continues to later browsers when earlier cookie sets lack a recognized session, allowing valid sessions to supply usage data. No current merge-blocking risk remains.

Suggested reviewers: finesssee

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The pull request fixes browser iteration when an earlier browser has irrelevant Ollama cookies. However, issue #426 identifies the concrete failure as the valid session cookie being rejected by per-co… Update or verify cookie_applies_to_ollama_url and ollama_cookie_header_for_url so valid Ollama session cookies are accepted with their real browser domain and path attributes. Add a regression test for that cookie-matching case, in addition…
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: continue checking browsers during Ollama cookie import.
Out of Scope Changes check ✅ Passed The changes are limited to Ollama browser-cookie resolution and focused regression tests. They support the linked issue and do not introduce unrelated code changes.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 1 files.
Full details: Linked Issues check

Explanation

The pull request fixes browser iteration when an earlier browser has irrelevant Ollama cookies. However, issue #426 identifies the concrete failure as the valid session cookie being rejected by per-cookie domain or path filtering. The provided changes do not show a fix or regression test for that filtering behavior.

Resolution

Update or verify cookie_applies_to_ollama_url and ollama_cookie_header_for_url so valid Ollama session cookies are accepted with their real browser domain and path attributes. Add a regression test for that cookie-matching case, in addition to the multi-browser test.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ollama Web/cookie source reports No cookies available despite a valid session

1 participant