Skip to content

System prompt KIMI_NOW is stale on session resume — cached timestamp never refreshes #446

Description

@yesme

Bug Description

The system prompt variable KIMI_NOW (injected via Jinja2 template in system.md) is evaluated only once at session creation time and then persisted to context.jsonl. On every subsequent session resume, the cached value is reused instead of being regenerated. This causes the agent to receive a stale timestamp that can be days or weeks old.

Reproduction Steps

  1. Create a new Kimi CLI session at time T0.
  2. Close / suspend the session.
  3. Wait some time (e.g., several days).
  4. Resume the same session.
  5. Observe that KIMI_NOW in the system prompt still shows T0.

Concrete Evidence

In our environment:

  • Session directory birth time: 2026-05-08 00:00:17
  • Current system time (via date): 2026-06-05T02:42:13+08:00
  • System prompt injected to the model: 2026-05-08T00:00:18
  • The stale timestamp is stored in the first line of context.jsonl:
    {"role":"_system_prompt","content":"...The current date and time in ISO format is 2026-05-08T00:00:18..."}

Root Cause

In kimi_cli/soul/agent.py:

# Line ~307
builtin_args=BuiltinSystemPromptArgs(
    KIMI_NOW=datetime.now().astimezone().isoformat(),  # <-- evaluated once at Runtime() construction
    ...
)

Runtime (and thus BuiltinSystemPromptArgs) is constructed when the session is first created. On resume, context.py reads the previously persisted system prompt from context.jsonl instead of regenerating it:

# context.py ~293
if role == "_system_prompt":
    self._system_prompt = content

Impact

  • Agent makes incorrect time-based judgments (file modification age, commit recency, web search relevance windows, etc.)
  • The system prompt itself tells the agent: "If you need the exact time, use Shell tool with proper command," yet the stale timestamp is silently presented as fact, leading the agent to skip verification.
  • In our case the agent directly quoted the injected time (2026-05-08) without running date, causing a ~4-week error in date-sensitive reasoning.

Environment

  • Version: kimi-cli 1.46.0
  • OS: Ubuntu (Linux)
  • Shell: bash

Suggested Fixes

Option A — Remove KIMI_NOW entirely:
The system prompt already contains the instruction "If you need the exact time, use Shell tool." Removing the variable eliminates the stale-data hazard without adding token cost.

Option B — Regenerate on each turn:
Re-evaluate datetime.now() and rebuild the system prompt on every turn. Accurate, but increases token usage.

Option C — Lazy substitution (recommended):
Keep the cached system prompt in context.jsonl, but replace KIMI_NOW with a sentinel (e.g., __KIMI_NOW_PLACEHOLDER__). At turn-time, substitute the placeholder with the actual current time before sending to the LLM. This preserves cache efficiency while guaranteeing freshness.


Happy to provide more details or test a patch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions