Skip to content

fix(checkpoint): serialize input state saves - #285

Merged
fangxiu-wf merged 1 commit into
mainfrom
codex/fix-input-state-save-race
Aug 20, 2026
Merged

fix(checkpoint): serialize input state saves#285
fangxiu-wf merged 1 commit into
mainfrom
codex/fix-input-state-save-race

Conversation

@rangemer333-cell

Copy link
Copy Markdown
Collaborator

Summary

  • serialize concurrent StateStore.save() calls through one in-flight save loop
  • track mutation and persisted revisions so updates made during a write are flushed before callers complete
  • keep failed revisions pending for a later retry
  • give atomic-write temporary files UUID-based unique names while retaining cleanup compatibility with the old format
  • add deterministic concurrency and failure-recovery tests

Why

Each input serializes its own collection cycle, but all inputs share one StateStore. Multiple inputs can therefore save input-state.json concurrently. The previous dirty boolean could be cleared by an older save after a newer mutation, and temporary names based only on PID and millisecond could collide.

Verification

  • npm test -- tests/unit/checkpoints/state-store.test.ts tests/unit/utils/fs-utils.test.ts tests/unit/inputs/base-input.test.ts tests/integration/restart-recovery.test.ts tests/integration/state-restore.test.ts (44/44)
  • npm run typecheck
  • npm run build

@fangxiu-wf fangxiu-wf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed head 71480aaf against base 8f47a1b7.

The revision-based save loop correctly serializes shared StateStore writes, drains mutations created during an active write, and preserves failed revisions for retry. Atomic temp-file collisions are also addressed.

Validation: 44/44 targeted checkpoint/restart tests passed; an additional completion-handoff concurrency case passed; typecheck and build passed. No blocking findings.

@linrunqi08

Copy link
Copy Markdown
Collaborator

🔍 Code Review Summary

Severity Count
Critical 0
High 0
Medium 0
Low 2

Lifecycle Verdict

Check Result
资源释放 PASS
死锁/卡死风险 PASS
状态恢复正确性 PASS
PowerShell CLM 合规 N/A

无 FAIL 项。变更不含 .ps1savePromise 单飞、stopAll 后再 save()、失败修订不推进 persistedRevision

Merge Gate(合入门禁)

APPROVE-READY ✅(阻断级别:Critical / High / MediumLow 不阻断;Lifecycle 任一 FAIL 也阻断)

无 open 阻断项。

总体结论

修订号 + 单飞 flush 循环修好了共享 StateStore 上「旧写清掉新 dirty」的竞态,UUID tmp 名消除同毫秒碰撞。无阻断问题,可以合入。两条 Low 为 follow-up:外层 .finally 清空 savePromise 的 microtask 交接窗口(未提交测试),以及 no-op 第二次 save() 未断言写次数。

Highlights(正向实践)

  • revision / persistedRevision 替代可被旧写清掉的 dirty
  • 写失败不推进 persisted revision,下次 save() 重试
  • atomicTmpPath 一处生成,清理正则兼容旧 {pid}.{ts}.tmp

✅ Medium/High 及以上问题已全部解决,本轮评审通过(approved)。


评审报告详见: code-review/pr-285/final-report.md
Generated by LoongSuite-Pilot Code Review Agent

@linrunqi08 linrunqi08 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Medium/High 及以上问题已全部解决,本轮评审通过(approved)。 Generated by LoongSuite-Pilot Code Review Agent

@fangxiu-wf
fangxiu-wf merged commit 094ed9d into main Aug 20, 2026
7 checks passed
@linrunqi08
linrunqi08 deleted the codex/fix-input-state-save-race branch August 20, 2026 02:16
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.

3 participants