Skip to content

feat(cache): Sprint 29 β€” streaming response cache with SSE replay (v1.9.0) - #6

Merged
wesleyscholl merged 2 commits into
mainfrom
claude/konjo-kyro-aLN93
May 25, 2026
Merged

wesleyscholl merged 2 commits into
mainfrom
claude/konjo-kyro-aLN93

Conversation

@konjoinfinity

Copy link
Copy Markdown
Contributor

Summary

  • New module konjoai/cache/streaming.py β€” StreamChunk, StreamingCacheEntry, StreamingResponseCache, singleton factory (get_streaming_cache)
  • POST /query/stream now checks the streaming cache before running the retrieval pipeline; on a miss it records each token and inter-chunk timing, then stores the complete response after the stream ends
  • On a cache hit, the route returns a StreamingResponse replaying stored SSE frames with cache_hit: true in every frame and configurable inter-chunk pacing (cache_stream_replay_delay_ms)
  • 3 new config fields (all False/0 by default β€” K3):
    • cache_stream_enabled β€” master switch
    • cache_stream_replay_delay_ms β€” fixed sleep between replayed chunks (0 = no sleep)
    • cache_stream_max_chunks β€” safety cap; oversized responses are not stored
  • 38 new tests covering models, lookup/store/replay, singleton factory, and route hit/miss/disabled paths

Invariant compliance

Gate Status
K1 β€” no silent failures store() wraps inner cache write in try/except; logs warning, never raises
K3 β€” graceful degradation get_streaming_cache() returns None when either cache_enabled or cache_stream_enabled is False; route falls through to full pipeline
K4 β€” dtype contract Dedicated SemanticCache inner instance asserts q_vec is float32 at store()
K5 β€” zero new hard deps asyncio, json, threading, time, dataclasses β€” all stdlib; numpy already required
K6 β€” backward-compatible Existing /query/stream SSE contract is unchanged on miss; cache_hit key absent on miss

Test plan

  • python -m pytest tests/unit/test_streaming_cache.py -v β€” 38 tests pass
  • python -m pytest tests/ -q β€” 1 165 passed, 7 skipped, 0 failures
  • ruff check / ruff format --check β€” clean

https://claude.ai/code/session_0171rxj96JzbbH6JwuMu2zfx


Generated by Claude Code

claude added 2 commits May 24, 2026 17:26
….9.0)

Store complete SSE token sequences on /query/stream cache miss; replay at
configured inter-chunk timing (replay_delay_ms) on cache hit.  The streaming
cache is a dedicated SemanticCache instance (no key collisions with the regular
query cache) gated behind cache_stream_enabled (K3 off by default).

- New module: konjoai/cache/streaming.py
  StreamChunk, StreamingCacheEntry, StreamingResponseCache, singleton factory
- konjoai/api/routes/query.py: streaming cache lookup + chunk recording in
  query_stream(); replay returns StreamingResponse with cache_hit=True frames
- konjoai/config.py: 3 new fields β€” cache_stream_enabled, cache_stream_replay_delay_ms,
  cache_stream_max_chunks (all K3/K5/K6 compliant)
- konjoai/cache/__init__.py: re-export Sprint 29 public symbols
- tests/unit/test_streaming_cache.py: 38 new tests (models, lookup, store,
  replay, singleton, API route hit/miss/disabled)
- Version bump 1.8.0 β†’ 1.9.0

https://claude.ai/code/session_0171rxj96JzbbH6JwuMu2zfx
@wesleyscholl
wesleyscholl marked this pull request as ready for review May 25, 2026 02:59
@wesleyscholl
wesleyscholl merged commit 10aaea9 into main May 25, 2026
7 checks passed
@wesleyscholl
wesleyscholl deleted the claude/konjo-kyro-aLN93 branch May 25, 2026 02:59
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.

3 participants