test(tracing): isolate span emission into per-test tmp dirs - #371
Merged
Conversation
Tracing is on by default and trace.span() calls are embedded in library code, so any test exercising the agent loop emitted spans with fabricated session keys into the real ~/.raven/traces store; they surfaced as phantom sessions in raven trajectory while the TUI /sessions list stayed clean. Add an autouse fixture that redirects RAVEN_TRACING_DIR to a per-test tmp directory and resets the module-level TraceStore cache around each test. Only the directory is redirected, not the enabled switch, so the suite keeps exercising the real emission path with zero behavior change. Tests that pin their own directory keep working: their setenv runs after the fixture and wins, and they already reset the cache themselves. Co-authored-by: Claude (claude-fable-5) <noreply@anthropic.com>
gloryfromca
reviewed
Aug 28, 2026
gloryfromca
left a comment
Contributor
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
I reviewed the full github/main...HEAD diff, the tracing configuration/store lifecycle and emission callers, every test override of RAVEN_TRACING_DIR, relevant fixture history, backward compatibility, and the repository rules/domain glossary. The fixture keeps tracing enabled, redirects each test to its own tmp_path, and resets the lazy store on both sides of the test; existing tracing tests still override the directory after the autouse fixture and reset the singleton where they emit, so no assertions were weakened to obtain isolation.
Verification:
git diff --check github/main...HEADpassed.uv run pytest tests/test_tracing_api.py tests/test_cli_tracing_commands.py tests/test_trajectory_store.py -q: 119 passed.- A controlled agent-loop emission test passed and wrote nothing to an externally supplied tracing directory, confirming the fixture's per-test override.
uv run pytest: 6,867 passed, 43 skipped, 13 deselected, with 4 failures and 2 errors before the process exited 139. One untouched theme assertion reproduces in isolation; the other five reports came after the suite exhausted file descriptors and all seven involved late-stage tests passed in a fresh-process rerun. These failures are not caused by the tracing fixture.
gloryfromca
approved these changes
Aug 28, 2026
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.
Summary
Unit tests were leaking tracing spans into the real
~/.raven/tracesstore. Tracing is on by default andtrace.span()calls are embedded in library code (agent loop, subagents, TUI RPC), so any test exercising those paths emitted spans with fabricated session keys (session-a,weixin:c,tui:default, ...). Those spans then surfaced as phantom sessions inraven trajectory, while the TUI/sessionslist (which reads the real session store) stayed clean.This PR adds an autouse fixture in
tests/conftest.pythat:RAVEN_TRACING_DIRto a per-test tmp directory, andTraceStorecache (raven.tracing.spans._store) around each test, since it pins the directory resolved at first emit.Key decisions:
monkeypatch.setenvruns after the fixture and wins, and they already reset the cache themselves.Type
Test-suite hygiene (
testcommit type).Verification
uv run pytest tests/test_tracing_api.py tests/test_trajectory_store.py tests/test_trajectory_bundle.py tests/test_trajectory_replay.py tests/test_trajectory_redact.py tests/test_cli_tracing_commands.py tests/test_cli_trajectory_commands.py tests/test_cli_trajectory_browse.py -q: 308 passed, 1 failed (test_viewer_health_true_for_our_viewer, fails identically on unmodifiedmain, environment-specific)uv run pytest tests/test_agent_loop_run_emit.py tests/test_subagent_manager.py tests/test_tui_rpc_turn_send.py tests/test_deep_research_tool.py tests/test_agent_loop_approval.py -q: 109 passed; the real~/.raven/traceslog did not grow during the runPositive check: running
tests/test_agent_loop_run_emit.pywith--basetempshows the previously leaked session keys (cli:c,tg:c,weixin:c) now land in per-test tmp dirsuv run pytest tests/ --ignore=tests/integration -q: 6837 passed, 11 failed, 20 errors; the same failure set reproduces on unmodifiedmain(environment-specific: cron/tz, everos server, theme, config loader, viewer health), zero regressions from this changeuv run ruff check tests/conftest.pyanduv run ruff format --check tests/conftest.py: both passRelevant tests pass locally
Relevant lint / type checks pass locally
User-facing docs or screenshots are updated when needed
Docs box left blank: test-only change, no user-facing docs affected.
Risk
Test-only change; no production code touched. One known interaction:
RAVEN_TRACING_DIRtakes precedence overRAVEN_HOME, so a future test that fakesRAVEN_HOMEand expects traces under it must also setRAVEN_TRACING_DIRitself. Rollback: revert the single commit.Related Issues
N/A