Skip to content

test(runtime): prove a lease closed in a forked child keeps the parent's locks - #1459

Merged
Brad-Edwards merged 1 commit into
devfrom
1344-runtime-owner-lease-fork
Oct 25, 2026
Merged

Brad-Edwards merged 1 commit into
devfrom
1344-runtime-owner-lease-fork

Conversation

@doublewhy

@doublewhy doublewhy commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #1344, the fixture-provenance audit. RuntimeOwnerLease.close() (control_plane_store_lease.py:217-231) releases its flock locks only in the process that acquired the lease, and _release_store_directory_guard (:113-120) does the same for the store-directory lock. The guards matter because after fork() parent and child share open file descriptions: a child that unlocked its inherited descriptors would release the parent's single-owner lease on the control-plane store.

Neither existing fork test can see these guards. test_runtime_owner_lease_rejects_and_closes_in_a_different_process_identity patches os.getpid and re-acquires after closing the only descriptor, which drops the lock either way; test_inherited_runtime_owner_fails_closed_after_fork never closes the lease in the child. Both still pass with either guard removed, and with both removed.

This PR adds a test that models the parent's surviving descriptors with os.dup() (same open file description, as after fork()), closes the lease as a non-owner, and probes both locks. No production code changes.

Requirement UIDs

  • None. Test-only change with no requirement scope.

Related Issues

Closes #1558

ADR Impact

  • None.

Changes

  • New test test_runtime_owner_lease_closed_in_a_forked_child_keeps_the_parent_locks in test_issue_1092_control_plane_crash_consistency.py. It duplicates the lease's lock-file and store-directory descriptors, closes the lease with os.getpid patched to a different process, asserts that a fresh descriptor can take neither lock while the duplicates are open, and that the lease can be re-acquired after they close. Skipped on Windows, where the directory guard does not exist and the lock is not a flock. A helper, _runtime_owner_lock_is_held, probes a path with the production _lock_runtime_owner.

Done-when matrix (issue #1558, verbatim):

Done-when Change Test that fails without it CI lane Evidence
The test fails with either guard removed and passes on dev. test_issue_1092_control_plane_crash_consistency.py:test_runtime_owner_lease_closed_in_a_forked_child_keeps_the_parent_locks MA (close() unlocks in any process) and MB (_release_store_directory_guard unlocks in any process), each reverted afterwards: the new test fails under each, and the two existing fork tests pass default lane, canonical / test-shard 108 passed, 2 skipped locally; CI run 37918028762
If #1461 has merged, the ST-1 entry in docs/research/fixture-provenance/index.md and its row in inventory.md record the fix. none: #1461 is still open (checked 2026-10-13) none none gh pr view 1461 shows OPEN

Test Plan

  • Unit tests pass
  • Integration tests pass if applicable
  • Full completion suite required in CI before merge
  • No coverage regression

uv run --project implementations/python --frozen --all-extras python -m pytest implementations/python/tests/test_issue_1092_control_plane_crash_consistency.py: 108 passed, 2 skipped, 3 deselected. With -m integration: 3 passed, 110 deselected. With MA, MB, or both patched in from a pytest plugin and integration tests selected (-m "not fuzz and not docker"), only the new test fails.

A real-fork check (standalone script, macOS, CPython 3.14.4 and 3.12.13, package code at e648556, unchanged from dev) confirmed the hazard: the parent acquires a lease and forks, the child closes its inherited lease, and a separate process then tries both flocks and RuntimeOwnerLease.acquire(). Both interpreters printed the same results:

Variant Lock-file flock Store-directory flock acquire()
production blocked blocked refused (_acquire_store_directory_guard)
MA acquired blocked refused (_acquire_store_directory_guard)
MB blocked acquired refused (_claim_runtime_owner_file)
MA and MB acquired acquired succeeds: a second owner

The new test uses os.dup() rather than os.fork(), so it runs in the default (non-integration) lane without forking. nox -s verify-fast-feedback -- --base-rev origin/dev passed; ruff format and check are clean from implementations/python.

CI on head e6485562 (dev base): CI run 37918028762 and Docs 37918027796 passed; 28 checks passed and only deploy was skipped (checked 2026-10-13). No research capture is recorded because no evidence-bound source changes.

Ground Control Checks

  • Repository policy command passes
  • The new test fails when either non-owner unlock guard is removed (mutation runs above)

Traceability

  • IMPLEMENTS: (none)
  • TESTS: implementations/python/tests/test_issue_1092_control_plane_crash_consistency.py
  • Covered code: implementations/python/packages/raes_runtime/control_plane_store_lease.py (RuntimeOwnerLease.close, _release_store_directory_guard)
  • Already traced under API-404 (lease module as IMPLEMENTS, docs/requirements/API-404/requirement.md:280; this test module as TESTS, :308); SEM-225 (:52) and RUN-320 (:101) also trace the test module. No traceability lines change.

Checklist

  • Code follows the project coding standards
  • FM: not applicable, no semantic change (one test and one test helper); no executable or runtime adoption is claimed.
  • No production module, published schema, research capture or evidence-bound file changes.
  • PR title is a Conventional Commit (release-please derives the version and CHANGELOG.md from it)

…t's locks

The fork test patched os.getpid in one process and then re-acquired the
lease, which succeeds whether or not close() unlocks in a non-owner
process. After a real fork the parent shares the child's open file
descriptions, so a child that unlocked them would release the parent's
lease. Hold duplicates of the lease descriptors, close as a non-owner and
probe both flock locks.
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