Repository navigation
Replies: 1 comment
|
Measured numbers and a captured-request comparison for this are in #9998: on one OpenClaw session, the first call after each new user message re-writes 169k of a 220k-token prompt, and later calls read 99% from cache. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Moved from #7783, opened by @exGeni on 2026-10-27. Feature requests now live in Discussions > Ideas.
What problem does this solve?
The OpenClaw context engine (
src/core/context-engine.ts, checked at master75c64150d725) renders the Live Context block intosystemPromptAdditionon everyassemble(). When the timezone is known, the block includes a clock:lines.push(`- **Time:** ${ctx.now} (${ctx.timezone})`);.ctx.nowcomes fromgetTimeInTz(), which formats withsecond: '2-digit'(line 390), so the value is an ISO time to the second.lines.push(`- **Home (${ctx.homeLocation.city}):** ${ctx.homeTime}`);. It is printed while the user is away from a configured home timezone.homeTimecomes fromformatShortTimeInTz()(lines 493-503: hour and minute).When the system prompt contains OpenClaw's cache boundary, OpenClaw places
systemPromptAdditiondirectly after it, ahead of the message history. The function isprependSystemPromptAdditionAfterCacheBoundary(openclaw/openclawpackages/ai/src/utils/system-prompt-cache-boundary.ts:132), called fromsrc/agents/harness/context-engine-lifecycle.ts:379(main7fa041d80fc2). OpenClaw's prompt-caching reference describes what this means on Anthropic routes (docs/reference/prompt-caching.md:411-414):Because the Time line includes seconds, two runs in different seconds produce different Live Context text. On Anthropic routes that use conversation checkpoints, each such change invalidates the conversation checkpoint, so the history cannot be read from cache on that run. The stable-system checkpoint can still be reused, but in a long session most prompt tokens are history.
OpenClaw handles its own time context differently. Its
docs/concepts/timezone.md:19(main) says: "The date and zone travel in the current-turn runtime context, outside the system prompt. Day rollover updates that context while preserving the complete system prompt and earlier conversation bytes for prefix-cache reuse. The context deliberately omits the live clock; when the agent needs exact current time andsession_statusis available, it calls that tool."Observations from one OpenClaw deployment (Anthropic models, gbrain context engine enabled). To reduce cache-expiry effects, we counted only follow-up requests sent within 5 minutes of the previous request in the same session. With the upstream Live Context block, 128 of 364 such requests (35.2%) read more than 90% of their prompt tokens from cache. After a local change that prints only the date (option 1 below), 83 of 128 did (64.8%). This is a before/after comparison on a live system, not a controlled experiment, and the clock does not explain every remaining miss: other parts of the addition also change between runs (see the note at the end).
The clock is deliberate. The file header (lines 4-8) says the engine exists to kill the "time warp" bug class, and line 745 tells the model "This block is computed on every turn. Trust it over compaction summaries for time/location/activity." This request does not dispute that goal. Date, day, zone, location, travel and calendar lines would still be recomputed each turn. The request is to avoid clock-driven invalidation of the conversation cache.
What does the solution look like?
These options would reduce or relocate clock-driven changes to the prompt. The choice is yours:
- **Date:** YYYY-MM-DD (<zone>), keep theDayline, print the home zone instead of a home clock, and add a short hint that exact time comes from a tool (in OpenClaw,session_status). This adopts OpenClaw's date-and-zone granularity while keeping gbrain's current system-prompt placement. It removes minutes and seconds as a source of change; other Live Context fields and other assembled additions can still change. The quiet-hours calculation (line 637) can keep using the hour internally. A test for this: render the block at two different times on the same local day with every other input held constant, and expect identical output.AssembleResult(src/context-engine/types.ts) that lets an engine place text after the history. The engine does returnmessages, so it could carry the clock in the latest turn. That would change the engine's stated design, which owns onlysystemPromptAddition(lines 10-11) and passes messages through unchanged (line 1405), so it is listed only for completeness.The trade-off: with options 1 and 2, the model has no minute-level time in the prompt. Tasks that need the current minute may need a tool call when a suitable tool is available, or can use timestamps already in the conversation (OpenClaw's message envelopes include the time,
docs/concepts/timezone.md:15).Alternatives considered
formatContextBlock(what we run now): about three changed lines plus a test. Its cost is a core patch that has to be carried across every upgrade.Environment: gbrain 0.60.462.0 installed; its
src/core/context-engine.tshas the same blob as master75c64150d725. OpenClaw 2026.10.6, whose bundled@openclaw/aiplaces the addition the same way. Bun 1.4.2, Linux.Note: the Retrieval Reflex pointers (#1981) are also appended to
systemPromptAddition(line 1387), and they change when the salient entities of the turn change. That content varies per turn by design, so this request leaves it out.All reactions