Skip to content

feat(databases): the one-writer lease and write sessions of a SpiralDB store (ITL-1452) - #547

Closed
eywalker wants to merge 2 commits into
mainfrom
eywalker/itl-1452-spiraldb-store-the-one-writer-lease-and
Closed

eywalker wants to merge 2 commits into
mainfrom
eywalker/itl-1452-spiraldb-store-the-one-writer-lease-and

Conversation

@eywalker

Copy link
Copy Markdown
Contributor

Fixes ITL-1452. Part of ITL-1446 (design: PR #542, sections 4, 8 and 11).

Inert. A private module, databases/_spiral_lease.py, with tests on the fake. No library module imports it (a test checks), so no job behaves differently and no hash, stored path, layout or golden value moves. No live SpiralDB was used. There is no changelog fragment of its own: nothing is visible to users.

This branch merges PR #544 (the stricter fake) in. Until #544 lands, its commits, including changelog.d/ITL-1446.md, show in this diff.

What it does

  • Lease. orcapod_lease_v1 is created exclusively; the owner text is the name of its one key column; SpiralDB's table id is the lease. One claim has one token (UUIDv7 with the operating system's random bits, so a fork cannot repeat it). A failed create is settled by one look at the name, against the token: mine, someone else's, absent, or unreadable. Only "mine" holds. No retry loop.
  • Release drops exactly the id. Only SpiralDB's answer about the id (done, or 404) says it is gone. If that cannot be had, the run raises with the id.
  • Clear (clear_lease) is by a person, for the exact id, and never drops a table that is not the dataset's current lease. Nothing expires.
  • Session: open, draining, flushing, closed. Admission is closed atomically. Registered work (the thread itself, not its awaiter) and commits in flight are waited for, then the final flushes run, then the lease is dropped. If draining fails, the lease stays. Cancellation never interrupts taking, draining or releasing.
  • Authority is an explicit WriteCapability, checked at admission for process, state, lease generation and dataset. Each piece of registered work has its own, revoked when the work ends. A context variable only locates it, and it is taken away around user code.

Decisions this rests on

# Where
S2, the named-table lease under L1 to L3 take_lease, _settle_create, Lease.check
S10, a lease is cleared by a person only clear_lease
S13, an unchanged rerun takes the lease write_session
S14, writes only inside a session current_capability, _Session.admit
S9, a CachedSource read is refused while another run holds the store the refusal exists; the call is job integration (PR 8)
S15, nothing writes a store table outside tests nothing imports the module

New, not in the design, please confirm: a commit that raised, and that its writer has not settled, may still land on the service, so the session leaves the lease behind (_Session._release, one place). The cost is that a network error in a commit can need a person to clear the lease.

Held back, after the second review of the design

Leases of several datasets in one run, one dataset under two addresses (refused, never adopted), automatic clearing, any claim that a timeout proves that no request can still land, and all integration. So the section 4.5 rows on two datasets and on aliases are implemented only as refusals, and the rows on job entry points, load_only and CachedSource belong to PR 8.

Second review Test
1: exact-id drop, never by name test_drops_go_by_id_and_a_repeated_drop_spares_a_newer_lease, test_never_two_holders_in_any_interleaving
2: one claim, transport replies reconciled; a name lookup proves no release test_a_create_that_landed_without_its_reply_is_recognised, test_a_lost_refusal_is_a_refusal, test_a_lookup_that_fails_never_grants_the_lease, test_a_name_that_looks_free_does_not_prove_the_lease_is_gone
3: no quiescence from a timeout test_a_late_create_is_a_lease_left_behind_never_a_second_holder, test_a_commit_that_failed_may_still_land_so_the_lease_stays
4: capability, suspended around user code and generator steps test_the_locator_alone_authorizes_nothing, test_a_users_thread_has_no_authority, test_a_users_generator_has_no_authority_at_any_step, test_works_capability_ends_with_the_work
5: atomic close, the thread and not its awaiter, controlled flush, forks test_closing_admits_only_what_is_already_running, test_a_cancelled_run_waits_for_the_commit_its_thread_is_sending, test_the_final_flush_runs_after_the_drain_and_before_release, test_an_interrupted_drain_keeps_the_lease, test_a_forked_child_cannot_write_and_never_releases
6: integration order not here (PR 8)

The documented window of 4.3 is asserted as it is: test_the_documented_window_a_commit_past_its_check_lands.

Tests

82 tests, no sleeps: each request goes through a scripted wire. test_never_two_holders_in_any_interleaving visits every order of the requests of 2 and 3 writers, and for 2 writers one fault at every place (crash before or after, lost reply, late create, late drop). Eleven deliberate breakages of the module, among them dropping by name and dropping the capability checks, each fail at least one test.

Added to the fake, each tied to a live measurement of section 4.1: an atomic exclusive create with a 409, drop by id with a 404, commits that are one step. Dropping by name looks the id up first (pyspiral 0.16.33's source).

Run locally: the suites that use the fake and the repository checks (2334 passed, 6 xfailed), ruff, whole-repository basedpyright (0 errors), golden --check clean. After that run only the lease tests changed, for types; those were run again.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 13 billable files and costs up to $3.25.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 59 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 105 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7a2248b and 324d01a.

Files selected for processing: 13

  • changelog.d/ITL-1446.md
  • docs/dev/design_issues/ITL-1162-CA3.md
  • docs/dev/plans/2026-11-24-itl-1446-strict-fake.md
  • docs/reference/database-types.md
  • src/orcapod/databases/_spiral_lease.py
  • src/orcapod/databases/spiraldb_connector.py
  • tests/test_core/data_tags/test_database_capability.py
  • tests/test_core/sources/test_spiraldb_table_source_fake.py
  • tests/test_core/sources/test_spiraldb_table_source_where.py
  • tests/test_databases/fake_pyspiral.py
  • tests/test_databases/test_spiral_lease.py
  • tests/test_databases/test_spiraldb_connector_fake.py
  • tests/test_databases/test_unstorable_columns.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@eywalker
eywalker marked this pull request as draft November 24, 2026 19:37
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.28770% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/orcapod/databases/_spiral_lease.py 96.43% 14 Missing ⚠️
src/orcapod/databases/spiraldb_connector.py 94.73% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/orcapod/databases/spiraldb_connector.py 98.21% <94.73%> (-0.33%) ⬇️
src/orcapod/databases/_spiral_lease.py 96.43% <96.43%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eywalker

eywalker commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing: this lease was written for the earlier SpiralDB client and a drop-based design. spiral-sdk offers no keyed-table drop and no conditional metadata write, so the lease is redesigned with generation tables (PR #588, section 5) and is being rebuilt on current main in ITL-1838. Tracked in ITL-1452.

Posted by a Claude Code agent on behalf of @eywalker.

@eywalker eywalker closed this Dec 1, 2026
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