What version of Kimi Code is running?
main at f06eb5c60e0a4e51162d1854dda1db41892b457c
Which open platform/subscription were you using?
Not provider-specific; this occurs while loading locally persisted session metadata.
Which model were you using?
Not model-specific.
What platform is your computer?
Source-level reproduction; the affected writers include local and SSH persistence paths.
What issue are you seeing?
If a session's state.json contains incomplete or otherwise invalid JSON, resuming that session rejects before any agent is reconstructed. The conversation records under the session's agent directories are stored separately, but the normal resume path cannot reach them without manually repairing the metadata.
The repository already has a test that reproduces this by replacing state.json with {bad json; resumeSession() rejects and records session_load_failed with a SyntaxError.
What steps can reproduce the bug?
- Create a session.
- Close it.
- Replace the session's
state.json contents with incomplete JSON such as {bad json.
- Attempt to resume the session.
- Observe that resume rejects before the main agent is reconstructed.
This is a deterministic malformed-file reproduction. An interruption during an in-place overwrite is a plausible way to produce such a file, but this report does not claim an observed production interruption.
What is the expected behavior?
Updating session metadata should not expose partially written JSON at the final path. If metadata is already invalid, resume should report an actionable session.state_invalid error while preserving the damaged file; it should not silently construct a session from empty or default metadata.
Automatic backup recovery is a separate policy decision. If added later, it should only accept a validated, known-good copy and should make recovery visible to the user.
Additional information
Confirmed source behavior
metadata change
|
v
write final state.json in place
|
+-- write completes --> valid new metadata
|
`-- write interrupted (hypothesis) --> partial JSON
|
v
next resume rejects
before agent replay
Proposed direction
Use same-directory temporary-file replacement for every production state.json writer:
- Write and close the complete temporary file.
- Replace the final path atomically where the backend supports it.
- Clean up the temporary file if replacement does not happen.
- Keep the existing live-session write queue so later metadata still wins.
- Translate malformed persisted metadata to
session.state_invalid, preserving the cause and the on-disk file.
The implementation needs an explicit persistence-abstraction contract because live metadata can use local or SSH-backed Kaos. Backup creation or automatic fallback is intentionally not required by this issue.
Acceptance criteria
- A failed/interrupted write before replacement leaves the previous valid
state.json readable.
- Live and offline session metadata mutations use the crash-safe replacement path.
- Malformed JSON returns the existing actionable
session.state_invalid error.
- Invalid metadata is never silently replaced with
{} or default session metadata.
- The serialized live metadata queue retains latest-write-wins behavior.
No directly related issue or pull request was found in a narrow search for state.json corruption, session resume, and atomic session metadata writes.
What version of Kimi Code is running?
mainatf06eb5c60e0a4e51162d1854dda1db41892b457cWhich open platform/subscription were you using?
Not provider-specific; this occurs while loading locally persisted session metadata.
Which model were you using?
Not model-specific.
What platform is your computer?
Source-level reproduction; the affected writers include local and SSH persistence paths.
What issue are you seeing?
If a session's
state.jsoncontains incomplete or otherwise invalid JSON, resuming that session rejects before any agent is reconstructed. The conversation records under the session's agent directories are stored separately, but the normal resume path cannot reach them without manually repairing the metadata.The repository already has a test that reproduces this by replacing
state.jsonwith{bad json;resumeSession()rejects and recordssession_load_failedwith aSyntaxError.What steps can reproduce the bug?
state.jsoncontents with incomplete JSON such as{bad json.This is a deterministic malformed-file reproduction. An interruption during an in-place overwrite is a plausible way to produce such a file, but this report does not claim an observed production interruption.
What is the expected behavior?
Updating session metadata should not expose partially written JSON at the final path. If metadata is already invalid, resume should report an actionable
session.state_invaliderror while preserving the damaged file; it should not silently construct a session from empty or default metadata.Automatic backup recovery is a separate policy decision. If added later, it should only accept a validated, known-good copy and should make recovery visible to the user.
Additional information
Confirmed source behavior
Session.writeMetadata()serializes writes but callspersistenceKaos.writeText()on the finalstate.jsonpath.Kaos.writeText()useswriteFile()and SSHKaos.writeText()uses an SFTP write on the final path.writeFile()on the finalstate.jsonpath.Session.resume()callsreadMetadata()before reconstructing agents.readMetadata()currently passes rawJSON.parse()failures through rather than translating them to the existing publicsession.state_invaliderror.Proposed direction
Use same-directory temporary-file replacement for every production
state.jsonwriter:session.state_invalid, preserving the cause and the on-disk file.The implementation needs an explicit persistence-abstraction contract because live metadata can use local or SSH-backed
Kaos. Backup creation or automatic fallback is intentionally not required by this issue.Acceptance criteria
state.jsonreadable.session.state_invaliderror.{}or default session metadata.No directly related issue or pull request was found in a narrow search for
state.jsoncorruption, session resume, and atomic session metadata writes.