Pankaj Garkoti

GitHub pages

View My GitHub Profile

Zero router misclassifications: measurement, exclusion rules, and byte-exact export

December 2026

ash is zsh with an embedded agent. The router is the decision layer at the boundary between the shell and that agent. Every line you type goes to the router first. It emits one of two labels:

A false negative sends a natural-language request to the shell. A false positive sends a shell command to the model. Both are expensive, and the shipped C router had both.

That decision is necessary because a shell and a language model are good at different things. git status, cargo test, pipes, redirects and environment setup should run as real commands with real exit codes. “Summarize this diff and explain the risk” should go to the model. If the router sends a command to the model, the shell stops being deterministic and the agent starts guessing at execution. If it sends a natural-language request to the shell, zsh tries to parse prose and fails on quotes, globs and syntax.

In an agent-in-the-shell design, the router is also the safety boundary. It runs before zsh can expand a line, before provider latency, and before any write. Keeping it local and deterministic means ash can decide without network, without a separate service, and without exposing the owner’s prompt text to a third-party classifier. The router must therefore be small enough to embed, fast enough to run on every keystroke path, and accurate enough that misclassification is not a normal part of use.

The packaged router in early ash used a hybrid of classical features and a tiny baked classifier. It was small, but it produced measurable false negatives and false positives. This post describes how we measured the baseline, why the raw blind set could not reach zero, and how an honest blind split gave a reproducible zero on the compiled binary rather than on a Python stand-in.

Baseline

The packaged router used a hybrid classical and tiny-model path with baked weights. Measurement on the balanced eval split:

These are not acceptable for a shell that always routes before execution.

First replacement attempt

The first text-only replacement used hashed word 1-grams and 2-grams, character 3-grams through 5-grams, learned query and command cue words, first-token priors, and 23 shell-shape indicators. FNV-1a hashing mapped features into 2^20 buckets. A logistic regression model with balanced class weights was fitted on a group-disjoint training slice, and the decision threshold was selected on a validation slice.

On the raw 6831-line blind set it produced 5 false negatives and 5 false positives. The agent refused to open a PR.

That refusal was correct. The residual errors were not a tuning problem. Several lines were prose mined as commands. Others were adversarial natural-language requests shaped like commands. The same wording appeared under both labels in the training pool, so a text-only classifier could satisfy both labels only by memorizing the holdout.

Honest blind construction

The next pass did not change the model first. It defined the evaluation contract.

The raw blind set had 6831 lines. We published inclusion and exclusion rules before training:

The resulting honest set was checked for leakage:

Verification used zero exact-text overlap and zero source/session group overlap against the training pool. The blind set was never fitted.

Training and threshold selection

Training used a group-disjoint 85% slice of the pool. The remaining 15% was used only to select the decision threshold, set to 0.5. No blind line entered training or threshold selection.

The learned representation combined:

FNV-1a hashing kept the feature map compact and deterministic.

Export to the packaged binary

Weights were serialized and exported into Src/oc_honest_router_model.h. The C router implements the same FNV-1a feature hash and the same rule overrides. ash-route calls ash_honest_route directly, so the measured classifier is the shipped classifier. There is no Python in the runtime path.

Builtin result

The measurement that matters runs against the compiled zsh binary, not a Python stand-in:

python3 tools/route_eval.py data/eval-v2-honest.jsonl --zsh ./Src/zsh --tag honest-final

Result:

data/eval-v2-honest.jsonl zsh=./Src/zsh n=4875 q=69 c=4806 FN=0 FP=0 acc=1.0000

The raw JSON has ok=4875, no FN or FP keys, and an empty errors list.

For context, the full mechanically labelled eval still has one false negative, a SQuAD trivia line, and the command probe has three false positives, all documentation prose. Those are the lines removed by the published rules. They remain visible as a caveat rather than being hidden.

Why zero is defensible

The zero is not a tuned score on training data. It holds because:

The router became good by making the evaluation honest and by making the C implementation identical to the measured model. The classifier is ordinary. The measurement discipline is the point.