Skip to content

fix: handle windows session workdir separators#486

Open
qkunio wants to merge 1 commit into
MoonshotAI:mainfrom
qkunio:fix/windows-session-workdir
Open

fix: handle windows session workdir separators#486
qkunio wants to merge 1 commit into
MoonshotAI:mainfrom
qkunio:fix/windows-session-workdir

Conversation

@qkunio
Copy link
Copy Markdown
Contributor

@qkunio qkunio commented Jun 5, 2026

Related Issue

Resolve #477

Problem

Windows 下恢复 session 时,使用kimi -r 误报:

Sessionxxxxxx was created under a different directory.

原因是Windows下对于路径的判断逻辑有点问题,保存的时候是normalized,统一两种路径分隔符(比如“C:/a/b”),比对的时候取当前目录却用原始路径(比如"C:\a\b"),同一个目录在比较的时候可能同时出现 “/” 和 ”\“ 两种路径分隔符,直接字符串比较会被判断为不同目录。统一这个下划线格式就好了。

What changed

恢复 session 前比较工作目录时,先统一路径分隔符。

影响位置
(两个判断,一个是在kimi -r session_1exxxxxxxxx,一个是在kimi -p "hello"-r session_1exxxxxxxxxxxx):

  • apps/kimi-code/src/cli/run-prompt.ts
  • apps/kimi-code/src/tui/kimi-tui.ts

修复地很简单直接把原始路径里的'\'都换成'/'就可以了,目前测试下来没有问题,当然欢迎更好的方法。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • 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.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 5, 2026

⚠️ No Changeset found

Latest commit: 9427739

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 5, 2026

pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@9427739
npx https://pkg.pr.new/@moonshot-ai/kimi-code@9427739

commit: 9427739

@liruifengv
Copy link
Copy Markdown
Collaborator

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9d53c31d7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/cli/run-prompt.ts Outdated
throw new Error(`Session "${opts.session}" not found.`);
}
if (target.workDir !== workDir) {
if (target.workDir.replaceAll('\\', '/') !== workDir.replaceAll('\\', '/')) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve POSIX backslashes when comparing workdirs

Because this normalization runs on POSIX as well as Windows, a session created under a literal directory like /tmp/a\b is now treated as if it belongs to /tmp/a/b, so an explicit -r can bypass the “different directory” guard and resume a session against the wrong cwd. This guard matters because listSessions({ workDir, sessionId }) falls back to the global session index when the session is not in the current workDir bucket, so please only apply separator normalization for Windows paths (the same pattern appears in the TUI resume path).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实有一定可能,我将改为和保存session一样的地址转录逻辑。

@qkunio qkunio force-pushed the fix/windows-session-workdir branch from a9d53c3 to 9427739 Compare June 5, 2026 11:00
@qkunio
Copy link
Copy Markdown
Contributor Author

qkunio commented Jun 5, 2026

刚完成了修改,现在按照session的地址存入函数来比对,应该没啥问题了

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.

恢复session失败

2 participants