[Bug] Agent workspace AGENTS.md silently never loads on Windows: st_dev mismatch between path-stat and handle-fstat in readInstructionFile() identity check
Summary
On Windows, the agent workspace-instructions loader rejects every AGENTS.md because its file-identity check compares st_dev between a path-based stat() and a handle-based fstat(). These two stat flavors return different st_dev values on Windows (path-stat → 0, handle-fstat → the real volume serial number), so the check can never pass: the file is silently skipped and the session system prompt reports:
No root AGENTS.md was found while preparing this turn.
Environment
- Chatbox 1.23.5 (Windows x64 installer)
- Windows 11 Pro, build 26200
- Workspace directory on an NTFS volume (
H:\ai-workspace\chatbox-work) - Underlying Node behavior reproduced with standalone Node v22.16.0 (same major as current Electron bundles)
Steps to reproduce
- Set an agent working directory (e.g.
H:\ai-workspace\chatbox-work) and place a validAGENTS.mdinside it. - Start a new agent session and ask whether AGENTS.md is loaded.
- The system prompt contains "No root AGENTS.md was found while preparing this turn." — with no error anywhere in the app logs.
Root cause
src/main/workspace-instructions.ts → readInstructionFile() (anti-TOCTOU identity check):
fileHandle = await open(filePath, fsConstants.O_RDONLY | noFollowFlag)
const fileStat = await fileHandle.stat() // handle-based fstat
...
const canonicalFileAfterOpen = await realpath(filePath)
...
const pathStat = await stat(canonicalFileAfterOpen) // path-based stat
if (pathStat.dev !== fileStat.dev || pathStat.ino !== fileStat.ino) return nullOn Windows (libuv / Node 22):
| stat flavor | st_dev |
st_ino |
|---|---|---|
fs.promises.stat(path) (path-based) |
0 |
NTFS file ID ✔ |
fileHandle.stat() (handle-based) |
volume serial number | NTFS file ID ✔ (identical) |
So pathStat.dev !== fileStat.dev is always true → return null → AGENTS.md never loads. The rejection is a bare return null with no logging anywhere in the loader, which makes it undiagnosable from logs.
Evidence 1 — standalone Node probe (same file, both stat flavors)
{ "file": "C:\\…\\Temp\\dev_ino_probe_c.txt",
"pathStat": { "dev": 0, "ino": 34058472181999096 },
"fstat": { "dev": 752017921, "ino": 34058472181999096 } }
{ "file": "H:\\…\\dev_ino_probe_h.txt",
"pathStat": { "dev": 0, "ino": 1125899906857611 },
"fstat": { "dev": 9361227, "ino": 1125899906857611 } }The mismatch occurs for files on C: as well as H: — i.e. this likely affects every Windows install with a workspace on any NTFS volume, not just secondary drives.
Evidence 2 — isolation inside Chatbox 1.23.5
Byte-patching the installed app to compare st_ino only (leaving every other check untouched: lstat isFile/symlink, realpath containment, open/reopen containment) makes AGENTS.md load immediately, on the same volume and same file. This confirms the dev comparison is the sole failing condition.
Suggested fix
On win32, treat st_dev as unreliable across stat flavors and anchor identity on st_ino (the NTFS file ID — stable and unique per volume):
const identityMatches = process.platform === 'win32'
? pathStat.ino === fileStat.ino
: pathStat.dev === fileStat.dev && pathStat.ino === fileStat.ino
if (!identityMatches) return nullAdditionally, please log a warning when any check inside readInstructionFile() rejects a file (currently every rejection path is silent). This single change would have made this issue trivially diagnosable from user reports.
中文摘要
Windows 上 readInstructionFile() 的防调包校验把「基于路径的 stat」与「基于句柄的 fstat」的 st_dev 相比较,但两者在 Windows 上天然不一致(路径 stat 恒为 0,句柄 fstat 是卷序列号),导致校验永远失败 → AGENTS.md 被静默跳过,任何 NTFS 卷上都加载不到(C: 与 H: 均已实测),且日志无任何报错。仅比较 st_ino(NTFS 文件 ID)即可修复,实测有效;同时建议校验拒绝时输出日志,避免同类问题无法排查。
Happy to test a fix build or provide more details (probe scripts, logs) if useful.
Source: chatboxai/chatbox