Skip to content

fix(node-sdk): flush plugin state through its writable handle on Windows - #230

Merged
1lck merged 2 commits into
Lithe-IDEA:mainfrom
WhiteZeek:fix/229-node-sdk-state-fsync
Dec 1, 2026
Merged

1lck merged 2 commits into
Lithe-IDEA:mainfrom
WhiteZeek:fix/229-node-sdk-state-fsync

Conversation

@WhiteZeek

@WhiteZeek WhiteZeek commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

Closes #229

PR 类型 / Type

  • fix:缺陷修复

改动说明 / What changes

复现与根因

Windows 上,Node 插件调用 StateStore.write 保存合法值时会在替换目标文件之前收到 EPERM。原实现先按路径写完临时文件,再以只读模式重新打开它,并在这个句柄上调用 fsyncSync。

改动

以 w 模式和原有的 0o600 权限打开临时文件。把 JSON 写入这个句柄,随后用它刷新到磁盘。现有的 finally 负责关闭句柄,之后执行原子重命名。

Windows CI 使用 Node.js 20 运行已有的 support.test.mjs,覆盖状态写入、重新打开和原值保留。Node SDK 或该工作流发生改动时,进入评审的 PR 和 main 推送都会触发检查。

范围检查 / Scope checks

检查项 结果
逻辑归属、插件归属 官方 Node SDK 负责执行原生文件写入。
发行包与资源 写入位置仍为宿主提供的插件状态目录。
性能与内存 每次写入少打开和关闭一次临时文件。
功能矩阵、插件契约、设置 修复已有 SDK 方法的持久化行为。公共参数、存储格式、协议版本均沿用现有定义。
统一日志、界面、i18n 沿用现有异常处理。此路径没有桌面 UI。

验证 / Verification

环境为 Windows 11 build 22631 x64、Node.js v20.20.2 和 v24.14.0、NTFS。

命令或操作 结果
node --test --test-name-pattern "state store" shared/plugins/sdk/node/test/support.test.mjs main 基线 1 项通过、2 项因 fsync EPERM 失败。修复后 3 项全部通过。
从 shared/plugins/sdk/node 运行 node --test --test-concurrency=1 --test-timeout=60000 test/*.test.mjs 90 项通过,4 项由测试跳过,0 项失败。
使用已有的 Windows Core 测试驱动加载本 PR 的 SDK 源码,运行 the_node_sdk_sample_backend_serves_build_requests_and_plugin_functions 通过。示例后端可保存构建结果,并在重启后恢复状态。
Windows CI 的原命令 node --test shared/plugins/sdk/node/test/support.test.mjs(Node.js v20.20.2) main 的两个状态写盘用例报 EPERM。同机运行本 PR,11 项通过、4 项平台跳过、0 项失败。
actionlint 1.7.12 和 git diff --check Windows 工作流静态检查及差异检查通过。

提交前确认 / Final checks

  • 从 Core 的 main 建分支,以 Draft 提交。
  • 改动包括 Node SDK 状态写入和对应的 Windows CI 工作流,复用已有回归用例。

@WhiteZeek
WhiteZeek marked this pull request as ready for review November 30, 2026 01:08

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@1lck
1lck merged commit 2175f49 into Lithe-IDEA:main Dec 1, 2026
12 checks passed
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] Windows 上 Node 插件 SDK 保存状态时 fsync 返回 EPERM

2 participants