Skip to content

fix(agent): refresh the system-prompt date line when UTC rolls over - #86942

Closed
ayushnangia wants to merge 2 commits into
NousResearch:mainfrom
ayushnangia:fix/system-prompt-date-rollover
Closed

ayushnangia wants to merge 2 commits into
NousResearch:mainfrom
ayushnangia:fix/system-prompt-date-rollover

Conversation

@ayushnangia

Copy link
Copy Markdown
Contributor

Summary

Fixes #86938: the system prompt's Conversation started: <date> line is built date-only and cached per session for prefix-cache stability (#20451, credit @iamfoz) — but a session running past UTC midnight kept yesterday's date forever.

Changes (implementation + test as separate commits)

  • agent/system_prompt.py: build_system_prompt records the stamped date on the agent (_system_prompt_date, %Y-%m-%d); new system_prompt_date_stale(agent) helper compares it against the current date (guarded, never raises).
  • agent/turn_context.py: the turn-start hook rebuilds the cached prompt once when the date is stale — same day-granularity as the original design, so the prefix-cache rationale is untouched (one rebuild per rollover, never per turn).

Validation

  • New tests: build records the date · rollover detected across 23:59→00:01 · no recorded date → not stale. Green.
  • scripts/run_tests.sh tests/agent/test_system_prompt.py tests/agent/test_turn_context.py39 passed, 0 failed

Credit: @iamfoz's #20451 rationale preserved intact; reporter of #86938 for the rollover catch.

@alt-glitch alt-glitch added type/feature New feature or request comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have needs-decision Awaiting maintainer decision before any implementation labels Aug 15, 2026
@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review for reference, author can ignore or act on any point.

fix(agent): refresh the system-prompt date line when UTC rolls over

  • The once-per-day rebuild deliberately invalidates the prefix cache mid-conversation (agent/turn_context.py:737-746). This is a bounded, documented exception to the "never rebuild mid-conversation" rule, but it still costs a full cache re-prime for every long-lived session at each UTC rollover — worth an explicit team sign-off that the daily re-prime is an acceptable trade against a stale "Conversation started:" line.
  • system_prompt_date_stale swallows all exceptions and returns False (agent/system_prompt.py:831-846): if hermes_time.now fails after the attribute is set, the stale date persists silently with no log. The fail-safe direction is right, but a debug-level log would make the visible staleness diagnosable.
  • The rollover rebuild path calls agent._build_system_prompt(system_message) directly, while the cold path uses restore_or_build_system_prompt(agent, system_message, conversation_history). If those two paths can diverge (history-dependent context, compression state), the rebuild could produce a one-turn prompt difference on rollover day — worth asserting they're equivalent.
  • Minor: build_system_prompt wraps the hermes_time import in a bare except Exception: pass (system_prompt.py:822-827); if the import ever fails, the date is never recorded and rollover refresh is silently disabled for that session. A stdlib fallback (datetime.now(timezone.utc)) would keep the mechanism working regardless.

@ayushnangia
ayushnangia force-pushed the fix/system-prompt-date-rollover branch from 4e502f6 to 528b3f3 Compare August 17, 2026 09:04
The 'Conversation started:' line is built date-only and cached per
session for prefix-cache stability (NousResearch#20451). A session running past UTC
midnight kept yesterday's date forever. Record the stamped date at build
time and rebuild the prompt exactly once per rollover at the turn-start
hook (NousResearch#86938) — day granularity keeps the cache intact within each day.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint needs-decision Awaiting maintainer decision before any implementation P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

system_prompt timestamp stale after UTC midnight - model reports wrong date in long sessions

3 participants