2026-12-03 ~6 min read Rust · Agent Harness · Benchmarks RSS

Stop Scripting How Your Coding Agent Thinks — Make the Tool Substrate Deterministic Instead

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).

Canonical English edition · Toggle 中文 above for a concise Chinese executive summary and localized navigation. Every command and benchmark table below is reproducible locally on public repos.

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:

  1. Reading an entire 1,800-line source file to locate one 25-line function.
  2. Dumping 35 KB of noisy cargo test or pytest logs straight into the conversation window, evicting the actual design context.
  3. 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.
  4. 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|...).

AST Symbol Read + Fail-Closed Hashline Patch
# Read only the target symbol with content-hashed line anchors
ap splice view src/parser.rs --symbol parse_header --hashline

# Verify anchors, parse Tree-sitter AST, run tests, rollback cleanly on failure
ap splice apply --hashline --stdin --test --rollback-on-test-fail

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 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).

Lossless FTS5 Log Sieving & Drill-Down
# Compress noisy test output while indexing 100% verbatim stdout/stderr
ap sieve run -- cargo test

# Query the indexed run in sub-milliseconds without re-running tests
ap sieve search "assertion failed"
ap sieve peek --lines 410-465

On the synthetic 597-line cargo test failure log bundled in our companion MIT Lite Kit (xgbtxy/ap-harness-lite), 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. You can test the deterministic compaction logic locally in your browser on the interactive ap sieve playground.

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.

Disjoint Multi-Agent File Lease & Handoff Capsule
# Acquire an atomic TTL file lease (exits 2 on contention across worktrees)
ap baton claim --owner worker-1 --ttl 300 --paths src/parser.rs

# Emit a compaction-proof <500-token handoff capsule
ap baton resume

Empirical Benchmark Summary (xgbtxy/ap v2.93.0)

Benchmark / Workload Baseline With ap Verified Delta
101,108 coding-agent tool-call traces Full-file reads + raw logs AST splice + FTS5 sieve -36.7% to -83.3% tokens · 1.52x–2.36x
597-line cargo test failure log (Lite Kit) 32,258 B (~8,065 tok) 1,307 B (~327 tok) -95.9% (2/2 failures kept)
Warm-cache workspace ap audit 10.03 s 416 ms 24.1x faster
10,000-rule FTS5/BM25 ap recall 20.57 ms 0.33 ms 62.3x faster
AST Hashline edits + automated test gate 62.5% mutation kill 100.0% mutation kill +37.5 pts
Negative control: tiny stdout (git status -s) 70 B raw 118 B wrapped +48 B overhead (use raw)

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#1372, opencontainers/runtime-spec#1337, opentelemetry-python, prometheus/client_golang, coredns, go-tuf, nats.go), HTTP engines (valyala/fasthttp#2613, gofiber/fiber), AI SDKs (onnxruntime, transformers, modelcontextprotocol/rust-sdk, a2a-go, a2aproject/a2a-python#1526), 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 KB stdout): ap bench ships with a built-in negative control showing that wrapping a 70 B output adds +48 B of wrapper metadata (118 B). Run git status -s directly or pass ap exec --raw.
  • Small files (<80 lines): Just read the file straight through.
  • Direct CLI beats eager MCP when you have a shell: ap mcp exposes 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, call ap directly.

Try It Yourself (100% MIT, Zero Trackers)

What deterministic local guardrails have saved you the most agent turns lately? Feel free to open a GitHub Issue or say hi on X (@yan179539549809).