{"slug": "stop-letting-ai-agents-approve-their-own-code-two-repo-split-cross-model-review", "title": "Stop Letting AI Agents Approve Their Own Code: Two-Repo Split, Cross-Model Review, and a $40 Cloud Test VM", "summary": "A developer running up to four parallel AI coding agents on a 16 GB MacBook described splitting their quantitative research codebase into two separate Git repositories, adding cross-model code review, and routing tests through a shared cloud VM to stop agents from approving their own work. The setup, which backs nearly 7,000 tests, uses per-invocation execution IDs, SHA-256 config hash checks, and a dedicated exit code (4) to block runs whose output is missing or tampered with even when the subprocess returns 0.", "body_md": "I run up to 4 AI coding agents in parallel on a 16 GB MacBook. Whenever two of them launched full `pytest` runs at the same time, macOS hit swap immediately and froze. Worse, when I let the same agent edit code, run tests, and report success, it sometimes relaxed assertions to make a failing test pass or returned an `exit 0` from stale artifacts left in a shared directory.\n\nTelling an LLM in a prompt to \"be careful\" or \"don't touch unrelated files\" stops working once the context window fills up. I replaced prompt-based discipline with hard repository boundaries, cross-model code review, and a shared cloud test runner. This setup currently backs my personal quantitative research codebase with nearly 7,000 tests, and every piece of it works just as well for any Python or backend project.\n\nWhen all my code lived in one repository, an agent fixing a data loader bug could casually edit the task scheduler or read out-of-sample validation data from an exploratory script. No amount of Markdown instructions stopped that reliably.\n\nI split the system into two separate Git repositories:\n\n`task_manager`)` quantation_factor_database`)` tools.agent_harness.cli`) and has zero scheduling privileges.\n| Approach | Risk of Cross-Module Edits | Concurrent Merge Conflicts | Trade-Off You Accept | \n|---|---|---|---|\n| Single repo + prompt rules | High after long sessions | High | Constant manual cleanup | \n| Monorepo with folder rules | Medium (direct imports still work) | Medium | Painful to split out public code later | \n| **Two separate Git repos** | **Low (process and repo boundary)** | **Low (independent test suites)** | **Must maintain a strict CLI and JSON contract** | \n\nSplitting into two repos does add overhead. Every cross-repo change requires updating the CLI flags and JSON schema on both sides, and we use Copybara to export allowlisted parts of the execution repo to our public open-source project [`GSX-Eis/jq-factor-lab`](https://github.com/GSX-Eis/jq-factor-lab). In return, an agent working on computation can never touch scheduling rules.\n\nLetting one model write a patch and verify it is an easy way to get false positives. A single model has blind spots around its own assumptions, and when a test fails, it often tries to work around the failure by loosening an assertion or returning a default value so the process exits with `0`.\n\nI also ran into silent cache bugs where a script exited `0` after writing an empty file, or a wrapper read an old report left behind in a shared output folder.\n\nTo stop both failure modes, I split work across four steps and different model families:\n\n`worktree`, so 4 agents never overwrite each other's files.`--no-ff` in a temporary When human planning docs and code disagree, agents often copy stale commands from an outdated README. I added a strict precedence rule in `AGENTS.md` at the repo root:\n\n`CLI --help` output (highest authority)`schemas/`)` README.md`\n`.planning/`, background only, never copy commands from here)\nOur CLI wrapper separates \"the subprocess didn't crash\" from \"the output is valid.\" Every invocation gets a fresh `execution_id`, writes to `attempts/<execution_id>/result.json`, and checks the SHA-256 hash of the source config. If the file is missing or the hash doesn't match, the wrapper blocks the run with exit code `4` even if the child process returned `0`:\n\n```\nEXIT_SUCCESS = 0       # Process exited 0 and schema + SHA-256 checks passed\nEXIT_PRECONDITION = 2  # Missing config or boundary violation before start\nEXIT_EXECUTION = 3     # Subprocess crashed, timed out, or killed by signal\nEXIT_QUALITY_GATE = 4  # Subprocess returned 0, but output is missing or tampered\n\ndef verify_bound_result(result_path: Path, expected_run_id: str, config_sha256: str) -> dict:\n    # Read only from this invocation's execution_id folder to avoid stale artifacts\n    payload = read_json_strict(result_path)\n    if payload.get(\"run_id\") != expected_run_id:\n        raise ContractGateError(\"run_id mismatch: refusing stale artifact\", code=EXIT_QUALITY_GATE)\n    if payload.get(\"source_config_sha256\") != config_sha256:\n        raise ContractGateError(\"config hash mismatch: evidence tampered\", code=EXIT_QUALITY_GATE)\n    return payload\n```\n\nOnce the execution repo grew to **418 test files across 12 shards** (nearly 7,000 tests), running suites locally on a 16 GB MacBook became unusable. I banned local `pytest` runs completely and moved all unit, shard, and full regression runs to a single **GCP Spot VM (`8 vCPU / 32 GiB RAM / 100 GB disk`)** with a hard **$40/month** budget.\n\nSharing one Spot VM behind a lock queue means only one full regression runs at a time, and concurrent worktrees either wait or exit with code `75` to retry. In exchange, the environment stays identical and cheap.\n\nBefore syncing code, the local runner acquires `quantation-gcp.lock` across worktrees. On the VM, every run goes through `/usr/local/bin/cloud-test-lease-run.sh` (a kernel `flock` lease) and locks numerical libraries to a single thread so 6 `pytest-xdist` workers don't oversubscribe 8 vCPUs:\n\n```\nREMOTE_THREAD_ENV = {\n    \"OPENBLAS_NUM_THREADS\": \"1\",\n    \"OMP_NUM_THREADS\": \"1\",\n    \"VECLIB_MAXIMUM_THREADS\": \"1\",\n    \"MKL_NUM_THREADS\": \"1\",\n    \"NUMBA_NUM_THREADS\": \"1\",\n}\n\ndef build_leased_remote_cmd(lease_cmd: str, lease_id: str, target_cmd: str) -> str:\n    # Keep fd 8 open for stdin (such as rsync filter rules) when the lease wrapper backgrounds\n    restore_stdin = \"exec \\\"$@\\\" <&8\"\n    return f\"exec 8<&0; exec {lease_cmd} {lease_id} -- sh -c '{restore_stdin}' sh {target_cmd}\"\n```\n\n`quant-idle.timer` checks active leases and SSH sessions every 5 minutes and powers off the VM after 20 minutes of idle time (agents are forbidden from running manual shutdown commands). Twice, a merge run hit SSH timeouts because the VM happened to be shutting down right as the job started. We fixed this in `CloudRunner` by checking instance state first and calling `gcloud compute instances start` when the VM is `TERMINATED`.` xdist` workers crashing Numba on `dcor`\nHumans leave fallback code around for backwards compatibility, but fallback paths give AI agents extra ways to fail. When SQLite and DuckDB coexisted in our repo, agents occasionally wrote results to the wrong backend inside an exception handler.\n\nI removed SQLAlchemy, SQLite loaders, and automatic `auto` backend detection completely, leaving **DuckDB + Parquet** as the only storage path, guarded by static contract tests that fail if anyone re-imports old database drivers.\n\nOn the scheduling side, `quality_gate.sh` runs a 10-step check before every merge, including Ruff, type checks, package boundary linting, and an isolated contract check in a temporary directory:\n\n```\n# Hard gate: verify package boundaries and run contract checks in an isolated temp dir\n\"$python_bin\" -m task_manager.tools.arch_linter --boundary --json || GATE_FAILED=1\n\n\"$python_bin\" - <<'PY'\nimport sqlite3\nfrom pathlib import Path\nfrom tempfile import TemporaryDirectory\n\n# Test schema contracts in an OS temp dir so we never touch the live workspace state/\nwith TemporaryDirectory(prefix=\"contract_gate_\") as tmp_dir:\n    root = Path(tmp_dir).resolve()\n    init_schema(sqlite3.connect(root / \"state.db\"))\n    raise SystemExit(run_cli([\"--task-root\", str(root), \"--json\", \"check\", \"contracts\"]))\nPY\n```\n\nHere's where both repositories stand on our latest verified runs:\n\n`--changed --fast` runs finish in 1 to 2 minutes.`quality_gate.sh`)\n| Failure Mode | Prompt-Only Fix (Fails) | Engineering Constraint (Works) | Cost You Pay | \n|---|---|---|---|\n| Agents edit unrelated core modules | \"Don't touch other files\" | Two separate repos + `arch_linter` | Must maintain CLI/JSON contract | \n| Same model loosens test assertions | \"Check edge cases carefully\" | Separate author and reviewer models | Extra review turn and tokens | \n| `exit 0` returned from empty/stale files | Trust process exit code | Fresh `execution_id` dir + config SHA-256 | Extra schema check in wrapper | \n| Concurrent `pytest` freezes 16GB Mac | Ask agents to run sequentially | Ban local `pytest` , route to Spot VM | Must maintain `rsync` filter rules | \n| Worktrees overwrite remote workspace | Coordinate manually in chat | Local lock + remote `flock` lease | One heavy suite runs at a time | \n| Agents pick stale docs or wrong DB | Patch the prompt repeatedly | Strict doc order + delete SQLite path | Must clean up legacy fallbacks | \n\nTwo limitations remain open. First, as I spin up more concurrent branches, queue wait times on a single 8-vCPU Spot VM may become a bottleneck. Second, both repos still carry pre-existing test failures (43 in control, 32 in execution) that we gate on \"zero new failures\" while paying down the backlog.\n\nWhen you run multiple AI coding agents in parallel, what breaks first in your workflow: stale context, tests passing on weak assertions, or agents stepping on each other's environments?\n\n*Disclosure: I built and run this system myself, verified every command, exit code, and test count against the actual repositories, and used AI tools to help draft and tighten the English prose.*", "url": "https://wpnews.pro/news/stop-letting-ai-agents-approve-their-own-code-two-repo-split-cross-model-review", "canonical_source": "https://dev.to/_088d9c6b7211315f6e47be/stop-letting-ai-agents-approve-their-own-code-two-repo-split-cross-model-review-and-a-40-cloud-2g36", "published_at": "2026-11-24 09:38:31+00:00", "updated_at": "2026-11-24 09:42:46.097556+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "mlops"], "entities": ["GSX-Eis", "jq-factor-lab", "Copybara", "Git"], "also_reported_by": [], "takeaway": "Separate the agent that writes code from the one that verifies it, isolate parallel agents in per-agent git worktrees, and gate every run on a fresh execution_id plus a SHA-256 config hash so a subprocess exit 0 with missing or stale output is rejected with exit code 4.", "recommendation": {"advice": "Give each parallel coding agent its own git worktree and a separate verifier model, and reject any run whose result.json is missing, stale, or fails a SHA-256 config hash check even if the process exited 0.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/stop-letting-ai-agents-approve-their-own-code-two-repo-split-cross-model-review", "markdown": "https://wpnews.pro/news/stop-letting-ai-agents-approve-their-own-code-two-repo-split-cross-model-review.md", "text": "https://wpnews.pro/news/stop-letting-ai-agents-approve-their-own-code-two-repo-split-cross-model-review.txt", "jsonld": "https://wpnews.pro/news/stop-letting-ai-agents-approve-their-own-code-two-repo-split-cross-model-review.jsonld"}}