Skip to content

openai runtime: prompt cache hits are bimodal — add per-session cache routing affinity #82

Description

@Yevanchen

Evidence (staging, 33 ping runs, gpt-5.5, identical per-session prompts)

Per-run cache_read_tokens from the mosoo usage ledger (runs 27–55s apart, well inside the OpenAI prefix-cache TTL):

  • stack A: [0×5, 10112, 0×6, 12160, 0, 12160, 0] — 3/16 hits
  • stack B: [0×5, 10112, 0×4, 12160, 0×6] — 2/17 hits
  • When a hit occurs it is near-full (10,112–12,160 of ~12,400 input tokens) → the prompt prefix is byte-stable; prefix hygiene is not the problem.
  • Aggregate hit rate is only 10–17%, versus 99.98% on the anthropic runtime (Agent SDK automatic caching) for the equivalent workload.

Hypothesis

Identical-prefix requests are being dispersed across OpenAI inference shards, so most requests miss a warm prefix cache that provably exists. OpenAI's automatic caching improves dramatically with a routing affinity hint (prompt_cache_key, previously the user field).

Ask

Give the openai runtime a stable per-session cache routing key:

  1. Check whether the pinned app-server (OPENAI_RUNTIME_VERSION=0.144.0) exposes prompt_cache_key / user in its config or protocol — the driver's generated protocol types currently contain no cache-related field, so this may require a version bump or an upstream request.
  2. If exposed: plumb a stable value (e.g. the mosoo session/thread id) from the boot payload into the app-server config; no prompt content changes.
  3. Re-measure the per-run cache_read_tokens distribution: expectation is near-100% hits within TTL.

Value

Primarily cost: each ping run pays ~12.4k input tokens at full price on a miss (−50%+ on the cached share at scale). Latency impact on gpt-5.5 is secondary — measured first-token windows were already ~0.4–1.5s even on misses.

Refs: langgenius/mosoo#387 (direction 2), staging artifact warm-ping-openai-v31-16pairs-20260724.json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions