Repository navigation
Description
Surfaced by the #1775 matrix re-run (run 3, rebased onto the #1778 runner). Distinct from #1775, which was about argument construction and error reporting.
Symptom
The agent completes a create instruction correctly, then re-executes it during the next turn, writing a second identical node.
From the daemon log (chat group 8c → 8d):
17:43:45 create_node is_error=true args={} <- reported as unparseable (#1775 fix)
17:43:46 create_node is_error=false {"content":"Kind of Blue by Miles Davis",
"node_type":"album_to_listen"} -> f1f25564
17:43:47 iteration=3 response="I have added \"Kind of Blue\"..." <- 8c ends, correctly, ONE node
17:43:49 iteration=0 search_nodes {"node_type":"venue_booking",...} <- 8d turn begins
17:43:50 iteration=1 create_node {"content":"Kind of Blue by Miles Davis",
"node_type":"album_to_listen"} -> 0bbcb76b <- DUPLICATE
17:43:53 iteration=3 create_node {"content":"the Blue Note [email protected]",
"node_type":"venue_booking"} <- 8d actual work
Two nodes now exist for one user request. A later search_nodes in the same run confirms it: Found 2 nodes matching "Kind of Blue".
Why the existing guard misses it
packages/agent/src/local_agent/agent_loop.rs has a duplicate-call guard, but seen_calls is scoped to a single run_turn and starts empty each turn. The repeat happens in the next turn, so there is nothing to match against. The guard is working as designed; its design does not cover this.
Note the iteration counter restarting at 0 in the log above — that is the turn boundary, and it is exactly where the guard resets.
Why the eval under-reports it
toolOnce counts tool names scraped per chat node. Because 8c and 8d share a chat, the single stray call is attributed to both, so 8c and 8d each report "got 2" from one extra write. Reading the assertion alone suggests two separate defects; the log shows one.
Not a regression from #1775
In all three #1775 runs the argument error is reported correctly, and in this run the model recovers from that message and creates the node successfully on the next call. The duplicate is a separate behavior that runs 1 and 2 happened not to exhibit — the matrix has large run-to-run variance (see the caveats in scripts/results-e4b.json).
Investigation notes
- Determine whether the model is re-reading the prior instruction from conversation history and treating it as pending, or whether the turn is being re-entered with stale history. Capture the assembled prompt for 8d with
NODESPACE_PROMPT_DUMPbefore theorising — inferring from behavior alone produced a wrong diagnosis twice on Agent emits malformed tool calls: title_template referencing undefined fields, and calls with empty arguments #1775/Agent guidance contains verbatim aichat-matrix prompts — the eval is measuring recall of planted examples, not generalization #1760. - Consider whether a write-intent guard should span the session rather than the turn, keyed on (tool, canonical args). Weigh against legitimate repeats: a user genuinely asking for the same node twice is rare but real, so a hard block may be wrong where a confirmation or a dedup-on-content check is not.
- Reproduce before fixing: this appeared in one of three runs, so treat it as intermittent and confirm a repro rate first.
Acceptance criteria
- Root-cause why the next turn re-executes the previous turn's create instruction (with a captured prompt dump, not inference)
- A completed create instruction is not re-executed on a subsequent turn
- A regression test covers the cross-turn case specifically — the existing per-turn guard tests do not
- State whether the eval should attribute tool calls per turn rather than per chat node, so one stray call stops failing two scenarios
Activity
Agent emits malformed tool calls: title_template referencing undefine…
malibio commentedon Jul 28, 2026
Baseline (worktree issue-1780-cross-turn-duplicate, from 7dcae76): Frontend: 170 test files passed, 4104 tests passed.
malibio commentedon Jul 28, 2026
Root cause (verified in code, not inferred)
The session does not persist across turns, and the persistence round-trip drops every trace of tool activity. Turn N+1 sees no evidence the work was done.
1. A brand-new ephemeral session is built for every turn.
packages/daemon/src/services/local_agent_service.rs:341run_ai_chat_turn::343let history = load_node_history(...)— re-read from the DB node:363let prior_history: Vec<ChatMessage> = history[..history.len()-1].to_vec();:373service.create_session(None, prior_history)— new session each turn:435service.end_session(&session_id)— destroyed at turn endSo
seen_callsis not merely turn-scoped by choice; the whole session object is gone. There is nothing to widen the guard's scope onto without changing what is persisted.2. The persisted message shape has nowhere to put tool calls.
AiChatMessage(packages/core/src/models/ai_chat_node.rs:38-52) is only:No
tool_calls, notool_call_id, noname.append_assistant_message(local_agent_service.rs:619) writes only the final proseresult.response— the assistant tool-call message and every tool result are never persisted at all.3. Reload discards anything that is not user/assistant text.
load_node_history(local_agent_service.rs:1342-1356):ChatMessage::text(packages/nlp-engine/src/chat/types.rs:145-154) hard-codestool_calls: Vec::new().4. The in-loop message that would carry the evidence is deliberately content-free.
agent_loop.rs:717-722pushesassistant_with_tool_calls(String::new(), tool_calls)— empty content by design (so the chat template stays clean). That message is in-memory only.Why this produces the duplicate
On turn 8d the model's history is:
The
create_nodecall, its arguments, and the returned node idf1f25564are all absent. The only evidence the instruction was satisfied is an unverifiable prose sentence. A model that treats its own prior prose as less authoritative than the explicit user instruction still visible above it re-executes the instruction. That is a soft, probabilistic cue — which is exactly why this reproduced in 1 of 3 runs rather than deterministically.This also means a cross-turn
seen_callsset is not implementable as stated in the issue: there is no cross-turn state to hold it. The durable fix is to persist tool-call evidence so the next turn can see its own completed work.Eval attribution (acceptance criterion 4)
The issue's premise here is incorrect — attribution is already per-turn, not per-chat-node.
scripts/aichat.ts:145-151capturesNS_LOGbyte size before the send;reportTurnLog(logSize)(:111-137) then tails only the bytes appended during that turn and emits one[tool]line per "Tool executed".runner.ts:71-99runTurnscrapes those into oneTurnRecordper send.So each stray call is attributed to exactly one turn. The reason 8c and 8d both failed is different:
agent-matrix.ts:240flattens across turns for the verdict —Scenarios 8c and 8d are separate scenarios that share a chat and are scored over the flattened turn list, so a
toolOncecount of 2 surfaces in both. No runner change is needed; if the double-reporting is worth removing, the change belongs in how matrix scenarios sharing a chat are scored, not in per-turn attribution.malibio commentedon Jul 28, 2026
Acceptance criterion 4 — eval attribution: no change needed
I said in my earlier comment that the double-reporting came from
agent-matrix.ts:240flattening across turns. That was wrong, and I'm correcting it: attribution is already strictly per-turn at every layer.scripts/aichat.ts:145-151records theNS_LOGbyte offset before the send;reportTurnLog(logSize)(:111-137) tails only bytes appended during that turn, emitting one[tool]line per "Tool executed".runner.ts:71-99runTurnscrapes those into oneTurnRecordper send.runner.ts:337scores with[scored]only — the scenario's own turn. Prior context turns (:330-332) are collected separately and explicitly "never scored". TheflatMapatagent-matrix.ts:240therefore runs over a single-element array.So one stray call cannot be counted against two scenarios. The issue's stated explanation ("because 8c and 8d share a chat, the single stray call is attributed to both") does not hold.
What actually happened in that run is that there were two separate stray
create_nodecalls, one in each turn — consistent with the daemon log, where the duplicate fires at 8diteration=1and 8d also does its own legitimatecreate_nodeatiteration=3for the venue booking. 8c reported 2 for its own reason; 8d reported 2 because it genuinely made twocreate_nodecalls in its own turn (the repeat of 8c's instruction plus its own work).Since attribution is already per-turn, I have made no eval change. The
toolOnceassertion is measuring the right thing; the duplicate write it caught was real.Deterministic cross-turn duplicate-write guard: make the persisted co…