Skip to content

fix(agents): keep date reasoning current in long-running sessions - #116090

Merged
vincentkoc merged 4 commits into
mainfrom
fix/temporal-context-grounding
Jul 29, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
fix/temporal-context-grounding

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Fixes #63181

Supersedes #91250 with a fix for the underlying temporal-grounding failure rather than a heading-only rename.

What Problem This Solves

Fixes an issue where users asking date-relative questions could get incorrect "today", "yesterday", or deadline reasoning in long-running sessions because the system prompt exposed only a time zone and relied on the model to notice message timestamps or call session_status.

Why This Change Was Made

OpenClaw now recomputes the user-local calendar date for every prompt build and places it with the IANA time zone at the front of the volatile system-prompt suffix. The live clock stays out of the prompt, exact time remains tool-backed, and date rollover or time-zone changes cannot invalidate the stable prompt-cache prefix.

The replacement design follows the stronger current harness pattern: Codex supplies current date plus time zone in per-turn environment context, while OpenCode emits a date baseline and rollover updates. Gemini CLI's first-message-only date context can become stale across resumed multi-day sessions, and Pi's date removal left users reporting random-date behavior. A heading rename alone would not fix the reported failure.

User Impact

Agents receive an explicit local calendar date on every turn, including after day rollover, while preserving prompt-cache reuse. Restricted agents are only told to use session_status for exact time when that tool is actually available.

Before:

## Current Date & Time
Time zone: America/Chicago

After:

## Temporal Context
Current date: 2026-01-05
Time zone: America/Chicago
For the exact current time, use `session_status`.

Evidence

  • 196 focused tests passed across prompt rendering, time-zone conversion, cache-boundary stability, embedded/CLI prompt assembly, command prompt assembly, compaction context, and prompt-composition scenarios.
  • Date rollover and time-zone changes produce byte-identical stable prefixes and only change the volatile suffix.
  • Restricted toolsets omit the session_status instruction.
  • Fresh autoreview: clean, no accepted/actionable findings, confidence 0.93.
  • node scripts/check-changed.mjs -- <20 touched files> passed on Blacksmith Testbox, including all policy guards, deadcode, three typecheck lanes, full core lint fanout, scripts, docs, and tooling: https://github.com/openclaw/openclaw/actions/runs/30490674386
  • git diff --check and targeted oxfmt --check passed.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Jul 29, 2026
@vincentkoc vincentkoc self-assigned this Jul 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Jul 29, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 29, 2026 21:32
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 6:06 PM ET / 22:06 UTC.

ClawSweeper review

What this changes

This PR replaces the system prompt’s timezone-only section with a user-local calendar date and time zone below the prompt-cache boundary, updates embedded, CLI, command, and compaction prompt assembly, and refreshes tests and documentation.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this PR open for maintainer review. The supplied exact-head evidence and CI results support the prompt change, but it intentionally aligns OpenClaw temporal context with Codex’s per-turn contract, which still needs the repository-required direct sibling-Codex source check before a merge verdict.

Priority: P2
Reviewed head: d064c20c5e3bbf40a033a1658ac1b06d40cb41d7
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has focused exact-head validation and no concrete patch finding from the supplied evidence, but direct Codex-contract inspection remains necessary before a higher-confidence merge assessment.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its supplied exact-head focused Testbox evidence and successful real-behavior-proof check remain useful supplemental validation.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its supplied exact-head focused Testbox evidence and successful real-behavior-proof check remain useful supplemental validation.
Evidence reviewed 5 items Prompt implementation: The proposed prompt section requires both a local date and time zone and places the optional exact-time guidance behind availability of the session-status tool.
Per-entry-point wiring: The branch changes the shared prompt-parameter builder to produce userDate and passes it through embedded, CLI, command, and compaction prompt assembly paths.
Focused validation supplied on exact head: The contributor reports an immutable-head Blacksmith Testbox run passing 252 focused tests across touched prompt entry points and compaction; the GitHub context also shows the relevant prompt, docs, lint, type, boundary, and real-behavior-proof checks succeeding on this head.
Findings None None.
Security None None.

How this fits together

OpenClaw builds a system prompt for embedded agents, CLI agents, command flows, and compaction. Configuration supplies the user time zone, prompt assembly computes the local date, and the resulting volatile suffix guides agent date reasoning without invalidating the stable prompt-cache prefix.

