Browse documentation

Technical documentation / Reference

Prompt-cache audit scripts

Feature docs index · Repository README

Purpose

Maintainer scripts under scripts/ check prompt-cache readiness without changing provider runtime code. The static audit is offline by default. The live checker requires explicit opt-in for networked cold/warm experiments.

Static audit: scripts/audit_prompt_cache.py

Use this script before and after prompt-cache provider work:

python3 scripts/audit_prompt_cache.py --repo .
python3 scripts/audit_prompt_cache.py --repo . --json > /tmp/magi-code-prompt-cache-audit.json
python3 scripts/audit_prompt_cache.py --repo . --strict
python3 scripts/audit_prompt_cache.py --self-test

Checks cover:

Status meanings:

StatusMeaning
PASSRequired static evidence exists.
FAILRequired implementation evidence is missing or contradicted.
WARNEvidence is incomplete, provider-specific, or optional outside strict mode.
N/ACheck does not apply to the detected provider shape or local recorder.

Exit codes:

ExitMeaning
0Audit completed with no FAIL findings. WARN allowed unless --strict is set.
1Audit completed with FAIL findings, or --strict promoted WARN to failing exit semantics.
2Usage error, missing/unreadable source file, invalid fixture/body data, or self-test failure.

--json emits one object with schema_version, repo, generated_at, overall_status, strict, and findings. Each finding includes stable fields such as id, status, severity, category, provider, file, symbol, evidence, expected, impact, suggested_fix, and references.

Use the audit output for findings on the checked revision rather than a fixed result count. context_cache.separation is N/A when no automatic disk snapshot recorder is found; retained local cache readers are not provider prompt-cache evidence. A codex.cache_scope failure means the audit did not find its recognized cache-scope field, not that live Codex caching fails.

Implemented static evidence includes:

Chat Completions bodies intentionally do not emit prompt_cache_key; only Responses-compatible request shapes receive that field.

Do not interpret PASS findings as proof of live provider cache hits. The static audit proves source evidence only; Codex cache scope remains unresolved.

Live checker: scripts/check_prompt_cache_live.py

Use this script only when you intentionally want a networked provider check:

python3 scripts/check_prompt_cache_live.py --help
python3 scripts/check_prompt_cache_live.py \
  --url https://example.invalid \
  --shape responses \
  --body-file scripts/fixtures/prompt_cache_audit/live_offline_body.json
python3 scripts/check_prompt_cache_live.py \
  --allow-network \
  --url "$URL" \
  --shape responses \
  --body-file /tmp/prompt-cache-live-body.json \
  --bearer-env OPENAI_API_KEY \
  --repeat 2 \
  --expect-warm-cache

Safety behavior:

Supported shapes:

ShapeUsage fields checked
responsesusage.input_tokens_details.cached_tokens, response.usage.input_tokens_details.cached_tokens, root and nested cache-write locations
chat-completionsusage.prompt_tokens_details.cached_tokens, usage.prompt_tokens, usage.completion_tokens, usage.total_tokens
codexResponses-style SSE/JSON fields plus Codex headers supplied through safe env flags; cache-key backend contract remains unverified.

Exit codes:

ExitMeaning
0Invocation and expectations succeeded.
2Usage, offline gate, body, header, or self-test error.
3Network/auth/provider response failure, or --expect-warm-cache found no positive cached-token field on warm attempt.

Verification

Credential-free checks:

python3 scripts/audit_prompt_cache.py --help
python3 scripts/check_prompt_cache_live.py --help
python3 scripts/audit_prompt_cache.py --self-test
python3 scripts/check_prompt_cache_live.py --self-test
python3 scripts/audit_prompt_cache.py --repo .
python3 scripts/audit_prompt_cache.py --repo . --strict
python3 scripts/audit_prompt_cache.py --repo . --json

Any FAIL finding makes both normal and strict audits exit 1. With no FAIL findings, WARN exits 0 normally and 1 under --strict. Static findings do not establish live provider cache behavior; missing recognized cache-scope evidence is not proof that live Codex caching fails.


Back to feature docs · Back to repository README

Edit this page on GitHub ↗