Repository navigation
Refactor architecture guards into a sharded Python linter - #2739
Merged
Daniel Meppiel (danielmeppiel) merged 15 commits intoSep 1, 2026
Merged
Daniel Meppiel (danielmeppiel) merged 15 commits into
Daniel Meppiel (danielmeppiel) merged 15 commits into
Conversation
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
August 31, 2026 13:47
Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: 2
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
scripts/architecture_linter/checks/install_request_and_source.py — _wrapper_default_args() slices wrapper.args.args[-default_count:] even when default_count == 0. In… |
|
scripts/architecture_linter/checks/install_deployment_shared.py — _duplicate_definition_lines() currently skips files with read_error, which can silently miss… |
What changed in this PR
This PR refactors the architecture ownership “canonical owner” guardrail from a large shell-driven lint pipeline into a sharded JSON registry plus a single-process Python linter, and updates tests/docs to assert the new rule-catalog contracts while preserving legacy/exact-revision behavior.
Changes:
- Introduces
.apm/architecture/owners/index.jsonplus six JSON shards for ownership metadata and updates guard consumption accordingly. - Adds a new
scripts/architecture_linter/engine (inventory, facts, rule groups, diagnostics, metrics) and a Python CLI entrypoint (scripts/lint_architecture_boundaries.py), replacing legacy ad-hoc scripts. - Migrates/updates integration and unit tests to assert rule IDs/descriptions and to use
run_selected_rules()+source_overridesinstead of shell execution.
| File | Description |
|---|---|
| tests/unit/scripts/test_architecture_registry_conflicts.py | New unit test proving shard-level owner additions merge without destabilizing projections/hashes. |
| tests/integration/test_architecture_marketplace_tag_pattern.py | Switches marketplace tag-pattern tests from shell guard text to rule-catalog + run_selected_rules. |
| tests/integration/test_architecture_marketplace_output_path.py | Switches output-path authority tests to rule-catalog + in-memory mutation via source_overrides. |
| tests/integration/test_architecture_intent_guards.py | Updates meta-guard assertion to check a registered semantic rule description instead of shell source. |
| tests/integration/test_architecture_hash_visible_lf_writes.py | Replaces subprocess checks with rule execution and in-memory mutation for LF-writer authority. |
| tests/integration/test_architecture_frontmatter_bom.py | Updates frontmatter BOM authority assertions to validate both registry ownership and rule catalog. |
| tests/integration/test_architecture_exemption_policies.py | New integration test enforcing explicit exemption-policy wiring in migrated checks. |
| tests/integration/test_architecture_contract_guards.py | Shifts contract guard assertions from legacy shell strings to registered rule metadata. |
| tests/integration/test_architecture_contract_compound_mutations.py | New mutation suite for executable-contract authority branches using run_selected_rules. |
| tests/integration/test_architecture_confirmed_bypass_mutations.py | New mutation regression suite covering previously-identified bypass shapes. |
| tests/integration/test_architecture_apply_to_patterns.py | Updates applyTo + compile-inventory authority tests to registry/rule-catalog APIs. |
| tests/integration/test_architecture_agents_footer.py | Updates footer authority tests to registry + rule execution with source_overrides. |
| scripts/lint_architecture_boundaries.py | New Python CLI entrypoint for full-catalog execution + deterministic metrics output. |
| scripts/check_agents_footer_authority.py | Removes legacy standalone footer-authority script (now enforced via rule catalog). |
| scripts/architecture_linter/process_audit.py | Adds child-process audit counting to enforce “single-process” contract. |
| scripts/architecture_linter/models.py | Adds frozen dataclasses for facts, rules, violations, failures, and run report/metrics. |
| scripts/architecture_linter/metrics.py | Deterministic JSON serialization/writing for run metrics (fail-closed on I/O). |
| scripts/architecture_linter/inventory.py | Deterministic, excluded-roots-aware repository inventory builder (fail-closed anchors). |
| scripts/architecture_linter/groups/transport_platform.py | Group catalog composing transport/platform check families. |
| scripts/architecture_linter/groups/registry_delegation.py | Group catalog composing registry delegation checks. |
| scripts/architecture_linter/groups/mutation_writes.py | Group catalog composing mutation/write check families. |
| scripts/architecture_linter/groups/marketplace_integrations.py | Group catalog for marketplace/integration checks. |
| scripts/architecture_linter/groups/install_deployment.py | Group catalog for install/deployment checks. |
| scripts/architecture_linter/groups/contracts_tests.py | Group catalog for contracts/tests checks and structural helpers. |
| scripts/architecture_linter/groups/common.py | Shared helper primitives (inventory selection, lexical scans, consistent violation shaping). |
| scripts/architecture_linter/groups/__init__.py | Documents explicit (non-discovered) group import strategy. |
| scripts/architecture_linter/checks/transport_sparse_and_updates.py | Ports sparse/self-update transport checks into facts-based rule implementations. |
| scripts/architecture_linter/checks/transport_platform_shared.py | Shared transport check helpers (lexical require/forbid/count, inventory scoping). |
| scripts/architecture_linter/checks/transport_cache_identity.py | Ports cache-identity rule including structural analyzer integration. |
| scripts/architecture_linter/checks/registry_shared.py | Shared helpers/constants for registry delegation checks. |
| scripts/architecture_linter/checks/python_semantics.py | Shared tree-index queries for semantic rules (no extra traversals). |
| scripts/architecture_linter/checks/mutation_write_shared.py | Shared helpers for hook/MCP mutation-write analyzers. |
| scripts/architecture_linter/checks/mutation_hook_membership.py | Implements hook membership / cleanup scope / user-root scope rules. |
| scripts/architecture_linter/checks/marketplace_integration_shared.py | Shared helper primitives for marketplace/integration analyzers. |
| scripts/architecture_linter/checks/marketplace_integration_analyzers.py | Thin catalog composing marketplace check-family modules in registration order. |
| scripts/architecture_linter/checks/marketplace_component_and_admission.py | Implements producer-admission checks (portable-surface gating, write_text_lf invariants). |
| scripts/architecture_linter/checks/install_request_and_source.py | Implements install request-defaults/source-plan/outcome authority checks. |
| scripts/architecture_linter/checks/install_policy_shared.py | Shared primitives for policy/intent lexical scans (configured vs scanned paths). |
| scripts/architecture_linter/checks/install_policy_plugin_and_approval.py | Implements semantic policy/approval/install-intent rules (guard-less). |
| scripts/architecture_linter/checks/install_policy_intent.py | Thin semantic rule catalog spliced into install/deployment analyzers. |
| scripts/architecture_linter/checks/install_policy_gitlab_and_bundle.py | Implements semantic GitLab/bundle/policy/winner-selection checks. |
| scripts/architecture_linter/checks/install_deployment_shared.py | Shared install/deployment helper primitives (lexical scanning, summaries, AST helpers). |
| scripts/architecture_linter/checks/install_deployment_analyzers.py | Thin rule catalog assembling install/deployment guard rules + semantic splice. |
| scripts/architecture_linter/checks/contracts_test_shared.py | Shared helper primitives for contract/test rule families. |
| scripts/architecture_linter/checks/contracts_generation_footer.py | New rule implementing footer wording authority within rule catalog. |
| scripts/architecture_linter/checks/agent_plugin_shared.py | Shared constants for agent-plugin boundary checks. |
| scripts/architecture_linter/checks/agent_plugin_scan_primitives.py | AST scan primitives for agent-plugin boundary enforcement. |
| scripts/architecture_linter/checks/__init__.py | Declares checks package purpose (pure analyzers). |
| scripts/architecture_linter/__init__.py | Declares architecture-linter package purpose. |
| docs/src/content/docs/contributing/development-guide.md | Documents new architecture guardrails workflow and stable lint command. |
| CHANGELOG.md | Adds an Unreleased changelog entry describing the new architecture linter/registry. |
| apm.lock.yaml | Updates generated lock metadata/hashes reflecting regenerated projections. |
| .apm/architecture/owners/index.json | Adds the registry index listing the six shard files. |
| .apm/architecture/owners/core-runtime.json | Adds v1 core-runtime ownership shard entries. |
| .apm/architecture/owners/install-deployment.json | Adds v1 install/deployment ownership shard entries. |
| .apm/architecture/owners/hooks-integrations.json | Adds v1 hooks/integrations ownership shard entries. |
| .apm/architecture/owners/transport-auth-platform.json | Adds v1 transport/auth/platform ownership shard entries. |
| .apm/architecture/owners/marketplace-plugins.json | Adds v1 marketplace/plugins ownership shard entries. |
| .apm/architecture/owners/contracts-tooling.json | Adds v1 contracts/tooling ownership shard entries. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+112
to
+114
| facts = provider.file_facts(path) | ||
| if getattr(facts, "read_error", None) is not None: | ||
| continue |
Consolidate legacy checker authorities into the registered catalog, bound retained AST facts, extend quality gates, and replace implementation-coupled tests with canonical mutation contracts. Co-authored-by: Copilot App <[email protected]>
Add an opt-in report output for the production-catalog 0/N/10N benchmark so fixed-cost-adjusted wall and deterministic-work evidence is reproducible. Co-authored-by: Copilot App <[email protected]>
Persist current-main ABBA, bounded RSS, 0/N/10N scaling, comparable test-slice, mutation parity, and conflict-reduction evidence; refresh only the generated linting instruction hash. Co-authored-by: Copilot App <[email protected]>
Keep failed spills cached without repeated AST walks, retire the final duplicate projection checker, replace brittle count contracts, and persist independent per-mutation legacy/candidate outcomes. Co-authored-by: Copilot App <[email protected]>
Record that the candidate worktree measured by the matrix is the commit containing the generated artifact, while retaining the pre-commit base SHA for provenance. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Port the nested Git compile boundary from the retired checker into the canonical registered rule and registry without instruction or lock churn. Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-architecture-guard-refactor
branch
September 1, 2026 04:03
Sergio Sisternes (sergio-sisternes-epam)
pushed a commit
that referenced
this pull request
Sep 1, 2026
…-apmignore-file-exclusion Port .apmignore canonical-owner AC35 onto the sharded architecture linter registry from #2739. Co-authored-by: Copilot App <[email protected]>
3 of 12 tasks
This was referenced Sep 5, 2026
Merged
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.

refactor(architecture): shard ownership metadata and consolidate linting
TL;DR
Moves executable canonical-owner metadata from an always-loaded Markdown table
into a strict index plus six cohesive JSON shards. Replaces the 2,102-line shell
linter and 25 live helper authorities with one fail-closed Python process while
preserving exact-revision legacy compatibility. Against current
main, warmmedian runtime falls from 50.69s to 12.48s (75.4% faster).
Important
This is one atomic cutover: registry, compatibility gate, canonical linter,
mutation coverage, generated projections, and empirical evidence ship together.
Problem (WHY)
apm.lock.yamldeployment hash.full-tree scans and AST work.
RSS through duplicated AST and tree-index representations.
recreating split authority.
ambiguous display aliases.
falling back from malformed JSON to legacy Markdown.
The design follows "Favor small, chainable primitives over monolithic frameworks."
and makes the proof executable because "Grounding outputs in deterministic tool execution transforms probabilistic generation into verifiable action.".
The concise instruction applies "Context arrives just-in-time, not just-in-case.".
Approach (WHAT)
Implementation (HOW)
.apm/architecture/owners/scripts/architecture_linter/scripts/architecture_linter/facts.pyscripts/architecture_linter/checks/tree_index.pyscripts/lint_architecture_boundaries.pyandscripts/lint-architecture-boundaries.shexec python3wrapper.scripts/check_*and legacy architecture testspackages/shepherd-driver/scripts/owner_touch_gate.py.apm/instructions/and.github/instructions/.github/workflows/ci.ymltests/**/test_architecture_*tests/perf/Diagrams
Legend: every semantic rule consumes one shared inventory and fact service; cold
test facts spill only after their one successful parse.
flowchart LR subgraph Registry[Owner registry] I[index.json] S[Six domain shards] I --> S end subgraph Engine[Single process] V[Strict validation] N[Deterministic inventory] F[Read-once and parse-once facts] T[Compact tree index] C[Bounded cold-fact spill] G[Six explicit rule groups] end subgraph Result[Result] A[Aggregate violations and failures] D[Ruff-style diagnostics and metrics] end S --> V V --> N N --> F F --> T T --> C C --> G G --> A A --> D classDef new stroke-dasharray: 5 5; class I,S,V,N,F,T,C,G,A,D new;Legend: each Git revision selects exactly one ownership format; present but
invalid JSON never falls back to Markdown.
flowchart LR R[Exact Git revision] --> P{Registry index present} P -->|Yes| J[Load and validate JSON union] P -->|No| L[Parse legacy Markdown table] J --> Q{Complete and valid} Q -->|No| X[Fail closed] Q -->|Yes| O[Revision owner records] L --> O O --> C[Combine exact base and head] C --> E[Recompute fresh evidence] E --> Z[Schema-compatible report v1] classDef new stroke-dasharray: 5 5; class P,J,Q,X,O,C,E new;Trade-offs
high-volume tests; rejected retaining every test AST. Peak RSS is about
332 MiB: 67-69% below the rejected 1 GiB candidate, but still 76.7% above
the 188 MiB legacy baseline.
rejected grep/AST expressions in registry files.
both a replacement god module and one file per owner.
AC labels only as display metadata because they are not one-to-one.
that genuinely predate JSON; malformed or removed JSON remains fatal.
Benefits
main, a 75.4% reduction.indexed at most once; the linter spawns zero child processes.
10.00x deterministic work for 10x added files, below the 15x gate.
instruction projection or its lock hash.
detects 100/103, so three boundaries are strengthened and none are weakened.
Validation
/usr/bin/time -lp bash scripts/lint-architecture-boundaries.sh(six ABBAsamples per implementation):
PYTEST_PERF=1 ... test_real_six_group_catalog_wall_time_scales_below_fifteen_x:Full quality and test evidence
Comparable architecture command with eight xdist workers:
Seven baseline failures are the stale plugin fixtures identified in review;
three are legacy Agent Plugin projection assertions. The candidate fixture
constructor writes the current minimal plugin
apm.yml; no product behaviorwas changed.
Raw timestamps, wall/user/sys/RSS samples, environment, scaling counters, and
methodology are tracked in
tests/perf/ARCHITECTURE_LINTER_PR2739_EVIDENCE.md.Scenario Evidence
tests/integration/test_architecture_linter_entrypoint.pytests/unit/scripts/test_architecture_runner.py::test_spill_reload_preserves_nested_function_qualnames::test_spill_write_failure_keeps_facts_without_rewalking::test_spill_load_failure_never_rebuilds_or_hides_the_failuretests/unit/scripts/test_architecture_registry_conflicts.pytests/unit/test_shepherd_owner_touch_gate.pytests/unit/scripts/test_architecture_registry.pytests/integration/test_architecture_owner_rule_mutations.pytests/integration/test_architecture_semantic_rule_mutations.pyHow to test
bash scripts/lint-architecture-boundaries.sh; expect exit 0 and no diagnostics.PYTEST_PERF=1; expect a ratio below 15x.uv run --frozen apm audit --ci; expect all 10 checks and drift replay to pass.Co-authored-by: Copilot [email protected]