Repository navigation
Description
Follow-up to #1787 / PR #1790, from that PR's review rounds.
Background
#1790 added a deterministic cross-turn duplicate-write guard: an incoming write is refused if its (tool, canonical_args) identity matches one persisted from an earlier turn in the same chat. That closed the correctness gap #1787 raised — the check no longer depends on the model honouring a prompt note.
Two gaps in the guard's coverage were found during review and deliberately deferred. Neither can cause a wrong refusal: both make the guard miss a duplicate it should catch, so they fail open. That is the safe direction, which is why they did not block the merge — but they do mean the guard is narrower in practice than it reads.
Gap 1: the args cap exempts the most expensive duplicate
CANONICAL_ARGS_MAX_CHARS (packages/agent/src/local_agent/agent_loop.rs:50) is 4096. A write whose canonical args exceed it persists no identity at all, and an entry without an identity can never match, so the write is unguarded.
create_nodes_from_markdown carries the whole import in its markdown argument. Any real import exceeds 4096 characters, so in practice this tool is never guarded — despite being the tool where a repeat is worst, since it duplicates an entire subtree rather than one node. The cap's own doc comment cites this tool as the motivating case, which makes the exemption easy to miss on a read.
The cap exists for a real reason: full canonical args are persisted into the ai-chat node's own message history, so storing a large import writes that content a second time. Dropping the identity when oversized (rather than truncating) is also correct as it stands — a truncated string could compare equal to a different call sharing a long prefix, turning a size limit into a wrong-suppression bug.
So the fix is not "raise the cap". Some options:
- Persist a digest of the canonical args for oversized calls instead of dropping the identity. Exact-match equality is all the guard needs, so a hash preserves the guarantee at constant size. This was considered during Deterministic cross-turn duplicate-write guard: make the persisted completed_writes enforceable, not advisory #1787 and the full-args form was chosen deliberately for debuggability; a hybrid (full args under the cap, digest above it) keeps both properties.
- Key long-form imports on a content digest of the specific large field rather than the whole arg blob.
- Leave the cap and accept the exemption, but correct the doc comment so it does not cite a tool it excludes.
Gap 2: delete_node has two canonical identities for one call
DeleteNodeParams (packages/agent/src/local_agent/tools.rs:140-143) accepts its target under both id and node_id via #[serde(alias = "node_id")]. Canonicalisation happens on the raw argument JSON, before serde applies the alias, so {"id":"x"} and {"node_id":"x"} produce different canonical strings for what is the same logical call.
A repeat that switches key spelling therefore slips the guard. The same alias appears on AgentUpdateNodeParams, AgentGetNodeParams, GetRelatedNodesParams and UpdateTaskStatusParams, but only delete_node is in the guarded set today, so only it is affected.
Fix direction: canonicalise after alias resolution — normalise argument keys through the tool's own params type before computing the identity, rather than normalising raw JSON. That would also make the identity robust to any future alias without a per-tool fix.
Notes
- Both gaps narrow coverage only. Neither can refuse a legitimate write, and neither can corrupt data.
- A third deferred suggestion from the same reviews, much smaller:
load_prior_writesandload_node_historyeach fetch the same ai-chat node, costing one redundant read per turn (packages/daemon/src/services/local_agent_service.rs).
Acceptance criteria
- A repeated
create_nodes_from_markdownwith identical arguments is refused across turns, without persisting the full import a second time into the chat node - Oversized arguments no longer silently disable the guard for a call — either an identity is still recorded, or the limitation is documented where it is actually true
- A repeated
delete_nodeis recognised as the same call whether the target is given asidornode_id - Tests cover both: an oversized-args repeat and an alias-spelling repeat, at the execution layer
Activity
malibio commentedon Jul 29, 2026
Frontend baseline: 170 test files passed, 4106 tests passed (45.64s).