Skip to content

fix(codebase_analyze): default to no file cap, treat max_files<=0 as unbounded - #25

Merged
cdeust merged 1 commit into
mainfrom
fix/codebase-analyze-uncap-max-files
May 12, 2026
Merged

cdeust merged 1 commit into
mainfrom
fix/codebase-analyze-uncap-max-files

Conversation

@cdeust

@cdeust cdeust commented May 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • The previous default max_files=500 (and the cortex-setup-project skill's explicit max_files=5000) silently truncated real codebases at the cap. During a full-scale bootstrap, ai-architect-prd-builder and ai-prd both hit the cap at exactly 5000 — meaning files were dropped from the knowledge graph with no warning.
  • Make max_files <= 0 mean "no limit" and default to 0. Positive values still cap (opt-in) and still preserve the ADR-0045 §R2 bounded-memory walk.
  • Unbounded mode walks the whole tree but only materialises post-filter survivors — memory is O(filtered_files), not O(tree_size).

Files changed

  • mcp_server/handlers/codebase_analyze.py — DEFAULT_MAX_FILES = 0; schema minimum: 0, removed maximum: 50000, description updated.
  • mcp_server/handlers/codebase_analyze_helpers.py — split collect_source_files into _collect_bounded (preserves §R2 streaming) and _collect_unbounded (filter-then-materialise). Shared _file_matches filter.
  • mcp_server/tool_registry_manage.py — max_files: int = 0.
  • tests_py/handlers/test_codebase_analyze_rglob.py — +4 regression tests (unbounded 7500-file walk, negative-as-unbounded, language/IGNORE_DIRS filters in unbounded mode), 7 existing bounded-mode tests unchanged.

Behavioural change

Callers that did not pass max_files previously got 500; they will now get the whole codebase. This is intentional — the silent truncation was the bug. Callers that need a cap can still pass one explicitly.

Test plan

  • pytest tests_py/handlers/test_codebase_analyze_rglob.py — 11/11 pass
  • pytest tests_py/handlers/test_ingest_codebase.py tests_py/handlers/test_backfill_discover_files_issue15.py tests_py/infrastructure/test_workflow_graph_source_native_ast.py — 30 passed, 8 skipped
  • Manual: re-run cortex-setup-project on a multi-repo bootstrap and verify no repo lands on a round-number cap

🤖 Generated with Claude Code

…unbounded

The previous default of max_files=500 — and the cortex-setup-project skill's
explicit max_files=5000 — silently truncated real codebases at exactly the
cap. Two of the user's repos (~ai-architect-prd-builder, ai-prd) hit 5000
exactly during a full-scale bootstrap, meaning files were dropped from the
knowledge graph.

Change the contract so max_files<=0 means "no limit". Split the helper
into _collect_bounded (preserves ADR-0045 §R2 streaming for callers who
opt into a cap) and _collect_unbounded (walks the whole tree but only
materialises post-filter survivors — memory is O(filtered_files), not
O(tree_size)). Default now 0 across handler, schema, and tool registry.

Add 4 regression tests: 7500-file unbounded walk, negative-as-unbounded,
language/IGNORE_DIRS filtering still applied in unbounded mode, plus the
existing 7 bounded-mode tests unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@cdeust
cdeust merged commit 2f42428 into main May 12, 2026
11 checks passed
cdeust added a commit that referenced this pull request May 12, 2026
Bundles four PRs landed since v3.15.3:

  #25  codebase_analyze: default max_files=0 (no cap); fixed truncation
       at 5000 in skill invocation
  #26  wiki slug/title leaks (.md.md, timestamp-slugs, path-titles)
  #27  ADR-2244 Phase 1: multi-axis classification (kind, lifecycle,
       audience, provenance) + Task #8 (file→reference/ routing fix)
  #28  ADR-2244 follow-up: data-driven axis registry replacing closed
       enums with wiki/_schema/<axis>/<value>.md user-extensible files

Changelog entry documents migration impact and the extension contract
for adding new classification values without code changes.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@cdeust
cdeust deleted the fix/codebase-analyze-uncap-max-files branch May 13, 2026 09:25
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