Skip to content

[BUG][Medium]- LM cache lifecycle causes history panics and stale responses #130

Open

Description

@arthurianresolve

Summary

LM::inspect_history() panics when caching is disabled, including with the default configuration used by Example 07. The prediction can succeed before history inspection crashes.

With caching enabled, LM::with_client() retains cached responses when replacing the provider client. Repeating an earlier request can return the previous provider’s response without calling the replacement. Cache state should follow the provider client that produced it.

Affected code

  • inspect_history() unconditionally unwraps the optional cache handler: lm/mod.rs:975-977.
  • Example 07 calls history inspection without enabling caching: 07-inspect-history.rs.
  • with_client() replaces the client while retaining the existing cache through ..self: lm/mod.rs:255-260.

Suggested resolution

Implemented on fix-cache-configuration-bug:

  • Return empty history when the cache handler is absent.
  • Enable caching explicitly in Example 07.
  • Start a fresh cache and history when replacing a client with caching enabled, preserving existing clones’ clients and caches.
  • Document cache-backed history and Predict::build_chat() for inspecting formatted prompts before sending them.
  • Add regression coverage for disabled caching, history ordering and limits, and client replacement.

Acceptance criteria

  • History inspection does not panic with default or explicitly disabled caching.
  • Example 07 records its completed response.
  • A replacement client receives repeated requests instead of replaying its predecessor’s cached responses.
  • Existing clones retain their original cached responses and history.
  • Users can inspect prompts before generation, without enabling caching.

Related issues

Validation performed

Before the fix, a test reproduced the stale-cache bug: after replacing the LM client, repeating the same request returned the old client’s response.

After the fix, at commit 6db328b:

  • All 13 LM tests passed, covering disabled caching, history ordering and limits, and cache isolation between replacement clients and existing clones.
  • A separate test passed for building a prompt with build_chat() and sending that same prompt through call_and_parse().
  • Formatting checks for the changed test file and git diff --check passed.

Tests ran locally with --no-default-features and mocked providers. Example 07 also compiled successfully after the initial history fix. Live-provider behavior and the full workspace test suite were not tested.

AI Disclosure

  • OpenAI Codex assisted with implementation, tests, and issue text drafting.
  • all fixes and drafts have been human-architected, human-directed and human-reviewed before publication

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions