Repository navigation
fix: Quiesce the MCP call-log dispatcher between tests - #5036
Conversation
The process-global `call_log._DISPATCHER` owns a daemon thread that keeps scanning every registered outbox root until its deliveries are acknowledged. No test daemon acknowledges them, so the thread outlives the test that started it. Its delivery path resolves `api_auth_token_path()` -- and therefore `XDG_DATA_HOME` -- at delivery time, so once a later test re-points XDG the surviving worker mints an API bearer token inside that test's tmp_path. That is a correct design for a long-lived MCP server process, whose environment is fixed; it is wrong for a process that re-points XDG between units of work. Rather than weaken the production route, give the dispatcher an explicit `quiesce()` that stops the worker, clears roots/retry/counters and leaves it restartable, and call it from the existing autouse singleton-reset fixture beside `reset_blob_store` and `reset_status_snapshot`. Problem: tests/unit/storage/test_archive_tier_init.py:: test_tier_prototype_is_atomically_published_and_restored_read_only counts `os.replace` calls through a global monkeypatch, so the leaked worker's `api-auth-token` replace was attributed to prototype publication. Reproduction at 14e1d82: devtools test tests/unit/mcp/test_contract_evidence.py \ tests/unit/storage/test_archive_tier_init.py -p no:randomly failed 3 of 4 attempts before this change and passes 4 of 4 after. Verification: devtools test tests/unit/mcp -> PASSED devtools test tests/unit/mcp/test_mcp_call_log.py -> PASSED Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reachedNext included review available in 33 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (3)
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. Comment |
Advances
polylogue-7lhl5. One confirmed order-dependent failure fixed; fourothers did not reproduce and were deliberately left unfixed rather than
papered over.
Summary
Quiesce the process-global MCP call-log dispatcher between tests, so its worker
thread stops writing into a later test's
tmp_path.Why this matters now
PR #5031 made the corpus collect as one unit, so cross-test pollution —
previously invisible, because every focused selection was green — will now appear
in the campaign's final full-corpus gate, where it is indistinguishable from a
product regression.
The leak
tests/unit/storage/test_archive_tier_init.py::test_tier_prototype_is_atomically_published_and_restored_read_onlyfails
assert 2 == 1on anos.replacecount.Minimal reproducer, bisected from a four-directory run →
tests/unit/mcp→ first8 files → one file:
Failed 3 of 4 attempts; passes alone. No seed involved — it is a thread race, not
a shuffle artifact.
Instrumenting the assertion caught the culprit: the extra
os.replacewas.api-auth-token.XXXX.tmp → api-auth-token, landing inside the tier-inittest's own
tmp_path/xdg-data/polylogue/.Owner is
polylogue/mcp/call_log.py's module-level_DISPATCHER— aprocess-global singleton whose daemon thread rescans every registered outbox root
every 0.25 s until deliveries are acknowledged. No test daemon acknowledges them,
so the thread outlives the MCP test that started it, and
_read_spooled_deliverycalls
resolve_api_auth_token(...), which resolvesapi_auth_token_path()/XDG_DATA_HOMEat delivery time. The tier-init test monkeypatchesos.replaceglobally, so the surviving worker's token mint was attributed toprototype publication.
Production-owned, but not a product bug
The dispatcher's process-lifetime thread is correct for a long-lived MCP
server whose environment is fixed. It is only wrong for a process that re-points
XDG between units of work — which is the test process. So the production route
was not weakened.
Added
_McpCallLogDispatcher.quiesce()/reset_mcp_call_log(): stops and joinsthe worker, raises if it will not stop, clears roots/retry/counters/wake queue,
and leaves it restartable — unlike the existing
shutdown(), which isterminal. Called from the existing autouse singleton-reset fixture in
tests/conftest.py, besidereset_blob_storeandreset_status_snapshot.Anti-vacuity — verified, not asserted
test_quiesce_stops_the_worker_clears_routing_and_allows_restartgoes red if_roots.clear()or the_stop.clear()/_thread = Nonerestart path isdropped.
test_global_dispatcher_is_quiesced_before_every_testgoes red if the conftestcall is removed and the file runs after any file that invokes an MCP tool.
Confirmed by commenting the call out and watching it fail, then restoring it.
polylogue/mcp/call_log.pyisoutof the derived schema-identity closure, sothere is no reconvergence implication.
Four cases did not reproduce — and no fix was invented for them
test_mcp_call_log.py,test_insight_export_bundles.py,test_session_insight_rebuild_progress.py, andtest_daemon_cli.py::test_run_daemon_services_stops_live_watcher_on_failureweregreen in both large combined runs: 8,620 tests
(
tests/unit/mcp core storage daemon) and ~9,200 tests(
tests/unit/api archive cli context coordinationplus the four targets), bothwith
-p no:randomly.Worth recording for whoever runs the final gate: the
test_mcp_call_logclusteris mechanistically consistent with the leak fixed here —
test_readiness_surface_exposes_outbox_pressureasserts on_DISPATCHER'scumulative
delivery_failures/wakeups_droppedand its registered roots, all ofwhich the global singleton carried across tests before this commit. That is
not claimed as verified.
Verification
Receipts:
20260913T214033Z-…-1609768-bae48713(first repro),…T224543Z-…-1825795(instrumented, showing the token replace),…T225139Z-…-1954749(fixed),…T225233Z-…-1975853(tests/unit/mcp),…T225912Z-…-2116330(9k combined),…T231042Z-…-2353742(anti-vacuity red).🤖 Generated with Claude Code
https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK