Repository navigation
Agent emits malformed tool calls: title_template referencing undefined fields, and calls with empty arguments - #1781
Conversation
…r them (#1775) The aichat-matrix failures in scenarios 3/4 and 8c are one defect, not two: the model constructs an invalid tool call, and the error it gets back does not say what to fix, so its retries degrade the arguments instead of repairing them. Ground truth from the daemon log — four consecutive create_schema retries: fields[1] missing "type" -> "missing field `type`" (retry) same shape -> "missing field `type`" (retry) fields[0] lost "name" -> "missing field `name`" (retry) both fields nameless -> "missing field `name`" Only the second entry was ever wrong; by the fourth attempt the model had corrupted the entry that started out correct. Serde reports the absent key with no position, so there is nothing in the message identifying which element to fix. Three changes, all at the reporting seam: - schema/mod.rs: locate malformed `fields` / `add_fields` entries before serde sees them, naming the index and the entry's own name, reporting every bad entry at once, and instructing the caller to leave the others untouched. - tools.rs: format schema errors with Display rather than Debug. `{:?}` wrapped the guidance in `InvalidParams("...")`, burying the repair instruction the message already carried — the comment there claimed the error was returned "so the model can self-correct", which the formatting defeated. - agent_loop.rs: stop substituting `{}` for unparseable arguments. That sent the tool a payload the model never wrote, surfacing as a missing-required-field error that described the substitute rather than the malformed JSON. An argument-less call still passes through, since `{}` is the faithful reading. No guidance rules were added. The rules for both failures already exist (agent_guidance.rs:25-26, the create_schema tool schema) and were in-prompt when the model emitted the bad calls; restating them is the degenerate move #1760 was filed to prevent. Also fixes the stale doc comment on MarkdownError claiming the agent formats with `{:?}`, and notes that Display text reaches the model verbatim. Found while investigating, filed separately as #1777: description-only create_schema fails for every inferred field, and the two create_schema routes disagree on whether field names carry a `custom:` prefix. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
The re-run ran against a purged DB and a daemon rebuilt with the fix, but the host had three concurrent agent sessions contending for 16GB and one GPU — two nodespaced daemons resident at ~7.4GB and ~5.3GB, plus a full cargo build under a second user. Scenario 1 hit the 240s timeout, inference reported "no model loaded", and a model reporting "loaded" still returned no assistant reply. Recording the contention rather than a number: a score measured under that load would describe the machine, not the agent. score and effective_passed are left at their previous values so nothing downstream reads an unverified result. Also notes that the no-model-loaded mode silently PASSES the noTools scenarios, since they assert the absence of tool calls and inference never ran — the same false-pass class this file already documents for scenario 3. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
The matrix re-run surfaced a shape the first fix missed. The model sent:
{"name":"Equipment Check-out Tracker","title_template":"{equipment} ({status})"}
with no `fields` array at all. `describe_malformed_fields` inspects entries
WITHIN that array, so an absent array passed straight through, and the request
died at the title_template validator with no equipment schema persisted — which
is why scenario 4 still had nothing to instantiate.
The existing validator error was already correct and, after the Display fix,
readable: "title_template references undefined field 'equipment' — add it to
schema.fields". It states the rule but not the edit, and reports one placeholder
per round-trip. The model made no second attempt.
So `describe_unresolved_title_template` now reports every unresolved placeholder
at once and spells out the entries to add ({"name":"equipment","type":"text"}),
while naming only the genuinely missing ones — listing a field that is already
defined is what pushes a caller into rewriting a working part of the call.
Deliberately NOT wired into update_schema: there a template may reference fields
already on the stored schema, which the payload alone cannot see, so pre-checking
would reject valid calls. The existing validator remains the authority there, and
a test pins that.
Also corrects an assertion in the previous commit's tests that required the error
NOT to contain a resolved placeholder — the message echoes the whole template for
context, so what matters is that the field is not listed among those to add.
core 1013 passed, agent 308 passed, clippy clean.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
Two runs on a purged DB with a daemon rebuilt from the fix, on a quiet machine.
Raw 10/12 then 9/12; effective 8/12 in run 2 — unchanged from the 8/12 baseline.
What is verified:
- 8c passes in BOTH runs. This is the defect the issue was filed for. The log
shows the empty-argument create_node now reported as unparseable arguments
rather than the harness's substituted {} surfacing as "missing field
`node_type`".
What is not fixed, stated plainly:
- Scenario 3 is a FALSE PASS in both runs and this work did not fix it. The model
sends a title_template with no fields array; the error now names every
unresolved placeholder and prescribes the exact entries to add, and the model
still does not repair the call — in run 2 it retried with empty arguments and
gave up. Better error text was necessary but not sufficient for this model on
this shape.
- Scenario 4 still cascades from 3, so the "instance request calls create_node"
criterion is not demonstrated by scenario 4 at all. 8c/8d cover it instead,
against types that do exist, and both pass.
Also records measured run-to-run variance: scenario 5 flipped between runs on
identical code (search_nodes -> search_semantic), the only scenario that moved.
A single-run delta of 1 on this matrix is noise, so the raw count should not be
read as movement — hence effective_passed is reported alongside it and left at 8.
Notes that the within-array field locating, the largest part of the change, went
unexercised by both runs and is covered by unit tests only.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
… new defect Rebased onto #1778's runner and re-ran on a purged DB with the preflight gate passing. Raw 8/12, effective 7/12. The preflight gate earns its keep immediately: run against a daemon with no model loaded it exits 2, writes no results file, and prints the fix — catching exactly the silent-false-pass mode that invalidated this issue's first re-run attempt, where noTools scenarios "passed" because inference never ran. Three runs of this work now exist and they disagree: 10/12, 9/12, 8/12, on code differing only by the title_template addition between runs 1-2 and 3. Scenario 5 flipped twice across runs. The headline count is not a usable signal at this variance; the caveats say so and point at the per-scenario traces instead. Run 3 surfaced a defect the earlier runs did not: a CROSS-TURN duplicate write. 8c completes correctly with one create_node, then 8d's turn re-executes the previous turn's instruction and writes the same node again. The duplicate-call guard cannot catch this — seen_calls is per-turn and resets at the turn boundary, by design. Because the eval scrapes tools per chat node, that single stray call fails BOTH 8c and 8d, which reads as two defects and is one. Filed as #1780; it is not a regression from this fix, and the argument-error reporting behaves correctly in all three runs. Adopts the runner's richer results schema (provenance, per-turn traces) rather than continuing to hand-build the old shape. Unchanged and still stated plainly: scenario 3 is a false pass in all three runs and this work did not fix it, scenario 4 cascades from it, and the within-array field locating remains unexercised by every run. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
Code review found a real defect I introduced, and it was the worst kind for this
change: a confident, prescriptive, WRONG repair instruction.
describe_unresolved_title_template was a second, hand-rolled implementation of a
rule that already had an authority (validate_template_tokens). I verified the two
disagree on real inputs by porting both algorithms:
template fields pre-check said authority says
"{a} {b" [a] OK (silently passed) unclosed '{' placeholder
"{} {b}" [] "add {name:b,type:text}" empty '{}' placeholder
"{{a}}" [a] "add {name:'{a'}" undefined field '{a'
Rows 1-2 are the damaging ones. For "{} {b}" the caller follows the prescription
exactly and is rejected anyway — sending the model into precisely the
corrupt-the-good-parts retry loop this whole change exists to prevent. The pre-check
also compared against raw field names while the authority compares post-storage
names, a second divergence on the description-inferred path.
The rule: one source of truth per validation rule. A second implementation with
different scanning semantics is not a nicer message, it is a disagreeing validator.
Reverted, and my own eval evidence already showed the addition never achieved its
goal — the model received the prescriptive error and still failed to repair.
Its three tests are replaced by three against the real authority, two of which pin
the exact inputs where the pre-check diverged, so a future reintroduction fails.
Also from the review:
- get_node still formatted a MarkdownError with {:?} — the same defect fixed for
create_schema/update_schema, in the same file, which made the newly documented
"Display reaches the model verbatim" invariant already false in-tree.
- Dropped the "Invalid parameters:" prefix from the new message; Display already
writes "invalid params: ", so the model read a doubled preamble first.
- Bounded consecutive unparseable-argument calls (MAX_CONSECUTIVE_PARSE_FAILURES).
The duplicate guard keys on canonical args, so differently-malformed retries never
match and could burn every iteration with zero tool executions. Set to 2, not 1:
one malformed call then a correct retry is normal recovery and observed in run 3.
core 1013 passed, agent 309 passed, clippy clean.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
Runs 2 and 3 measured a pre-check that no longer exists. The recorded scenario-3 outcome is unchanged — the model still failed to repair — but the caveat claimed a mechanism (all placeholders reported, entries prescribed) that was removed in review for disagreeing with the authoritative validator. Says so plainly rather than leaving a caveat describing code that is not in the tree. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
`key` names the array being validated ("fields" / "add_fields") and is used as
that outside the loop, but the inner loop rebound it to a per-entry property
name. One identifier, two meanings, in a function whose whole purpose is naming
things precisely — renamed to `required_key`.
Skipped from the review, deliberately: the four pre-existing "Invalid parameters:"
stutter sites at mod.rs:218/433/501/581. They predate this branch and are
unrelated to argument-error reporting; fixing them here is scope creep on a change
about to merge. Worth a follow-up sweep with the other Display/Debug seams.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C2fwCrhS3Bfq4uDGM61iCr
|
Heads-up for the #1777 branch ( Both branches append test blocks to the end of One thing worth knowing rather than discovering during the resolve: my |
Closes #1775