{"slug": "how-to-ship-5000-lines-of-reliable-code-a-day-with-a-multi-agent-architecture", "title": "How to Ship 5,000 Lines of Reliable Code a Day With a Multi-Agent Architecture", "summary": "A developer described a three-role multi-agent coding setup (Leader, Dev, Reviewer) that ships roughly 5,000 lines of code a day by capping each task at 800 lines before review and gating merges through a `dev` buffer branch. The setup uses two automated gates — a per-sub-issue read-only review before landing on `dev`, and a full-regression release check before `main` — plus event-driven CI wake-ups and native dependency blocking to avoid polling loops. The developer also wrote a small Python check to catch pytest runs that report green while silently skipping tests.", "body_md": "About two weeks after I started running multiple coding agents in real repositories, my normal PR workflow fell apart. I'd wake up to diffs over a thousand lines that froze the GitHub tab, AI reviewers and AI authors bouncing the same PR back and forth five times over variable names, green CI runs hiding silently skipped tests, and an agent changing a default product threshold without mentioning it anywhere in the PR.\n\nReading 5,000 lines of diff by hand every day doesn't work. What fixed it for me was tightening both ends of the loop: capping every task at 800 lines before review starts, then running two automated gates so I only have to sign off on a handful of plain-language behavior changes before merging to `main`.\n\nHere's the setup I'm running now, including the 3-role split on a `dev` branch, the six rules that stopped review loops, and the small Python check I wrote to catch fake-green `pytest` runs.\n\nWhen an agent hands over a huge diff touching dozens of files across unrelated modules, tweaking the review prompt won't help much. The review problem usually starts upstream.\n\nMy first attempt copied a standard team chart: PM, architect, frontend, backend, QA, and a separate observer agent all talking in the same issue thread. I ripped it out after a week.\n\nEvery handoff added another round of summarization, so by the time code reached QA the original acceptance criteria had drifted. Agents kept `@`-mentioning each other in the same comment thread, waking up three sessions at once just to acknowledge messages and re-read the repo.\n\nI stripped it down to three roles with hard file and branch boundaries:\n\n| Role | Owns | Not allowed to | \n|---|---|---|\n| **Leader** | Task splitting, 500/800-line caps, boundary counterexamples for risky tasks, merging into `dev` , running full Tier 2 regression | Write feature code, open feature PRs, merge straight to `main` | \n| **Dev** | Coding in an isolated branch or worktree, writing tests, running Tier 0/1 checks, pasting `--shortstat` counts, self-review | Push to `dev` or`main` , run`amend` ,`rebase` , or`force push` after review starts | \n| **Reviewer** | Cross-model read-only checks at Gate 1 (sub-issue into `dev` ) and Gate 2 (release check on`dev` ) | Edit files, commit, push, or open feature sub-issues | \n\nDropping the standalone observer meant moving \"check for silent product changes\" into Reviewer's Gate 2 pass. Gate 2 carries a bit more context now, but I don't have to pay for another agent wake-up cycle on every epic.\n\n`dev` as a Buffer Between Two Gates\nSub-issues never merge straight into `main` (or `master`). Everything lands on `dev` first.\n\n**Gate 1** guards each sub-issue going into `dev`. Dev branches off `dev`, runs local static checks and targeted module shards (1 to 2 minutes), and gets a read-only pass from Reviewer. Sub-issues merge into `dev` automatically (via PR auto-merge or Leader `--no-ff`) with zero human sign-off, leaving only a ticket record if you want to check what changed. Parallel tasks don't stall behind each other waiting on slow full-suite runs.\n\n**Gate 2** runs once all sub-issues for an epic have landed on `dev`. Leader runs the full regression suite and baseline check on `dev`, then hands the combined diff to Reviewer. My job is just the final `dev -> main` merge.\n\nRunning agents concurrently exposed two fast ways to burn budget: polling loops waiting on CI, and copy-pasting workflow instructions into every repo until they drift apart.\n\nFor scheduling, sub-issues declare native dependencies with `--blocked-by <id>` so downstream tasks unblock automatically when upstream ones close. Waiting on GitHub CI uses event wake-ups (`--until-pr checks`) instead of `gh pr checks --watch` or `sleep` loops. Every handoff comment `@`-mentions exactly one next owner, never `@Reviewer` and `@Leader` together.\n\nFor configuration, I keep three layers:\n\n`--auto --merge --match-head-commit`) on a full-stack Web repo and local worktree merges (` git merge --no-ff`) on a private compute-heavy Python repo.\nCoding agents don't naturally slice work into reviewable commits. Give one a medium-sized feature and it'll happily refactor twenty adjacent files along the way.\n\nEach sub-issue targets **<= 500 handwritten lines** of app and test code, with a **hard cap of 800 lines** (generated clients, lockfiles, and frozen data snapshots don't count). Before pinging Reviewer, Dev runs `git diff --shortstat <base>..HEAD` and pastes the handwritten count into the comment. If the change is clearly going to cross 800 lines and the ticket doesn't have an explicit Leader exemption (which requires a reason and a commit-by-commit reading guide), Dev stops and asks Leader to split the task. If an unexempted >800-line diff still shows up at Gate 1, Reviewer rejects it immediately without reading the code.\n\nI also enforce a quick YAGNI pass. Leader writes down what's explicitly out of scope during planning, dead paths get deleted rather than wrapped in compatibility shims, and Dev reads its own full `git diff <start_sha>..HEAD` to trim speculative abstractions before opening review.\n\nOnce PRs stay small, Gate 1 focuses on three recurring headaches: same-model blind spots, weak tests, and infinite nitpick threads.\n\nWhen the same model family writes the implementation, writes the tests, and reviews the diff, it tends to miss the exact same edge cases twice. Pairing Dev and Reviewer on different model families breaks that pattern. Making Reviewer strictly read-only keeps it from quietly patching code mid-review and forces every defect into a concrete comment.\n\nAt Gate 1, Reviewer checks the tests before looking at business logic. It looks for mock-only tests (`mock.assert_called_once()` with no state or output assertion), missing fail-before-fix proof on bug fixes, quiet edits to frozen golden fixtures, and scattered one-off `test_fix_*.py` files that belong as `pytest.mark.parametrize` rows in the module's main test file.\n\nOn risky tasks (numerical core code, auth rules, schema migrations, or dual-path refactors), Leader writes a short table of boundary counterexamples upfront. Reviewer then runs 1 or 2 edge cases in a quick read-only script to make sure the code and tests aren't sharing the same wrong assumption.\n\nEarly AI reviewers wasted hours rejecting PRs over naming preferences, or finding new complaints in untouched code on round three. Three rules cleared that up:\n\n`downgrade` or multiple Alembic heads)`>2s` slow tests)\nNaming tweaks, minor readability nits, and optional helper extractions go into a non-blocking list and still approve.\n\n`category`, `file:line`, `repro evidence`, `expected fix`). Round 2+ only checks whether those blockers were fixed and whether new commits introduced new bugs. No dredging up fresh nits from old unchanged lines.`blocked` and hands it to Leader. Gate 2 stops at Landing sub-issues on `dev` is only halfway to production. Gate 2 checks how everything fits together before I merge to `main`.\n\n`main..dev` and `base_sha..dev`)\nWhen two epics are active on `dev` at once, `main..dev` includes commits from the other epic. Looking only at `main..dev` blames the wrong task, while looking only at individual PRs misses integration seams.\n\nLeader records `base_sha` when an epic starts, so Reviewer checks both views at Gate 2: `main..dev` for the full release candidate (cross-module contracts, migration chain, security redlines), and `base_sha..dev` to isolate what this epic actually changed. Anything left over from another in-flight epic gets flagged as a warning rather than blocking the current one.\n\nAcross both the compute-heavy Python repo and the full-stack Web repo, I split test execution into four tiers:\n\n`--changed`), domain shards (`--shard`), and 20 quick property-test cases.`.test_durations` with Longest Processing Time (LPT) bin-packing and `worksteal`, `--durations=20` reporting (holding default unit tests under `2s`), plus the baseline check.\nMultiple repos share one 8-slot cloud VM via `cloud-test-queue`. Each lease is tied to an open file descriptor locked with kernel `flock`, so if a worker dies or SSH drops, the kernel frees the slot right away with no brittle TTL cleanup cron. `slots` and `min_slots` flex capacity across jobs, and `CLOUD_TEST_QUEUE_SLOTS` caps worker concurrency so runs don't OOM each other.\n\nEven with that in place, `pytest` can still exit `0` when something goes wrong: a command aimed at an empty folder, an xdist worker crashing and dropping a batch of tests, or an agent adding `@pytest.mark.skip` to get past a failure. I wrote a small stdlib-only gate called `test-baseline-gate` that runs `--collect-only` independently, verifies the baseline's canonical `set_sha256`, and compares every collected node against actual outcomes:\n\n``` python\ndef evaluate(\n    baseline: Baseline,\n    expected: set[str],\n    outcomes: Mapping[str, str],\n    *,\n    scoped_nodes: Collection[str],\n) -> GateVerdict:\n    failures = {node for node, outcome in outcomes.items() if outcome in FAILURES}\n    scoped = baseline.entries.keys() & scoped_nodes\n    return GateVerdict(\n        unreported=tuple(sorted(expected - outcomes.keys())),       # crashed worker dropped tests\n        unexpected_failures=tuple(sorted(failures - scoped)),       # new regression outside baseline\n        outcome_changed=tuple(sorted(                               # failed <-> error flip\n            n for n in scoped & failures if outcomes[n] != baseline.entries[n][\"outcome\"]\n        )),\n        missing_from_run=tuple(sorted(                              # deleted, skipped, or xfailed\n            n for n in scoped\n            if n not in expected or (n not in failures and outcomes.get(n) != \"passed\")\n        )),\n        resolved_baseline=tuple(sorted(                             # fixed baseline needs explicit refresh\n            n for n in scoped & expected if outcomes.get(n) == \"passed\"\n        )),\n        empty_collection=not expected,                              # ran against 0 tests\n    )\n```\n\nIf any of those six tuples isn't empty, Gate 2 fails. Reviewer also runs a short Test GC pass at Gate 2: deleting retired tests for removed features, dropping brittle mock-call-count checks, and folding one-off regression files into `parametrize` tables.\n\nOnce tests and static checks cover correctness, the biggest surprise left is an agent making a product call you never asked for: picking a default threshold, turning a manual suggestion into an auto-apply action, or loosening notification rules.\n\nAt Gate 2, Reviewer scans for user-visible behavior changes and groups them by effect (if a dozen files implement one new default, that's one item). Anything crossing a redline, like irreversible deletes or flipping \"suggest\" to \"auto-run\", blocks the release. Everything else gets summarized into **at most 3 plain-language bullets** (`when X happens -> system does Y -> how to change it`) for me to approve or tweak before merging.\n\nMaintaining a `dev` branch, a 6-section Project Context, a shared `flock` test queue, and baseline hashes is way too much machinery for a 300-line one-off script or a weekend prototype.\n\nIt only starts making sense when you're running concurrent agents week after week across real repos, like a compute-heavy Python codebase and a full-stack Web app (or keeping public tooling like [`GSX-Eis/jq-factor-lab`](https://github.com/GSX-Eis/jq-factor-lab) alongside private workspaces). One rough edge I'm still working out: on the rare 20-file interface rename that genuinely crosses 800 lines, getting Leader to write a short, useful commit-by-commit review guide without blowing up Reviewer's context still takes manual nudging.\n\nMy daily role is much narrower now: set the redlines, settle escalated deadlocks, check those <= 3 behavior notes, and merge `dev -> main`.\n\nIf you're running multiple coding agents in parallel, what's been the hardest part to keep under control in your review flow?\n\n*Disclosure: I built and run this multi-agent engineering workflow myself, verified every architecture rule, threshold, and code snippet against the actual implementation, and used AI tools to help draft and tighten the English prose.*", "url": "https://wpnews.pro/news/how-to-ship-5000-lines-of-reliable-code-a-day-with-a-multi-agent-architecture", "canonical_source": "https://dev.to/_088d9c6b7211315f6e47be/how-to-ship-5000-lines-of-reliable-code-a-day-with-a-multi-agent-architecture-3fb", "published_at": "2026-11-30 04:38:17+00:00", "updated_at": "2026-11-30 04:45:58.179732+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools"], "entities": ["GitHub", "pytest"], "also_reported_by": [], "takeaway": "Capping each agent task at 800 lines before review and routing all merges through a `dev` buffer with a read-only cross-model review gate keeps parallel coding agents reviewable at roughly 5,000 lines a day.", "recommendation": {"advice": "Cap agent tasks at 800 lines before review and gate merges through a `dev` branch with a read-only reviewer pass, so humans only sign off on plain-language behavior changes.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/how-to-ship-5000-lines-of-reliable-code-a-day-with-a-multi-agent-architecture", "markdown": "https://wpnews.pro/news/how-to-ship-5000-lines-of-reliable-code-a-day-with-a-multi-agent-architecture.md", "text": "https://wpnews.pro/news/how-to-ship-5000-lines-of-reliable-code-a-day-with-a-multi-agent-architecture.txt", "jsonld": "https://wpnews.pro/news/how-to-ship-5000-lines-of-reliable-code-a-day-with-a-multi-agent-architecture.jsonld"}}