Skip to content

fix(host-runtime): drain checkpoint writes across turn settlement - #1978

Merged
vastsa merged 1 commit into
vastsa:mainfrom
FuYukiH:fix/checkpoint-write-lifecycle
Oct 29, 2026
Merged

vastsa merged 1 commit into
vastsa:mainfrom
FuYukiH:fix/checkpoint-write-lifecycle

Conversation

@FuYukiH

@FuYukiH FuYukiH commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

When shutdown starts while a checkpoint save is already in flight and no newer snapshot is queued, flushAll() can return immediately. The runtime then disposes the host before the save is acknowledged. Settling a message also removed the save's serialization state, so a later turn could start a second write to the same checkpoint file.

Keep issued save promises separate from pending message state. Writes stay serialized per session across settlement, and a drain joins the work accepted at its boundary. A final-message flush stays scoped to that message so ongoing streaming cannot indefinitely extend it or bypass the next reply's throttle.

The process regression fails on the original implementation with disposal closed the host before its save reply. After the fix, the checkpoint survives a host-peer restart, consecutive turns retain the newest reply, and another session can save while the first is held.

Validation on Windows x64, Node 24.14.0, Pi 1.4.0:

  • Full host-runtime suite: 157 passed, 3 Windows symlink tests skipped. Used --maxWorkers=2 --testTimeout=30000 --hookTimeout=60000 for filesystem fixtures.
  • Related Desktop checkpoint, outbox, event-persistence and shutdown suites: 61 passed.
  • node scripts/e2e-checkpoint-lifecycle.mjs: passed using the production RPC transport, event pipeline and checkpointer, real child processes, and temporary disk files. A controlled Node JSON-RPC peer substitutes for Rust host-core; this is not a full packaged-app/Rust recovery test.
  • Desktop and dependency builds, Desktop typecheck, Biome lint, style tokens, policy sync, docs checks and PR-base check passed.

Candidate: 25bca249dc0989f105b413029ed3784b286c5900; base: 9e5da834fe4c05509cc60038eb2038898f88286d. The persistence spec and the process regression scenario are updated.

Settling a message removed the only record of its unfinished save. A new
turn could then issue another write to the same checkpoint file, while a
shutdown flush could return with the previous RPC still outstanding.

Track issued writes independently of pending message state and serialize
them per session. Drains join the work accepted at their boundary, and
late final-message settlement cannot clear a newer reply's throttle.

Add controlled lifecycle regressions and a process-level RPC/disk probe
covering shutdown, restart and successive turns.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verified the original defect independently: rebuilding the original main checkpointer and running the process scenario fails with disposal closed the host before its save reply. Restoring this candidate passes the same scenario, including restart persistence, cross-turn serialization and independent-session progress.

The production change is confined to the checkpointer: physical writes survive logical settlement, per-session serialization is retained, and message-scoped drains do not force the next reply past its throttle. No storage format or RPC contract change.

Local validation on head 25bca24 (macOS, Node 26): locked dependencies installed in an isolated worktree; host-runtime and Desktop dependency builds passed; host-runtime 160/160 tests passed; Desktop checkpoint/lifecycle/outbox/shutdown tests 48/48 passed; process regression passed; diff check passed. Initial reused dependencies were incompatible; final runs use the lockfile installation. Six remote checks are green. Latest main 9e5da83 is an ancestor; PR merge candidate and tested head share tree 77b4dba1f80b4f02c52d0681a5584ae32adcc231.

Coverage limit: the process fixture uses the production transport/pipeline with a controlled Node RPC peer and temporary disk files; no local packaged Electron or actual Rust crash-recovery test was run. Remote Electron and Rust Windows checks are green.

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.

2 participants