Skip to content

CI: a module-cycle ratchet that stops the top-level module cycle absorbing more modules - #387

Merged
GLinnik21 merged 2 commits into
mainfrom
lane/cycle-ratchet
Oct 2, 2026
Merged

GLinnik21 merged 2 commits into
mainfrom
lane/cycle-ratchet

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

What

A ratchet that stops the app crate's top-level module cycle absorbing more modules. This PR does not untangle anything. It holds the cycle's membership, not its edges: another upward reference between two modules already on the cycle (a sixth ui -> screens) does not fail it (ci/check-deps.sh and review still own that).

ci/check-module-cycle.py builds the top-level module graph from production code only, computes strongly connected components and compares them with the committed ci/module-cycle-baseline.json.

  • FAIL when a module outside the baseline joins a cycle (a new upward crate::x reference, a new top-level module that lands inside the cycle, or two cycles merging). It prints the module and the file:line references that close the path.
  • Notice (exit 0) when a baseline member left the cycle: run --update-baseline to lock in the gain.
  • --update-baseline rewrites the JSON; --report is the hand-off list for the refactoring session; --dot emits graphviz.

Graph construction: the real module tree is walked from lib.rs (mod x;, #[path], literal include!), so files reached only through #[cfg(test)] modules are never read. Comments and string contents are blanked, then #[cfg(test)] items are blanked by brace matching (not "everything after the first #[cfg(test)]", which is what hid ff -> hls in the earlier regex scan). Limitations (textual matching, super::, macros, glob re-exports) are in the script docstring.

Runs in make check-python (CI host-python), about 1.4 s. ci/test_module_cycle.py covers it against a synthetic crate: layered graph passes, an upward edge names file:line, test-only edges are ignored, a new module inside the cycle fails, shrink notices, --update-baseline round-trips. Red on the real tree was shown in a scratch copy by adding a crate::ui reference to paths.rs.

--report summary (this tree)

  • 56 top-level modules; the largest cycle holds 44 (every production reference counted, comments and test code excluded).
  • Outside the cycle (12): aq, cbuf, checkpoint, coldstart, dynlib, fontcov, hwcnt, imgcache, paths, sha256, surface, svg. (The earlier regex scan put hls and keymanager outside; they are inside: ff -> hls -> plex -> ... -> ff, and plex calls keymanager.)
  • Heaviest mutual pairs: screens <-> ui (1413 / 5), app <-> ui (488 / 1), player <-> route (322 / 131), app <-> player (223 / 6), plex <-> route (1 / 211).
  • Thin back-edges that run against the intended layering (full file:line list in --report):
    • plex -> route (1): plex/session.rs:3914
    • ui -> app (1): ui/more_menu.rs:655
    • ui -> screens (5): ui/player_hud.rs:655, 737, 1839, ui/chapters_panel.rs:260, 313
    • player -> app (6): player/pump.rs:389, player/preview.rs:777-778, player/machine.rs:38, 63
    • text -> ui (11): text.rs:81, 576, 1473, ...
    • gfx -> ui (43)
  • Other thin minority-direction edges in the cycle (webos -> ui, pms -> ui, plex -> ui, route -> ui, ui -> dev, ui -> lab, ui -> browse, ui -> metadata, ...) are listed by --report too.

Verification

  • make check (run on the first commit; the amend changed only prose and the script docstring): test result: ok. 5454 passed; 0 failed; 7 ignored, test result: ok. 102 passed; 0 failed, test result: ok. 5534 passed; 0 failed; 7 ignored, exit 0.
  • After the amend: make check-python exit 0 (ci/test_module_cycle.py: Ran 18 tests, OK; module-cycle: ok (44 modules on the cycle, baseline 44; 12 outside)).
  • doc-claim-auditor: two overclaims in the new prose (membership vs edges), fixed.
  • Host-only tooling change; no device verification.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PUkd69QzFciCfQucbfiyKv

GLinnik21 and others added 2 commits October 2, 2026 03:41
…rbing more modules

44 of the app crate's 56 top-level modules sit on one strongly connected component (~98% of the
code): a few thin upward references (ui -> screens/app, gfx/text -> ui, plex -> route) close it.
Untangling that is separate work; this stops it getting worse.

ci/check-module-cycle.py builds the module graph from production code only (the module tree walked
from lib.rs, so files reached through #[cfg(test)] mods are never read; comments and string
contents blanked; #[cfg(test)] items blanked by brace matching, not "everything after the first
cfg(test)"), computes SCCs and compares with ci/module-cycle-baseline.json. A module that newly
joins a cycle, or a new module that lands inside it, fails with the file:line references that
close the path; a member leaving the cycle prints a notice. It holds membership, not edges: a
further reference between two modules already on the cycle is not caught. --update-baseline
accepts a change, --report is the hand-off work list (thin back-edges with file:line, layer
breaks), --dot emits graphviz. Runs in make check-python (CI host-python), ~1.4 s;
ci/test_module_cycle.py covers it against a synthetic crate.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PUkd69QzFciCfQucbfiyKv
@GLinnik21
GLinnik21 merged commit bc4dc8b into main Oct 2, 2026
11 of 14 checks passed
@GLinnik21
GLinnik21 deleted the lane/cycle-ratchet branch October 2, 2026 01:21
GLinnik21 added a commit that referenced this pull request Oct 2, 2026
… cycle (#389)

spki imported the base64 helper from keymanager, and keymanager sits on the large top-level
module cycle, so the spki -> keymanager reference pulled spki onto it (net -> spki closes it) and
tripped the module-cycle ratchet added in #387. The helper references no other crate module, so it
now lives in its own leaf module, crate::b64, with its behaviour and test unchanged. keymanager and
spki both import it from there; spki and b64 stay outside the cycle and the ratchet baseline is
untouched.


Claude-Session: https://claude.ai/code/session_01PUkd69QzFciCfQucbfiyKv

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Oct 26, 2026
…1053)

Merging was done with ad-hoc `gh` calls, and twice it went wrong: #387 merged RED because
`gh pr merge` was chained after a watcher that read "run completed" mid-run, and #924 read
`gh run list` as success while checks were still running. `tools/pr-land.py` is now the one place
that judges a PR's checks and merges it.

- `pr-land.py gate N [--sha S]`: one verdict, one exit code. 0 green, 1 red, 3 refused (not OPEN,
  wrong base, BEHIND/DIRTY/HAS_HOOKS, a required check skipping or unknown, an unlisted merge
  state), 4 not yet (running, missing required check, empty or unstable list), 5 the head moved off
  S. Required checks come from the base branch's ruleset; a base that requires nothing needs a
  stable check list over two polls. Green requires `mergeStateStatus == CLEAN`.
- `pr-land.py wait N --sha S [--timeout]`: the same judgment, polled.
- `pr-land.py merge N --sha S --subject T (--body-file F | --body-from-pr)`: waits, then
  `gh pr merge N --squash --match-head-commit S`, with the SHA that was gated (never re-read), no
  `--admin`, `--auto` or branch deletion. A head race re-gates and retries only with the same SHA,
  otherwise exit 5. The squash message is scanned against the repo's private-value list through
  `outbound-guard.py` (fails closed), and what was scanned is byte-identical to what is sent.
  Afterwards it fetches `main` and checks the squash commit is an ancestor; a verify failure says
  the merge went through.
- UNSTABLE (required checks pass, a non-required one such as CodeQL is still running or failed) is
  judged by its rows: a failed row is red and named, a pending row is "not yet", never green until
  CLEAN.

Stage 1a of the automation series. `restack`, the `land-pr` skill and the outbound-guard refusal of
a raw `gh pr merge` follow in their own changes.

One independent review of the combined diff found no path to `gh pr merge` without green checks and
the gated head, one MAJOR (UNSTABLE refused by name) and four MINOR; all fixed with the new cases
red first. `python3 tools/test_pr_land.py`: 69 tests OK (fake `gh`, injected clock, temp dirs).
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