Skip to content

fix: default L1-Status header for standalone CachekitIO usage#64

Open
27Bslash6 wants to merge 4 commits intomainfrom
fix/cachekitio-standalone-l1-status
Open

fix: default L1-Status header for standalone CachekitIO usage#64
27Bslash6 wants to merge 4 commits intomainfrom
fix/cachekitio-standalone-l1-status

Conversation

@27Bslash6
Copy link
Contributor

Summary

Fix standalone CachekitIO backend to always send X-CacheKit-L1-Status header.

Problem

When _inject_metrics_headers() receives None stats (standalone backend without @cache decorator), it returned an empty dict {}. The SaaS requires X-CacheKit-L1-Status for ck_sdk_* API keys and returns 400 without it.

Additionally, both call sites (_request_sync, _request_async) guarded with if stats is not None, meaning the function was never called for standalone usage — the fix inside the function was dead code.

Fix

  1. _inject_metrics_headers(None) now returns {"X-CacheKit-L1-Status": "disabled"}
  2. Removed if stats is not None guard from both call sites — headers always injected
  3. Updated doctest to match new behavior

Test plan

  • 32 tests passing
  • Expert panel review: code craftsman caught the call site guard bug

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/cachekit/backends/cachekitio/backend.py 0.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

When _inject_metrics_headers() receives None stats (standalone backend
without @cache decorator), return X-CacheKit-L1-Status: disabled instead
of empty dict. Also remove the `if stats is not None` guard at both call
sites (_request_sync, _request_async) so headers are always injected.

Without this fix, standalone usage with ck_sdk_* API keys triggers 400
from the SaaS which requires the L1-Status header.
@27Bslash6 27Bslash6 force-pushed the fix/cachekitio-standalone-l1-status branch from 10440d2 to 09dc062 Compare March 19, 2026 11:33
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.

1 participant