Skip to content

Fix LM history inspection and cache isolation on client replacement - #131

Open
arthurianresolve wants to merge 3 commits into
krypticmouse:mainfrom
arthurianresolve:fix-cache-configuration-bug
Open

arthurianresolve wants to merge 3 commits into
krypticmouse:mainfrom
arthurianresolve:fix-cache-configuration-bug

Conversation

@arthurianresolve

@arthurianresolve arthurianresolve commented Nov 9, 2026 •

Copy link
Copy Markdown

Summary of Fix

  • Return empty history when caching is disabled, preventing inspect_history() from panicking.
  • Enable caching in Example 07 so its completed response appears in history.
  • Start a fresh cache and history when replacing an LM client. Existing clones retain their original client, cached responses, and history.
  • Document inspecting formatted prompts with Predict::build_chat() before sending them.
  • Add regression coverage for cache configuration, history ordering and limits, and client replacement.

Fixes #130
Fixes #84

Why

Caching defaults to disabled, but history inspection previously unwrapped the optional cache handler. Example 07 could therefore complete its prediction and then crash while reading history.

Separately, with_client() replaced the provider while retaining its predecessor’s cache. Repeating a request could return the old provider’s response without invoking the replacement. Creating a fresh cache prevents that reuse without clearing caches belonging to existing clones.

Related work

#85 asks how to inspect generated prompts when examples fail to produce the expected output format. The documentation now shows the build_chat() → call_and_parse() flow. This addresses prompt inspection; it does not claim to resolve every reported output-format failure.

Testing

  • cargo test -p dspy-rs --no-default-features --test test_lm — 13 passed, including cache isolation between replacement clients and existing clones.
  • cargo test -p dspy-rs --no-default-features --test test_predict_conversation forward_returns_chat_and_prediction — passed.
  • cargo build -p dspy-rs --no-default-features --example 07-inspect-history — passed after the initial history fix.
  • rustfmt --check --edition 2024 crates/dspy-rs/src/core/lm/mod.rs crates/dspy-rs/tests/test_lm.rs crates/dspy-rs/examples/07-inspect-history.rs — passed.
  • git diff --check — passed.

Before the fix, a mocked client-replacement test reproduced the stale response. Tests used mocked providers; live-provider behavior and the full workspace suite were not tested.

AI Disclosure

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

@mintlify

mintlify Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 4ba0016.

Approve preview

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.

[BUG][Medium]- LM cache lifecycle causes history panics and stale responses Running Example 07 fails for me.

1 participant