Skip to content

fix(provider): preserve prompt-cache hits during batch lookup - #1639

Merged
Gajesh2007 merged 1 commit into
masterfrom
codex/prompt-cache-batch-hits
Oct 28, 2026
Merged

Gajesh2007 merged 1 commit into
masterfrom
codex/prompt-cache-batch-hits

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

CI remains incomplete. Provider SDK Tests, docs and release-integrity checks passed on this commit. The original unit run and one retry each passed all 5,812 general tests in 808 suites (803.7 s and 807.6 s), then the 900-second watchdog stopped the remaining isolated suites. No assertion failure appears in either captured general run; this does not establish a clean full unit gate. The prompt-parity retry failed during fixture provisioning with artifact size or SHA-256 mismatch, before public golden-vector tests; the separate Nemotron parity tests passed. External deployment and sandbox-receipt checks also remain unresolved. No watchdog or fixture-integrity checks were weakened. The retry completed: its separate native startup, memory/media admission, complete-prefix, retained-fault, lifecycle and audio gates passed. Locally, the first two isolated suites left unfinished by the watchdog (SSDShorterNativeBlockRestoreTests and SSDNativeCheckpointOracleTests) also passed in fresh processes on this exact commit: four tests, with the pinned source-matched Metal library. This additional evidence does not replace the incomplete full unit gate.

Batch prompt-token lookup can evict entries that the same request has not looked up yet. With a 4,096-byte budget, 25 pieces occupy only 4,000 bytes; promoting the first old-generation hit rotates the cache and makes twelve other resident pieces miss. Those pieces are needlessly tokenized again.

Snapshot the batch's hits under the existing lock before any promotion, then apply the existing bounded admission policy. Swift arrays share their token storage. Batches without old-generation hits skip the promotion pass. Cache scopes, tokenizer output, flags and byte limits are unchanged.

Before

flowchart TD
  A["Request: batch of prompt pieces"] --> B["lookup: read first old hit"]
  B --> C["admit: rotate young into old"]
  C --> D["Unread old entries disappear"]
  D --> E["Later pieces miss and tokenize again"]
  classDef input fill:#dbeafe,stroke:#2563eb,color:#172554;
  classDef code fill:#fef3c7,stroke:#b45309,color:#451a03;
  classDef loss fill:#fee2e2,stroke:#b91c1c,color:#450a0a;
  class A input;
  class B,C code;
  class D,E loss;
Loading

After

flowchart TD
  A["Request: batch of prompt pieces"] --> B["lookup: snapshot every hit under lock"]
  B --> C{"Any old-generation hit?"}
  C -->|Yes| D["Promote with existing bounded admission"]
  C -->|No| E["Return snapshot"]
  D --> E
  E --> F["Reuse every hit present at batch entry"]
  classDef input fill:#dbeafe,stroke:#2563eb,color:#172554;
  classDef code fill:#fef3c7,stroke:#b45309,color:#451a03;
  classDef kept fill:#dcfce7,stroke:#15803d,color:#052e16;
  class A input;
  class B,C,D code;
  class E,F kept;
Loading

Validation:

  • Additional local public golden-vector qualification passed on this exact commit: the unmodified fixture provisioner downloaded all seven pinned manifests with strict size/SHA-256 verification, then PROMPT_PARITY_REQUIRED=1 ... swift test --skip-build --no-parallel --filter ProductionPromptParityTests passed (one suite/test, 14.5 s). This is the existing service/tokenizer/contract/vector check; its pipeline calls omit promptCacheScope, so it is not additional coverage of warm scoped token caching. The twenty focused tests above provide the cache-specific proof. No model weights or live cross-implementation service were used.
  • The generation-rotation regression fails against the original implementation: twelve resident hits become nil. It passes with the fix.
  • 20 selected Swift tests pass across PromptTokenCacheTests, ChatTemplateLoopRewritesTests and InboundChatRequestDecodeTests. Coverage includes exact token equivalence with synthetic Qwen/GPT-2/Gemma tokenizers, duplicate keys, true misses, multiple rotations, accounting, subsequent eviction and batches without old hits.
  • Command: swift test --package-path provider-swift --build-system native --scratch-path /private/tmp/darkbloom-prompt-cache-01a1809c --jobs 4 --filter 'PromptTokenCacheTests|ChatTemplateLoopRewritesTests|InboundChatRequestDecodeTests'.
  • make docs-impact-check BASE=origin/master, make docs-check, make changelog-check, make changelog-preview and git diff --check pass.
  • Dedicated independent refactor review completed. It added the no-promotion fast path and strengthened multi-rotation/accounting coverage; no unresolved findings.

No interface or migration changes. This demonstrates avoided tokenizer work; it does not claim a measured end-to-end latency gain. Optional real-model fixtures were unset, and the full GPU suite was not run. The native Swift build system and isolated scratch directory were used after the default Desktop build encountered code-signing filesystem-detritus errors.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Error Error Oct 28, 2026 9:43pm UTC
d-inference-console-ui-dev Error Error Oct 28, 2026 9:43pm UTC
d-inference-landing Ready Ready Preview Oct 28, 2026 9:43pm UTC
darkbloom-status Ready Ready Preview Oct 28, 2026 9:43pm UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 28, 2026 9:43pm UTC

Request Review

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 31730f8c953d against base 300134d24a09.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Review in progress; coverage is not complete

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 19/37 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

Bedrock: 7 request(s), 334213 uncached + 0 cache-read + 0 cache-write input / 4206 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately.
Workload allowance: 14 native request(s), including one shared response repair; 500 emergency ceiling. Selected depth and integration rounds are admitted as their scope becomes known.

@Gajesh2007
Gajesh2007 merged commit ad44c47 into master Oct 28, 2026
21 of 23 checks passed
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 28, 2026
Freshness refresh: master gained #1637, #1639, #1640, #1646 and #1655. The merge has no conflicts and leaves the SDK pin unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 29, 2026
Brings in the SSD cache changes merged since this branch's base (#1642,
#1647, #1648, #1649, #1651) plus #1639, #1640 and #1646. The only conflict
was the docs/reference/ssd-kv-cache.md table: keep this PR's victim
selection row and master's updated maintenance sweep row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch had an error being deployed

2 failed and 3 active deployments
Preview – d-inference-landing — 31730f8c Deployed Oct 28, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 31730f8c Deployed Oct 28, 2026 by vercel[bot]
Preview – darkbloom-status — 31730f8c Deployed Oct 28, 2026 by vercel[bot]
Preview – d-inference — 31730f8c Deployed Oct 28, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 31730f8c Deployed Oct 28, 2026 by vercel[bot]
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.

2 participants