feat: optional result cache (off by default, never persists keys) — closes #6#37
Merged
Conversation
Adds an opt-in on-disk result cache (PDD §9 #4 / issue #6) so repeated and eval runs are cheap. Off by default; enabled via config (cache: true) or the --cache/--no-cache CLI flag. The cache key is a SHA-256 over the normalized prompt, ordered council members (friendly name + resolved model id), mode, synthesizer/judge identity, and mode params (temperature, debate rounds, adversarial proposer). Member order is preserved because debate/adversarial ordering affects output. Security posture: no env-var value or name reaches the cache key or the stored payload; the only os.environ read in cache.py is XDG_CACHE_HOME (a path). The stored payload is CouncilResult.model_dump(mode=json), which carries no secrets. A security test sets a fake key and asserts it appears in neither the key nor the on-disk artifact. Storage: one JSON file per entry under $XDG_CACHE_HOME/conclave (else ~/.cache/conclave), written atomically via temp+replace. A corrupt/unreadable entry is treated as a miss (logged), never a crash; write failures degrade to a live run. call_model's never-raises invariant and BYO-keys posture are untouched. Cache hits are signaled via a new CouncilResult.cached bool (default False). closes #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements issue #6 / PDD §9 #4: an opt-in result cache keyed on
(prompt, council, mode, model ids)so repeated and eval runs are cheap. Off by default. Never persists API keys.Behavior
cache: trueor--cache).cache: bool = FalseonConclaveConfig--cache/--no-cache(default unset → defers to config)Council(..., cache: bool | None = None)— explicit arg overrides configCouncilResultwith new fieldcached=Trueand does not call the providers.ask(synthesize/raw),debate, andadversarial.Cache key
SHA-256 over a canonical JSON document of only output-affecting, secret-free identity:
normalized prompt · mode · ordered
(friendly_name, resolved_model_id)member pairs · synthesizer/judge name + resolved id · temperature ·rounds(debate) ·proposer(adversarial).Member order is preserved, not sorted: for synthesize/raw order is irrelevant, but debate assigns letter labels by position and adversarial defaults the proposer to the first member — so preserving order is the conservative, always-correct choice.
Storage
One JSON file per entry under
$XDG_CACHE_HOME/conclave(else~/.cache/conclave), written atomically (temp +replace). Payload isCouncilResult.model_dump(mode="json")— no secrets. A corrupt/unreadable entry is a miss (logged), never a crash; write failures degrade to a live run.call_model's never-raises invariant and the BYO-keys posture are untouched.Security
The only
os.environaccess incache.pyisXDG_CACHE_HOME(a path). No key value or env-var name reaches the cache key or the stored payload. A dedicated test sets a fake key and asserts it appears in neither the key string nor the on-disk artifact.Tests
--cache/--no-cacheend-to-endmake_keyunit checks (determinism, order-sensitivity, whitespace normalization)142 tests pass (126 before → +16),
ruff checkclean,ruff format --checkclean.Files
src/conclave/cache.py(new),src/conclave/{models,config,council,cli}.py,tests/test_cache.py(new),tests/test_cli.py,README.md,config.example.yml.Do not merge — orchestrator reviews and merges.