Repository navigation
feat(devtools): make the surface layering rule real via a ratchet baseline - #3452
Conversation
…eline Problem: docs/plans/layering.yaml's cli/mcp/api/daemon rules carried a description and no `disallow` key, so devtools/verify_layering.py's rule loop (only appends a violation when `disallow`/`allow` entries exist) was structurally unable to flag anything under them -- "Surfaces may not import substrate internals directly (docs/plans/layering.yaml enforces this)" (CLAUDE.md, docs/architecture-spine.md) was asserted but not enforced. Measured: 311 direct substrate imports across the 4 surface packages via the tool's own per-(file, module) import collector (a raw `git grep -c` line count gives ~409-433 depending on how you count multiple names imported from one module on one line -- see below), and `devtools verify layering` reported "No layering violations found." Turning the rule on outright would have produced an immediate, permanent red gate: 311 violations, none of which are wrong today (nothing here regressed; the rule was simply never checked). A rule that starts red and can never plausibly go green is not a real gate. Solution -- ratchet, not a clean-cut boundary: - Added `disallow.from: [polylogue/storage, polylogue/pipeline, polylogue/sources]` to the cli/mcp/api/daemon rules (mirroring the already-real reverse-direction rules on storage/pipeline/sources). - Added `disallow.baseline: <path>` support to verify_layering.py: a checked-in JSON inventory of exact (target, file, import) triples, generated by running the tool itself against origin/master with the new disallow list active. A baselined violation is reported separately (informational) and does not fail the gate; anything NOT in the baseline fails. The baseline can only shrink safely (an entry stops being exempt the moment its exact triple stops reproducing) and every new violation is visible in review as a diff to the JSON file. Also reports "N baseline entries no longer reproduce" so shrinking the file is discoverable, not just theoretically possible. - `docs/plans/layering-surface-baseline.json`: the 311-entry baseline, generated by the tool (not hand-typed) so it is self-consistent with the exact matching logic that will check it going forward. - Wired `devtools verify layering` into the required per-PR `lint` CI job (previously only reachable via the local pre-push `devtools verify`, so a green `gh pr checks` never meant this ran). - Corrected CLAUDE.md and docs/architecture-spine.md to state the real shape: the reverse direction (substrate must not import surfaces) is a real, zero-exception rule; the surface direction is a ratchet over a large pre-existing baseline, not a clean boundary. Shape of the 311 (measured via a one-off AST classifier, see PR body for the full breakdown): ~44 are TYPE_CHECKING-only (already effectively safe, no runtime coupling), ~4 look like re-exports (imported name appears in the importing module's own __all__), and the remaining ~89% are genuine runtime imports of substrate internals from surface code -- this is not mostly noise, it is real, if long-tolerated, coupling. Verification: - devtools verify layering: exits 0, reports "311 pre-existing baselined violation(s) exempted"; manually inserting an unbaselined disallowed import and re-running confirms exit 1 (ratchet fires); removing it and re-running confirms exit 0 again (no false positive). - Manually inserting a stale baseline entry confirms the "N baseline entries no longer reproduce" hint fires without failing the gate. - devtools test tests/unit/devtools/test_topology_gates.py: 24 passed (renamed one test whose name asserted the now-invalidated "cli importing storage is ok" claim; added 5 new tests covering _load_baseline parsing and the ratchet's exempt/fail/stale-report behavior end-to-end through verify_layering.main()). - mypy --strict on devtools/verify_layering.py and the touched test file: no issues. - ruff check/format: clean. - devtools render all --check: no drift. - devtools verify ci-workflows: 17 workflow files checked, no errors (one pre-existing, unrelated warning about interactive-pty's `-n 0` argument being misparsed as a path). Ref polylogue-2ciy Co-Authored-By: Claude <[email protected]>
…ne key Problem: adding disallow.baseline to layering.yaml (previous commit) broke devtools verify manifests -- LayeringConstraint's pydantic model had extra="forbid" and no baseline field, so every rule using the new key failed with "Extra inputs are not permitted". Missed in the previous commit because devtools verify layering was run directly rather than the full devtools verify --quick gate. What changed: added baseline: str | None = None to LayeringConstraint. Verification: devtools verify manifests -- "manifest consistency checks passed". devtools verify --quick -- exit_code 0 (previously 1 on this step). mypy --strict / ruff check+format on the touched file: clean. Ref polylogue-2ciy Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 58 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Comment-only export after adding implementation-trail note to polylogue-2ciy pointing at PR #3452. Ref polylogue-2ciy Co-Authored-By: Claude <[email protected]>
Summary
docs/plans/layering.yaml'scli/mcp/api/daemonrules gain realdisallowblocks, enforced through a checked-in known-violations ratchetbaseline rather than a mass migration, and
devtools verify layeringiswired into the required per-PR
lintCI job.Problem
CLAUDE.md and
docs/architecture-spine.mdboth assert "Surfaces may notimport substrate internals directly (
docs/plans/layering.yamlenforcesthis)". In the manifest, every substrate rule (
storage/pipeline/sources) carries a realdisallowlist; every surface rule (cli/mcp/api/daemon) carries only adescription.devtools/verify_layering.py'srule loop only emits a violation when
disallow/allowentries exist, sothe four surface rules were structurally inert —
devtools verify layeringreported "No layering violations found" regardless of what surface code
imported.
Measured (via the tool's own
_collect_imports, i.e. self-consistent withwhat the new rule actually checks): 311 direct substrate imports across
cli(spread across the package)/mcp/api/daemon. A rawgit grep -cline count gives ~409–433 depending on how you count multiple names imported
from one module on one
from x import a, bline — both numbers describe thesame real gap, just at different granularity; the tool's own de-duplicated
per-(file, module) count is what the new rule actually enforces against.
Also not previously true:
.github/workflows/ci.yml's requiredlintjobnever ran
devtools verify layering— it was reachable only through thelocal pre-push
devtools verify --quick, so a greengh pr checksnevermeant this check ran.
Solution
Turning the rule on outright would have produced an immediate, permanent red
gate (311 violations, none of which are a regression — the rule was simply
never checked before). Instead:
disallow.from: [polylogue/storage, polylogue/pipeline, polylogue/sources]to all four surface rules, mirroring the already-realreverse-direction rules.
verify_layering.py(
disallow.baseline: <path>): a checked-in JSON inventory of exact(target, file, import)triples. A baselined violation is reportedseparately (informational) and does not fail the gate; anything not
in the baseline fails. An entry stops being exempt the instant its exact
triple stops reproducing (moved/renamed imports are not silently
re-grandfathered), and the tool reports "N baseline entries no longer
reproduce" so shrinking the file over time is discoverable rather than
merely theoretically possible.
docs/plans/layering-surface-baseline.json: the 311-entry baseline,generated by running the tool itself against the new disallow list, not
hand-typed — so it is byte-for-byte consistent with the matching logic
that will check it going forward.
devtools verify layeringinto the required per-PRlintCI job.polylogue/verification/manifests/models.py'sLayeringConstraintpydantic model (extra="forbid") about the newbaselinefield —devtools verify manifestsfailed on the first passbecause this schema didn't know the key existed.
docs/architecture-spine.md: the reversedirection (substrate must not import surfaces) is real and
zero-exception; the surface direction is a ratchet over a large
pre-existing baseline, not a clean boundary — stated as such now.
Shape of the 311 (AC #2)
One-off AST classifier (TYPE_CHECKING-guarded imports vs. imports whose
name reappears in the importing module's own
__all__, as a re-exportproxy) over the same import set:
(433 here counts every
ImportFromnode incl. duplicates across lineswithin a file for the classifier pass; the enforced baseline dedupes to 311
unique
(file, module)pairs via_collect_imports.) ~89% (385/433) aregenuine runtime imports of substrate internals from surface code, not
type-only or re-export noise — this is real, if long-tolerated, coupling,
not a false-positive-heavy measurement artifact.
Which AC option was chosen (AC #1)
Baseline/allowlist so the count can only shrink — not "enforce on an
already-clean subset", because no surface package is currently clean
(cli=121→ dedup ~104-121, mcp=16, api=74, daemon=222 all >0 before dedup;
the enforced/deduped counts are smaller but still all nonzero). There is no
clean subset to carve out a zero-exception rule from yet.
Verification
devtools verify layering: exits 0, reports "311 pre-existing baselinedviolation(s) exempted". Manually inserting an unbaselined disallowed
import and re-running: exit 1 (ratchet fires). Removing it: exit 0 again
(no false positive). Manually inserting a stale baseline entry: "1
baseline entr(y/ies) no longer reproduce" hint fires without failing.
devtools test tests/unit/devtools/test_topology_gates.py: 24 passed(renamed one test whose name asserted the now-invalidated "cli importing
storage is ok" claim; added 5 new tests covering
_load_baselineparsingand the ratchet's exempt/fail/stale-report behavior end-to-end through
verify_layering.main()).devtools verify manifests: "manifest consistency checks passed" (afterthe pydantic model fix).
mypy --stricton all touched files: no issues.ruff check/format --check: clean.devtools render all --check: no drift.devtools verify ci-workflows: 17 workflow files checked, no errors (onepre-existing, unrelated warning about
interactive-pty's-n 0argument).devtools verify --quick: exit_code 0 (full quick lane, rerun afterrebasing onto the latest
origin/master).Ref polylogue-2ciy