Skip to content

Unit tests leave the graph-marks and drops timers cancelled - #145

Merged
zlareb1 merged 20 commits into
mainfrom
fix/provider-runtime-test-task-registry
Oct 23, 2026
Merged

zlareb1 merged 20 commits into
mainfrom
fix/provider-runtime-test-task-registry

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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_write failed once in CI (seed 397842202731) with assert 'fake-ngram-3072' == 'text-embedding-test': the second load_active_configuration() returned before applying the committed model. The captured log for that test shows graph writes not recorded (non-fatal, 1): ClickHouse client not connected from server/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_later retry. 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_empty reset the usage, drops and namespace-marks buffers but not this one. Each firing spawns a flush through a TaskSet, which registers it as a deferred task. When one is pending at the second load_active_configuration(), drain_task_sets(timeout_s=0) reports work left and the model switch is skipped.

_tasks_left_as_found now resets every deferred ledger, graph_write_marks included (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_empty is 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_later dropped the call_later handle. A drop recorded in one test fired up to 2 s later inside another test and registered a loom-drops-flush task there, which a zero-timeout drain counts before it has run. drops now keeps the handle in _timer, clears it when it fires, and its reset cancels it, as namespace_write_marks does.

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 in tests/unit/test_memory_drops.py, whose _quiet_ledger keeps only the _flush_later stub (its resets move to the suite teardown, and the _flush_and_rearm stub 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, whose local_marks fixture is replaced by a plain import of graph_write_marks, and tests/unit/test_traverse_reads_own_graph_writes.py, whose server fixture no longer resets it (the teardown now does).

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: revert; nothing is stored.

Tests

  • make format-check lint typecheck passes, including generator checks.
  • 64 focused drops, graph expiry, namespace marks and provider-runtime tests pass with the failing CI seed.
  • A teardown probe (not committed: under random order a cross-test check cannot pick its neighbour) confirms that graph marks and their delayed flush are cleared between tests. The two-test provider-transition reproduction (an earlier test that records a graph write, then 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_writing arms 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.
  • Latest-head CI must complete the full unit and integration suites before merge.

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.spawn and drain_task_sets.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Latest-head full unit and integration CI passes before merge. Local validation is recorded above.
  • Generated files are regenerated in this PR, not by hand. (none affected)
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (no migration)
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version. (no plugin change)
  • The frontend builds and its tests pass, if frontend/ changed. (no frontend change)
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 2 commits October 22, 2026 14:17
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]>
@zlareb1 zlareb1 changed the title Provider runtime tests drain only the deferred tasks they register Unit tests leave the graph-marks retry timer disarmed Oct 22, 2026
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]>
@zlareb1 zlareb1 changed the title Unit tests leave the graph-marks retry timer disarmed Unit tests leave the graph-marks and drops timers cancelled Oct 22, 2026
zlareb1 and others added 17 commits October 22, 2026 14:32
… 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]>
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]>
…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]>
…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
@zlareb1
zlareb1 merged commit 22526f0 into main Oct 23, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/provider-runtime-test-task-registry branch October 23, 2026 07:44
@pufit pufit mentioned this pull request Oct 25, 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