Repository navigation
Description
Context & Rationale
AGENTS.md:14 says cyclomatic complexity ≤ 10 is strictly enforced project-wide, and that devops scan complexity and the architectural invariant tests validate it. At ef21785 nothing enforces it:
pyproject.toml:93does not selectC901, and there is no[tool.ruff.lint.mccabe]section.devops cihas no complexity step (commands/ci.pynever mentions complexity).devops scan complexityonly reports, and exits 0 on a breach (commands/scan.py:406-480).- The
structural-invariantspre-commit hook blocks only on nesting. It prints complexity breaches as a note (security/structural_invariants.py:112-117), andtests/test_structural_invariant_hook.py:45-56pins that it does not block. test_no_excessive_nesting_in_srcscans withmax_complexity=100(tests/test_architectural_invariants.py:152).
Reviewers and agents trust the claim, so stating it as enforced is worse than stating it as a target. The same claim names the wrong enforcer in CONTRIBUTING.md:13, docs/SDLC.md:129 and docs/ROUTINE_TASKS.md:55.
There are two counts. Owner decision D1 picks ruff's.
- ruff C901 (standard McCabe): 73 functions over 10 in 44
srcfiles, and 3 intests(tests/conftest.py:58,tests/test_ai_client_providers_and_embeddings.py:657,tests/test_architectural_invariants.py:282). Measured with ruff 0.16.8:ruff check --no-cache --isolated --select C901 --config 'lint.mccabe.max-complexity = 10' src(ortests). - The in-house counter (
security/complexity.py:106-123, mirrored instructural_invariants.py:15-39): 235 over 10 insrc. It adds +1 for everyassert, everywithand every extra boolean operand, which McCabe does not. The old figure of 240 was an earlier in-house count. - The two sets are not nested. Ruff flags 5
srcfunctions that the in-house scanner passes, for exampleget_toolsatai/harness/shell.py:335(13) and the closurerun_codeatai/harness/os_access.py:234(22).
Other facts the builder needs:
-
_ruff_enforces(tests/test_architectural_invariants.py:445-470, used at:486-505) reads onlylint.selectandlint.ignore. An agent could still raisemax-complexity, add aper-file-ignoresentry, add a nestedruff.toml, or use a blanket or file-level noqa. Today there are no per-file-ignores, no file-level noqa and no nested ruff config. PGH004 (blanketnoqa) reports 0 hits. -
Ruff 0.16.8 still honours the deprecated top-level lint settings in
[tool.ruff].per-file-ignores = {"pkg/*" = ["C901"]}orextend-ignore = ["C901"]there silences C901 with only a deprecation warning.includeandextendchange which files or which settings apply. Today[tool.ruff]holds onlytarget-version,line-length,excludeandlint, and[tool.ruff.lint]holds onlyselectandignore. -
With RUF100 selected, 9
noqacodes are stale today:ai/gateway_bench.py:69,:97and:100(S310);ai/gateway_tune.py:432(S603);tests/test_ai_gateway_tune.py:338(S102);tests/test_exceptions.py:172-173(F401);tests/test_sandbox_metrics.py:229andtests/test_sandbox_probe.py:133(N802).
Bandit reads the
# noseccomments on those lines, notnoqa. -
--selecton the command line replaces the configuredselect. Soruff check --select RUF100reports every code for a rule it did not select as unused: 31 codes today, and 98 once the C901 markers exist (the 76 new markers plus F401, N802 and UP036 codes the project needs). With the project'sselectin force, RUF100 reports exactly the 9 above. -
uv run devops cidefaults to--fix. It runsruff check --fix .before the lint check (commands/ci.py:349-355,:709), so a stale marker is removed in the working tree and the gate still passes.--checkturns the fix pass off. GitHub CI runs plainruff check .(.github/workflows/ci.yml:51). -
Under ruff,
FileSystem.get_tools(ai/harness/filesystem.py:320) scores 2. C901 therefore covers whattest_filesystem_get_tools_complexity(tests/test_architectural_invariants.py:160-167) guards. -
test_complexity_is_reported_without_blockingstarts a subprocess that importsdevops_cli.security. Its call took 12.4 s when run alone at ef21785, and a bare hook run on one file takes 6.5-7.4 s. -
ai/instruction_generator.pyhas no counterpart toAGENTS.md:14. Its only complexity text (:244-249) is about nesting, so it needs no change. -
Adding
C901,RUF100,PGH004toruff check .did not change lint time: 0.60-0.88 s with or without them. -
Counting
noqacomments withtokenizeover the 867 files insrcandteststook 1.2-8.0 s across runs. A regex over the file text took 0.02-0.24 s.
Scope & Deliverables
- Deliverable:
-
Config.
pyproject.tomlselectsC901,RUF100andPGH004, and sets[tool.ruff.lint.mccabe] max-complexity = 10. -
Baseline. On the release tip after the last rebase, with the config change in place:
- Run
uv run ruff check --select C901 --add-noqa .once. - Remove the 9 stale codes with
uv run ruff check --fix --fixable RUF100 .. Do not pass--select RUF100: it replaces the configuredselectand strips all 98 codes, the new markers included. - Keep the
# noseccomments. Keep the reason ontests/test_ai_gateway_tune.py:338("the script under test") as a plain comment.
No function is decomposed in this PR.
- Run
-
Meta-test in
tests/test_architectural_invariants.py. One pure helper takes the parsedpyproject.tomland the source roots, and returns every escape it finds:[tool.ruff]has a key outsidetarget-version,line-length,excludeandlint. This one check covers the deprecated top-level lint settings,include,extend,extend-excludeand any key ruff adds later.[tool.ruff.lint]has a key outsideselect,extend-select,ignore,extend-ignore,per-file-ignores,extend-per-file-ignoresandmccabe. This coverslint.exclude.excludeis not["repos"].- one of
C901,RUF100orPGH004is not enforced. This reuses_ruff_enforcesoverselect + extend-selectandignore + extend-ignore. The three codes live inCONST_COMPLEXITY_LINT_RULESinconfig/constants.py, and the two key allowlists sit beside them. mccabehas a key other thanmax-complexity, ormax-complexityis missing or differs fromDEFAULT_MAX_COMPLEXITY.- a
per-file-ignoresorextend-per-file-ignoresentry covers C901 (ALL,C,C9,C90orC901). - a file under
src/ortests/has a file-level# ruff: noqaor# flake8: noqa. - a
ruff.toml,.ruff.tomlorpyproject.tomlexists undersrc/ortests/.
-
Ceiling test. It counts
noqacomments that name C901 undersrc/andtests/. It counts codes, so# noqa: C901, N802counts once, and it uses a regex over the file text. It fails when the count exceedsDEFAULT_C901_SUPPRESSION_CEILINGinconfig/defaults.py, next toDEFAULT_MAX_COMPLEXITY. The ceiling equals the count at merge. The failure message names the files and says to decompose the function, not to raise the ceiling. -
Hook. The hook becomes nesting-only. Delete the complexity accumulation in
_measure,MAX_COMPLEXITY, themax_complexityparameters,over_complexand the note insecurity/structural_invariants.py. Deletetest_complexity_is_reported_without_blockingandtest_filesystem_get_tools_complexity. Rewrite the complexity clause of the hook comment at.pre-commit-config.yaml:47-51: complexity is ruff C901 in theruff-checkhook. The comment's import claim belongs to refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773. -
Docs.
AGENTS.md:14names the real enforcers. Proposed text: "Cyclomatic complexity ≤ 10 is ruffC901(standard McCabe), run byuv run devops ciand the pre-commit ruff hook. Functions over the cap when it was turned on carry# noqa: C901. RUF100 removes a marker once its function is fixed, and a test keeps the count from growing. Nesting depth ≤ 5 is enforced by thestructural-invariantshook andtest_no_excessive_nesting_in_src.devops scan complexityreports a different, in-house count and does not gate." Make the same correction inCONTRIBUTING.md:13,docs/SDLC.md:129anddocs/ROUTINE_TASKS.md:55. -
Roadmap and task file. The edits depend on the state of
docs/ROADMAP.mdwhen the PR starts:- If it is still hand-edited, tick this item's entry (
:221-223) and state what shipped. Add to the hook entry's "Not delivered" note (:220) that feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks #586 enforces C901. Mark "Metric Provenance: radon's Cyclomatic Complexity Behind One Adapter" (:872-876) as superseded by D1. In:899, drop the clause that saysC901is absent fromselectand the hook reports without failing. - If feat(github): github-sourced roadmap, migration and generated roadmap view (
devops roadmap migrate,render) #739 has made it a generated view, make none of these edits. The PR description names the radon entry as superseded instead.
Rewrite
docs/agent/tasks/task-586-cyclomatic-complexity-debt-reduction.mdso it matches what shipped. Drop the stalev0.2.24milestone line and the duplicated deliverable lines. Record the counts and the durations from the criteria below. - If it is still hand-edited, tick this item's entry (
-
- Acceptance criteria:
uv run devops ci --check --no-cachepasses on the committed PR head.--checkskips theruff check --fixpass, so this proves that no stale or blanketnoqaremains in the commit. GitHub CI's plainruff check .must also pass.- The baseline touched no
noqacode the project needs:git diff -U0 <base> -- src tests | grep -c '^-.*# noqa'prints 9, the lines listed in the Context. - The meta-test passes on the real
pyproject.toml. A parametrized test feeds the helper in-memory config dicts andtmp_pathfiles, one per escape in the Deliverable, and asserts that each one is reported. The cases include a top-level[tool.ruff] per-file-ignorescoveringC901, a top-levelextend-ignore = ["C901"],include,extendandlint.exclude. No test runs the ruff binary. - The ceiling test passes at merge. Three numbers are equal at merge, and the task file records all three:
DEFAULT_C901_SUPPRESSION_CEILING, the counting helper's result oversrcandtests, and the count printed byuv run ruff check --select C901 --ignore-noqa --statistics --exit-zero .. - A
tmp_pathfixture over a ceiling makes the counting helper report the excess and name the file. The fixture uses both forms that--add-noqawrites:def f(x): # noqa: C901and a merged# noqa: C901, N802. The new tests build that text at run time so that their own source does not match the counting regex. - The builder runs this and records the output in the task file:
p=src/devops_cli/_c901_probe.py { echo 'def f(x):'; for i in $(seq 10); do printf ' if x == %d:\n return %d\n' $i $i; done; echo ' return None'; } > $p uv run ruff check $p # C901 `f` is too complex (11 > 10), exit 1 uv run pre-commit run ruff-check --files $p # Failed sed -i '1s/$/ # noqa: C901/' $p && sed -i '/x == 10/,+1d' $p uv run ruff check $p # RUF100 unused noqa, exit 1 uv run ruff check --fix $p; grep -c noqa $p # 0 rm $p rg -n -i complexity src/devops_cli/security/structural_invariants.pyreturns nothing. The four remaining tests intests/test_structural_invariant_hook.pypass.rg -n C901 AGENTS.md CONTRIBUTING.md docs/SDLC.md docs/ROUTINE_TASKS.mdshows each of the four corrected lines.rg -n 'nothing enforces it|240 functions' .pre-commit-config.yaml src testsreturns nothing.git diffshows no change toAGENTS.md:15-17or.github/pull_request_template.md.uv run ruff check .wall time changes by less than 1 s, measured before and after. The task file records the--durationsof each new test, which together stay under 1 s, and the test step's--durationsdifference, which should be negative because one hook subprocess (6.5-12.4 s measured) comes out.
- Key questions:
- Is standard McCabe (73 + 3) or the in-house count (235) the definition? Owner decision D1: ruff C901, standard McCabe.
- Is the inline baseline the "large suppression commit" feat(cli): blind exception handling policy #423 warns against? Owner decision D1 chooses the inline baseline. Each marker sits on one function, RUF100 removes it when that function is fixed, and the ceiling stops the count from growing.
- Do tests count? (proposed) Yes.
ruff check .coverstests/, D1 calls the cap project-wide, and the 3 test breaches get markers like the others. - Should the ceiling test use
≤or==? (proposed)≤, as test(cli): suppression comments may not grow unnoticed #849's constraint says. With==, two PRs that each fix one function would both lower the ceiling to the same value, merge cleanly, and leave the release branch red. The defaultdevops ci --fixalso removes a marker as soon as its function drops under the cap, which==would turn into a red gate mid-PR. A PR that removes markers lowers the ceiling in the same PR, and a new# noqa: C901or a raised ceiling shows up in review as a changed line. - Where do the rule list, the key allowlists and the ceiling live? (proposed) The rule list and the allowlists go in
config/constants.py, next toCONST_TEST_ASSERTION_LINT_RULES. The ceiling goes inconfig/defaults.py, where test(cli): suppression comments may not grow unnoticed #849 puts its ceilings, so test(cli): suppression comments may not grow unnoticed #849 can absorb it. - Regex or
tokenizefor counting? (proposed) Regex.tokenizeover the tree took 1.2-8.0 s, which is over the 1 s budget, and the regex took 0.02-0.24 s. A string literal that happens to match only overcounts, which fails safe. - Should the meta-test cover more than D1's list? (proposed) Yes. It uses key allowlists for
[tool.ruff]and[tool.ruff.lint]rather than a list of known escapes. Ruff still honours deprecated top-levelper-file-ignoresandextend-ignore, and a list of escapes misses those and any key ruff adds later. A new key then needs a reviewed edit to the allowlist.per-file-ignoresstays allowed, as D1 only forbids C901 in it, so feat(cli): extend the ruff rule set to the correctness families #420 can add entries for other rules. - What happens to the hook's complexity code? (proposed) Delete it, so the hook is nesting-only. refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773 then shares one nesting module, and its McCabe alignment applies to
devops scan complexity. - Should the 5 stale codes for unselected rules (S310 three times, S603, S102) be removed? (proposed) Yes. RUF100 would fail on them, bandit reads the
# noseccomments that stay, and feat(cli): extend the ruff rule set to the correctness families #420 does not selectS. - Does
devops scan complexitychange? (proposed) No. It keeps the in-house count until refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773 aligns it with McCabe, andROADMAP.md:860(gate integrity, no issue) still applies to it. - In-flight work moves the counts. For example, fix(test): the test network guard refuses loopback connects to services the test did not start #837 edits
prevent_external_network_calls, one of the 3 test breaches, and feat(k8s): truthful pod status, filters, container-aware logs and pod inspector in the dashboard (tab-k8s) #686 adds code undersrc/devops_cli/ui. (proposed) Run--add-noqaon the release tip after the last rebase, and set the ceiling to the count at merge.
- Constraint:
- D1: no radon, no lizard, no new dependency.
AGENTS.md:15-17is out of scope. docs(agents): instruction surfaces state only what is true, anddevops ai agentsnever overwrites AGENTS.md #840 removes the "every assert adds +1 to McCabe" sentence (D1), and test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 retires the tuple-assert mandate. The other copies of the mandate's McCabe justification also belong to test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851:.devops/review.md:77,ai/review/verification.py:1093,ai/tasks/verify_finding_system.md:27andai/review/common_hallucinations.json:749.- The PR template line (
.github/pull_request_template.md:29) belongs to feat(github): pr readiness requires an issue-linked, completed task file #704. - New in-gate tests cost at most 1 s combined, with no network and no ruff subprocess. They use structural tuple assertions until test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 settles that.
Strategic Alignment
- Milestone: v0.2.25
- Depends on: none. fix(test): the test network guard refuses loopback connects to services the test did not start #837 (current release) edits one of the baselined test functions and lands first.
- Unblocks: test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851, refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773 and test(cli): suppression comments may not grow unnoticed #849 (backlog) depend on this item. feat(cli): extend the ruff rule set to the correctness families #420 (v0.2.26) keeps
RUF100andPGH004selected when it enables its families, and adds any new ruff key to the allowlists in its own PR. - Related:
- docs(agents): instruction surfaces state only what is true, and
devops ai agentsnever overwrites AGENTS.md #840 removes theAGENTS.md:16sentence (D1). - feat(review): branch and pr reviews compute their own base-vs-head symbol delta #593 PR2's lizard delta is review-only, not an enforced definition (D1).
- feat(cli): blind exception handling policy #423 sets the BLE001 suppression policy.
- feat(github): github-sourced roadmap, migration and generated roadmap view (
devops roadmap migrate,render) #739 (v0.2.25) decides whetherdocs/ROADMAP.mdis still hand-edited. - Roadmap entries without an issue:
ROADMAP.md:860(gate integrity),:872(radon, superseded),:998(per-module complexity metrics) and:1064(type escape-hatch ratchet).
- docs(agents): instruction surfaces state only what is true, and
Owner decisions (2026-10-01)
From the agentic quality assessment (https://claude.ai/artifact/K7S7AkKJymFydhjwexigiN), decided by the owner. These replace any matching proposed answer above.
- D1, the complexity definition. ruff C901 (standard McCabe) is the enforced definition of the ≤ 10 cap; the in-house counter is not. Inline baseline with a one-time
ruff check --add-noqa; RUF100 removes a marker once its function is fixed; PGH004 bans blanketnoqa; a ceiling test on C901 suppressions that may only go down; a meta-test that pinsmax-complexityand forbids C901 in per-file-ignores. No radon and no lizard. AGENTS.md:16's 'every assert adds +1 to McCabe' is removed (docs(agents): instruction surfaces state only what is true, anddevops ai agentsnever overwrites AGENTS.md #840), and the tuple-assert mandate is settled in test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 1, 2026
Retargeted from the shipped v0.2.23 to v0.2.25. It is still valid (checked 2026-10-01), and a P1 left open in a shipped release keeps precedence over P1 work committed later.
[-]feat(cli): cyclomatic complexity debt reduction[/-][+]feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks[/+]feat(cli): enforce the complexity cap with ruff C901 and an inline ba…
dan-petty commentedon Oct 3, 2026
Closed by #1078, merged into
release/v0.2.25.GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by
devops gh issues close-merged.feat(release): v0.2.25 (#1089)