Repository navigation
fix: preserve local prompt caches across midnight - #168169
Conversation
Move current date and timezone from the system prompt to the existing per-turn runtime context, preserving date grounding without invalidating positional history caches. Cover midnight rollover and resumed CLI turns, and isolate the touched source-delivery fixture from shared temporary session databases. Fixes #148304
|
🦞👀 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: needs changes before merge. What this changesMoves date and timezone facts outside the system prompt and retains earlier runtime context on Chat Completions and Ollama routes. Example: An Ollama conversation crosses 2026-10-09T23:59:59Z to 2026-10-10T00:00:01Z.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains This PR addresses a current cache-invalidation defect and has no actionable diff findings; it merits landing review rather than cleanup closure. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherAgent preparation combines configuration, conversation history, and current runtime facts into provider requests; replay policy controls whether earlier hidden context remains in history. flowchart LR
A[User turn and configuration] --> B[Agent preparation]
B --> C[Stable system prompt]
B --> D[Temporal runtime facts]
D --> E[Replay policy and history]
C --> F[Provider request]
E --> F
Technical reviewBest possible solution: Land the existing-owner repair through the native workflow after confirming the recorded architecture failure qualifies for inherited-failure admission. Do we have a high-confidence way to reproduce the issue? Current-main source places the changing date before conversation history; the linked report supplies vLLM measurements, and the PR supplies real CLI baseline and candidate captures. Is this the best way to solve the issue? The repair preserves fresh date grounding and existing provider overrides without introducing configuration, a parallel context owner, or a storage migration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dd036a4b1d85. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -34, Tests +162, Docs +7, Other -2. Total +133 across 33 files. Added test files: 1. View PR surface stats
Review metrics
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 HistoryReview history (10 earlier review cycles; latest 8 shown)
Reviewed October 10, 2026, 6:19 AM ET / 10:19 UTC (Revision 11). |
Keep the independently landed fixture isolation from 22bca7d in the same form to avoid a merge conflict. Prompt behavior is unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
* fix(agents): preserve prompt caches across midnight Move current date and timezone from the system prompt to the existing per-turn runtime context, preserving date grounding without invalidating positional history caches. Cover midnight rollover and resumed CLI turns, and isolate the touched source-delivery fixture from shared temporary session databases. Fixes openclaw#148304 * test(agents): align isolated source-delivery fixture with main Keep the independently landed fixture isolation from 4fbda69 in the same form to avoid a merge conflict. Prompt behavior is unchanged. * fix: retain temporal context for prompt prefix reuse * test: expect retained runtime context for native Ollama * test: preserve idle facts expectations for code mode fixture
Related: #148304, #123265, #150286
What Problem This Solves
Fixes daily prompt-cache invalidation when the calendar date changes in the system message ahead of conversation history.
User Impact
Local models keep their complete system prompt reusable across midnight while receiving today's date and configured timezone every normal turn. Chat Completions and native Ollama retain previously sent hidden runtime context, allowing subsequent requests to extend the previous request's exact prefix. No new configuration is required. Retained messages count toward normal history and compaction budgets; explicit provider replay overrides remain respected.
Why This Change Was Made
Temporal facts use the existing embedded runtime-facts tail and generic CLI turn context. Main's interrupted-input previews coexist in those same owners, outside the system prompt. Obsolete system-date parameters and rendering plumbing are removed. Native Codex and AgentsAPI retain their existing temporal owners; raw probes and settled-tool finalization retain their exact-context exclusions. Cron and heartbeat keep their existing context lifecycles.
A mandatory transient carrier would regress exact-entry caches, so the existing transcript-policy owner supplies the Chat Completions/Ollama retention default. Transient routes still omit empty producer snapshots; retained routes request eligible empty snapshots to clear earlier active state. The existing interrupted-input integration test now requires both interrupted and temporal facts on embedded and CLI paths.
Production +52/−86 lines; tests/support +390/−228; docs +21/−14; two obsolete mock-baseline entries removed.
Thanks to @arthur-drozdov for the report and vLLM measurements.
Evidence
Current candidate:
6013fdcd517dae5341f0da4ffe1911b6fc0f70bd, merging main861d68f4f251020449b63ab383c934cd8941052bwithout rewriting the PR's history. The resolution retains both main's interrupted-input context and this temporal tail.Native Ollama 0.40.2 /
qwen3:8b, through realpnpm openclaw --profile prefix-date agent --localcalls with isolated state and a process-local clock:The integrated three-turn run crosses
2026-10-09T23:59:59Z→2026-10-10T00:00:01Z, then continues on the new day. Every date answer is correct. Captured system bytes and tools stay identical, and serialized previous-request messages remain an exact prefix of every subsequent request. The new runtime tail includes main's explicit interrupted-input clearing snapshot; the merged main and isolated workspace account for the system-size difference from the earlier candidate. All seven generated native-harness snapshots remain byte-identical: 0 token drift.A fourth real CLI turn successfully continued a synthetic interrupted input, answering
IRIS-516 2026-10-10. The fixture was staged through the canonical pending-input owner, not raw SQL. Its retired execution authority was rejected, its preview and date stayed out of the system prompt, and the old interrupted record remained unchanged after the new turn. This is real model/CLI proof of consuming the preview, with synthetic preparation of the historical record; it does not claim a live Gateway interruption.The task-owned Ollama process uses the same installed weights to avoid shared-server cache interference. Original captured-request replay on that process reproduced the baseline cache count. The shared server is untouched. Earlier shared-daemon zero-cache readings were not used as passing evidence.
Validation on the integrated candidate:
node scripts/run-vitest.mjs <files> --maxWorkers=1; the two grouped runs took 1,077.92s and 592.79s wall. The existing runner/SQLite/compiled-worker graph dominates wall time; no new Gateway boots, sleeps, polling or worker pins were added.pnpm prompt:snapshots:gen: seven files regenerated, zero differences.pnpm build qaRuntime: 284.15s wall, 2m44s reported build phases. The earlier full package/declaration build stalled and is not claimed as passing.Prior-head compatibility evidence (
08671b022d739b1108250d588ec53ae21bd7f1ac): a real session created by registry[email protected]resumed on the candidate after Doctor's existing v24 → v25 migration with integrity checks and recovery backups. The candidate received old user/assistant text and answeredAMBER-7264 2026-10-10; every original config value remained equal while Doctor added its normal metadata/default fields. Published/candidate CLI wall times were 137.73s/97.03s. The published driver emitted cleanup-timeout warnings after its successful turn; Doctor and candidate exited successfully. This PR introduces no storage-format or schema change.Previous-head CI and
openclaw/ci-gatepassed (54 successful jobs, 23 skipped), and ClawSweeper rated that head 5/6 with no actionable findings after accepting the upgrade proof. Its only remaining item was the merge conflict resolved here. Exact-head CI run 38041136173 completed with 50 successful jobs and two inherited failures, leavingopenclaw/ci-gatered:a4445770combines this head with mainafafe747. Its Kysely diagnostics namedoctor-migration-preservation.tsandopenclaw-migration-witness.ts, introduced upstream by974443a0a903(fix(update): verify migration preservation against original backups #168321). Neither file exists in this PR head or its main parent. The fresh-main audit checkout atab251835d1d3independently reproduces the same diagnostics withpnpm lint:kysely.session-dashboard.e2e.test.tspin-button clicks time out because.chat-gutter-stack--detailsintercepts pointer events. That overlay came fromb883658c8178(feat(ui): group session context and task progress in Details #161674). The UI tree, manifest and lockfile are unchanged by this PR relative to its main parent; these tests use fixed mock-Gateway history and do not execute agent prompt assembly. Relevant UI/test sources remain identical through the fresh-main audit pin.No rerun or extra push was made merely to obtain green. These failures require the existing inherited-failure landing policy, not a prompt-date branch repair. Current-head ClawSweeper found no actionable findings, accepted the integrated live/upgrade evidence, and requested attribution of the architecture failure; that attribution is recorded above. Hosted-provider evidence remains request-boundary proof, not live hosted API traffic. The campaign lead explicitly waives proof-only review holds; substantive findings remain actionable.
Additional carrier-cluster audit: #150290's producer-level empty-snapshot omission is already implemented by merged #163471, including the CLI clearing caller missing from the older contributor patch. No duplicate producer patch is included here.
A controlled native Ollama read-tool run on fresh main
ab251835d1d3captured the runtime carrier moving from immediately after its user to after the tool result; serialized previous-request prefix equality failed. With this candidate, the carrier stayed next to its original user through the tool round and next user turn, and prefix equality held. The tool-continuation cached count was 6,217/6,452 (96.4%) before and 6,513/6,581 (99.0%) after; the candidate's next user request reused 6,504/6,862 (94.8%). Ollama's longest-prefix cache remained high even before; the captures, rather than those percentages alone, establish the exact-entry-prefix defect. No Halogen runtime claim is made.The real read returned synthetic file code
FENNEL-287. Main's completion answered from the interrupted preview (IRIS-516); this candidate correctly answered the file code after the tool. A later user follow-up still answeredIRIS-516despite preserved request bytes. That residual semantic issue is part of #164791's provider-role policy question: native Ollama deliberately keeps user-role compatibility carriers. This PR does not change protocol/transcript representation or add a retention setting; those changes require the maintainer decision requested by that issue. The interrupted record was prepared through the canonical state owner in isolated state, and every model request used the real OpenClaw CLI.