Skip to content

fix(agent-core-v2): compare working directories as paths before sending the date reminder - #5576

Merged
RealKai42 merged 1 commit into
mainfrom
fix/date-reminder-windows-cwd
Nov 26, 2026
Merged

RealKai42 merged 1 commit into
mainfrom
fix/date-reminder-windows-cwd

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Requirement or Bug

在 Windows 上,从终端启动的会话(TUI、print 模式),以及 SDK 用户建的会话,模型从来收不到「今天的日期」这条提醒,跨过午夜也收不到「日期变了」。模型只能靠训练数据猜日期,用户收不到任何信号:没有报错,也没有日志。#5570 加的 E5 场景(tests/e2e/scenarios/cache/date-change-keeps-the-prefix.spec.ts)第一次在 CI 的 Windows 作业上跑,就发现了这个问题。

Bug Reproduction Steps

  1. 在 Windows 上用 TUI 开一个会话,发一条消息;
  2. 看发给模型服务的第一次请求:没有 Today's date is … 这条提醒。

CI 上的复现:#5570 的 Windows tui 作业,E5 场景断言第一次请求的提醒里有本地日期,实际提醒是空的。同一个场景在 Linux 的 TUI、Windows 的 ACP、Desktop、Web 上都通过。

Root Cause

日期提醒有一道判断:只有在「system 渲染时的 cwd」和「当前 cwd」是同一个目录时才发,否则说明 system 是为别的目录渲染的,先不发。这道判断从一开始就用字符串 !== 比较,而两边在 Windows 上的写法不同:

cwd 从哪来 Windows 上的样子
当前 cwd SDK 建会话时用 normalizeWorkDir 把工作目录改成正斜杠,会话的 cwd 就是这个值 C:/Users/me/project
system 渲染时的 cwd EnvironmentWorkspaceView 用本机环境的路径模块(Windows 上是 node:path/win32)做 resolve C:\Users\me\project

两者永远不相等,判断就把日期提醒当成「不属于当前目录」静默丢掉。ACP、Desktop、Web 不经过 SDK 的正斜杠归一,Linux 和 macOS 只有正斜杠,所以只有 Windows 上经 SDK 建的会话受影响。

这是根本修复:判断的用意不变,只是把「是不是同一个目录」从字符串相等改成路径等价。

Code Changes

 belongsToCurrentCwd()
   environment = system 渲染时记下的 cwd
   if environment.cwd is empty: return true
-  return environment.cwd === (环境绑定的 cwd ?? 会话 cwd)
+  return sameDir(environment.cwd, 环境绑定的 cwd ?? 会话 cwd)

sameDir 是引擎里现成的目录比较(packages/agent-core-v2/src/_base/utils/workdir-slug.ts,工作区根目录也用它):先规范化路径,统一斜杠方向、去掉末尾斜杠,Windows 形状的路径不分大小写。

阅读顺序:

  1. packages/agent-core-v2/src/features/dateChange/dateChangeService.ts 的 belongsToCurrentCwd();
  2. packages/agent-core-v2/test/features/dateChange/dateChangeInjection.test.ts 新增的 AgentDateChangeService on a Windows session cwd。

Behavior Changes and Affected Users

行为 之前 之后 谁依赖旧行为 退路
Windows 上经 SDK 建的会话(TUI、print 模式、SDK 用户)的日期提醒 从不发:第一次请求不带今天的日期,跨天也不提醒 和其他面一样:第一次请求带今天的日期,跨天时提醒日期变了 无,缺这条提醒是 bug —
system 渲染的 cwd 和当前 cwd 只差斜杠方向、末尾斜杠、Windows 盘符或路径大小写、. 和重复斜杠 不发日期提醒 发 无 —
system 是为别的目录渲染的(比如切换环境之后、system 还没重新渲染) 不发 不发,不变 远程环境和切换 cwd 的会话 —
Linux、macOS 上的所有面;Windows 上的 ACP、Desktop、Web 发 发,不变 — —

提示词:两句提醒的文字都没改(Today's date is …、The date has changed. Today's date is now …),变化的是收到它们的人群:Windows 上的 TUI、print 模式和 SDK 会话从此能收到。这两句原来就约束「以最新的日期提醒为准,不要主动告诉用户」,现在对这个人群同样生效。

旧会话:Windows 上升级前建的会话恢复后,下一步会补一条「今天的日期」提醒,追加在历史末尾,不改写已有的请求前缀。

