Skip to content

fix: recover model cache after provider failures - #1587

Open
cccplex wants to merge 1 commit into
CopilotC-Nvim:mainfrom
cccplex:fix/copilot-model-cache
Open

cccplex wants to merge 1 commit into
CopilotC-Nvim:mainfrom
cccplex:fix/copilot-model-cache

Conversation

@cccplex

@cccplex cccplex commented Oct 22, 2026

Copy link
Copy Markdown

Problem

Failed model discovery is cached as an empty list for five minutes,
hiding available models and replacing previously successful results.

Fix

  • Preserve cached models and expiration on failure.
  • Retry discovery on the next call; no added retry loop.
  • Still cache genuinely successful empty results.

This fixes failure caching, not the underlying invalid API response.

Tests

11 regression tests added; eight fail without the fix.
All 102 tests, StyLua, and whitespace checks pass.
Auto chat manually verified, including after restarting Neovim.

Related: #1343 also changes discovery error handling; this approach preserves
cached models and allows other providers to remain usable.

@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

First review of this model-cache recovery fix (1 commit, 2 files).

  • get_cached preserves stale data on failure (lua/CopilotChat/client.lua:83-91) — a nil from the filler now returns any previously cached value and leaves _expires_at untouched, so the entry stays expired and is refetched on the next call instead of caching an empty result for the full 5-minute TTL. Because the inner cache is a plain table (not the defaulttable wrapper), cache[key] or {} does not auto-vivify and _expires_at is only ever written alongside cache[key], so the _expires_at > now comparison can't be reached with a nil/table value.
  • Client:models reports failure as nil (lua/CopilotChat/client.lua:243-255) — the auth-failure and get_models-failure branches now return nil, and a nil provider result is passed through unchanged, engaging the recovery path. Genuinely successful empty lists are still cached.
  • New regression suite (tests/client_spec.lua) — 243 lines covering first-fetch caching, retry after auth/model-fetch failure, the expiry boundary, stale preservation then recovery, preservation when auth refresh fails, persistent-failure retry without an internal loop, genuine empty-list caching, nil provider result not cached, independent per-provider caching, and an end-to-end auto recovery after an invalid JSON response.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant