Skip to content

fix(usage): preserve source-aware cache evidence across attempts - #7485

Closed
yuanyuanlove wants to merge 1 commit into
lidge-jun:devfrom
yuanyuanlove:feature-20261021-cache-evidence
Closed

yuanyuanlove wants to merge 1 commit into
lidge-jun:devfrom
yuanyuanlove:feature-20261021-cache-evidence

Conversation

@yuanyuanlove

@yuanyuanlove yuanyuanlove commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Preserve allowlisted cache evidence from upstream and adapter observations through physical attempts, multi-round guards, ledger reloads and filtered summaries. Explicit upstream zero remains observed; omitted fields, malformed evidence and client-defaulted counters do not become measurements.
  • Keep canonical cache reads separate from cache creation: 40 read + 10 write remains 40 read. Historical combined-cache records keep their existing compatibility recovery. Only complete observed reads and their matching inputs contribute to hit rates; partial totals remain visible.
  • Exclude unsent usage-free candidates, retain missing physical-send gaps across recovery/account rotation, and prevent an unresolved final send from borrowing earlier usage for settlement. Preserve the latest raw diagnostic observation separately from aggregate evidence.
  • Cover Anthropic, native Responses JSON/SSE/compact, native-control chains, Advisor/empty/terminal guards and web-search loops. Internal metadata does not enter client wire payloads. Existing cache diagnostics remain opt-in and off by default.

No routing, compression, provider policy or performance claim is included. This is an accounting correctness change, independent of the optional continuation-diagnostics enhancement.

Verification

All implementation, tests and compilation ran in an isolated Linux cloud workspace with Bun 1.4.3. No live model/provider calls were made; transport fixtures use synthetic upstreams.

  • 553 focused tests passed across 21 files: the new cache-telemetry evidence/attempt/flow/HTTP/native-seam/guard tests; Anthropic evidence and existing error/thinking-usage tests; Advisor evidence/retention; existing empty/terminal guards; cache diagnostics, key attribution, request logs, spend-cache provenance, usage summaries; web-search evidence/iteration/error usage.
  • 88 additional existing native steering, native injection and OpenGateway receipt tests passed.
  • bun run typecheck, bun run privacy:scan, bun run structure:check passed.
  • bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts tests/lab/core-lab-boundary.test.ts: 61 passed; no ratchet caps raised.
  • bun build src/cli/index.ts --target bun and native bun build src/cli/index.ts --compile succeeded. The compiled CLI's isolated --version smoke returned opencodex 2.91.0. This is backend/CLI compilation, not a GUI or release-package build.
  • Offline docs build passed with ASTRO_TELEMETRY_DISABLED=1 OPENCODEX_DOCS_OFFLINE=1 bun run build from docs-site: 585 pages, 83,068 internal links checked.
  • Independent read-only code review and full-range git diff --check passed. A disposable union with the independent optional-diagnostics branch passed focused tests, type/privacy/structure/layout/ratchet checks and native compilation; two adjacent diagnostic/doc conflicts were resolved there by retaining both changes, not in either independent PR branch.

Remaining coverage: keep this draft. test:changed could not start its selected tests because its automatic missing-GUI-dependency installation was blocked in the validation environment. Two broader existing server/compaction slices attempted inherited proxy transports before their global fetch mocks, so those runs were stopped and are not claimed passing. The full suite, packaged GUI and native macOS/Windows execution were not run. The repository's focused-validation resource/scope exception is used; current-head CI and maintainer review are still required.

Related open work reviewed for overlap: #7436 (committed-child/Kiro usage evidence), #7473 (prompt-cache-key source semantics), #7308 (prefix/renewal behavior). No commits from those or existing contributor branches are included.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.
  • Full/current-head CI and maintainer review completed.

Publication baseline

This unchanged 47-file candidate was validated on d82b2173eb1c5ffb28bc145f20e24a5466910b73. Before publication, dev advanced to cf9965c3f647c45901498358e2d25ddd5df74e07 via #7480 (dependency-security updates to the root/GUI manifests and lockfiles only). Those four files do not overlap this PR. The focused results above describe this tested candidate, not a rerun against the updated dependencies; current-base CI is still required.

Companion optional diagnostics draft: #7479.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@lidge-jun

Copy link
Copy Markdown
Owner

Thank you for the work here. We're closing this to keep the review queue manageable: it conflicts with dev at a size we can't review as one change. You're welcome to reopen this or open a smaller PR against dev.

@lidge-jun lidge-jun closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants