Repository navigation
Description
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):
1500lines OR25,000tokens, 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:
800lines OR15,000tokens. 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:
Makefilelinttarget. Add a Python step that walks**/*.pyunderorchestrator/,gateway/,shared/,sandbox/,scripts/and fails on files over the cap. Mirror existing pattern of bandit/safety/trivy inmake security..pre-commit-config.yamlif one exists.- A short
scripts/lint_file_sizes.pyis 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:
- Pipeline lifecycle (start, restart, cancel)
- Phase execution (refine, plan, implement)
- BRC consensus orchestration (
_run_concurrent_phase,_handle_brc_consensus_timeout, the post-timeout polling loop from Implement phase fails after 90 min even when BRC consensus is actively converging (consensus_timeout_minutes=30 + blind 1h container-wait window) #1921) - Worktree management
- Container coordination
- Phase-prompt building (
_build_phase_prompt) - Many other concerns
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
- [#1921 follow-up] Implement phase still force-kills at 90 min — post_timeout_budget is hardcoded 3600s with no per-phase / per-complexity knob #2245 — 90-min implement-phase force-kill. File-size cost compounds with iteration cost.
- .egg-state/oversight/*-oversight.jsonl files appear as modified mid-pipeline, causing coder merge-conflict friction #2244 —
.egg-state/oversight/*-oversight.jsonlcollisions. Different file-related cost; same agent-budget pressure. - Producer-dependency wait time consumes consensus budget — tester polling for coder's PROPOSE costs ~50min before tester can start its own work #2246 — tester wait-loop pattern. Different again, but same family of "structural costs eat the consensus budget."
Acceptance criteria
- A new lint check (in
make lintor a dedicatedmake lint-sizetarget) fails the build when any tracked Python source file inorchestrator/,gateway/,shared/,sandbox/, orscripts/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
jwbron commentedon Apr 29, 2026
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 / 60KBscripts/file-size-allowlist.yaml— grandfathered baselines for the 15 currently-oversize files (one-way ratchet: growth past baseline still fails)scripts/check-*.pyauto-discovery inmake lint-custom(no Makefile changes)Test files exempt (parametrized cases legitimately push line counts). Decomposition follow-ups for the 15 grandfathered files (
pipelines.py15,356 lines,gateway.py9,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.
Fix #2248: add max-file-size lint to cap Python source-file growth (#…
Bump file-size allowlist baseline for pipelines.py / peer_consensus.py
file-size lint: drop per-file baselines from allowlist
file-size lint: drop per-file baselines from allowlist (#2274)
Fix #2263: per-phase consensus timeout defaults (refine/plan/implemen…
Fix file-size lint: allowlist orchestrator/kubernetes_spawner.py
Fix #2410: plumb slice_id through restart and uncommitted-change paths (
Fix #2399: push pipeline tip to <branch>/work so slice refs coexist (#…
slice-4 (#2777): restart hardening — slice-aware restart_phase, eager…
slice-4 v2 (#2777): address reviewer_code + reviewer_contract v1 NACKs
fix(orchestrator): reconcile diverged state-branch pushes and escalat…
Fix checks: allowlist orchestrator/event_loop.py in file-size lint