Skip to content

Add a max-file-size lint to prevent oversize source files (orchestrator/routes/pipelines.py is 670KB / 15,356 lines) #2248

Closed

Description

@jwbron

Problem

A handful of source files in this repo are dramatically larger than their siblings, to the point that they materially slow down every BRC implement-phase agent that has to read them — and they will keep growing without a structural deterrent.

Concrete current sizes (from wc -l on main):

   15,356  orchestrator/routes/pipelines.py
    9,753  gateway/gateway.py
    2,817  orchestrator/mcp_tools.py
    1,986  orchestrator/routes/signals.py
    1,604  orchestrator/routes/deployment.py
    1,284  shared/egg_contracts/plan_parser.py
    1,144  orchestrator/routes/phases.py
      903  orchestrator/routes/decisions.py
      759  orchestrator/routes/messages.py
      ...  (everything else is < 500 lines)

pipelines.py is 7.7× the next-largest route in the same directory. gateway.py is similarly an outlier in gateway/. These two files alone hit 1.04 MB and 25k+ lines combined.

Why this matters operationally

On issue-1557-v2 slice 1 implement, coder hit the Read tool's hard limits multiple times trying to navigate these files:

  • orchestrator/routes/pipelines.py (670KB) — exceeded the 256KB hard limit at the Read tool level. From the actual coder log:
    Tool result is_error=True content=\"File content (654.2KB) exceeds maximum allowed size (256KB).
    Use offset and l...\"
    
  • orchestrator/mcp_tools.py (38k tokens) — exceeded the 25k token soft limit:
    Tool result is_error=True content=\"File content (38529 tokens) exceeds maximum allowed tokens (25000).
    Use offset and l...\"
    

Each oversize file forces the agent into a Grep-then-paginated-Read workflow: find the line range you care about, then Read with offset + limit, often multiple times. Every paginated read is another LLM turn. On issue-1557-v2 slice 1, coder had to do this for pipelines.py (to find submit_task and the route handler), mcp_tools.py (to find the submit_task MCP wrapper), and gateway.py (to find the 6 routes being auth-widened). That's measurable budget loss on top of the 90-min consensus wall (#2245).

It also means every iteration re-pays the cost because the agent's context resets between BRC cycles. Coder paid the pipelines.py navigation cost three times on issue-1557-v2: v1 at T+0→T+43, v2 at T+50→T+82, v3 at T+82→T+86.

Proposed fix: max-file-size lint

Add a pre-commit / CI lint that fails when a Python source file exceeds a configured cap. Suggested defaults:

  • Hard cap (lint failure): 1500 lines OR 25,000 tokens, whichever comes first. The 25k token limit aligns with the Read tool's soft limit so any conformant file is fully readable in one Read call.
  • Soft warning: 800 lines OR 15,000 tokens. Encourages decomposition before files become a problem.

Plus a small grandfathering allowlist (with the cap value at the time of grandfathering, so growth is still caught).

Where to put it

Existing tooling locations to consider:

  • Makefile lint target. Add a Python step that walks **/*.py under orchestrator/, gateway/, shared/, sandbox/, scripts/ and fails on files over the cap. Mirror existing pattern of bandit/safety/trivy in make security.
  • .pre-commit-config.yaml if one exists.
  • A short scripts/lint_file_sizes.py is enough — no need for a new tool.

What this forces

It forces decomposition of pipelines.py specifically. The existing route-file pattern already shows the right shape: most routes/*.py files are 100-1000 lines and cohesive around one resource. pipelines.py is doing too much:

Splitting along these seams (e.g. orchestrator/concurrent_phase.py, orchestrator/worktree_lifecycle.py, orchestrator/phase_prompt_builder.py) would simultaneously fix the agent navigation cost and improve code organization. Same exercise for gateway/gateway.py.

Out of scope

  • Don't decompose tests files mechanically. Test files commonly exceed reasonable line counts because they bundle parametrized cases. The lint should target source dirs.
  • Don't reformat .json / .yaml / .md — line-count caps don't match content semantics there. Lint is Python-only.

Related

Acceptance criteria

  • A new lint check (in make lint or a dedicated make lint-size target) fails the build when any tracked Python source file in orchestrator/, gateway/, shared/, sandbox/, or scripts/ exceeds the hard cap.
  • The cap and the allowlist live in a config file that's reviewable in PRs.
  • An initial PR populates the allowlist with current oversize files and their current line counts so existing files don't fail CI on day one. Each entry is a follow-up PR target for decomposition; growth on grandfathered files is still rejected.
  • Decomposition follow-up issues (per file in the allowlist) are filed separately so this issue scope stays bounded.

Source

Pipeline issue-1557-v2 (Apr 29 2026 SDLC run for GitHub issue #1557, jwbron/egg). Coder logs at 4a9f67f6-75e6-4bab-b553-9fab36ab7c2c showed multiple Read-tool failures on oversize files; subsequent post-mortem confirmed the pattern was costing measurable budget on every implement-phase agent.

Activity

  1. jwbron commented on Apr 29, 2026

    @jwbron
    OwnerAuthor

    Closing — PR #2250 fully addresses the scope. Ships:

    • scripts/check-file-sizes.py — Python lint that fails on files exceeding 1500 lines or 100,000 bytes (~29k tokens) and warns at 800 lines / 60KB
    • scripts/file-size-allowlist.yaml — grandfathered baselines for the 15 currently-oversize files (one-way ratchet: growth past baseline still fails)
    • 22 unit tests
    • Wired into existing scripts/check-*.py auto-discovery in make lint-custom (no Makefile changes)

    Test files exempt (parametrized cases legitimately push line counts). Decomposition follow-ups for the 15 grandfathered files (pipelines.py 15,356 lines, gateway.py 9,753 lines, etc.) should be filed as separate issues per file — explicitly out of scope per this issue's acceptance criteria.

    Note: PR body says "per #2248" rather than "Closes #2248", so it won't auto-close on merge — closing manually here.

  2. added a commit that references this issue on Apr 29, 2026
    41550fa
  3. added 3 commits that reference this issue on Apr 29, 2026
  4. added 2 commits that reference this issue on May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions