fix(app): refresh stale frozen system prompt on session resume#2519
Open
Nas01010101 wants to merge 3 commits into
MoonshotAI:mainMoonshotAI/kimi-cli:mainfrom
Nas01010101:fix-2420-stale-system-promptNas01010101/kimi-cli:fix-2420-stale-system-promptCopy head branch name to clipboard
Open
fix(app): refresh stale frozen system prompt on session resume#2519Nas01010101 wants to merge 3 commits intoMoonshotAI:mainMoonshotAI/kimi-cli:mainfrom Nas01010101:fix-2420-stale-system-promptNas01010101/kimi-cli:fix-2420-stale-system-promptCopy head branch name to clipboard
Nas01010101 wants to merge 3 commits into
MoonshotAI:mainMoonshotAI/kimi-cli:mainfrom
Nas01010101:fix-2420-stale-system-promptNas01010101/kimi-cli:fix-2420-stale-system-promptCopy head branch name to clipboard
Conversation
Resuming a session unconditionally adopted the _system_prompt record frozen in context.jsonl, so skills added to ~/.kimi/skills, AGENTS.md edits, and prompt-affecting config changes silently never reached resumed sessions. Adopt the freshly generated prompt when it differs and persist it; write_system_prompt now drops the previous _system_prompt record when rewriting, since restoration takes the last record and a leftover stale one would win again on the next restore. Resolve MoonshotAI#2420
This was referenced Jul 19, 2026
prepare_soul froze the persisted subagent system prompt the same way KimiCLI.create did for root sessions; apply the same refresh-on-diff so resumed subagents also pick up skills and AGENTS.md changes.
Author
|
Pushed a follow-up commit extending the fix to subagents: Full suite re-run after the change: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Resolve #2420
Description
Resuming a session unconditionally adopts the
_system_promptrecord frozen incontext.jsonl(KimiCLI.create, introduced in #1417), so:~/.kimi/skills/never appear in resumed sessions,AGENTS.mdedits never reach resumed sessions,/forkcopies the stale prompt along, so forking can't recover either.This implements Option A from #2420: when the freshly generated prompt differs from the frozen one, adopt the fresh prompt and persist it; when they're equal, the frozen record is left untouched. The
context.jsonlinvariant from #1417 — the file always carries the prompt actually in use, readable by frontends/vis tools — is preserved.Latent bug fixed along the way:
Context.write_system_prompt()prepended a new_system_promptrecord without removing the existing one, whilerestore()applies the last_system_promptrecord seen — so a refreshed prompt would silently lose to the stale leftover on the very next restore. The rewrite now drops previous_system_promptrecords (streaming, byte-preserving for non-prompt lines, atomic via temp file as before).Real-behavior proof (deterministic, local mock provider)
~/.kimi/skills/skill-one/, runkimi --print -p "first session"→ request system prompt listsskill-one. ✅~/.kimi/skills/skill-two/, runkimi --print -C -p "resumed":main:skill-one: True, skill-two: False❌ (bug reproduced)skill-one: True, skill-two: True✅Verification
main):tests/core/test_context.py::test_write_system_prompt_replaces_existing_recordtests/core/test_resume_system_prompt.py— stale prompt refreshed & persisted / unchanged prompt untouched / new session written.uv run pytest tests/core→ 862 passed; fulltests/suite green.ruff/pyrightclean.Notes for reviewers
The generated prompt includes volatile builtins (
KIMI_NOW,KIMI_WORK_DIR_LS), so in practice the prompt is rewritten on most resumes. That refreshes the stale timestamp/directory listing too (previously the model was told the session's original creation time as "now"). If you'd rather compare only the stable sections to preserve cross-restart provider prompt caching, happy to adjust — see #2420 discussion.Checklist
## Unreleasedentry;make gen-changelogneeds kimi API auth).make gen-docs— N/A: no user-facing docs change.