Skip to content

fix(agent-core-v2): tolerate stray files in the sessions directory during index scans - #3501

Open
zhi1ong wants to merge 1 commit into
MoonshotAI:mainfrom
zhi1ong:fix/session-index-stray-files
Open

fix(agent-core-v2): tolerate stray files in the sessions directory during index scans#3501
zhi1ong wants to merge 1 commit into
MoonshotAI:mainfrom
zhi1ong:fix/session-index-stray-files

Conversation

@zhi1ong

@zhi1ong zhi1ong commented Sep 3, 2026

Copy link
Copy Markdown

Related Issue

Resolve #3500

(Filed with this PR; awaiting a maintainer's /approve.)

Problem

On 0.40.x the resume picker (kimi -r, /sessions) and kimi session list list no sessions at all when any workspace bucket directory under ~/.kimi-code/sessions/ contains a stray regular file — macOS Finder's .DS_Store is the common trigger. The scan added in #3422 stats <entry>/state.json for every entry of every bucket directory; for a regular-file entry that fails with ENOTDIR, which the node-fs storage translated to StorageError(io_failed) ("storage stat failed: unrecognized I/O error"), rejecting the whole scan. Projection, startup freshness checks, periodic reconciliation, and the authoritative fallback read all fail, so fresh processes cannot list any session. Long-running servers degrade into a per-entry-tolerant branch and keep working, which makes the failure look like frontends see different session sets.

What changed

  • node-fs storage: isEnoent is now isMissingEntry and also matches ENOTDIR. A regular file in place of a scope directory means the probed key cannot exist, so read, readStream, list, delete, size, and mtime report it as missing instead of throwing. This fits the existing storage contract ("undefined = missing"), heals every session-index scan path through one seam, and matches the in-memory backend, where probing a path below a value already resolves to missing.
  • Alternative considered: per-entry catches inside the session-index scans. Rejected — it patches only the session domain while other storage consumers stay fragile, and swallowing arbitrary stat errors there could mask real corruption; the storage layer is where ENOENT semantics already live.
  • Test: regression case covering a regular file in place of a scope directory for all probe operations.
  • Changeset: patch entry for @moonshot-ai/kimi-code.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…ring index scans

The session index mtime probes stat <entry>/state.json for every entry of
every workspace bucket directory. A stray regular file inside a bucket
(e.g. a Finder .DS_Store) makes that stat fail with ENOTDIR, which the
node-fs storage translated to StorageError(io_failed), rejecting the
whole scan: freshness checks, (re)projection, reconciliation, and the
authoritative read path all fail, so the resume picker and
kimi session list show no sessions.

Treat ENOTDIR like ENOENT in the node-fs storage probes: a regular file
in place of a scope directory means the key cannot exist, so read,
readStream, list, delete, size, and mtime now report it as missing
instead of failing. This matches the in-memory backend, where probing a
path below a value already resolves to missing.
@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7c25b1b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-03T04:58:12.372110Z 7c25b1b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Resume picker and kimi session list show no sessions when a stray file sits in a sessions bucket directory

1 participant