Repository navigation
fix(local): replace install state atomically - #934
rudycelekli wants to merge 2 commits into
Conversation
Yanami-2K
left a comment
There was a problem hiding this comment.
改成临时文件 + os.replace 的方向是对的,测试也确实断言了替换失败时旧清单逐字节保留、没有残留临时文件。但有一处行为变化没有在描述里说明(描述写的是 "This changes only publication of the inventory"):
local/src/devflow_cli/core.pysave_state:tempfile.mkstemp创建的文件权限固定是0600,os.replace后.devflow/install-state.json也变成0600;原来的path.write_text按 umask 创建(通常是0644)。项目目录被别的用户或容器内不同 uid 读取时(例如共享工作区、CI 以另一用户执行loopforge status),升级后会读不到清单。建议在os.replace前对临时文件os.chmod:已有清单就沿用它的st_mode,没有就用0o666 & ~umask;并在test_failed_state_replace_preserves_previous_records旁加一个断言:正常保存后权限与改动前一致。- (非阻塞)
os.replace前没有handle.flush()+os.fsync(),掉电时仍可能得到空文件。描述只覆盖进程中断,可以接受,但如果目标包括崩溃安全,建议一起补上。
另外,本 PR 只跑了开源扫描检查,validate / smoke-install 等 CI 没有触发,合入前请维护者触发完整 CI。
62137cc to
b01aca4
Compare
|
Addressed the permission regression and the optional flush/fsync suggestion in Fresh local validation passed: generated-host check, full
|
What changed
The Local installer previously wrote
.devflow/install-state.jsondirectly, so an interrupted write could leave its previous inventory empty or incomplete. Save now stages complete JSON beside the inventory, flushes and fsyncs the staged file, then publishes it withos.replace.The replacement preserves an existing inventory's POSIX permission bits. A new inventory uses the original creation behavior (
0666filtered by the process umask), allowing shared-workspace readers to retain access. Failed replacement keeps the previous bytes intact and removes the staged file. The fsync covers staged file contents; this does not claim directory-entry durability after power loss.Scope and compatibility
0640, and new files under umasks022,027, and077.Current validation
Python 3.12.11 and Node 24.19.0, using disposable task-local packaging tools and caches:
python3 scripts/build-classic-hosts.py --check— passed.bash scripts/validate.sh— passed.bash scripts/smoke-install.sh— passed, including 27 installer tests, Portable tests, wheel installation and permission-hook regression checks.bash scripts/smoke-npm.sh— passed.bash scripts/smoke-curl-install.sh— passed against localhost fixtures.bash scripts/e2e.sh— passed (34 tests, one browser module skipped because Playwright is unavailable).bash scripts/test-observability.sh— passed for all three Classic bundles.git diff --check— passed.bash scripts/scan-secrets.shcould not run: its pinned helper supports Linux x86_64 only, while this environment is macOS ARM64. The public-content/credential-pattern checks invalidate.shpassed; they do not substitute for that scanner. Full platform and hosted required CI have not been rerun locally and must be verified before merge. Initial sandbox/cache and missing-pip failures were resolved with disposable tooling; no shared Python environment was modified and no model/provider calls were made.Safety