Skip to content

fix: harden Firecracker ZFS snapshot lifecycle#142

Open
lox wants to merge 4 commits intomainfrom
codex/fix-zfs-snapshot-durability
Open

fix: harden Firecracker ZFS snapshot lifecycle#142
lox wants to merge 4 commits intomainfrom
codex/fix-zfs-snapshot-durability

Conversation

@lox
Copy link
Copy Markdown
Contributor

@lox lox commented Apr 3, 2026

Summary

  • flush host-side buffered writes before taking Firecracker ZFS snapshots so restored sandboxes see the latest rootfs state
  • keep the root helper aligned with the ZFS runtime by allowing the dataset-access doctor probe and waiting for cloned zvol device nodes to appear
  • add Firecracker snapshot regression coverage for the ZFS host-sync path

Root cause

ZFS snapshots were being taken after the guest ran sync, but before the host had flushed buffered writes for the zvol. That meant the stored snapshot could capture an older rootfs state than the live sandbox, which showed up as restored sandboxes missing /workspace after repo bootstrap.

Impact

  • snapshot-backed Firecracker sandboxes on ZFS restore the expected workspace contents again
  • ZFS doctor checks and clone/create flows work reliably with the privileged helper

Validation

  • mise exec -- go test ./internal/backend/firecracker ./internal/volumestore ./scripts -run 'Test(CreateSnapshot|SnapshotDriverNeedsHostSync|ZFSDriver|RootHelper|Helper)'
  • bash -n scripts/cleanroom-root-helper.sh
  • remote validation on cleanroom-prod-apse2-linux-i-0b35e6770b45a7db1 (100.127.229.48): repo-aware create, ZFS snapshot create, create-from-snapshot, exec from /workspace, interactive console, cleanup, and cleanroom doctor (summary: 34 pass, 3 warn, 0 fail)

Notes

During validation I cleaned up one leftover test snapshot dataset directly after the listener had already dropped sandbox state. The restore regression itself is fixed by this change, but that cleanup edge may still be worth a separate follow-up if it reproduces consistently.

@lox lox changed the title [codex] Harden Firecracker ZFS snapshot lifecycle fix: harden Firecracker ZFS snapshot lifecycle Apr 3, 2026
@lox lox marked this pull request as ready for review April 3, 2026 22:19
Copy link
Copy Markdown

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

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: 7b57849f0d

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +512 to +513
if err := flushSnapshotHostFilesystem(ctx, driverCfg.Snapshots.Driver); err != nil {
return nil, err
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Resume sandbox after host sync failure

CreateSnapshot pauses the VM process and then immediately returns on flushSnapshotHostFilesystem errors, but the resume defer is only installed afterward. If host sync fails (including context cancellation/timeouts), the function exits with the Firecracker process still SIGSTOPed, leaving the sandbox unusable until manual intervention. Move defer setup (or an explicit resume-on-error path) to immediately after pauseSandboxProcess succeeds so all early returns unpause the sandbox.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e14e8eb: the resume defer now installs immediately after pauseSandboxProcess succeeds, so a failed host sync still sends SIGCONT before CreateSnapshot returns. I also added a regression test for the ZFS path that forces host sync to fail and asserts the sandbox is resumed and snapshotting never starts.

@lox
Copy link
Copy Markdown
Contributor Author

lox commented Apr 3, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant