Skip to content

fix: preserve local prompt caches across midnight - #168169

Merged
steipete merged 6 commits into
mainfrom
fix/prompt-date-tail-context
Oct 10, 2026
Merged

steipete merged 6 commits into
mainfrom
fix/prompt-date-tail-context

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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 main 861d68f4f251020449b63ab383c934cd8941052b without 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 real pnpm openclaw --profile prefix-date agent --local calls with isolated state and a process-local clock:

Case System across midnight Second request cached Third request cached
Original CLI baseline Different, 7,600 bytes 1,309/2,451 (53.4%) —
Earlier retained-context full/lean proof Identical, 7,490 bytes 2,402/2,533 (94.8%) 2,520/2,651 (95.1%)
Integrated candidate, native Ollama Identical, 7,574 bytes 2,445/2,598 (94.1%) 2,585/2,738 (94.4%)

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:

  • 353 tests across 19 focused files passed, including the previously used date, system prompt, CLI, source-delivery, subagent, prompt-phase, recovery, provider cache-boundary, retry/reopen, policy and new interrupted-input composition coverage. Single-worker commands used 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.
  • The original full/minimal system rollover regression failed before the date move. The retention regression failed before the policy repair (zero saved carriers instead of two), then passed for both transport defaults, explicit overrides, retry equality, reopen prefix preservation and reset cleanup. Earlier initial validation covered 342 tests; those older runs are not represented as current-head CI.
  • Core and touched-test typechecks, scoped core lint/format, max-lines, line-cap, assertion-safety, timeout-race, mock-export, config-doc, plugin-inventory and database-worker guards passed. An initial guard invocation during the unresolved merge evaluated inherited main changes; the committed-merge run passed with no baseline growth.
  • 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.
  • Fresh independent Codex autoreview: scoped-clean, no actionable P0–P2 findings.

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 answered AMBER-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-gate passed (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, leaving openclaw/ci-gate red:

  • Architecture: the CI synthetic merge a4445770 combines this head with main afafe747. Its Kysely diagnostics name doctor-migration-preservation.ts and openclaw-migration-witness.ts, introduced upstream by 974443a0a903 (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 at ab251835d1d3 independently reproduces the same diagnostics with pnpm lint:kysely.
  • UI E2E: two session-dashboard.e2e.test.ts pin-button clicks time out because .chat-gutter-stack--details intercepts pointer events. That overlay came from b883658c8178 (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 ab251835d1d3 captured 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 answered IRIS-516 despite 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.

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
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Moves 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.

  • Before: The changed system date invalidates cached conversation tokens.
  • After: The system stays identical, earlier request messages remain a prefix, and the new turn receives 2026-10-10.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with shipped-entry-point evidence, relevant regressions, and no actionable findings; failed CI still requires native admission.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied real OpenClaw CLI/Ollama output covers exact-head midnight rollover, correct dates, preserved system and request-prefix bytes, and tool continuation; prior-head stable-session upgrade evidence remains applicable to the unchanged storage contract.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A daily date change forces local positional caches to recompute long conversation history.
Reason: The measured latency problem has a narrow owner-level repair that preserves date awareness and removes obsolete plumbing.

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
Reviewed head: 6013fdcd517dae5341f0da4ffe1911b6fc0f70bd

Before merge

  • Complete next step - Verify the architecture job's exact diagnostic against the recorded main reproduction before selecting inherited-failure admission; raw-log retrieval was blocked in this review environment.

Findings

None.

Agent review details

How this fits together

Agent 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
Loading

Technical review

Best 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

  • Temporal grounding changes intended behavior with a stated reason (54e273e: Supply fresh local dates to prevent incorrect relative-date reasoning in long-running sessions.)
  • Canonical temporal renderer keeps the original intent (defd9eb: Share timezone-aware rendering across native and Codex temporal owners.)
  • Replay-policy retention changes intended behavior with a stated reason (46ab36a: Retain prompt updates and runtime context through the existing replay-policy owner.)
  • Typed runtime-context carriers keeps the original intent (cd9913f: Centralize carrier semantics, provider projection, privacy, and empty-snapshot handling.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source -34, Tests +162, Docs +7, Other -2. Total +133 across 33 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 10 52 86 -34
Tests 19 390 228 +162
Docs 3 21 14 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 2 -2
Total 33 463 330 +133

Review metrics

Metric Value Why it matters
Production versus test changes Production +52/-86; tests and support +390/-228. Production shrinks while focused coverage protects rollover, retention, reopening, and composition with interrupted input.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster. Replaced prior rating: 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Midnight rollover causes avoidable prefill latency in long-lived local-model sessions without establishing a core outage.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster. Replaced prior rating: 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-10T05:09:34.465Z sha 2920ba6 :: needs changes before merge. :: [P2] Preserve exact-entry cache reuse when adding temporal carriers | [P2] Update existing prompt-context tests for mandatory temporal facts
  • reviewed 2026-10-10T05:16:23.838Z sha 2920ba6 :: needs changes before merge. :: [P2] Preserve exact-entry cache reuse when adding temporal carriers | [P2] Update existing prompt-context tests for mandatory temporal facts
  • reviewed 2026-10-10T06:42:53.813Z sha 2920ba6 :: needs changes before merge. :: [P2] Preserve exact-entry cache reuse when adding temporal carriers | [P2] Update consumer tests for mandatory temporal facts
  • reviewed 2026-10-10T07:20:13.399Z sha 08671b0 :: blocked before merge. :: none
  • reviewed 2026-10-10T07:59:00.025Z sha 08671b0 :: needs changes before merge. :: none
  • reviewed 2026-10-10T08:29:28.748Z sha 08671b0 :: needs changes before merge. :: none
  • reviewed 2026-10-10T09:29:45.492Z sha 6013fdc :: needs changes before merge. :: none
  • reviewed 2026-10-10T09:35:44.056Z sha 6013fdc :: needs changes before merge. :: none

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 clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 10, 2026
@steipete
steipete marked this pull request as ready for review October 10, 2026 04:53
@steipete
steipete marked this pull request as draft October 10, 2026 05:07
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 10, 2026
@steipete
steipete marked this pull request as ready for review October 10, 2026 07:08
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Oct 10, 2026
@steipete steipete added the ci:no-fail-fast Keep all selected CI matrix jobs running after failures on the next PR run. label Oct 10, 2026
@steipete steipete self-assigned this Oct 10, 2026
@steipete
steipete merged commit 6a9bcca into main Oct 10, 2026
143 of 148 checks passed
@steipete
steipete deleted the fix/prompt-date-tail-context branch October 10, 2026 10:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling ci:no-fail-fast Keep all selected CI matrix jobs running after failures on the next PR run. docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant