Repository navigation
fix(settings): 保护损坏的设置文件免于默认值覆盖 (#1943) - #2051
Merged
Merged
Conversation
2 tasks done
Contributor
Author
修复证据与截图说明(HEAD
|
…943-protect-settings-file
初版在加载失败后拒绝 Save,对 Store 的所有文件生效:最近项目、编辑器会话、 插件启用状态等文件损坏后永远写不进去,每次保存都报错。改为下一次 Save 先把 原文件改名为 <名称>.unreadable-<UTC 时间> 再写入;检查、改名和清除失败记录在 同一把锁内,并发保存只移走一次原文件。改名失败时保存报错、原文件留在原处。 同步测试、Agent Note 和功能矩阵,并合并最新 main。
xiaoyumuxi
marked this pull request as ready for review
November 17, 2026 05:05
xiaoyumuxi
requested review from
1lck,
Mucheen and
xiaoyumuxi
as code owners
November 17, 2026 05:05
xiaoyumuxi
deleted the
lithe-support/issue-1943-protect-settings-file
branch
November 20, 2026 01:35
27 of 28 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
settings.json如果被手动编辑损坏,store.Load会返回解码错误;workbench.New继续以默认设置启动,之后用户改主题等操作调用saveSettings,原来的store.Save会用默认值替换整个旧文件,永久丢失原来仍然有效的设置(#1943)。改动 / Changes
desktop/internal/store/store.go:按文件名记录最近一次致命 Load 失败(读取失败或 JSON 解码失败)。下一次 Save 这个文件时,先把原文件改名为<名称>.unreadable-<UTC 时间>(store.SetAsideName),再正常原子写入新值;原文件字节不变,之后的保存照常。检查失败记录、改名、清除记录在同一把锁内,并发的两次保存只移走一次原文件。改名失败时这次保存报错,原文件留在原处。kept/Unread机制保留,不当作致命失败。desktop/internal/store/store_test.go:三项回归测试,覆盖读不出的文件在保存前另存且内容不变、同一次失败只另存一次、其他文件不受影响、文件已删除或被 Remove 后不另存。application-settings跨平台矩阵的证据与验证动作(保留 macOS/Windows 的partial/pending),增加中文 Agent Note 记录数据保护边界。不在本 PR 范围内 / Out of scope
类型专属:fix
复现与根因
{"name":"kept","count":12,}这样的损坏 JSON,调用 Load 后以默认值调用 Save。修复前最小 Go 复现的TestCorruptLoadMustNotOverwriteOriginal失败:Save overwrote unreadable settings (expected error);修复后的相同逻辑最小复现 3 个测试通过。store.Load致命 JSON 解码失败仅清掉保留的未知字段状态,store.Save无论先前 Load 是否失败都会执行 WriteFile。窗口代码的settingsErr -> settings{}放大了覆盖范围。基于当前 main 源码确认;未通过 git blame 定位最早引入提交。desktop/internal/store;原始 Issue 在 macOS 报告,Windows 原生尚未复现。检查项
.agents/notes/implemented/bug-fix/2026-11-16-settings-failed-load-protection.md。范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/application-settings.json,新增 Store 回归证据,两端原有partial/pending状态不变。scripts/platform-feature-matrix/verify-platform-feature-matrix.sh和 change 门禁尚未执行,待 CI / 完整检出。.artifacts生成文件。插件归属 / Plugin ownership
UI 验证 / UI evidence
N/A:此 PR 未修改任何页面、控件、文案、菜单或通知呈现代码;仅让现有
saveSettings的失败分支处理存储错误。启动时明确提示仍在 Out of scope,不将此 PR 冒充视觉修复;没有实际 PNG,未上传截图。统一日志系统 / Structured logging
workbench.New已记录 Load 失败;现有saveSettings在 Save 报错时记一次终态并展示保存失败通知。界面文案 / i18n
N/A:没有新增或修改界面文案,也没有手改翻译或生成文件;完整 i18n 门禁未执行。
逻辑归属 / Logic placement
性能与内存 / Performance and memory
设置 / Settings
N/A:不增加设置选项/页面;只在损坏文件保护期内拒绝持久化,不自动重置或覆盖用户原文件。
插件契约 / Plugin contract
N/A:不修改宿主方法、通知、SDK、Core 契约和插件协议。
发行包与资源 / Bundle and resources
N/A:不新增下载物、构建资源、缓存或运行时 bundle 写入;修改的仅是用户配置文件的写入保护。
无用代码与重构 / Dead code and refactoring
验证 / Verification
GOTOOLCHAIN=local go test -v ./...(修复前)Save overwrote unreadable settings (expected error)GOTOOLCHAIN=local go test -v -race ./...(保护后)限制: 当前执行环境为独立 Linux 容器,并非用户的 Mac;没有 Go 1.27.3 完整仓库和 Rust 工具链,
github.comDNS 也不可达,不能克隆并完整编译。已通过自建 Lithe-Support MCP 读取与提交全部 GitHub 变更,GitHub 写入身份为lithe-support[bot]。Draft PR 供 Linux CI 验证后再决定是否进入评审,不将测试源文件的存在当作执行证据。提交前确认 / Final checks
efd00f340575026d492abf435e1c062bd6b6bed9创建独立lithe-support/issue-1943-protect-settings-file分支,目标 main。.artifacts、构建产物、凭据、私人设置或用户数据。