MoonshotAI / MoonshotAI/kimi-cli

Session resume overrides newly generated system prompt, preventing skill/config updates from taking effect / 恢复会话时旧系统提示覆盖新生成的提示,导致技能与配置更新无法生效

Open
#2,420 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

Problem Description

When a user resumes an old session, Kimi CLI reads the stale _system_prompt from context.jsonl and unconditionally overrides the freshly generated system prompt from load_agent(). This causes:

  1. New skills never appear: Adding a skill to ~/.kimi/skills/ and restarting/resuming the session still shows the old skill list in the system prompt.
  2. Config changes are silently ignored: Modifying settings that affect the system prompt (e.g. merge_all_available_skills) has no effect after resume.
  3. /fork cannot fix it: /fork copies the old context.jsonl verbatim, including the stale system prompt.

Reproduction Steps

  1. Start a session (system prompt loads N skills).
  2. Add a new skill to ~/.kimi/skills/.
  3. Exit and re-enter Kimi CLI (auto-resumes last session).
  4. Observe ## Available skills in the system prompt — still only N skills, the new one is missing.
  5. Check logs: Discovered {N+1} skill(s) is logged, but the system prompt does not reflect it.

Root Cause

The root cause is in src/kimi_cli/app.py:

context = Context(session.context_file)
await context.restore()

if context.system_prompt is not None:
    agent = dataclasses.replace(agent, system_prompt=context.system_prompt)  # stale overrides fresh
else:
    await context.write_system_prompt(agent.system_prompt)

Runtime.create() and load_agent() do re-discover skills from disk and render a fresh system prompt. However, context.restore() reads the persisted _system_prompt and overwrites the fresh one unconditionally.

Impact

  • Users cannot update skills via normal restart.
  • Users cannot update skills via /fork.
  • Workaround requires manually deleting context.jsonl or using kimi --new.

Suggested Fixes

Option A (recommended): When resuming, compare the skills section of the old vs. new system prompt. If they differ (or if KIMI_AGENTS_MD / other external-state sections differ), use the newly generated prompt and persist it:

context = Context(session.context_file)
await context.restore()

if context.system_prompt is not None:
    if _skills_section_changed(context.system_prompt, agent.system_prompt):
        await context.write_system_prompt(agent.system_prompt)
    else:
        agent = dataclasses.replace(agent, system_prompt=context.system_prompt)
else:
    await context.write_system_prompt(agent.system_prompt)

Option B: Add a config flag always_regenerate_system_prompt = true for power users.

Option C: During /fork, do not copy _system_prompt from context.jsonl; let the forked session regenerate it.

Environment

  • kimi-cli version: 1.46.0
  • OS: Windows 11

問題描述

當用戶恢復舊 session 時,Kimi CLI 會從 context.jsonl 中讀取舊的 _system_prompt,並用它無條件覆蓋 load_agent() 剛剛新生成的系統提示。這導致:

  1. 新增的技能永遠不會出現:用戶在 ~/.kimi/skills/ 新增了 skill,重啟/恢復 session 後系統提示仍然顯示舊的 skill 列表。
  2. 配置變更被靜默忽略:修改 merge_all_available_skills 等影響系統提示的配置後,重啟仍然使用舊配置生成的系統提示。
  3. /fork 也無法解決/fork 直接複製舊的 context.jsonl,包括舊的系統提示。

復現步驟

  1. 創建一個 session(此時系統提示載入 N 個 skills)。
  2. ~/.kimi/skills/ 新增一個 skill。
  3. 退出 Kimi CLI,重新進入(會自動恢復上個 session)。
  4. 觀察系統提示的 ## Available skills 區塊——仍然只有 N 個 skills,新增的 skill 沒有出現。
  5. 檢查日誌可見 Discovered {N+1} skill(s),但系統提示中並未反映。

根因分析

問題出在 src/kimi_cli/app.py

context = Context(session.context_file)
await context.restore()

if context.system_prompt is not None:
    agent = dataclasses.replace(agent, system_prompt=context.system_prompt)  # 用舊的覆蓋新的
else:
    await context.write_system_prompt(agent.system_prompt)

Runtime.create()load_agent() 確實會根據當前磁盤狀態重新發現 skills 並生成新的系統提示,但 context.restore() 讀取的舊 _system_prompt無條件覆蓋它。

影響範圍

  • 用戶無法通過正常重啟更新 skills。
  • 用戶無法通過 /fork 更新 skills。
  • 必須手動刪除 context.jsonl 或使用 kimi --new 才能看到新技能。

建議修復方案

方案 A(推薦):恢復 session 時比較新舊系統提示,若 KIMI_SKILLSKIMI_AGENTS_MD 等依賴外部狀態的部分發生變化,則使用新生成的系統提示:

context = Context(session.context_file)
await context.restore()

if context.system_prompt is not None:
    if _skills_section_changed(context.system_prompt, agent.system_prompt):
        await context.write_system_prompt(agent.system_prompt)
    else:
        agent = dataclasses.replace(agent, system_prompt=context.system_prompt)
else:
    await context.write_system_prompt(agent.system_prompt)

方案 B:提供配置選項 always_regenerate_system_prompt = true,讓進階用戶選擇始終使用最新生成的系統提示。

方案 C/fork 時不複製 context.jsonl 中的 _system_prompt,而是讓新會話重新生成。

環境

  • kimi-cli version: 1.46.0
  • OS: Windows 11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/kimi_cli/app.py at the session restore path, then trace Context.restore(), Runtime.create(), load_agent(), and the /fork handling described in the issue. Verify resumed and forked sessions use the freshly generated prompt when skills or prompt-related configuration has changed, while preserving the stored prompt when it has not.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.