Repository navigation
fix(agents): keep prompt cache identity stable across session turns - #181301
Conversation
Remove delivery- and client-dependent WebChat affinity overrides so operator, WebChat, internal completion, requester-settle, and recovery turns use the existing session-boundary cache key owner. Preserve explicit caller keys and reset/compaction rotation. Extend the capturing Gateway regression across operator ingress, WebChat, child announcement, and restart. Keep the existing WebChat prefix checks and cover the shared cache key across all six parent requests.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 58aecc77f6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ); | ||
| return `openclaw-webchat-${digest}`; | ||
| } | ||
|
|
There was a problem hiding this comment.
Preserve full session scope in the fallback cache key
When two WebChat conversations share a persisted sessionId across different session keys or agents, or when long IDs differ only after the 62-code-point truncation, removing this digest makes both fall through to <truncated-sessionId>:<boundary>. The removed key included provider, model, agent, and the full session key, so these distinct conversations now compete for the same provider cache affinity and can lose the reuse this change is intended to preserve. Keep a bounded digest of the complete session scope while retaining the lifecycle suffix.
AGENTS.md reference: AGENTS.md:L69-L69
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesThis PR removes delivery-dependent and client-dependent cache-key overrides so session turns share the existing session-boundary identity. Example: Session 11af5b93-1401-4f59-961e-c44241201c93 receives an operator turn followed by a requester-settle wake.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a source-confirmed cache-affinity mismatch still present on main, using the existing owner without adding production machinery; no actionable correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway chat and agent-command ingress prepare embedded runs; transcript preparation derives cache identity from the physical session and lifecycle boundary before the provider transport serializes the request. flowchart TD
A[Gateway chat] --> C[Embedded run]
B[Agent command and recovery] --> C
C --> D[Transcript preparation]
D --> E[Session boundary cache key]
E --> F[Provider request]
Technical reviewBest possible solution: Use the existing transcript-boundary derivation for implicit cache identity across every ingress while preserving explicit overrides. Do we have a high-confidence way to reproduce the issue? Current-main source shows delivery and client facts selecting a digest instead of the existing session-boundary fallback; the PR reports a matching captured miss and a regression failing on the base, but no target code was executed during this review. Is this the best way to solve the issue? Removing both selectors is the smallest complete repair: the existing owner already handles explicit overrides, boundary rotation and length limits, and the obsolete helper has no remaining references. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2c2c2f30e4e4. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -53, Tests +15, Docs +1. Total -37 across 6 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 23, 2026, 12:25 AM ET / 04:25 UTC. |
|
Follow-up from automated review: assess cache affinity for distinct session scopes that deliberately share a persisted session ID, including truncation collisions for unusually long IDs. This patch keeps the existing session-boundary key format and removes per-turn selectors; changing that owner's key format is outside this focused fix. The finding does not identify data-loss, security, or money risk. |
…penclaw#181301) Remove delivery- and client-dependent WebChat affinity overrides so operator, WebChat, internal completion, requester-settle, and recovery turns use the existing session-boundary cache key owner. Preserve explicit caller keys and reset/compaction rotation. Extend the capturing Gateway regression across operator ingress, WebChat, child announcement, and restart. Update the prompt-caching documentation.
What Problem This Solves
A session's
prompt_cache_keychanged between turns, which drops the provider prompt cache entirely.Tapped Responses bodies from one fleet parent session showed operator and recovery turns using
<session-id>:0, while its requester-settle wake requests switched toopenclaw-webchat-<hash>, then switched back. The Gateway logged a complete miss on the settle wake:Two caller-side selectors competed with the session-boundary owner:
attempt-execution.tspicked a WebChat affinity key from persisted internal delivery.chat-send-agent-dispatch.tspicked one from the client type.Both overrode the session fallback, so cache identity depended on per-turn delivery facts. That violates the prompt-prefix contract.
User Impact
Operator, WebChat, child announcement, requester-settle, and recovery turns retain the same session cache identity. Explicit overrides and reset/compaction rotation are unchanged. No migration or user action is required.
Why This Change Was Made
Both selectors and their now-unused helper are removed (net −37 lines). The existing session-boundary owner (
session-boundary-prompt-cache-key.ts) supplies one key,<session-id>:<boundary-count>, for every turn of a session: operator, WebChat, child announcement, settle and restart recovery. Explicit overrides and reset/compaction rotation are unchanged.docs/reference/prompt-caching.mdis updated.Evidence
src/gateway/gateway.prompt-cache.test.ts, extended across operator ingress, WebChat, child announcement and restart: red on base (expected<sid>:0, receivedopenclaw-webchat-…) and green with the fix. Also green, on a Crabbox host (Node 24.22.1): Gateway chat (74), session-boundary keys (3), session replay (48), stream resolution (10), prefix stability (6), worker inference (43).kill -9while two fleet parents were still in their first turn, every Responses body recorded: all 17 sessions (parents and children) used exactly oneprompt_cache_keyfor every request. Noopenclaw-webchat-…keys appeared, and no cache read dropped to 0.