Skip to content

State move: keep running holders after clock corrections; refuse a foreign unfinished move - #873

Merged
ualtinok merged 2 commits into
mainfrom
fix/state-move-fence
Nov 23, 2026
Merged

ualtinok merged 2 commits into
mainfrom
fix/state-move-fence

Conversation

@antauth-alfonso

@antauth-alfonso antauth-alfonso Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Two defects in the shared state-move code (used by OpenCode since 2.9.0), found by an Athena audit of the pending Pi move.

  1. A running older plugin could be treated as gone after a clock correction. holderEntryIsLive applied the before-this-boot rule (which reads the wall clock) before the pid and incarnation check. A process that registered while the clock was slow, then saw the clock corrected forward, looked older than this boot, so the move fence skipped it and a later registration could prune it. Now a dead pid is stale; a known incarnation decides (equal = live, different = reused pid); only when the incarnation can't settle it does the boot rule apply.

  2. A crashed move could be taken over by a start with another XDG_STATE_HOME. If a move stopped right after setting the journal aside, a start under a different state root saw no record of its own, moved without the journal and retired the old files, leaving neither attempt able to serve local accounts. Under the old folder's holder lock, before snapshotting, the mover now looks for another attempt's set-aside journal and refuses (move-unfinished-elsewhere), naming the journal and telling the user to start again with the setting used then. Nothing is adopted or removed.

Tests (red on main, green here): a wall-clock step forward with a matching incarnation keeps the holder and the next registration doesn't prune it; a foreign unfinished move refuses with the old folder byte-identical, and the original start still rolls back and finishes; a start's own crashed move under another state root still recovers.

Known residual: the check for artifacts of plugin releases older than 2.4.0 (preNArtifactBlockers) still compares a process's start time with a wall-clock timestamp, so a clock step can make a live pre-2.4.0 process look like a reused pid. Those releases register nothing; not changed here.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue was found.

Summary

Keeps live holders after a forward clock correction and stops a new move when another state folder owns a set-aside journal.

  • Live holders survive a forward clock correction.
  • A new move stops when another state folder has an unfinished journal.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Start under layout lock] --> B{Own unfinished move?}
  B -- Yes --> C[Roll back own move]
  C --> A
  B -- No --> D[Take holder locks]
  D --> E{Can list journal folder?}
  E -- No --> F[Recheck pointers and stay legacy]
  E -- Yes --> G{Set-aside journal exists?}
  G -- Yes --> H[Refuse and request original state setting]
  G -- No --> I[Check holders and move preconditions]
  I --> J[Move only when safe]
Loading

Reviews (3) · Last reviewed commit: "Changelog: under Unreleased" · Reviewed by Greptile

@ualtinok
ualtinok force-pushed the fix/state-move-fence branch 2 times, most recently from 8295127 to b0ebf28 Compare November 23, 2026 17:33
@ualtinok
ualtinok force-pushed the fix/state-move-fence branch from b0ebf28 to 5fea617 Compare November 23, 2026 17:48
@ualtinok
ualtinok merged commit 7bb9194 into main Nov 23, 2026
18 checks passed
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