Skip to content

[fix] Make checkpoint replacement atomic via tmp/old rename sequence - #155

Open
dodatboii wants to merge 3 commits into
Ascend:mainfrom
dodatboii:optimize_save_load_checkpoint
Open

[fix] Make checkpoint replacement atomic via tmp/old rename sequence#155
dodatboii wants to merge 3 commits into
Ascend:mainfrom
dodatboii:optimize_save_load_checkpoint

Conversation

@dodatboii

@dodatboii dodatboii commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Previously, save_checkpoint deleted the existing checkpoint directory before renaming the new one into place. A failure between those two steps (cross-device rename, disk full) destroyed both the old and new checkpoints.

Now the old directory is renamed aside to .old first and only removed once the new checkpoint is confirmed in place; on failure it is restored automatically. Directory layout and the public API are unchanged.

Previously, save_checkpoint deleted the existing checkpoint directory before renaming the new one into place. A failure between those two steps (cross-device rename, disk full) destroyed both the old and new checkpoints. Now the old directory is renamed aside to `.old` first and only removed once the new checkpoint is confirmed in place; on failure it is restored automatically. Directory layout and the public API are unchanged.

Signed-off-by: dodatboii <zhangyixiang9@huawei.com>
Signed-off-by: dodatboii <zhangyixiang9@huawei.com>
@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

dodatboii, thanks for your pull request. All authors of the commits have signed the CLA. 👍

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce4d39fb85

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1047 to 1049
checkpoint_dir.rename(old_dir)

tmp_dir.rename(checkpoint_dir)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the checkpoint path present throughout replacement

When replacing an existing checkpoint, checkpoint_dir.rename(old_dir) removes the supported load path before the following rename installs the new version. A concurrent load_checkpoint(checkpoint_dir) can therefore observe a missing directory, and process termination between these statements leaves a restart unable to load the checkpoint without manually discovering .old. This two-rename sequence does not provide the documented atomic replacement or automatic rollback; use an atomic indirection/exchange mechanism or add startup/load recovery for .old.

AGENTS.md reference: AGENTS.md:L17-L18

Useful? React with 👍 / 👎.

Signed-off-by: dodatboii <zhangyixiang9@huawei.com>
@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

dodatboii, thanks for your pull request. All authors of the commits have signed the CLA. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants