Skip to content

fix(ai): response cache singleton ignores cache_enabled=False from later clients #1375

Closed as not planned

Description

@dan-petty

Problem

get_llm_response_cache (src/devops_cli/ai/response_cache.py, around line 433) creates the process-wide _GLOBAL_LLM_CACHE once and then returns it unchanged, whatever enabled, cache_dir, ttl_seconds or max_entries a later caller passes. LLMClient.__init__ (src/devops_cli/ai/client/unified.py:220-227) takes its _cache from it. So LLMClient(..., cache_enabled=False) still reads and writes an enabled cache whenever an earlier client in the same process created it enabled.

Callers that rely on cache_enabled=False: commands/review.py:333, :560 and :889 (--no-cache / --force), commands/ai.py:566, :662 and :809, and ai/review/runner.py:1611.

I found this while writing the #816 review test. The test suite works around it with the autouse isolate_llm_response_cache fixture, which creates the singleton enabled. The skeptic review of #816 flagged it as well.

Proposed remedy

The client applies its own cache_enabled (and directory and limits) instead of inheriting the singleton's. For example, keep the singleton per settings, or make use_cache default to the client's own enabled flag. Add a test where an enabled client is created first and a later cache_enabled=False client neither reads nor writes the cache.

Evidence

Code-level only: the singleton branch if _GLOBAL_LLM_CACHE is None: in get_llm_response_cache. I have not yet reproduced it as a user-visible --no-cache hit.


Found on 2026-10-08 while implementing #816. Filed directly with no priority; the roadmap service's intake sets Priority, Value and Effort.

Activity

  1. added
    type/bug
    scope/ai
    source/agent
    on Oct 8, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P2-Medium. It defeats documented --no-cache/--force flags in review commands, but the author has not yet reproduced a user-visible cache hit and the test suite currently works around it.
    • Value: Medium. Users who pass --no-cache or --force expect no cache interaction; silently ignoring that flag undermines trust in the CLI's documented behavior.
    • Effort: Low. The fix is localized to get_llm_response_cache and LLMClient.__init__: apply the client's own enabled flag and settings rather than inheriting the singleton's, plus one regression test.
  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Closing as a duplicate of #1014, which keeps it. #1014's 2026-10-08 criterion "status and clear see the clients' cache" builds the cache once from settings, requires that a cache_enabled=False client neither reads nor writes it, names the same callers and has this item's test. The code is unchanged at release/v0.2.29 (ai/response_cache.py:428-444, ai/client/unified.py:219-224). This item's seventh caller, ai/review/runner.py:1611, passes cache_enabled straight through, so #1014 covers it too.

    Found by the 2026-10-08 backlog review.

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

    scope/aisource/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions