Repository navigation
Unit tests leave the graph-marks and drops timers cancelled - #145
Merged
Merged
Conversation
load_active_configuration skips the model switch while drain_task_sets reports work left, and that registry is process-wide: a task another test left pending made the switch order-dependent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A failed graph-marks flush re-arms a call_later retry that outlives its test; each firing registers a deferred flush, so a later test's drain_task_sets saw work and load_active_configuration skipped the model switch. Reverts the module-level registry patch, which did not cover this. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A drop recorded in one test fired its flush timer inside a later test and registered a task a zero-timeout drain counts. drops keeps the call_later handle so its reset can cancel it, as namespace_write_marks does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… the teardown now covers Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Describe why cleanup is needed without repeating the fixture mechanics. Signed-off-by: Lareb Zafar <[email protected]>
A drops or graph-marks timer due during the async teardown fired after _tasks_left_as_found listed the leaked tasks, so its flush task survived into the next test. The fixture now resets the ledgers before listing; the later reset clears what a cancelled flush leaves. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s left A leaked task cancelled during teardown can re-arm a ledger timer or spawn a graph-marks end task from its done callback, so _tasks_left_as_found repeats the reset and the sweep, and the separate ledger fixture is gone. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…eset test checks no flush writes Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…et it calls Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…test-task-registry Signed-off-by: zlareb1 <[email protected]> # Conflicts: # tests/unit/conftest.py
Merged
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
...
Why
tests/unit/test_provider_runtime.py::test_committed_embedding_change_waits_for_registered_deferred_writefailed once in CI (seed 397842202731) withassert 'fake-ngram-3072' == 'text-embedding-test': the secondload_active_configuration()returned before applying the committed model. The captured log for that test showsgraph writes not recorded (non-fatal, 1): ClickHouse client not connectedfromserver/memory/app/graph_write_marks.py.That is a graph-marks flush running during the test. An earlier unit test records a graph write with no ClickHouse client; the flush fails and re-arms a
call_laterretry. The timer is not a task, so_tasks_left_as_found(which cancels the tasks a test leaves) never cancels it, and_deferred_ledgers_left_emptyreset the usage, drops and namespace-marks buffers but not this one. Each firing spawns a flush through aTaskSet, which registers it as a deferred task. When one is pending at the secondload_active_configuration(),drain_task_sets(timeout_s=0)reports work left and the model switch is skipped._tasks_left_as_foundnow resets every deferred ledger,graph_write_marksincluded (its reset cancels the timer and clears the unrecorded marks), before it lists the leaked tasks: a timer due during the async teardown would otherwise spawn its flush after the list was taken. A leaked task cancelled there can re-arm a timer or spawn a graph-marks end task from its done callback, so the reset and the sweep repeat. After three passes the ledgers are reset, the leftovers cancelled, the ledgers reset once more, and a leftover that was not already cancelling fails that test instead of leaking into the next; the exemption covers the usage flusher, which the reset itself has just cancelled._deferred_ledgers_left_emptyis folded into it, so the order is explicit in one fixture.The drops ledger's timer has the same shape and the same effect:
drops._reset_for_tests()cleared the buffer but could not cancel the timer, because_flush_laterdropped thecall_laterhandle. A drop recorded in one test fired up to 2 s later inside another test and registered aloom-drops-flushtask there, which a zero-timeout drain counts before it has run.dropsnow keeps the handle in_timer, clears it when it fires, and its reset cancels it, asnamespace_write_marksdoes.Scope and risk
tests/unit/conftest.py(the teardown fixture),server/memory/app/drops.py(the timer handle is kept so it can be cancelled; the flush itself is unchanged), a new unit test intests/unit/test_memory_drops.py, whose_quiet_ledgerkeeps only the_flush_laterstub (its resets move to the suite teardown, and the_flush_and_rearmstub is deleted because the teardown now cancels the earlier test's drops timer it guarded against),tests/unit/test_facts_expire_marks_graph_write.py, whoselocal_marksfixture is replaced by a plain import ofgraph_write_marks, andtests/unit/test_traverse_reads_own_graph_writes.py, whoseserverfixture no longer resets it (the teardown now does).Compatibility, rollout and rollback
Tests
make format-check lint typecheckpasses, including generator checks.tests/unit/test_provider_runtime.py::test_committed_embedding_change_waits_for_registered_deferred_write, run with-p no:randomly) fails on the base and passes with this cleanup.test_reset_stops_an_armed_flush_from_writingarms a real 10 ms drops timer, resets, buffers a row that arms no timer of its own, waits past the first timer, and checks that the row is still buffered and nothing was inserted; without the cancel, the first timer flushes that row.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (Claude Code). The cause was traced from the CI log's captured warning through
graph_write_marks' retry timer,TaskSet.spawnanddrain_task_sets.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
main; no merged migration is edited. (no migration)frontend/changed. (no frontend change)docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code