Skip to content

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

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

runewright[bot] wants to merge 3 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 aa2218e.

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. The new head commit carries the same file tree as the previously reviewed commit, so no code changed and nothing new needs review.

  • No open findings remain from any reviewer.

No open findings · Reviewed aa2218e5 · review run · $0.52 · 0m43s · 15 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.

@N4M3Z N4M3Z added the review:runeseer Summons the adjudicating correctness lane label Nov 25, 2026
@runeseer

runeseer Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

review/correctness round 2 started on f1a35464 at ledger generation 1.

@github-actions github-actions Bot removed the review:runeseer Summons the adjudicating correctness lane label Nov 25, 2026

@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 f1a3546 at ledger generation 1. Dismissed automatically on any new push or generation.

…","generation":1,"digest":"5c9ee55a787590551f2a82b9417e1bc0ff7d95a422cc3e7d88c8cb601ee07a51"}
@macroscopeapp

macroscopeapp Bot commented Nov 25, 2026

Copy link
Copy Markdown

Approvability

Verdict: Approved at aa2218e

Macroscope's review found this PR approvable — The change explicitly releases the archive lock when its existing scope ends, preventing inherited descriptor copies from delaying retries. Transaction locking scope and archive data operations remain unchanged, with a focused regression test added.

Notes:

  • Macroscope's correctness review did not run, so approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@runeseer

runeseer Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

review/correctness round 3 started on aa2218e5 at ledger generation 1.

@runeseer

runeseer Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @N4M3Z's task in 43s —— View job


Runeseer review — clean

  • Read the range from the previously reviewed commit to this head
  • Read the lane inputs and the ledger
  • Judge the current-head review bodies and issue comments
  • Write the verdict

Looks good. This head carries the same file tree as the previously reviewed commit f1a35464 — git diff across the range is empty, so no code changed and nothing new needs review.

  • No open findings remain from any reviewer, and the ledger lists no open threads.

No open findings · Reviewed aa2218e5 · · change/archive-lock-release

@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 aa2218e at ledger generation 1. Dismissed automatically on any new push or generation.

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