follow-up: Stateful Sense 持久化加固 (RFC #308) #313
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
来源
PR #312 code review 中的非阻塞建议,需要 follow-up 修复。
待办
1. writeState 原子写入(防 crash 损坏)
当前
writeFileSync直接写目标文件,如果写入过程中 crash 会导致 state.json 损坏。修复: 改为 write-temp + rename:
2. readState 错误处理
当前
readState静默吞掉所有错误(包括 JSON 解析失败)。应区分「文件不存在」和「文件损坏」:3. State 内存更新时序
当前
executeCompute先更新runtime.state = result.state,再writeState。如果写盘失败,内存 state 已变但磁盘未同步。修复: 先写盘成功,再更新内存:
4. SenseInfo.triggers 类型加固
triggers: string[]改为triggers: ReadonlyArray<string>,防止外部误修改。5. JSON state 持久化文档
在 CLAUDE.md 或 docs/ 补充一段说明 Sense state 持久化的机制:
data/senses/<name>.jsoninitialStateexport优先级
中 — 不影响功能但影响可靠性
Ref: #308