Skip to content

test: give each xdist worker its own default unit-test SQLite file (#4051) - #4079

Merged
vybe merged 3 commits into
devfrom
fix/4051-per-worker-unit-db
Nov 1, 2026
Merged

vybe merged 3 commits into
devfrom
fix/4051-per-worker-unit-db

Conversation

@dolho

@dolho dolho commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Summary

tests/unit/conftest.py defaulted TRINITY_DB_PATH with os.environ.setdefault(..., os.getpid()). The same applied to TRINITY_RETAINED_RESULTS_DIR and TRINITY_CHAT_SESSION_FILE. The xdist controller loads that conftest first, so the value carried the controller's pid. Every worker inherited it, and each worker's setdefault was a no-op, so under CI's -n auto all workers shared one SQLite file.

A value this conftest defaulted is now recorded in TRINITY_UNIT_TESTS_DEFAULTED_ENV, and any process that inherits it re-derives the value from its own pid. A value set from outside (a developer's own TRINITY_DB_PATH) is still left alone. This makes the existing comment in backend-unit-test.yml true as written ("conftest pins TRINITY_DB_PATH per PID ... which is what makes per-worker DB state correct"). The workflow file is not edited.

Tests

tests/unit/test_4051_per_worker_unit_db.py asserts that each defaulted path carries this process's pid:

  • -n 2 without the fix: all three cases fail, each naming another process's pid.
  • -n 2 with the fix: they pass.
  • A serial run passes either way, so CI's -n auto is where the test bites.

Not done locally: the issue's third criterion, comparing the full unit tier serial vs -n auto on one seed. The full tier is long, and network-dependent files time out in my environment on dev too. CI's -n auto run of this PR is the first data point.

Fixes #4051

🤖 Generated with Claude Code

…4051)

tests/unit/conftest.py defaulted TRINITY_DB_PATH (and the retained-results
dir and chat-session marker) with os.environ.setdefault(..., pid). The
xdist controller loads that conftest first, so the value carried the
controller's pid, every worker inherited it, and each worker's setdefault
was a no-op: under CI's -n auto all workers shared one SQLite file,
contrary to the backend-unit-test.yml comment that says conftest pins
it per PID.

A value this conftest defaulted is now recorded in
TRINITY_UNIT_TESTS_DEFAULTED_ENV, and a process that inherits it
re-derives it from its own pid. A value set from outside is still left
alone. The CI comment is now accurate as written.

The new test fails under -n 2 without the fix (all three paths carry
another process's pid) and passes with it; a serial run passes either
way.

Fixes #4051

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dolho

dolho commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Review via /review (pre-landing structural review). Self-review by the PR author's session; obasilakis is requested as the independent reviewer.

/review Report

Branch: fix/4051-per-worker-unit-db → dev (merge-base b90035764)
Files Changed: 3 (+71/−5)
Scope: CLEAN. Test infrastructure only (tests/unit/conftest.py).
Plan Completion: 2 done / 1 partial

  • DONE: each xdist worker opens its own default DB file (_pin_per_process, keyed on the worker's own pid). The retained-results dir and the chat-session marker get the same treatment.
  • DONE: a -n 2 probe shows distinct paths (the new test is red under -n 2 without the fix).
  • PARTIAL: "the full unit tier's serial and -n auto results are compared on one seed" was not run locally (scope cut: tier length, plus network-bound files that time out in the author's environment on dev too). Impact LOW: CI's -n auto run of this PR is the first data point.

Execution coverage (Step 2.5)

changed symbol executed by live consumer verdict
_pin_per_process / TRINITY_UNIT_TESTS_DEFAULTED_ENV every unit session (conftest import), asserted by test_4051_per_worker_unit_db.py the unit tier itself ✅ executed

Fix mutation: with tests/unit/conftest.py reverted, under -n 2 all 3 parametrized cases are red (each names another process's pid). Serial runs are green either way, as the module docstring says.

Critical Findings

None.

Informational Findings

[I1] The CI workflow comment is left as-is (Confidence: 8/10)
File: .github/workflows/backend-unit-test.yml:233-239
Issue: the comment was false on dev and is true with this PR. It isn't edited because the author's token can't push workflow files. No action needed unless you want the comment to cite #4051.

Clean Categories

  • 4.1–4.5: no production code, SQL, auth, credentials or docs.
  • 4.8: an explicit outside TRINITY_DB_PATH is still honoured (not in the marker, so left alone).

Summary

  • Critical: 0
  • Informational: 1
  • Scope: clean; one acceptance criterion partial (full-tier comparison deferred to CI)

@dolho
dolho requested a review from obasilakis October 29, 2026 11:12
@github-actions

Copy link
Copy Markdown

⚠️ Live-instance suite skipped — merge conflict against dev.

Resolve by merging dev locally and pushing the result; the next nightly re-tests.

@github-actions

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

# Conflicts:
#	tests/registry.json

@obasilakis obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/review + /validate-pr: APPROVE on code (lane B). Needs a rebase.

  • BLOCKER (mechanical) tests/registry.json:3: conflicts with dev; no CI has run.
  • Mutation: reverting conftest.py to merge-base and running the new test with -n 2 fails all 3 cases, each naming the controller pid. With the fix: 3 passed under -n 2 and serially. Externally set TRINITY_DB_PATH still left alone (_defaulted_by_us).
  • WARN #4051 AC3 (serial vs -n auto full unit tier on one seed) not done, as the body says. Tests that passed only via a shared DB file may change result; CI's -n auto run is the first data point.
  • INFO tests/unit/conftest.py:85-104: temp DB / retained-results dir / chat-session file never cleaned up (pre-existing); now one set per worker plus controller.

Ran /review + /validate-pr (report-only mode).

…cal, per the merge-train note on the PR

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vybe

vybe commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

merge-train: merged dev into this branch and rebuilt tests/registry.json from the merge stages (your entry kept, dev's entries added, nothing else touched) — commit 32ea422. Mechanical, no behaviour change. The earlier red regression diff was the ent419 wall-clock flake, and the CodeQL re-run is green.

@vybe
vybe merged commit a262c5d into dev Nov 1, 2026
23 checks passed
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.

4 participants