覆盖:

  • 引擎单测 AgentDateChangeService on a Windows session cwd:会话 cwd 是 SDK 写法 C:/Users/me/project、或者盘符是小写 c:\…,渲染的 cwd 是 C:\Users\me\project 时,第一步发今天的日期,拨动时钟后发「日期变了」。修复前这 2 条都失败,提醒是空的,和 CI 上的现象一致。另有 1 条:真的是另一个 Windows 目录时一条都不发,证明判断的用意还在。原有的「为别的目录渲染时不发」「渲染的 cwd 为空时照发」用例继续通过。
  • E2E:E5 场景已随 test: let e2e scenarios move the local date through a test clock file #5570 在 main 上,本 PR 的「Windows tui」作业会从真实入口验证。

验证:见折叠块。

运行的命令和结果

基线是 main f94b9a2f3,在 macOS 上跑。单测直接构造 Windows 写法的路径字符串,不依赖本机平台;Windows 上的真实行为交给本 PR 的 Windows E2E 作业。

  • 新增的 2 条回归用例在修复前失败(expected [] to deeply equal [ StringContaining "2026-07-29" ]),修复后通过。
  • pnpm exec vitest run 跑 packages/agent-core-v2/test/features/dateChange、test/session/agentLifecycle/agentLifecycle.test.ts、test/agent/profile、test/app/config/config.test.ts、test/agent/environmentBinding、test/features/reminder、test/remote 和 packages/kap-server/test/prompts.test.ts:21 个文件 637 条通过。
  • pnpm lint:通过。
  • pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit:通过。
  • pnpm run check:duplication f94b9a2f3:没有新增重复。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c84661e

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

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/agent-core-v2 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 Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T16:52:45.305973Z c84661e 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.

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c84661e
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c84661e

commit: c84661e

@RealKai42
RealKai42 merged commit cad77bf into main Nov 26, 2026
22 checks passed
@RealKai42
RealKai42 deleted the fix/date-reminder-windows-cwd branch November 26, 2026 17:34
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Dec 2, 2026
`bun scripts/upstream-ledger.mjs --refresh` at upstream/main 4eb2919
added 126 rows, so every open upstream commit and every PR it references
now has a ledger row: 0/596, down from 125 at 8bf8ba3 and 126 at the
fetched tip. The refresh only reads `upstream/main ^ main`, so the three
release-2.6.2 commits named by the mission (MoonshotAI#4875/MoonshotAI#4905/MoonshotAI#4922) gained
rows with the refresh's row shape.

Settled with live probes in this tree:

- ported: MoonshotAI#5533 (docs 2.8.1 changelog), MoonshotAI#4875 (registry search_url and
  feedback_url plus the feedback service), MoonshotAI#4905 (Kimi upload status
  validation in packages/core), MoonshotAI#4922 (swarm task events in
  sessionTaskFeed), MoonshotAI#5438 (unload only declared dynamic tools), MoonshotAI#5592
  (dynamic tool replacement order), MoonshotAI#5595 (append-log known length),
  MoonshotAI#5573 (skill roots for every work dir), MoonshotAI#5576 (date reminder cwd
  comparison), MoonshotAI#5618 (session titles for skill openers), MoonshotAI#5638 (frozen
  loop tool baseline), MoonshotAI#5626 (legacy turn-input origins)
- partial: MoonshotAI#5505 (processLiveness source and consumers present; the
  upstream unit test file was never carried), MoonshotAI#5571 (program-resume and
  OSC 7577 present; the upstream test helper was never carried), MoonshotAI#5532
  (gitService half present; fsService still leaks the environment lease
  at fsService.ts:1133 and :1267), MoonshotAI#5557 (app-client icon registry kept;
  the move to app-ui was never carried)
- not-applicable: MoonshotAI#4655 (upstream reverted auto review in MoonshotAI#5649), MoonshotAI#5333
  (PLAYBOOK:111 deliberate flat experimental flags)

M39's "likely present" list was checked, not trusted: MoonshotAI#5438 is present
(upstream test passes), MoonshotAI#5487 is not (nativeStartSettleMs/leg.nativeSettled
absent), MoonshotAI#5635 is not (ToolsSettled absent), MoonshotAI#5429 needs a visual probe.
The remaining 194 pending rows stay open with their reasons; no feature
was ported and no upstream-drift allowlist entry was added.

Verification: verify -> 332 closed rows, 332 carry every file of their
PR; 317 probes pass, 2 foreign-runner skips, 0 fail; a second verify is
byte-identical (ledger sha256 cbf53638...). Probe tests 29 pass; bun run
lint and node scripts/checks/ratchet.mjs green.
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.

1 participant