flowchart LR
  A[Agent configuration] --> B[Resolve user time zone]
  B --> C[Compute local calendar date]
  C --> D[Build volatile temporal context]
  D --> E[System prompt cache boundary]
  E --> F[Embedded, CLI, command, and compaction prompts]
  F --> G[Agent date reasoning]
Loading

Decision needed

Question Recommendation
Does the direct sibling-Codex source contract confirm that OpenClaw should recompute and expose only local calendar date plus IANA time zone per prompt build, while keeping exact current time tool-backed? Confirm the Codex contract and merge: Inspect the matching sibling Codex turn-context and world-state paths, then accept this cache-boundary-safe implementation if its date and time-zone semantics match.

Why: The branch deliberately adopts a dependency-informed temporal-context model, and repository policy reserves Codex-related verdicts for a reviewer who has personally inspected the exact sibling runtime behavior.

Before merge

  • Resolve merge risk (P1) - The prompt bytes change across normal and compaction sessions; before merge, direct inspection of the sibling Codex per-turn date/time-zone contract should confirm that the chosen refresh semantics match the dependency rather than only the PR description.
  • Resolve merge risk (P1) - A local-date value is intentionally volatile while the prompt prefix remains cache-stable; maintainer review should retain the supplied rollover and time-zone boundary evidence when accepting that session-context tradeoff.
  • Complete next step (P2) - A protected maintainer-authored PR needs human approval, and the remaining Codex dependency-contract confirmation is a review judgment rather than a safe automated branch repair.
Agent review details

Security

None.

PR surface

Source +1, Tests +24, Docs +1. Total +26 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 10 45 44 +1
Tests 6 92 68 +24
Docs 5 22 21 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 159 133 +26

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: docs/concepts/system-prompt.md, persistent cache schema: docs/date-time.md. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify the per-turn temporal contract before merge (recommended)
    Compare the exact sibling Codex turn-context behavior with OpenClaw’s date/time-zone construction, then merge if the contract and cache-boundary invariants match.
  2. Pause for semantic redesign
    If direct dependency inspection shows a different contract, pause this branch and choose a documented OpenClaw-specific temporal-context policy before landing.

Technical review

Best possible solution:

Keep the date and IANA time zone in the cache-volatile prompt suffix, retain exact time as tool-backed guidance only when that tool exists, and merge only after direct Codex-contract confirmation plus normal maintainer approval.

Do we have a high-confidence way to reproduce the issue?

Unclear: the original temporal-grounding failure is source-reproducible from the prior timezone-only prompt shape, and this branch adds date-rollover tests, but this review did not independently run a current-main live long-session reproduction.

Is this the best way to solve the issue?

Unclear: the shared prompt-builder approach is the narrowest apparent fix because it reaches embedded, CLI, command, and compaction paths, but the claimed Codex semantic match still requires direct dependency-source confirmation.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against 51241c4e00ff.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded agent prompt-correctness improvement for relative-date reasoning, with meaningful but non-emergency user impact.
  • merge-risk: 🚨 session-state: The PR changes volatile system-prompt context used by long-running and compaction sessions, so an incorrect cache boundary or refresh contract could alter ongoing agent reasoning.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its supplied exact-head focused Testbox evidence and successful real-behavior-proof check remain useful supplemental validation.

Evidence

What I checked:

  • Prompt implementation: The proposed prompt section requires both a local date and time zone and places the optional exact-time guidance behind availability of the session-status tool. (src/agents/system-prompt.ts:429, d064c20c5e3b)
  • Per-entry-point wiring: The branch changes the shared prompt-parameter builder to produce userDate and passes it through embedded, CLI, command, and compaction prompt assembly paths. (src/agents/system-prompt-params.ts:55, d064c20c5e3b)
  • Focused validation supplied on exact head: The contributor reports an immutable-head Blacksmith Testbox run passing 252 focused tests across touched prompt entry points and compaction; the GitHub context also shows the relevant prompt, docs, lint, type, boundary, and real-behavior-proof checks succeeding on this head. (src/agents/system-prompt.test.ts:715, d064c20c5e3b)
  • Related bug ownership: The PR is presented as the broader candidate fix for the open temporal-grounding report, while the older heading-only PR remains open and behind current main. (src/agents/system-prompt.ts:429, d064c20c5e3b)
  • Required dependency-contract gap: Repository policy requires the acting reviewer to inspect the sibling Codex source for exact protocol/runtime behavior before a Codex-related verdict. That direct source inspection could not be completed in this read-only review environment.

