published · 5 min read

My Agent's Long Task Died on One Invented Line of Python

Three stumbles in a day, and why a job whose questions are known in advance can now skip the model-written program.

The Python call sha256(ctx.encode("utf-8")).hexdigest() on a dark ground, with .encode("utf-8"), which turned the text into the bytes the helper rejected, in large amber type, above the words 195 paid reads, then this.

An AI agent drafted this from my projects, and another agent checked the draft claim by claim against the code and the run records or briefs that were kept. The projects and opinions are mine.

On September 17 a long contract-review task went through Azdaja, a recursive language model layer for coding agents, in two variants of the same setup, and both ran again after a fix. In each run the model was to write a Python program that cut the contracts into chunks, sent them in large batched prompts to the same model, and assembled the results. The first pair died on a timeout. In the rerun, both programs were rejected for length and had to be repaired. Then, after 195 paid semantic reads between them, both failed on their very last step.

The first two failures: a timeout and a length cap

Both runs died at 60.009 seconds. I'd set a two-minute limit, and Azdaja had a separate, undocumented 60-second idle ceiling that fired first. The error didn't say which limit it was. Fixing the timeout didn't teach anything about the model: make the idle limit honour the configured limit on the opt-in path, leave defaults unchanged, and prove it with a test that fails on old code.

With the timeout gone, both model-written programs went over Azdaja's 50-line limit for a single program, and each used one repair attempt to get under it.

The third failure: a hash call on the last step

Once repaired, both runs got going. One completed 75 semantic reads, the other 120. Then both died on their final step, on the same kind of line:

sha256(ctx.encode("utf-8")).hexdigest()   # what the model wrote
sha256(ctx)                               # what Azdaja's helper actually takes

In Python's standard library, that's how you hash a string. Azdaja's workspace has its own sha256 helper that takes text and returns hex directly. The model wrote an idiom it knows, the helper rejected it ("sha256 requires exactly one string"), and final assembly crashed. Azdaja doesn't repair a program that has already made model calls, so both runs ended there. Everything before the crash had been paid for. Offline, the agents changed that single expression and re-ran both whole programs, with a local stand-in replaying saved replies in place of new model calls. Between 79% and 84% of the fields were correct (macro-F1 0.62 and 0.72). Even after recovery, 0 of the 4 dependent query sets came out exactly right. The joins ran on recovered fields, and errors in those fields carried through.

Two runs on one timeline: both die at 60.009 seconds, both are rejected at the 50-line limit, then one logs 75 ticks and the other 120 before both die on the final step.
A tick is a paid read. Distances show order and don't show time.

What changed

There were two kinds of change, and the small kind went into prompts: "sha256(text) returns a hexadecimal string. Use sha256(ctx), not bytes, .encode(), hashlib or .hexdigest()." The task text already said source_sha256 is sha256(ctx), and both runs wrote the standard-library form anyway; the new line adds what the helper takes and returns. Hours later a preflight check landed that rejects this exact mistake before the program runs and sends it back for repair. Both apply only when Jev is enabled, both have been tested only against a local fixture, and neither stops the next misused API.

The bigger change was a separate path with no model-written program at all. For a task where you already know the list of questions (these passages, this question about each), there's no reason for a model to write the program that walks the list. Azdaja now has a batch runner for that:

az jev batch --input ./review-plan/plan.jsonl \
  --execute --output ./review-job \
  --max-requests 256 --max-input-tokens 2000000 --max-seconds 600

A work list here is a file, one record per line (a passage and the typed questions to ask about it), validated in full before anything is sent. A run needs --execute and three explicit budgets. Before each request leaves the process the runner records its intent, and it saves each validated answer before sending the next request. That last part matters for resuming. If a run stops, completed answers are reused without an API key or any requests. If there's a request with recorded intent and no saved answer, it might have been billed without an answer arriving, and the runner refuses to guess: it stops and tells you, instead of silently paying twice.

A grid of records with an intent row and an answer row. The run stops after an intent with no answer; resuming reuses the completed answers and then stops at that record.
These records are drawn and don't come from a run.

In the batch runner, final assembly is native code and can't fail on a misused hash call.

A narrower review of the same 102 contracts ran as a batch on September 18: one fixed question, whether a passage restricts assignment without consent, over 138 passages. All 138 completed in about two and a half minutes. Resuming it afterwards with the key removed reused all 138 and sent zero requests. It's a different job from those failed runs, so it shows the runner finishes and resumes. It doesn't show that the runner is faster or more accurate.

A side finding: optional tools go unused

One of those failed runs had an extra capability available, Jev, the decision model from my second Azdaja post, and didn't call it. From the results file:

Merely enabling a capability is not treatment exposure.

In another benchmark attempt, with the skill merely available, the Azdaja arms made zero inner model calls and didn't return a usable answer. A related change had shipped two days before these runs. An early version was built to take over flagged prompts once the skill loaded, blocking other tools. Since v0.1.16 the Claude Code hook stays off unless you opt in by setting AZDAJA_CLAUDE_ACTIVATION to request, session or repository.

Splitting the work between model and native code

When a model writes control flow, every line is a chance to call an API the way it works elsewhere, not the way yours works. That's fine for exploration, where a crash costs a retry, and expensive at the end of a long paid run. So let the model decide what to ask (the plan, questions and interpretation) and let native code do the walking: iterate, budget, save, resume, assemble.

Splitting the work this way isn't new: ReWOO has a model plan all its tool calls before seeing any of their results, and reports using far fewer tokens. Others put the loop in model-written code on purpose. In Recursive Language Models, the model writes programs that call it on as many slices of the input as it needs, and the paper reports that models without enough coding ability struggle in that role. Anthropic also argues for loops and conditionals in agent-written code, since direct tool calls send all intermediate results through the model, and notes that running such code adds operational overhead and security considerations.

Install and the batch runner

curl -fsSL https://azdaja.dev/install | sh

You'll find the batch runner's docs, including the work-list format, in docs/jev-batch.md. Jev needs your own TypeSafe key. Azdaja itself is free and MIT licensed. Code and setup notes: https://github.com/kubet/azdaja