-
Notifications
You must be signed in to change notification settings - Fork 815
Session switch crashes: _system_prompt role not handled in Context.restore() #1443
Copy link
Copy link
Closed
Description
Bug Description
Switching sessions via /sessions crashes with a Pydantic validation error when the target session's context.jsonl contains a {"role": "_system_prompt", ...} entry.
Steps to Reproduce
- Start a kimi session and use it normally
- Run
/sessionsand select a different session to switch to - Crash occurs during session restore
Error
pydantic_core._pydantic_core.ValidationError: 1 validation error for Message
role
Input should be 'system', 'user', 'assistant' or 'tool' [type=literal_error, input_value='_system_prompt', input_type=str]
Root Cause
In kimi_cli/soul/context.py, the restore() method (line ~41-48) filters out internal metadata roles _usage and _checkpoint before passing messages to Message.model_validate(), but does not filter _system_prompt:
# Current code in restore()
if line_json["role"] == "_usage":
self._token_count = line_json["token_count"]
continue
if line_json["role"] == "_checkpoint":
self._next_checkpoint_id = line_json["id"] + 1
continue
message = Message.model_validate(line_json) # crashes on _system_promptThe same issue exists in revert_to() (~line 128-134).
Proposed Fix
Add a catch-all for any internal role (prefixed with _) so that future internal roles are also handled gracefully:
# In restore()
if line_json["role"] == "_usage":
self._token_count = line_json["token_count"]
continue
if line_json["role"] == "_checkpoint":
self._next_checkpoint_id = line_json["id"] + 1
continue
if line_json["role"].startswith("_"):
continue
message = Message.model_validate(line_json)
self._history.append(message)# In revert_to()
if line_json["role"] == "_usage":
self._token_count = line_json["token_count"]
elif line_json["role"] == "_checkpoint":
self._next_checkpoint_id = line_json["id"] + 1
elif not line_json["role"].startswith("_"):
message = Message.model_validate(line_json)
self._history.append(message)Environment
- kimi-cli version: 1.12.0
- kosong version: 0.42.0
- Python: 3.13.5
- OS: Linux (Ubuntu)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels