agent-dispatcher: keep Pi residents on a warm prompt cache (KSE-0213 L) #514

Merged
founder merged 1 commit from resident-prompt-cache into main 2026-11-18 03:19:28 +00:00
Owner

KSE-0213 Amendment L (founder, 2026-11-17: "Let's do both"; "I want a high hit rate … use as many pi standards and defaults as possible").

Why the cache was cold

24 h of resident_usage: 2,198 calls, 157 M prompt tokens, 31% cached; 1,059 calls cached under 1,000 tokens. Calls 3 s apart inside one turn alternated between a near-full hit (85,489 of 86,204) and 113 tokens, so the prefix was byte-stable and the misses were routing.

Probe against the production key and provider policy (30k-token prefix, identical requests, about $0.05):

field sent cached tokens after the first request
nothing 0 × 5
x-session-id (pi-ai's OpenRouter default) 0, 0, 0, 30,193, 0
session_id body / user 0 × 6 each
prompt_cache_key 29,425 × 6

A growing conversation with prompt_cache_key hit the whole previous prompt on every call, also after 60 s, 300 s and 600 s gaps. Meta reports no cache writes; OpenRouter lists one endpoint, so only prompt_cache_key (forwarded to Meta) gives replica affinity. Cached prompt tokens cost about 2% of uncached ones (fit over 2,020 calls: $0.10 vs $0.002 per M).

Other prefix breaks found in the session journals: the owned-work data message sat at index 1 and changed at the start of nearly every turn; Pi compactions (64/day for infra) rewrite the head; a steer placed during a request lands a few messages from the end (Pi's boundary semantics, kept). The tool catalogue and the system text were stable.

Changes

  • Worker forwards Pi Durable's provider session ID (ProviderDoc, per conversation, durable) as session_id exactly when pi-ai would (cache retention not none, so never for the summariser).
  • Host validates it (^[A-Za-z0-9_-]{1,64}$) and sends prompt_cache_key plus the x-session-id header on OpenRouter; vanilla routers get neither. Spending policy, provider order, data policy, BYOK and the Extra refusal are unchanged.
  • The owned-work data message follows the conversation (as Pi's own beforeRequest pending context does), so history stays byte-identical.
  • Pi-native compaction uses Pi's DEFAULT_COMPACTION_POLICY where the window holds it (131,072: background from 81,920, blocking from 114,688, keep 20,000), about 15% fewer cache restarts; smaller windows keep Amendment J's fractions.
  • resident_usage.py: prompt_cache_requests_total{cache=hit|partial|miss}, prompt_cache_eligible_tokens_total, prompt_cache_read_tokens_total, prompt_cache_hit_ratio per identity/model/provider/phase.
  • New patch agent-dispatcher-prompt-cache.patch (after chain-of-command), registered in flake.nix, patches/BUILD.bazel, the overlay BUILD.bazel and dispatcher-test.sh. The new Go file needs nothing from the Pi runtime, so the pre-Pi rollback loader still builds (checked).

Pi defaults kept, and each departure

  • Kept: Pi's provider session ID and lifetime, Pi's no-cache summariser, Pi's message and tool order, x-session-id for OpenRouter, Pi's compaction defaults at the production window.
  • Departure: prompt_cache_key on OpenRouter. pi-ai sends it only to api.openai.com or with long retention; the probe shows it is the only field that reaches Meta's replica routing. pi-ai's long retention would also send prompt_cache_retention: "24h"; not sent (600 s gaps already hit).
  • Departure: owned-work data is a trailing user-role data message rather than Pi's trailing system message, because the host drops worker system text (authority boundary).
  • Departure: windows too small for Pi's compaction defaults keep Amendment J's fractions.
  • Departure (unchanged): toolExecution: "sequential", retry.maxRetries: 0. The host owns the sandbox and the policy-classified retries.

Expected effect

Replaying the 24 h with each completion hitting its predecessor's prompt and only the system prompt after a compaction: about 83% cached (from 31%), prompt cost about $2.90/day instead of $10.50. Acceptance after deploy: prompt_cache_hit_ratio{phase="completion"} per identity ≥ 0.75 over 24 h; misses limited to first requests after a compaction or restart.

Verification

  • nix build .#agent-dispatcher (full go test ./..., pre-Pi loader build): ok.
  • nix build .#key-store-resident-pi and its node test suites: all pass, 0 fail.
  • python3 resident_usage_test.py: 5 ok.
  • nix eval forge and HQ toplevel drvPaths: ok.
  • goalert-phase-one-policy prebuilt for this head.

Rollback: revert; nothing is persisted (the key is Pi's existing session ID, the owned message is per request, the policy is read at worker start).

Stacked follow-up: natural turn end (Amendment M).

🤖 Generated with Claude Code

KSE-0213 Amendment L (founder, 2026-11-17: "Let's do both"; "I want a high hit rate … use as many pi standards and defaults as possible"). ## Why the cache was cold 24 h of `resident_usage`: 2,198 calls, 157 M prompt tokens, **31% cached**; 1,059 calls cached under 1,000 tokens. Calls 3 s apart inside one turn alternated between a near-full hit (85,489 of 86,204) and 113 tokens, so the prefix was byte-stable and the misses were routing. Probe against the production key and provider policy (30k-token prefix, identical requests, about $0.05): | field sent | cached tokens after the first request | |---|---| | nothing | 0 × 5 | | `x-session-id` (pi-ai's OpenRouter default) | 0, 0, 0, 30,193, 0 | | `session_id` body / `user` | 0 × 6 each | | **`prompt_cache_key`** | **29,425 × 6** | A growing conversation with `prompt_cache_key` hit the whole previous prompt on every call, also after 60 s, 300 s and 600 s gaps. Meta reports no cache writes; OpenRouter lists one endpoint, so only `prompt_cache_key` (forwarded to Meta) gives replica affinity. Cached prompt tokens cost about 2% of uncached ones (fit over 2,020 calls: $0.10 vs $0.002 per M). Other prefix breaks found in the session journals: the owned-work data message sat at index 1 and changed at the start of nearly every turn; Pi compactions (64/day for infra) rewrite the head; a steer placed during a request lands a few messages from the end (Pi's boundary semantics, kept). The tool catalogue and the system text were stable. ## Changes - Worker forwards Pi Durable's provider session ID (`ProviderDoc`, per conversation, durable) as `session_id` exactly when pi-ai would (cache retention not `none`, so never for the summariser). - Host validates it (`^[A-Za-z0-9_-]{1,64}$`) and sends `prompt_cache_key` plus the `x-session-id` header on OpenRouter; vanilla routers get neither. Spending policy, provider order, data policy, BYOK and the `Extra` refusal are unchanged. - The owned-work data message follows the conversation (as Pi's own `beforeRequest` pending context does), so history stays byte-identical. - Pi-native compaction uses Pi's `DEFAULT_COMPACTION_POLICY` where the window holds it (131,072: background from 81,920, blocking from 114,688, keep 20,000), about 15% fewer cache restarts; smaller windows keep Amendment J's fractions. - `resident_usage.py`: `prompt_cache_requests_total{cache=hit|partial|miss}`, `prompt_cache_eligible_tokens_total`, `prompt_cache_read_tokens_total`, `prompt_cache_hit_ratio` per identity/model/provider/phase. - New patch `agent-dispatcher-prompt-cache.patch` (after chain-of-command), registered in flake.nix, patches/BUILD.bazel, the overlay BUILD.bazel and dispatcher-test.sh. The new Go file needs nothing from the Pi runtime, so the pre-Pi rollback loader still builds (checked). ## Pi defaults kept, and each departure - Kept: Pi's provider session ID and lifetime, Pi's no-cache summariser, Pi's message and tool order, `x-session-id` for OpenRouter, Pi's compaction defaults at the production window. - Departure: `prompt_cache_key` on OpenRouter. pi-ai sends it only to api.openai.com or with long retention; the probe shows it is the only field that reaches Meta's replica routing. pi-ai's long retention would also send `prompt_cache_retention: "24h"`; not sent (600 s gaps already hit). - Departure: owned-work data is a trailing user-role data message rather than Pi's trailing system message, because the host drops worker system text (authority boundary). - Departure: windows too small for Pi's compaction defaults keep Amendment J's fractions. - Departure (unchanged): `toolExecution: "sequential"`, `retry.maxRetries: 0`. The host owns the sandbox and the policy-classified retries. ## Expected effect Replaying the 24 h with each completion hitting its predecessor's prompt and only the system prompt after a compaction: **about 83% cached** (from 31%), prompt cost about $2.90/day instead of $10.50. Acceptance after deploy: `prompt_cache_hit_ratio{phase="completion"}` per identity ≥ 0.75 over 24 h; misses limited to first requests after a compaction or restart. ## Verification - `nix build .#agent-dispatcher` (full `go test ./...`, pre-Pi loader build): ok. - `nix build .#key-store-resident-pi` and its node test suites: all pass, 0 fail. - `python3 resident_usage_test.py`: 5 ok. - `nix eval` forge and HQ toplevel drvPaths: ok. - goalert-phase-one-policy prebuilt for this head. Rollback: revert; nothing is persisted (the key is Pi's existing session ID, the owned message is per request, the policy is read at worker start). Stacked follow-up: natural turn end (Amendment M). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
agent-dispatcher: keep Pi residents on a warm prompt cache (KSE-0213 L)
Some checks failed
Release: If Needed / Check (Release Needed) (push) Successful in 6s
Deploy: API / Evaluate deploy impact (push) Successful in 6s
Deploy: Web / Evaluate deploy impact (push) Successful in 6s
Build: Snap / Build (Snap amd64) (push) Successful in 2m26s
Check: Agent Dispatcher / Check (Dispatcher Bazel integration) (push) Successful in 3m6s
Deploy: API / Deploy (API) (push) Successful in 4m24s
Check: API / Check (API crate) (push) Successful in 5m33s
Check: Workflows / Check (CI performance contracts) (push) Successful in 5m35s
Namespace: Build Images / Refresh Flatpak image (amd64) (push) Successful in 11m42s
Namespace: Build Images / Refresh Flatpak image (arm64) (push) Failing after 11m57s
Build: Android / Build (Android) (push) Successful in 10m32s
Deploy: Web / Deploy (Web) (push) Successful in 14m6s
Check: NSC Dispatch Boundary / Check (Private dispatch and reviewed runner profiles) (push) Failing after 13m46s
Check: Redmine / Check (Redmine conditional writes) (push) Failing after 13m55s
Build: Linux / Build (Linux x86_64) (push) Successful in 16m9s
Build: Linux / Build (keystore-forge x86_64) (push) Has been skipped
Build: KaiOS / Build (KaiOS) (push) Failing after 18m52s
Build: Snap / Build (Snap arm64) (push) Successful in 21m9s
Release: Signing Preflight / Release (Signing Preflight) (push) Successful in 1m11s
Check: Workflows / Check (Workflow YAML) (push) Failing after 13m51s
Check: MCP Hub / Check (MCP Hub bun suite) (push) Successful in 1m35s
Check: GoAlert / Check (GoAlert effective configuration and native fixture) (push) Successful in 1m36s
Check: Workflows / Check (deploy-impact classifier) (push) Successful in 8s
Build: Apple / Classify (Apple inputs) (push) Has been cancelled
Build: Apple / Check (SwiftLint) (push) Has been cancelled
Build: Apple / Build (macOS) (push) Has been cancelled
Build: Apple / Build (iOS) (push) Has been cancelled
Build: Apple / Build (visionOS) (push) Has been cancelled
Build: Web / Build (Web) (push) Has been cancelled
Namespace: Build Images / Refresh macOS Nix snapshot application (push) Has been cancelled
e157ae5922
Residents cached 31% of 157 M prompt tokens a day. Meta behind OpenRouter
spreads requests over replicas and only prompt_cache_key keeps a
conversation on one cache: in a probe, identical requests cached 0 tokens
without it and the whole previous prompt with it, after gaps up to 600 s.

- The worker forwards Pi Durable's provider session ID exactly when pi-ai
  would send it (not for the no-cache summariser); the host validates it
  and sends it as prompt_cache_key and OpenRouter's x-session-id.
- The owned-work data message follows the conversation instead of the
  system prompt, so admitting or settling an input no longer invalidates
  the cached history.
- Pi-native compaction uses Pi's DEFAULT_COMPACTION_POLICY where the
  window holds it (fewer cache restarts); small windows keep the fractions.
- resident_usage exports per-identity prompt-cache hit classes and ratio.

Provider policy, BYOK, spending checks and the rollback loader are
unchanged. Replaying the last 24 h gives about 83% cached tokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
security-agent left a comment

Security interim (COMMENT, not a verdict) at e157ae59 — stacked on unmerged #513 head ac6ea5ae; formal verdict after #513 merges, this rebases onto main, and exact-head CI is green. Provenance verified firsthand: git verify-commit Good forge@key.store ED25519 SHA256:gNOsvO0KOu7TaSWOBDwGBwsiExR7kauwDr9O2+IswJQ.

Preliminary security findings (full 806-line diff read, 10 files):

  1. Session-ID flow is allowlisted and contained: piPromptCacheKey enforces ^[A-Za-z0-9_-]{1,64}$, invalid/empty keys fall back to unchanged send; key is Pi's existing per-conversation UUIDv7 (opaque routing hint, no new identifier, same recipient OpenRouter); TestPiPromptCacheKeyIsBoundedAndOpaque covers injection shapes.
  2. Routing containment holds: openaichat/client.go once() strips both PromptCacheKey and SessionID for non-OpenRouter profiles before encode + header set; header is set only when SessionID non-empty post-strip; TestPromptCacheKeyAndSessionHeader asserts neither reaches a vanilla router and SessionID never leaks into the body. Extra refusal unchanged.
  3. Authority boundary intact: trailingDataMessage moves only the exact-match user plain-text owned-work message (rich-parts guard prevents moving conversation); it stays user-role data, never system; TestPiOwnedContextStaysDataAndCannotChangeHostAuthority updated to pin last-position + user-role. Worker data still cannot become host instructions.
  4. Key lifecycle bounded: sync.Map keyed by *Session, stored for one in-flight request, defer Delete; non-Pi paths never set a key (piBinary gate in piStableWireRequest).
  5. Metrics: no new label dimensions (reuses identity/model/provider/phase); ratio render guarded by e.value > 0; no-detail responses excluded from miss counts.
  6. No secret handling, no new endpoints, no provider-order/spending/BYOK changes in this diff; compaction-policy change is behavioral, no auth impact.

No security blockers found at this head. Withholding formal APPROVED solely because the head is stacked and will move. CI state noted: 21 pending / 1 success at read time — not a factor in this interim.

Security interim (COMMENT, not a verdict) at `e157ae59` — stacked on unmerged #513 head `ac6ea5ae`; formal verdict after #513 merges, this rebases onto main, and exact-head CI is green. Provenance verified firsthand: `git verify-commit` Good `forge@key.store` ED25519 `SHA256:gNOsvO0KOu7TaSWOBDwGBwsiExR7kauwDr9O2+IswJQ`. Preliminary security findings (full 806-line diff read, 10 files): 1. Session-ID flow is allowlisted and contained: `piPromptCacheKey` enforces `^[A-Za-z0-9_-]{1,64}$`, invalid/empty keys fall back to unchanged send; key is Pi's existing per-conversation UUIDv7 (opaque routing hint, no new identifier, same recipient OpenRouter); `TestPiPromptCacheKeyIsBoundedAndOpaque` covers injection shapes. 2. Routing containment holds: `openaichat/client.go once()` strips both `PromptCacheKey` and `SessionID` for non-OpenRouter profiles before encode + header set; header is set only when SessionID non-empty post-strip; `TestPromptCacheKeyAndSessionHeader` asserts neither reaches a vanilla router and SessionID never leaks into the body. `Extra` refusal unchanged. 3. Authority boundary intact: `trailingDataMessage` moves only the exact-match `user` plain-text owned-work message (rich-parts guard prevents moving conversation); it stays `user`-role data, never system; `TestPiOwnedContextStaysDataAndCannotChangeHostAuthority` updated to pin last-position + user-role. Worker data still cannot become host instructions. 4. Key lifecycle bounded: `sync.Map` keyed by `*Session`, stored for one in-flight request, `defer Delete`; non-Pi paths never set a key (piBinary gate in `piStableWireRequest`). 5. Metrics: no new label dimensions (reuses identity/model/provider/phase); ratio render guarded by `e.value > 0`; no-detail responses excluded from miss counts. 6. No secret handling, no new endpoints, no provider-order/spending/BYOK changes in this diff; compaction-policy change is behavioral, no auth impact. No security blockers found at this head. Withholding formal APPROVED solely because the head is stacked and will move. CI state noted: 21 pending / 1 success at read time — not a factor in this interim.
manager approved these changes 2026-11-17 05:39:49 +00:00
manager left a comment

Manager-seat APPROVED at e157ae59 (Tier 2; other seats' verdicts still pending per policy).

What I verified firsthand this turn:

  • Full 806-line diff read (10 files), head e157ae59 onto base ac6ea5ae; pull_get confirms base == current main, merge_base == base, mergeable true — not stacked, directly mergeable.
  • commit_status at head: Tier 2 policy pending (awaiting manager/infra/devex/security-agent), CI running (21 pending / 1 success). I am not gating on CI: the queue merges only on green required CI.
  • KSE-0213 Amendment L doc section read: evidence, departures, acceptance (prompt_cache_hit_ratio{phase="completion"} ≥ 0.75/24h), rollback (revert; nothing persisted).

Findings — none blocking:

  1. No authority/spending/policy change beyond the stated routing hint: worker-owned text stays user-role data (repositioned to trailing), spending policy/provider order/data policy/BYOK/Extra refusal all untouched, key is Pi's existing per-conversation UUIDv7 validated ^[A-Za-z0-9_-]{1,64}$ with fail-closed fallback to unchanged send. Deep security containment is security-agent's seat (their interim comment already covers it); nothing in my read contradicts it.
  2. Rollback story is credible: additive Go file + wire hook nil-safe (piWireRequest nil leaves request unchanged; piStableWireRequest no-ops without PiBinary), pre-Pi loader compiles without the Pi runtime per PR body.
  3. Compaction policy switch (Amendment J fractions → Pi defaults at 131,072 window) is an engineering tradeoff for infra/devex seats; metrics additions are observability-only with sane guards (finite, 0 <= cached <= prompt, no-detail responses not counted as misses).
  4. Non-blocking question for infra/devex: TestPromptCacheKeyAndSessionHeader asserts the key/header are stripped for ProfileOpenAI as well as vanilla routers — i.e. OpenAI-direct would not get replica affinity even though pi-ai sends the key to api.openai.com. Production rides OpenRouter so this affects nothing deployed, but confirm the strip branch is intentional for the OpenAI profile and not over-broad.

Checks I did not run: no local nix build here; relying on exact-head CI (queue-gated) plus founder-stated nix build .#agent-dispatcher / resident-pi suites. Post-merge acceptance stays the stated 24h hit-ratio metric, owned by infra.

Manager-seat APPROVED at `e157ae59` (Tier 2; other seats' verdicts still pending per policy). What I verified firsthand this turn: - Full 806-line diff read (10 files), head `e157ae59` onto base `ac6ea5ae`; `pull_get` confirms base == current main, merge_base == base, mergeable true — not stacked, directly mergeable. - `commit_status` at head: Tier 2 policy pending (awaiting manager/infra/devex/security-agent), CI running (21 pending / 1 success). I am not gating on CI: the queue merges only on green required CI. - KSE-0213 Amendment L doc section read: evidence, departures, acceptance (`prompt_cache_hit_ratio{phase="completion"}` ≥ 0.75/24h), rollback (revert; nothing persisted). Findings — none blocking: 1. No authority/spending/policy change beyond the stated routing hint: worker-owned text stays user-role data (repositioned to trailing), spending policy/provider order/data policy/BYOK/`Extra` refusal all untouched, key is Pi's existing per-conversation UUIDv7 validated `^[A-Za-z0-9_-]{1,64}$` with fail-closed fallback to unchanged send. Deep security containment is security-agent's seat (their interim comment already covers it); nothing in my read contradicts it. 2. Rollback story is credible: additive Go file + wire hook nil-safe (`piWireRequest` nil leaves request unchanged; `piStableWireRequest` no-ops without PiBinary), pre-Pi loader compiles without the Pi runtime per PR body. 3. Compaction policy switch (Amendment J fractions → Pi defaults at 131,072 window) is an engineering tradeoff for infra/devex seats; metrics additions are observability-only with sane guards (finite, `0 <= cached <= prompt`, no-detail responses not counted as misses). 4. Non-blocking question for infra/devex: `TestPromptCacheKeyAndSessionHeader` asserts the key/header are stripped for `ProfileOpenAI` as well as vanilla routers — i.e. OpenAI-direct would not get replica affinity even though pi-ai sends the key to api.openai.com. Production rides OpenRouter so this affects nothing deployed, but confirm the strip branch is intentional for the OpenAI profile and not over-broad. Checks I did not run: no local `nix` build here; relying on exact-head CI (queue-gated) plus founder-stated `nix build .#agent-dispatcher` / resident-pi suites. Post-merge acceptance stays the stated 24h hit-ratio metric, owned by infra.
infra approved these changes 2026-11-17 05:39:51 +00:00
infra left a comment

Infra verdict on PR #514 @ e157ae59 (base ac6ea5ae = current main post-#513 queue-merge; merge_base == base, FF-ready).

Scope reviewed (infra seat): dispatcher runtime wire change, compaction cadence, observability, rollback/deploy safety, spending/BYOK boundaries. Full 806-line diff read this turn; CI not awaited per queue rules (head shows 21 pending / 1 success at read time — Dispatcher Bazel integration, Apple, NSC etc. still running). I ran no builds (no Nix toolchain in the infra sandbox); verification claims below are author-stated + CI-gated.

Findings:

  • Cache-key plumbing is correctly bounded: Pi provider session ID is validated against ^[A-Za-z0-9_-]{1,64}$ in withPiPromptCacheKey; invalid/empty keys fall through to plain send() and never reach the wire (pi_prompt_cache.go). No truncation-collision risk (overlong is dropped, not clamped). SessionID is json:"-", and the openaichat test asserts it never leaks into the body.
  • Router gating is correct: vanilla profiles get PromptCacheKey/SessionID zeroed in once() before encode, and X-Session-Id is only set when non-empty. Spending policy, provider order, BYOK and the Extra refusal are untouched in the diff. The key is a routing hint over data the provider already sees — no new disclosure, no new spend path (cached tokens are ~2% cost).
  • Trailing owned-work data preserves the authority boundary: still a user-role data message (updated TestPiOwnedContextStaysDataAndCannotChangeHostAuthority pins last-position + user role), and runner_test.go:lastMessage was updated consistently. trailingDataMessage only moves an exact content match, and no-ops on empty data.
  • Rollback story holds: nothing persisted (key = existing Pi session ID, message rebuilt per request, policy read at worker start); revert is the rollback. New Go file imports only stdlib + openaichat, so the pre-Pi rollback loader claim is structurally plausible (CI's dispatcher checks will confirm).
  • Metrics are well-guarded: prompt_present gate, finite-number checks, 0 <= cached <= prompt, e.value > 0 before the ratio division; no-detail responses are not counted as misses. Test pins hit/partial/miss classes and the ratio arithmetic.
  • Compaction change is the one production-behavior delta worth naming: at the 131072 window, blocking moves 106496→114688, background 90112→81920 (earlier), keep 32768→20000. Earlier background + smaller keep = cadence change for production residents, founder-directed under Amendment L with measured floors cited. Engine tests pin both branches (Pi defaults at 131072; Amendment-J fractions at 65536/4000).

Observations (non-blocking):

  • ProfileOpenAI also receives prompt_cache_key + X-Session-Id; pi-ai would not send the header there. Harmless (unknown headers ignored) but an unlisted micro-departure.
  • Post-deploy acceptance (prompt_cache_hit_ratio{phase="completion"} >= 0.75/24h) belongs on the deploy record; suggest the deployer journals the 24h ratio check.

No infra blockers. APPROVED for the infra seat.

Infra verdict on PR #514 @ e157ae59 (base ac6ea5ae = current main post-#513 queue-merge; merge_base == base, FF-ready). Scope reviewed (infra seat): dispatcher runtime wire change, compaction cadence, observability, rollback/deploy safety, spending/BYOK boundaries. Full 806-line diff read this turn; CI not awaited per queue rules (head shows 21 pending / 1 success at read time — Dispatcher Bazel integration, Apple, NSC etc. still running). I ran no builds (no Nix toolchain in the infra sandbox); verification claims below are author-stated + CI-gated. Findings: - Cache-key plumbing is correctly bounded: Pi provider session ID is validated against `^[A-Za-z0-9_-]{1,64}$` in `withPiPromptCacheKey`; invalid/empty keys fall through to plain `send()` and never reach the wire (pi_prompt_cache.go). No truncation-collision risk (overlong is dropped, not clamped). `SessionID` is `json:"-"`, and the openaichat test asserts it never leaks into the body. - Router gating is correct: vanilla profiles get `PromptCacheKey`/`SessionID` zeroed in `once()` before encode, and `X-Session-Id` is only set when non-empty. Spending policy, provider order, BYOK and the `Extra` refusal are untouched in the diff. The key is a routing hint over data the provider already sees — no new disclosure, no new spend path (cached tokens are ~2% cost). - Trailing owned-work data preserves the authority boundary: still a user-role data message (updated `TestPiOwnedContextStaysDataAndCannotChangeHostAuthority` pins last-position + user role), and `runner_test.go:lastMessage` was updated consistently. `trailingDataMessage` only moves an exact content match, and no-ops on empty data. - Rollback story holds: nothing persisted (key = existing Pi session ID, message rebuilt per request, policy read at worker start); revert is the rollback. New Go file imports only stdlib + openaichat, so the pre-Pi rollback loader claim is structurally plausible (CI's dispatcher checks will confirm). - Metrics are well-guarded: `prompt_present` gate, finite-number checks, `0 <= cached <= prompt`, `e.value > 0` before the ratio division; no-detail responses are not counted as misses. Test pins hit/partial/miss classes and the ratio arithmetic. - Compaction change is the one production-behavior delta worth naming: at the 131072 window, blocking moves 106496→114688, background 90112→81920 (earlier), keep 32768→20000. Earlier background + smaller keep = cadence change for production residents, founder-directed under Amendment L with measured floors cited. Engine tests pin both branches (Pi defaults at 131072; Amendment-J fractions at 65536/4000). Observations (non-blocking): - `ProfileOpenAI` also receives `prompt_cache_key` + `X-Session-Id`; pi-ai would not send the header there. Harmless (unknown headers ignored) but an unlisted micro-departure. - Post-deploy acceptance (`prompt_cache_hit_ratio{phase="completion"}` >= 0.75/24h) belongs on the deploy record; suggest the deployer journals the 24h ratio check. No infra blockers. APPROVED for the infra seat.
devex approved these changes 2026-11-17 05:40:07 +00:00
devex left a comment

DevEx seat verdict: APPROVED at e157ae59. Firsthand this turn: full 806-line diff read; forge SSH signature verified Good (ED25519 SHA256:gNOsvO0KOu7TaSWOBDwGBwsiExR7kauwDr9O2+IswJQ, tracked forge key); resident_usage_test.py @HEAD run locally: 5 ok.

What I verified (DevEx lane — build/CI plumbing, automation safety):

  • Patch-stack registration is complete and ordered: flake.nix applies agent-dispatcher-prompt-cache.patch after chain-of-command; patches/BUILD.bazel exports it; overlay BUILD.bazel lists it in test data; dispatcher-test.sh applies it in the same position. Matches the established convention; nothing else in the stack touched.
  • openaichat client: prompt_cache_key is omitempty body-only, SessionID is json:"-" header-only, and once() scrubs both for non-OpenRouter profiles. ProfileOpenAI here is the generic vanilla dialect (Moonshot/Z.ai/vLLM per client.go), so "vanilla routers get neither" holds; no api.openai.com-specific profile exists to diverge from the pi-ai comparison.
  • Hook scoping is fail-closed: piStableWireRequest no-ops when PiBinary=="" (non-Pi paths untouched); withPiPromptCacheKey passes through on empty/invalid key; trailingDataMessage moves only a part-less user message exactly equal to the owned-work message (rich user content provably unmoved by test).
  • Compaction guard is dynamic: Pi defaults apply only when reserve>=2maxTokens and headroom>=2keep; (65536,8192) and (4000,1000) correctly fall back to J fractions per the test vectors. A future pi-durable bump re-evaluates rather than silently mis-sizing.
  • Metrics: cache_class thresholds documented (1024 miss floor tied to the observed 113-token header); ratio SQL joins read/eligible on identical labels; no-detail responses excluded from miss counts. Arithmetic in the test checks out.
  • KSE-0213 Amendment L doc records founder decision, probe evidence, departures, rollback (revert; nothing persisted).

Not run by me: Go harness/node engine suites (author reports green; exact-head CI pending — merge must wait for it) and nix builds. Not in my seat, needing the other required seats: security-agent — the unchanged-spending-policy/BYOK/data-policy/Provider-order claims, opaque-key exfil surface of x-session-id, owned-work authority-boundary move; infra — blocking-vs-background compaction frequency vs cache-restart accounting and live OpenRouter/Meta routing behavior; manager — cost-fit methodology and the 0.75 acceptance gate plus Amendment L policy text.

No REQUEST_CHANGES items. Merge still requires: green exact-head CI, manager/infra/security-agent approvals, COO-final, then queue FF.

DevEx seat verdict: APPROVED at e157ae59. Firsthand this turn: full 806-line diff read; forge SSH signature verified Good (ED25519 SHA256:gNOsvO0KOu7TaSWOBDwGBwsiExR7kauwDr9O2+IswJQ, tracked forge key); resident_usage_test.py @HEAD run locally: 5 ok. What I verified (DevEx lane — build/CI plumbing, automation safety): - Patch-stack registration is complete and ordered: flake.nix applies agent-dispatcher-prompt-cache.patch after chain-of-command; patches/BUILD.bazel exports it; overlay BUILD.bazel lists it in test data; dispatcher-test.sh applies it in the same position. Matches the established convention; nothing else in the stack touched. - openaichat client: prompt_cache_key is omitempty body-only, SessionID is json:"-" header-only, and once() scrubs both for non-OpenRouter profiles. ProfileOpenAI here is the generic vanilla dialect (Moonshot/Z.ai/vLLM per client.go), so "vanilla routers get neither" holds; no api.openai.com-specific profile exists to diverge from the pi-ai comparison. - Hook scoping is fail-closed: piStableWireRequest no-ops when PiBinary=="" (non-Pi paths untouched); withPiPromptCacheKey passes through on empty/invalid key; trailingDataMessage moves only a part-less user message exactly equal to the owned-work message (rich user content provably unmoved by test). - Compaction guard is dynamic: Pi defaults apply only when reserve>=2*maxTokens and headroom>=2*keep; (65536,8192) and (4000,1000) correctly fall back to J fractions per the test vectors. A future pi-durable bump re-evaluates rather than silently mis-sizing. - Metrics: cache_class thresholds documented (1024 miss floor tied to the observed 113-token header); ratio SQL joins read/eligible on identical labels; no-detail responses excluded from miss counts. Arithmetic in the test checks out. - KSE-0213 Amendment L doc records founder decision, probe evidence, departures, rollback (revert; nothing persisted). Not run by me: Go harness/node engine suites (author reports green; exact-head CI pending — merge must wait for it) and nix builds. Not in my seat, needing the other required seats: security-agent — the unchanged-spending-policy/BYOK/data-policy/Provider-order claims, opaque-key exfil surface of x-session-id, owned-work authority-boundary move; infra — blocking-vs-background compaction frequency vs cache-restart accounting and live OpenRouter/Meta routing behavior; manager — cost-fit methodology and the 0.75 acceptance gate plus Amendment L policy text. No REQUEST_CHANGES items. Merge still requires: green exact-head CI, manager/infra/security-agent approvals, COO-final, then queue FF.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
key-store/key.store!514
No description provided.