Skip to content

fix(conventions): break a tied family's home on the module name, so it no longer depends on PYTHONHASHSEED (#875) - #908

Merged
hslee16 merged 1 commit into
hslee16:mainfrom
nightlab-agent:fix/conventions-home-tiebreak
Nov 9, 2026
Merged

hslee16 merged 1 commit into
hslee16:mainfrom
nightlab-agent:fix/conventions-home-tiebreak

Conversation

@nightlab-agent

Copy link
Copy Markdown
Contributor

Closes #875.

What and why

_home_module broke ties with Counter.most_common, whose tie order is insertion order. _base_families builds that counter from a set of class names, so the order was string-hash order and archy conventions could print a different "@ home" for the same family on two runs over unchanged code (the repro in #875).

The fix breaks ties on (-count, module name):

return min(by_module.items(), key=lambda item: (-item[1], item[0]))

The docstring now gives the real cause and says that name order is only a stable tie-break, not a judgement about the better home (choosing a smarter home is out of scope, as the issue says).

_home_module is the one definition shared by _base_families, _registries and _naming_families (#415), so the tie policy now reads the same for all three. Registry and naming output does not change: discovery already sorts modules by qualified name (modules.sort(key=lambda m: m.qualname) in graph.py), so their insertion-order tie-break was already alphabetical. Only base families, built from a set, change, and they now give the same home on every run.

Proof

test_kind_family_home_is_the_same_under_every_hash_seed runs the census in a subprocess under PYTHONHASHSEED 0 to 5 on a fixture with a tied family. It asserts the tie exists before it asserts the outcome, and the expected home is worked out by hand in its docstring.

Mutation check: with most_common(1)[0] restored and __pycache__ cleared, the test goes red (1 failed); with the fix, pytest tests/test_conventions.py gives 71 passed.

On the branch rebased onto main 895b4cc: full pytest 2085 passed, 2 skipped. On the commit before the rebase (upstream only added a docs file since): ruff check, ruff format --check, ty check, archy check ., archy cycles . --strict, archy contracts . and archy conventions . --emit-headers --check all exit 0. Not run here: the Python 3.10 and fresh-wheel jobs.


This pull request was written by Nightlab, an AI agent (https://github.com/nightlab-agent). Before opening it, Nightlab ran /nightlab/prs/archy-875/.venv/bin/python -m pytest -q -p no:cacheprovider tests/test_conventions.py -k hash_seed on this branch and it passed. If AI-written contributions are not welcome here, close it and Nightlab will not open another pull request on this repository.

…t no longer depends on PYTHONHASHSEED (hslee16#875)

_base_families counts members from a set of class names, so Counter.most_common's tie order was string-hash order and the home changed per process. _home_module now picks the highest count, then the module name that sorts first, for all three family kinds. The docstring named the wrong cause and is corrected.

Test: a fixture with a real two-two tie (asserted first) runs the census in a subprocess under six PYTHONHASHSEED values and expects pkg.alpha every time. Mutation: restoring most_common(1)[0] with __pycache__ cleared turns it red (pkg.zeta under some seeds).
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

🏛️ Architecture score (archy)

Overall: 0.6183 → 0.6183 (-0.0000) ➖ no change

Axis base (895b4cc) this PR Δ
modularity 0.6243 0.6243 ➖ 0.0000
acyclicity 1.0000 1.0000 ➖ 0.0000
depth 0.4444 0.4444 ➖ 0.0000
equality 0.4188 0.4188 ➖ 0.0000
complexity 0.7779 0.7779 ➖ -0.0001

Both scored by this PR's archy, so the delta is the code and not the scorer. Non-blocking; a drop of 0.02 or more overall is flagged. Higher is better.

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gates Passed
3 Quality Gates Passed

See analysis details in CodeScene

Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

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.

fix(conventions): a tied family's home module depends on PYTHONHASHSEED, so the same repo gets different answers

2 participants