Repository navigation
fix(kernel): wait out shared-registry locks on lease renewal - #689
khaliqgant wants to merge 2 commits into
Conversation
A review fleet sharing one relayflowd registry failed heartbeats with `journal_write_failed: persist renewed lease deadline: SQLite journal failed: database is locked`, and the step then ended terminal. The registry was already WAL with a 5s busy_timeout, but every short-lived open re-ran `PRAGMA journal_mode=WAL` (an exclusive lock the busy handler does not cover; the retry is ~100ms) and re-executed schema DDL. Under load that writer queue outlasted 5s. The run journal set WAL and never armed a busy_timeout, so a second connection failed immediately. Every open now arms a 15s busy_timeout — inside the 30s protocol timeout and the slack on a 30s lease — and switches to WAL only when the file is not already WAL. Registry DDL runs only when the schema is not current. Read-only opens get the same timeout. A renewal that still cannot commit returns the SQLite error; it is not swallowed. No fleet concurrency cap. One WAL writer plus the wait serializes the heartbeats; a cap would only hide a lock that is still too long. Regression: renew_deadline commits while another connection holds a read, and waits out a short IMMEDIATE write instead of returning database is locked. With the timeout forced to zero that test fails with `SQLite journal failed: database is locked`.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Shared SQLite WAL setup kernel/relayflowd-journal/src/sqlite.rs |
Adds a 15-second busy timeout, bounded WAL-switch retries, and helpers for WAL validation and read-only connection timeouts. |
Journal connection configuration kernel/relayflowd-journal/src/lib.rs |
Applies the shared helpers to journal opens. Writable configuration validates WAL mode and enables foreign keys. A non-WAL mode returns JournalNotWal. |
Registry open and schema checks kernel/relayflowd-journal/src/registry.rs |
Uses shared WAL setup and checks for five tables and the event_dedupe.boot_id column before running schema setup. Adds tests for busy timeouts, WAL mode, and lease-renewal behavior. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Suggested reviewers: kjgbot, miyaontherelay
Merge Risk: 
Low · up to 55214
-
An uncommon lock sequence could delay a heartbeat until its renewed lease has expired. The change is mergeable with owner awareness of this edge case.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the problem (lease renewal failing with 'database is locked' on a shared relayflowd.sqlite3), the fix (15-second busy timeout on every open, WAL switch only when needed, skipping registry DDL when the schema is current, returning rather than swallowing failed writes), a follow-up commit that changes lease TTL measurement, and the tests run. This maps directly to the raw summary's changes in lib.rs, registry.rs, and sqlite.rs, so the description is clearly related to the changeset.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 3 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the WAL at dawn
Then sets the timeout before it’s gone
The tables stand in tidy rows
A lease renews as SQLite flows
Soft paws thump: the checks are done
[High impact] The PR appears safe to merge; the previous lease-duration issue is fixed and no new blocking issue remains.
|
The worker adds lease_ttl_ms to the time it sent the heartbeat. Measuring that duration after the durable write subtracted a long lock twice, so the worker could abandon a lease the daemon had just extended.
Summary
Review flows on a loaded Linux host failed lease renewal on the one
relayflowd.sqlite3shared by adversarial-review, context-review, and ci:journal_write_failed: persist renewed lease deadline: SQLite journal failed: database is lockedSteps then ended as
run_terminal … cannot accept mutations. Seen with@relayflows/runtime-linux-x642.0.55 at load 20–60.The registry was already WAL with a 5s
busy_timeout, but every short-lived open re-ranPRAGMA journal_mode=WAL(an exclusive lock the busy handler does not cover, retried for about 100ms) and re-executed schema DDL. The run journal set WAL and leftbusy_timeoutat 0.Every open now waits 15 seconds, switches to WAL only when the file is not already WAL, and skips registry DDL once the schema is current. A write that still cannot commit is returned. It is not swallowed. There is no fleet concurrency cap.
Follow-up
7a569cfckeepslease_ttl_msmeasured from the instant the daemon set the deadline, before the durable write. The worker adds that duration to the time it sent the heartbeat. Measuring after the write counted the wait twice: a 14s lock left the worker about 2s on a lease the daemon had just extended. The worker deadline is unchanged when the write is fast.Validation
cargo test -p relayflowd-journal --offline -- --test-threads=8fromkernel/: 35 passed, including:renew_deadline_commits_while_another_connection_holds_a_readrenew_deadline_waits_out_a_short_write_instead_of_failing_lockedrenew_deadline_does_not_swallow_a_write_that_cannot_commitfailed_commit_is_returned_not_swallowedWith the timeout forced to zero, the wait-out test fails with
SQLite journal failed: database is locked.cargo test -p relayflowd --offline --lib -- heartbeat_ttl_keeps_the_full_lease_across_a_slow_durable_write heartbeat_carries_the_remaining_lease_as_a_duration --test-threads=1: both passed. The new test holdsBEGIN IMMEDIATEfor 2 seconds across the heartbeat and requireslease_ttl_ms >= 29_000.Agent session:
01a19b64-f33d-7f63-bb7f-eb61212c7809