Repository navigation
Conversation
… retry budget Root cause: every realtime retry of a mutation rejected with DatabaseTemporarilyUnavailableError goes through _schedule_compaction_retry, whose budget (5 attempts, 0.1 s * 2**n with jitter) is about 3 s in total. The errors actually raised mean another owner in this process holds the database for a bounded time: a Rust run (a resync's scan, tens of seconds) or a compaction (up to 660 s). A write landing during such a hold spent its whole budget in ~3 s, recorded "retry budget exhausted", added the path to failed_files and left the service degraded. A resync's scan later indexed the file, but the error and the degraded state persisted; after a compaction hold the file stayed unindexed until its next change. Design: - DatabaseProvider and SerialDatabaseProvider gain is_compaction_in_progress(), delegating to the executor beside is_rust_pipeline_in_progress(). - The realtime mixin's _database_held_by_owner() reads both flags. - _schedule_compaction_retry, while the database is held, registers the retry with retry_count unchanged and starts one task that polls every _HELD_DB_RETRY_DELAY_SECONDS (0.5 s) until the hold clears, dropping a superseded or stale-delete mutation on each wake, then hands off to _retry_mutation_after_delay. Waiting on the flag rather than re-enqueueing avoids re-hashing and re-parsing every parked file on each poll. Not held: the budgeted backoff is unchanged, so a genuine failure still ends. - _derive_live_indexing_state reports busy, not stalled, while a known owner holds the database and the backlog is non-empty. Tests: one new test, test_write_rejected_while_db_held_waits_for_release, which fails on main (TimeoutError: the budget is exhausted at once and the file is never processed) and passes with the fix. The existing fakes in test_realtime_compaction_retry.py now report the database as not held, so the exhaustion tests keep guarding the no-holder path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 11, 2026
Brings in the 14 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A realtime file write that hits a database held by another owner in the same process gives up after about 3 s, even though the hold is known and bounded.
Every realtime retry of a mutation rejected with
DatabaseTemporarilyUnavailableErrorgoes through_schedule_compaction_retry. Its budget is 5 attempts at 0.1 s × 2ⁿ with jitter, about 3 s in total. But the errors actually raised there mean an owner in this process holds the database for a bounded time: a Rust run (a resync's scan, tens of seconds) or a compaction (up to 660 s). A write landing during such a hold spends its whole budget in about 3 s, then:retry budget exhausted,failed_files,degraded. Nothing clears that state.After a resync, the scan has indexed the file anyway, so the error and the degraded status are false. After a compaction hold, the file stays unindexed until it next changes.
Reproduced on Linux (watchdog 7.1.0,
max_queued_events64): 500 files written into an existing directory, so that each run had a real kernel inotify overflow and the resync it triggers. In 1 of 6 runs the service endeddegradedwith 14 failed files andretry budget exhausted, while all 500 files were indexed. (That run also had #509's overflow-to-resync and #510's handover underneath; without #510 a resync that overlaps writes usually fails earlier, in the handover, and this symptom hides behind that one.)Fix
Wait out a known hold instead of spending the budget on it:
DatabaseProviderandSerialDatabaseProvidergainis_compaction_in_progress(), beside the existingis_rust_pipeline_in_progress()._schedule_compaction_retryregisters the retry without spending budget, and starts one task that polls the hold every 0.5 s (_HELD_DB_RETRY_DELAY_SECONDS). On each wake it drops a mutation that has been superseded, or a stale delete. When the hold clears it hands off to the existing_retry_mutation_after_delay._derive_live_indexing_statereportsbusy, notstalled, while a known owner holds the database and work is queued.Concurrency. The two hold flags are
threading.Events, set by the executor thread or the loop and only read on the loop. All pending-mutation state stays on the loop. The polling task is a transient task, sostop()cancels it.Alternative considered: re-enqueue each parked mutation on every poll. That re-hashes and re-parses every parked file twice a second for the length of the hold; polling one flag costs nothing.
Tests
tests/unit/test_realtime_compaction_retry.py::test_write_rejected_while_db_held_waits_for_releasefails onmainwithTimeoutError(the budget is exhausted at once and the file is never processed) and passes with the fix. The module's existing fakes now report the database as not held, so the exhaustion tests keep guarding the no-holder path.Suites run serially:
tests/realtime,test_realtime_functional,test_realtime_failures,test_duckdb_compaction,unit/test_rust_pipeline_runner,unit/test_checksum_verify_flow,unit/test_coordinator_per_file_txn,unit/test_realtime_compaction_retryandtest_mcp_tool_consistency. 340 passed / 34 skipped onmain, 341 / 34 with this change.tests/test_smoke.py: 14 passed.ruff checkreports the same findings on the changed files as onmain.End to end, in the same setup as above: 0 of 6 runs ended degraded; every run indexed 500/500 and went idle. The rate before (1 of 6) is too low for that to be strong evidence on its own; the unit test carries the proof. Not measured end to end:
busyinstead ofstalledduring a compaction hold, and the compaction-hold case where a file stayed unindexed until its next change.Overlap
#510 also edits
realtime/pipeline.py(its resync retry) andrealtime/service.py(constants), in different hunks; the two merge cleanly together, and each merges cleanly ontomain.🤖 Generated with Claude Code, reviewed by FStrasz