Skip to content

fix(evidence): retry manifest parse when a peer replaced it during recovery - #162

Merged
ElbertePlinio merged 4 commits into
mainfrom
fix/159-recovery-replaced-manifest
Sep 11, 2026
Merged

ElbertePlinio merged 4 commits into
mainfrom
fix/159-recovery-replaced-manifest

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Recovery inspects manifest.json before taking a run's journal lock. When a peer recovery won the lock and replaced the manifest by rename, the loser's open descriptor pointed at the unlinked inode, so the singleton-regular-file check saw nlink === 0 and the run was reported as skipped with reason invalid evidence manifest although the peer had recovered it.

The parse now reopens manifest.json once when the opened inode reports nlink === 0. Hard links (nlink >= 2), symlinks and non-regular files are still rejected through the unchanged O_RDONLY|O_NOFOLLOW|O_NONBLOCK open and singleton check. Finalization under the lock also re-checks the read-only input condition, so a run a peer already finalized is indexed rather than rewritten. Tests: deterministic rename between open and stat, a hard-linked manifest still skipped, and the four-process race now requires every process to report the same recovered state.

Validation: bunx vitest run packages/core (28 files, 664 tests), bun run lint, bunx tsc --noEmit, bunx complexity-gate check --changed.

Closes #159

…covery

Recovery inspects manifest.json before taking a run's journal lock. When a
peer recovery won the lock and replaced the manifest by rename, the loser's
open descriptor pointed at the unlinked inode, so the singleton-regular-file
check saw nlink 0 and the run was reported as an invalid manifest even though
the peer had recovered it. The parse now reopens manifest.json once when the
opened inode reports nlink 0; hard links, symlinks and non-regular files are
still rejected. Finalization under the lock also re-checks the read-only input
condition, so a run a peer already finalized is indexed rather than rewritten.

Closes #159
A peer recovery renames manifest.json twice while it holds the journal lock,
once to seal it and once to publish it with the report, so a reader outside
the lock can land on an unlinked inode twice and exhaust the bounded retry.
Manifest inspection now reports that case as "replaced" instead of invalid,
and recovery takes the journal lock and re-reads what the peer left; under the
lock no cooperating rename can happen, so one retry stays enough there. Hard
links, symlinks and special files are still refused as unsafe.

Reading the manifest now opens and closes each descriptor exactly once, and
the tests cover both peer renames landing across a reader's two opens and a
peer finalizing a run between inspection and the lock.
@ElbertePlinio

Copy link
Copy Markdown
Member Author

Second independent review (Fable, native, read-only) on 0caa81d agreed with the Astra finding on the double rename and added two non-blocking notes (untested finalizeLockedRun path, double close); all three were repaired in 648159d and the Astra recheck on c4d215f accepted with no new findings.

@ElbertePlinio
ElbertePlinio merged commit 1031bcc into main Sep 11, 2026
10 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.

evidence: concurrent recovery reports a replaced manifest as invalid

1 participant