Lessons from auditing 101,108 coding-agent tool calls, shipping 74 merged upstream PRs across Go/Rust/Python, and building a zero-dependency Rust harness (xgbtxy/ap + ap-harness-lite v1.1.0).
There is a funny pattern you notice once you run coding agents every day for months across real repositories: every time a smarter model drops, teams rush to write even more orchestration glue around it. State machines telling the model when to think, rigid planner prompts, custom retry supervisors, and 3,000-token system instructions warning it not to break files.
And yet, across model upgrades, the agent still burns half its context budget on the exact same mundane failures:
- Reading an entire 1,800-line source file to locate one 25-line function.
- Dumping 35 KB of noisy
cargo testorpytestlogs straight into the conversation window, evicting the actual design context. - Patching code by bare line number after an earlier edit shifted the file—corrupting an adjacent block and burning four more turns fixing a syntax error it created itself.
- Running two parallel agents in the same repo and watching them silently overwrite each other's changes, or timing out a test suite on Windows while orphaned child processes keep file locks open.
When I audited 101,108 real coding-agent tool-call traces, the takeaway was blunt: over-controlling how frontier models reason usually hurts, while leaving the tool substrate fuzzy guarantees wasted tokens and flaky edits.
I like to keep my own building philosophy simple: technology has fewer real walls than ever right now—when useful tools and open specifications are this accessible, the main craft is picking clean local building blocks and shipping the right fix at the right time.
So instead of building another heavy Python prompt-orchestration framework, I inverted the stack: give the model maximum room to reason, and move five mechanical invariants into a single statically linked pure-Rust binary (xgbtxy/ap, MIT, v2.93.0) with zero runtime dependencies.
1. Read Enclosing AST Symbols, Edit by Content Hash (ap splice --hashline)
Line numbers are terrible edit coordinates for LLMs; search-and-replace breaks on repeated indentation. Compiling six Tree-sitter grammars (Rust, Go, Python, TypeScript, JavaScript, C) directly into ap lets any agent read only the enclosing symbol, tagged with short content hashes (42:a3|...).
When the agent submits a patch via ap splice apply --hashline --stdin --test --rollback-on-test-fail, ap verifies every anchor hash before touching disk, checks Tree-sitter syntax, runs the test gate, and rolls back cleanly if tests fail. In our empirical runs, pairing AST-bounded edits with automated checks lifted mutation-kill coverage from 62.5% to 100.0%.
2. Lossless SQLite FTS5 Log Compression (ap sieve)
Piping noisy test logs through head or tail throws away the middle error frame permanently. ap sieve run emits a compact digest for the model while indexing 100% of the verbatim output into an embedded SQLite FTS5 store (ap sieve search / ap sieve peek --lines).
On the synthetic 597-line cargo test failure log bundled in our companion MIT Lite Kit (xgbtxy/ap-harness-lite v1.1.0), ap sieve shrinks 32,258 B (~8,065 tokens) down to 1,307 B (~327 tokens) — a 95.9% cut while keeping both buried assertion failures directly readable.
3. Budgeted Micro-Rule Retrieval (ap recall)
Instead of paying for a monolithic instruction file on every turn, ap recall queries an embedded FTS5/BM25 store and injects only the 1–3 matching rules under a strict token budget. In v2.93.0, 10,000-rule lookup latency dropped from 20.57ms to 0.33ms (62.3x), and warm-cache ap audit dropped from 10.03s to 416ms (24.1x).
4. Cooperative File Leases & OS Process Containment (ap baton + ap-winjob)
Parallel agents shouldn't rely on polite prompt instructions to avoid stepping on each other. ap baton claim --owner <id> --ttl <sec> provides atomic TTL-backed cooperative file leases across linked Git worktrees (exit 2 on contention) plus <500-token ap baton resume handoff capsules. On Windows, ap exec binds child process trees inside a Win32 Job Object (ap-winjob) so timeouts terminate the entire process tree cleanly with zero orphaned runners.
5. The Same Discipline Scales Beyond Agents: 74 Upstream PRs & 3 Verified IETF Errata
The unexpected side effect of building zero-false-positive local checks is how cleanly the habit transfers to open-source maintenance and formal standards work. Across 74 officially merged upstream PRs—spanning Apache (arrow-go, datafusion-sqlparser-rs, opendal, spark), CNCF & OCI (etcd-io/bbolt, opencontainers/runtime-spec, opentelemetry-python, prometheus/client_golang, coredns, go-tuf, nats.go), HTTP engines (valyala/fasthttp, gofiber/fiber), AI SDKs (onnxruntime, transformers, modelcontextprotocol/rust-sdk, a2aproject/a2a-python, a2a-go), and W3C/standards repos (RDFLib/rdflib, CycloneDX)—plus 3 officially Verified IETF RFC errata (EID 9311, EID 9330, EID 9352, 0 Held, 0 Rejected), busy maintainers merge small, test-backed fixes quickly when the noise floor is zero.
Honest Negative Controls (When NOT to Use ap)
Every tool has break-even thresholds, and hiding them wastes everyone's time:
-
Tiny commands (
<1.2 KBstdout):ap benchships with a built-in negative control showing that wrapping a70 Boutput adds+48 Bof wrapper metadata (118 B). Rungit status -sdirectly or passap exec --raw. -
Small files (
<80lines): Just read the file straight through. -
Direct CLI beats eager MCP when you have a shell:
ap mcpexposes 37 stdio tools for MCP-only hosts, but loading 37 JSON schemas eagerly into every turn defeats token savings. If your agent has shell access, callapdirectly.
Try It Yourself (100% MIT, Zero Trackers)
- Canonical Engineering Essay: https://xgbtxy.github.io/essays/deterministic-harness.html
- Essay #2 (Zero-FP OSS & IETF Errata): https://xgbtxy.github.io/essays/zero-fp-oss-and-ietf-errata.html
- Interactive Token-Savings Estimator &
ap sievePlayground: https://xgbtxy.github.io/ - Pure-Rust Single Binary (
v2.93.0, 5 platforms): https://github.com/xgbtxy/ap - Free MIT Companion Lite Kit (
v1.1.0, FTS5 recipes + 24/24 CI-tested Task-DAG validator): https://github.com/xgbtxy/ap-harness-lite/releases/tag/v1.1.0 - Short
1080pTerminal Walkthroughs (~100s each): https://www.youtube.com/playlist?list=PLBVbhUxEeai4
What deterministic local guardrails have saved you the most agent turns lately?
Top comments (0)