Skip to content

fix(spec): unlock the archive lock before its file closes - #91

Open
runewright[bot] wants to merge 2 commits into
mainfrom
change/archive-lock-release
Open

runewright[bot] wants to merge 2 commits into
mainfrom
change/archive-lock-release

Conversation

@runewright

@runewright runewright Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Releases the spec archive lock when a transaction ends, so an immediate retry no longer fails while another thread's child process still holds a copy of the lock descriptor.

Plan

The lock belongs to the open file description, and a child process spawned by any thread inherits the descriptor until its exec. Closing the file alone leaves the lock held, so the guard unlocks first.

Changes

  • Adds HeldLock in rune-docs/src/spec/transaction/mod.rs, which unlocks the lock file in Drop before the descriptor closes.
  • Stores a HeldLock in Transaction, and wraps the lock in acquire_with_io and health_findings.
  • Adds a_dropped_transaction_releases_the_lock_that_a_duplicate_descriptor_shares in rune-docs/src/spec/transaction/tests.rs, ignored on Windows.
  • Adds one CHANGELOG.md line under Fixed.

Testing

  • A scratch stress loop of the archive and its retry, with four threads spawning processes beside it, failed 26 of 2000 runs on main and 0 of 2000 with the fix, on macOS. The same loop without the spawning threads failed 0 of 2000.
  • The guarded push pipeline, with cargo test, passed on this head.

Release Notes

  • Fixed: an immediate retry of a spec archive no longer fails because another process still holds the archive lock.

Open-Seal-Nonce: 1c077194f7bbf491d568b42fd139b78bab3679942cafc575a8f37cdafdb732d8

Note

Unlock spec archive lock before its file closes

  • Adds a HeldLock guard in mod.rs that wraps the lock file and explicitly unlocks it on Drop, before the descriptor closes. This fixes retries that fail when a child process holds a copied descriptor, since a close alone does not release the lock in that case.
  • Transaction now stores a HeldLock instead of a File, and acquire_with_io, health_findings, and incomplete_transaction_findings all use the guard, including on early returns.
  • Adds a regression test in tests.rs that duplicates the lock descriptor, drops the transaction, and verifies another transaction can acquire the lock. The test is ignored on Windows.
  • Risk: if the explicit unlock fails, the file close still releases the lock as before, so behavior is unchanged on Windows.

Macroscope summarized 8521a5e.

The transaction held the archive lock as a plain File and released it only
by closing the file. The lock is a flock on the open file description, so
a child process that another thread spawned while the lock was held kept a
copy of the descriptor until it exec-ed or exited, and the lock with it.
An immediate retry then failed with "another spec archive transaction
holds" the lock: spec::tests::archive_retry_reports_the_existing_dated_archive
failed that way on the cli 84 Test job, because rune-docs unit tests run as
threads of one process and the doctor tests spawn children.

HeldLock unlocks in Drop before the close, for the transaction and for the
doctor probe. A new test holds a duplicate descriptor, drops the
transaction, and takes the lock again; it fails with the CI error without
the unlock. In a stress loop with four spawning threads, 26 of 2000
retries failed before the change and 0 of 2000 after.

Co-Authored-By: Martin Zeman <N4M3Z@users.noreply.github.com>
@github-actions github-actions Bot added size:small auto: changed-lines bucket area:docs auto: documentation and markdown labels Nov 24, 2026
@runeseer

runeseer Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

review/correctness round 1 started on 8521a5e0 at ledger generation 1.

@runeseer

runeseer Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @Runewright[bot]'s task in 3m 4s —— View job


Correctness review

  • Read the diff against origin/main
  • Read the lane inputs and ledger
  • Trace every lock-release path
  • Write the verdict

Looks good. HeldLock::drop calls unlock() before the descriptor closes, so a forked child's inherited copy of the fd no longer keeps the spec archive lock held after a transaction ends. On Unix the flock belongs to the open file description, and close releases it only once every fd referring to that description is closed, so the explicit LOCK_UN is the correct fix.

Verified:

  • Both construction sites carry HeldLock now (rune-docs/src/spec/transaction/mod.rs:269, :697), and the old _lock: File field has no remaining holder.
  • The wrap happens with no fallible step between try_lock() and HeldLock(lock) (mod.rs:247-259, :633-644), so no window drops a locked File unwrapped.
  • Every early return after the wrap unlocks on the way out: health_findings at mod.rs:648 and :652, and incomplete_transaction_findings at :681 and :688.
  • HeldLock is only ever built over a File whose try_lock() returned Ok, so the drop never unlocks an unlocked descriptor.
  • The new test is a real regression test: try_clone shares the open file description, so without the unlock() the second acquire would hit WouldBlock and panic (tests.rs:308-317).
  • The changelog entry satisfies rune-docs/src/changelog.rs: [Unreleased] is the first release heading, the entry is verb-first, under the 200-character limit, and carries no em-dash or type: prefix.

Minor, non-blocking:

  • The same close-only release pattern remains at other lock sites — the deploy target lock (src/cli/deploy/mod.rs:116) and the signer repository lock (src/cli/sign/queue/store.rs:325) both rely on File drop. Out of scope for this PR, but the same child-process window applies. Fix this →
  • The PR body is still the unfilled template — the Plan, Changes, and Testing sections need filling before rune sign open.

I could not run cargo test -p rune-docs transaction in this environment (the command is outside my allowed tools), so the review above is static. Add Bash(cargo test:*) to --allowedTools if you want the suite exercised here.
· change/archive-lock-release

@runeseer

runeseer Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Runeseer review — clean

Looks good. HeldLock::drop releases the flock before the descriptor closes, so a forked child's inherited copy no longer keeps the spec archive lock held after a transaction ends.

  • Every construction site now carries HeldLock, and each early return in health_findings and incomplete_transaction_findings unlocks on the way out.
  • Minor: other lock sites, such as the deploy target lock and the signer repository lock, still release by close alone.
  • The PR body is still the unfilled template.

No open findings · Reviewed 8521a5e0 · review run · $1.15 · 3m4s · 27 turns

@runeseer runeseer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Earned approval: review/correctness returned a clean verdict for 8521a5e at ledger generation 1. Dismissed automatically on any new push or generation.

…ee":"562b4177558209dc6be51729b53e926ed2a11c39","nonce":"1c077194f7bbf491d568b42fd139b78bab3679942cafc575a8f37cdafdb732d8"}
@N4M3Z
N4M3Z marked this pull request as ready for review November 25, 2026 00:17
@N4M3Z
N4M3Z self-requested a review as a code owner November 25, 2026 00:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T00:18:19.133647Z f1a3546 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-25T00:20:21.910302Z f1a3546 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Labels

area:docs auto: documentation and markdown size:small auto: changed-lines bucket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant