feat(ckpt):make deamon persist#520
Open
Ziqi002 wants to merge 5 commits into
Open
Conversation
- introduce a mechanism for persisting daemon process state - refactor daemon startup: unified recovery from disk state (config takes precedence) - index files are migrated from the Btrfs snapshot directory to the state directory - introduce snapshot "missing" markers and user-visible prompts - integration of state persistence with auto-cleanup and workspace management - add configurations: StateDirectory=ws-ckpt / RuntimeDirectory=ws-ckpt add
6eaca8b to
8211e75
Compare
8211e75 to
c54aece
Compare
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.
Description
feat(ckpt): daemon 状态持久化与架构重构
将 ws-ckpt daemon 改造为有状态模式:通过
/var/lib/ws-ckpt/state.json持久化核心运行时信息,实现快速恢复启动、崩溃检测、旧版数据自动迁移。持久化内容 (
c05349c)文件路径:
/var/lib/ws-ckpt/state.json,原子写入(tmp+fsync+rename),daemon 启动后 + 关闭前各保存一次。version: u32backend: BackendIdentitypaths: BackendPathsworkspaces: Vec<WorkspaceEntry>其他变更
1. daemon 架构模块化拆分 (
c05349c)原 lib.rs(522行) 拆分为:
startup.rs— 启动决策(有 state → 恢复 / 无 state → 新装+迁移)lockfile.rs— flock 单实例 + 崩溃检测lib.rs— 精简为纯编排层(~157行)2. 旧版数据自动迁移 (
c05349c)新增
common/migration.rs:无 state.json 时扫描 snapshots_root 下旧版 index.json,迁移至state_dir/indexes/并生成 state.json3. 防御性错误处理 (
c05349c)?补充.context()#[non_exhaustive]保障字段扩展兼容create_backend/detect_and_create_backend收窄为pub(crate)4. 运行时路径统一至 FHS 标准 (
2a826c0)BTRFS_IMG_PATH:/data/ws-ckpt/→/var/lib/ws-ckpt/StateDirectory=ws-ckpt%ghost目录5. 移除 OverlayFS 占位后端 (
134cd36)overlayfs.rs,移除BackendPaths::OverlayFsvariantauto/btrfs-base/btrfs-loop6. RPM spec 修复 (
a89dd95)%pre中阻断安装的逻辑,目录创建移至%post7. bootstrap 重构为 trait 方法 (
aae4ce8)bootstrap.rs(678行),改为StorageBackend::bootstrap()trait 方法daemon/util.rs提取ensure_symlinks()backend.bootstrap(config).await,消除分支冗余Related Issue
closes #491
closes #501
Type of Change
Scope
cosh(copilot-shell)sec-core(agent-sec-core)skill(os-skills)sight(agentsight)tokenless(tokenless)ckpt(ws-ckpt)Checklist
cosh: Lint passes, type check passes, and tests passsec-core(Rust):cargo clippy -- -D warningsandcargo fmt --checkpasssec-core(Python): Ruff format and pytest passskill: Skill directory structure is valid and shell scripts pass syntax checksight:cargo clippy -- -D warningsandcargo fmt --checkpasstokenless:cargo clippy -- -D warningsandcargo fmt --checkpasspackage-lock.json/Cargo.lock)Testing
场景 1:state.json 持久化与 restart 恢复
验证目标:daemon 重启后从 state.json 恢复状态,不依赖 btrfs 扫描。
场景 2:backend 类型持久化权威性(篡改 state.json 后 hard fail)
验证目标:篡改 backend_type 使其与环境冲突时,daemon 拒绝启动并给出修复提示。
场景 3:crash 检测 lockfile 机制(kill -9 模拟 crash vs 正常 stop)
验证目标:kill -9 后 lockfile 残留,重启时检测到 crash 并进入 reconcile;正常 stop 时 lockfile 清理干净,重启无误报。
场景 4:v0 布局自动迁移(mock 旧版本布局)
验证目标:手动构造 v0 版本的文件布局(index.json 在 btrfs 设备内,无 state.json),验证新版 daemon 启动时能自动发现并迁移。
场景 5:btrfs 设备丢失时精确报错(state.json 有记录但子卷不在)
验证目标:当 btrfs 设备丢失时,daemon 能基于 state.json 中的记录给出精确的工作区级别错误信息,而非笼统地报告 "无工作区"。
场景 6:子卷单独丢失 — reconcile MISSING 标记
验证目标:daemon 启动 reconcile 阶段发现快照子卷丢失时,正确标记 MISSING 并阻止对该快照的 rollback 操作,同时不影响其他正常快照。恢复子卷后重启能自动消除 MISSING 标记。
Additional Notes