Likely related people:

  • vincentkoc: Authored all four commits on the current PR head, including the core prompt wiring, documentation refresh, and compaction-harness repair; repository context identifies the author as a MEMBER. (role: recent temporal-context contributor; confidence: medium; commits: f58fe6261fd9, 41d34ca58c90, 6c75e19f2f62; files: src/agents/system-prompt.ts, src/agents/system-prompt-params.ts, src/agents/embedded-agent-runner/prepared-compaction-runtime.ts)
  • deepujain: Is credited as co-author of the core implementation commit and authored the earlier open heading-only temporal-context PR that this branch supersedes in scope. (role: adjacent temporal-context contributor; confidence: medium; commits: f58fe6261fd9; files: src/agents/system-prompt.ts, docs/date-time.md)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Personally inspect the matching sibling Codex per-turn date/time-zone source paths and compare their refresh semantics with this prompt builder.
  • Record that contract comparison in the maintainer review before merging.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-07-29T21:37:01.527Z sha f391484 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T21:44:11.746Z sha 56882a306969b765120c56af553f865d0ebe8208 :: found issues before merge. :: [P2] Remove the release-owned changelog edit
  • reviewed 2026-07-29T21:50:28.865Z sha 56882a306969b765120c56af553f865d0ebe8208 :: found issues before merge. :: [P2] Remove the release-owned changelog entry
  • reviewed 2026-07-29T22:01:10.594Z sha d064c20 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 29, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

ClawSweeper rank-up move resolution for exact head 56882a306969b765120c56af553f865d0ebe8208:

The completed review on f391484… had no code findings. Both rank-up moves are now satisfied on 56882a3….

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc force-pushed the fix/temporal-context-grounding branch from 56882a3 to d064c20 Compare July 29, 2026 21:57
@vincentkoc

vincentkoc commented Jul 29, 2026 •

Copy link
Copy Markdown
Member Author

ClawSweeper finding resolution for exact head d064c20c5e3bbf40a033a1658ac1b06d40cb41d7:

  • Removed the normal-PR CHANGELOG.md entry as requested. Contributor credit remains in the implementation commit and PR context.
  • Rebased onto current origin/main (51241c4e00ff3056dfae87aa45b69744c2ce3e8a).
  • Fixed the exact CI regression by adding the new formatDateStamp export to the compaction harness's full date-time module mock.
  • Focused Blacksmith Testbox proof passed all 119 compaction-hook tests: https://github.com/openclaw/openclaw/actions/runs/30493971284
  • Fresh branch autoreview after the rebase is clean with no accepted/actionable findings.
  • Docs map, formatting, MDX, link audit, and git diff --check pass on this head.

Expanded immutable-head Blacksmith Testbox proof passed 252 tests across every touched prompt entry point plus compaction: https://github.com/openclaw/openclaw/actions/runs/30494288303

GitHub CI is running on this exact head.

Maintainer dependency-contract gate completed directly against sibling Codex source at 414782450952a196bbb64b1605a458c2531c47b6:

  • codex-rs/core/src/session/turn_context.rs:420-427 computes local YYYY-MM-DD plus the IANA timezone, with a UTC fallback.
  • codex-rs/core/src/session/turn_context.rs:546-566 refreshes both values while building each TurnContext.
  • codex-rs/core/src/context/world_state/environment.rs:97-138 emits a new user-role world-state fragment when the date or timezone changes.
  • codex-rs/core/src/context/world_state/environment.rs:214-215 renders <current_date> and <timezone>.

This confirms the PR's contract: refresh calendar date and timezone below the stable prompt-cache prefix, while keeping exact clock time tool-backed. ClawSweeper's remaining rank-up move is satisfied.

@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 29, 2026
@vincentkoc
vincentkoc enabled auto-merge (squash) July 29, 2026 22:08
@vincentkoc
vincentkoc merged commit 54e273e into main Jul 29, 2026
126 of 132 checks passed
@vincentkoc
vincentkoc deleted the fix/temporal-context-grounding branch July 29, 2026 22:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
…enclaw#116090)

* fix(agents): ground date reasoning below cache boundary

Co-authored-by: Deepak Jain <[email protected]>

* docs: refresh temporal context map

* chore: leave release notes to release curation

* test(agents): keep compaction date mock complete

---------

Co-authored-by: Deepak Jain <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading prompt section can cause incorrect date reasoning even when timezone-only behavior is intended

1 participant