AI
Microsoft Foundry: diagnose prompt cache misses before adding model capacity
A production runbook for separating prompt-prefix drift, tool catalog churn, cache-key fragmentation and real model saturation before scaling capacity or rolling back an agent release.
An operations agent becomes slower and more expensive immediately after a tool catalog release. Request volume, answer quality and completion size remain stable, but input processing grows and p95 latency crosses the production objective. Increasing model capacity looks like the safe response.
Capacity may not be the constraint. Prompt caching reuses computation only when a sufficiently long leading prefix matches. A reordered system instruction, a volatile timestamp inserted too early, a tool schema generated in a different order or an unstable cache key can turn one reusable prefix into thousands of variants. Scaling then pays for the fragmentation without correcting it.
The running case is a Microsoft Foundry operations agent using Azure OpenAI models, a stable system policy, several read-only tools and a structured response schema. This runbook determines whether the release caused cache misses, whether the deployment is genuinely saturated, and whether to promote, correct or roll back.
Freeze the serving and cache contract
Keep the current release available for evidence, but stop its rollout. Route a small control slice to the last known-good release and disable unrelated prompt, model, SDK and tool changes. Record the complete contract that can affect the request prefix.
incident: INC-AI-1162
window_utc: 2026-11-15T06:20:00Z/2026-11-15T07:05:00Z
serving:
foundry_project: <project-reference>
deployment: ops-agent-prod
model: <model-and-version>
api_surface: <responses-or-chat-completions>
region: <region>
releases:
control: ops-agent-2026.11.13.4
candidate: ops-agent-2026.11.15.1
prompt_digest_control: <sha256>
prompt_digest_candidate: <sha256>
tool_catalog_control: ops-tools-v52
tool_catalog_candidate: ops-tools-v53
output_schema_control: incident-report-v7
output_schema_candidate: incident-report-v7
evidence:
request_count: <count>
prompt_tokens: <sum>
cached_tokens: <sum>
cache_write_tokens: <sum-or-not-exposed>
latency_p50_ms: <value>
latency_p95_ms: <value>
throttled_requests: <count>
deployment_utilization: <metric-reference>
rollback:
route_to_release: ops-agent-2026.11.13.4
tool_catalog: ops-tools-v52 Do not label a request as cached from latency alone. Use the token usage returned by the API. cached_tokens is the direct per-request signal; cache_write_tokens is available only on supported model and deployment combinations. Preserve absent fields as absent instead of converting them to zero.
Measure cache reuse by release and prompt family
An estate-wide average hides the release boundary. Calculate cached input as a share of eligible prompt tokens for the control and candidate, then split by agent release, deployment, route, tool catalog and a non-sensitive prompt-family identifier.
let start = datetime(2026-11-15T06:20:00Z);
let stop = datetime(2026-11-15T07:05:00Z);
customEvents
| where timestamp between (start .. stop)
| where name == "agent.model.completed"
| extend release = tostring(customDimensions.agent_release),
deployment = tostring(customDimensions.model_deployment),
promptFamily = tostring(customDimensions.prompt_family),
promptTokens = tolong(customMeasurements.prompt_tokens),
cachedTokens = tolong(customMeasurements.cached_tokens),
durationMs = todouble(customMeasurements.duration_ms),
throttled = tobool(customDimensions.throttled)
| summarize requests=count(),
prompt_tokens=sum(promptTokens),
cached_tokens=sum(cachedTokens),
p95_ms=percentile(durationMs, 95),
throttles=countif(throttled)
by bin(timestamp, 5m), release, deployment, promptFamily
| extend cache_reuse_ratio = iff(prompt_tokens > 0,
todouble(cached_tokens) / todouble(prompt_tokens), real(null))
| order by timestamp asc Adapt table and field names to the instrumentation in use. Never log the raw prompt or cacheable prefix merely to debug caching. A keyed digest, token count, catalog version and ordered component list are enough to compare request construction without copying production content into telemetry.
Also separate cache misses from saturation. A cache-reuse drop with stable request rate and no throttling points to request construction. High utilization, queue time or throttling on both control and candidate can justify a capacity decision, but only after the same prompt family is compared.
Prove whether the leading prefix is stable
Prompt caching is based on exact leading content, not semantic equivalence. For supported Azure OpenAI models, an eligible request needs at least 1,024 input tokens and the first 1,024 tokens must match. A single early difference can remove the initial cache hit even when an operator considers both prompts identical.
Build a canonical manifest before sending the request. Hash each component after the same serialization used by the client, while retaining only safe metadata.
{
"request_id": "req-7f2c",
"agent_release": "ops-agent-2026.11.15.1",
"prompt_family": "ops-triage-readonly-v18",
"total_input_tokens": 6842,
"ordered_prefix_components": [
{"name": "system_policy", "sha256": "<digest>", "bytes": 9210},
{"name": "developer_policy", "sha256": "<digest>", "bytes": 1840},
{"name": "tool_definitions", "sha256": "<digest>", "bytes": 12740},
{"name": "structured_output_schema", "sha256": "<digest>", "bytes": 2210}
],
"dynamic_content_starts_after": "structured_output_schema",
"prompt_cache_key_hash": "<keyed-digest>"
} Compare one healthy control request and one candidate request for the same test input. Find the first component and byte offset that differs. Typical causes are:
- a request ID, timestamp, locale or feature flag inserted before stable instructions;
- nondeterministic ordering of tool definitions, JSON properties or enum values;
- generated tool descriptions containing deployment-specific URLs;
- a structured output schema that changes order on each process start;
- conversation history prepended instead of appended;
- two request builders producing different whitespace or escaping.
Tool definitions and structured output schemas participate in the cacheable input. A tool catalog release can therefore change cache behavior even when no system prompt file changed.
Separate cold cache, fragmentation and eviction
A miss immediately after deployment is not automatically a regression. Classify the pattern before editing the prompt.
Cold cache produces misses at the beginning of a stable stream, followed by reuse for the same prefix. Prefix fragmentation produces many low-volume digests that never accumulate reuse. Eviction or idle expiry shows reuse followed by a gap and a new warm-up. Ineligible requests stay below the relevant input length and should not be included in the expected-hit denominator.
customEvents
| where timestamp > ago(2h)
| where name == "agent.model.completed"
| extend release = tostring(customDimensions.agent_release),
family = tostring(customDimensions.prompt_family),
prefix = tostring(customDimensions.prefix_digest),
inputTokens = tolong(customMeasurements.prompt_tokens),
cachedTokens = tolong(customMeasurements.cached_tokens)
| where inputTokens >= 1024
| summarize requests=count(),
cache_hits=countif(cachedTokens > 0),
first_seen=min(timestamp),
last_seen=max(timestamp)
by release, family, prefix
| summarize prefixes=dcount(prefix),
singleton_prefixes=countif(requests == 1),
requests=sum(requests),
cache_hits=sum(cache_hits)
by release, family
| extend hit_request_ratio = todouble(cache_hits) / todouble(requests)
| order by singleton_prefixes desc Do not compare low-traffic canary reuse directly with a busy control. Replay a bounded, production-shaped sequence so both releases see the same prompt families, order and spacing.
Inspect the cache key without making it a bucket
Where the selected model and API support prompt_cache_key, use it to keep requests with a common prefix mapped consistently. The key does not make different prefixes equivalent and must not encode a user ID, raw prompt or secret.
Check key cardinality and stability. A random value per request prevents reuse. One global key for unrelated prefixes creates contention and an unreadable operational contract. Derive a bounded key from stable, non-sensitive dimensions such as agent family, policy version and tool catalog version, then log only its digest.
If the client or deployment does not support an explicit cache key, omit it. Do not introduce an undocumented parameter during an incident to chase a metric.
Canary the corrected request builder
Create a candidate that changes request construction only. Keep model, deployment, API, instructions, tools, output schema and test sequence fixed. Move volatile content after stable components, use deterministic serialization and preserve the append-only order of conversation messages.
Run three controls:
- Repeat one long request to prove warm-up followed by reuse.
- Alternate two known prompt families to prove isolation and stable mapping.
- Change one tool schema intentionally to prove the expected miss, then confirm reuse on repetition.
Compare cache reuse, p50 and p95 latency, input cost, throttling and output equivalence. Prompt caching should reduce repeated input processing; it must not become an explanation for a response-quality change. If outputs differ materially, investigate the effective prompt, tools, model and sampling parameters.
Decide: promote, correct, scale or roll back
Promote the release when the prefix manifest is deterministic, the canary warms as expected, latency returns inside the objective and quality and safety gates remain green.
Correct the request builder when volatile metadata, ordering or key cardinality explains fragmentation. Keep the correction isolated from prompt semantics and rerun the same evidence set.
Scale model capacity only when comparable control and candidate traffic show real utilization, queueing or throttling after cache behavior is understood. Record whether the sizing model assumes a cache reuse rate; otherwise the next prefix change will invalidate it again.
Roll back when the candidate cannot reproduce a stable prefix, cost or latency exceeds the incident budget, or the correction would require an untested SDK, API or model change. Restore the previous application release and tool catalog together if their serialization contracts are coupled.
Validate after rollout or rollback
Observe at least one full traffic cycle. Confirm cache reuse by prompt family rather than only globally, stable prefix and key cardinality, latency percentiles, throttles, token cost and quality gates. Retain the control slice until the candidate has warmed under representative concurrency.
Finally, add a release check that generates the same request twice and compares its safe prefix manifest. This does not guarantee a service-side hit, but it catches the deterministic failures the application owns before production.
Conclusion
A prompt cache miss is usually a contract signal, not a capacity verdict. By tying token usage to a deterministic prefix manifest, tool catalog, schema and release, the team can distinguish normal warm-up from fragmentation and real saturation. The operational decision then becomes defensible: promote a stable builder, correct one moving component, add justified capacity or roll back the complete request contract.