pi ports prompt cache warming to p2: shared pi-ai helpers and a hook-only warming plugin
Pi merged a single pull request across November 7 and 8, and it is a feature: #11857, authored by mitsuhiko (Earendil’s co-founder) and merged on November 8, brings pi to seventy-eight merges since v1.5.0 shipped on November 2. It ports the prompt cache warming that pi-coding-agent has run since v0.86.0 over to p2, the repository’s experimental self-hosted Pi Durable UI, and the policy travels through a new shared layer rather than a copy. Every behavioral claim below comes from the PR’s own body, and the three-way file split matches its changed-file list.
The PR opens with the cost case. p2 speaks to Anthropic — and to Claude models on Radius — under a five-minute prompt cache that nothing refreshed, so any request after a gap of more than 305 seconds rewrote the full prompt. Across p2’s sessions from October 12 through November 5 the body counts 789 such rewrites, about $1,430 extra, 26 percent of p2’s spend; its worked example is a coordinator that waits eleven minutes for subagent reports and then pays to write 579k tokens again ($2.80). Replaying pi-coding-agent’s warming policy over the same request log, the PR estimates, would have moved p2’s cache read-plus-write spend from $4,674 to roughly $3,618.
The plumbing splits three ways. packages/ai gains src/cache-warming.ts, where the policy leaves pi-coding-agent as shared helpers — getPromptCacheTtlMs, getCacheWarmingDelayMs, isCacheWarmingReplayable, getCacheWarmingRequestOptions and evaluateCacheWarming, plus the CACHE_WARMING_* constants — and pi-coding-agent’s CacheWarmer now calls them with no behavior change; pi-durable is untouched. In p2, the Harness’s Models proxy opened by openHarness() starts remembering each streamSimple request by the message its result() resolved with, and HarnessParts.requestOf(message) hands it back once as a ModelRequest: the model, the messages after beforeRequest, and the options stripped of that attempt’s signal, telemetry and onPayload. Compaction summaries and the refreshes themselves go through completeSimple and are not remembered.
The warming runs in a new plugins/cache-warming, a hook-only Durable extension holding one warming run per conversation. afterResponse looks the request up with requestOf and starts — or replaces — the conversation’s run; each refresh resends the request with a one-token output budget, no retries and disableContinuation, and its usage is booked into the conversation’s pi.usage. The policy is pi’s: refresh at 90 percent of the TTL, for up to 60 minutes while a run streams and 30 minutes after it settles, and only when the expected savings reach at least $0.05. A phase check gates every refresh — none while pi.live.generation exists, streaming while pi.live.run exists, idle otherwise and only for top-level conversations, so settled subagents and one-shot agents are never warmed — and warming stops outright once the next request would start differently: another model, or a context that no longer begins with the sent messages (reset, compaction). A new cacheWarming setting ships with idle as p2’s default alongside streaming and off, switches live through ExtensionSwitches, and the worker stays alive while a run is armed under a new cacheWarming liveness kind.
Radius itself is untouched by the diff: its gateway’s /v1/config already declares promptCache windows — short 300, long 3600 — for the Claude 4.8 and 5.x models, so pi-coding-agent and p2 warm them alike, while the Claude 4.5 models on Radius declare none, which the PR calls correct, since budget thinking cannot be replayed with maxTokens: 1. What did not make the cut: pi’s /session warming-status line and its cache_warming_decision override hook. The merge sits on main awaiting the release after v1.5.0 — the newest tag (November 2) predates it — and the PR’s own test notes flag that the full apps/p2 suite was not run.