Repository navigation
Description
Overview
A post-merge audit of #2257 (d393ad19) found two substantive gaps that survived three prior review passes — one that survived because every regression test used the same phrasing, one that survived because a follow-up call site outside the diff was never traced. Filing for follow-up work; the merged change is a clear net improvement and this is a refinement, not a revert.
Problem Statement
1. Narrated-call detector discards a correct answer on unspaced fenced JSON
looks_like_narrated_tool_call's own-line branch requires the brace adjacent to the tool name (rest.starts_with('{')) to distinguish a narrated call (create_node{"content":...}, no space) from documentation (create_node {...}, space). The reasoning is right for documentation, but a code comment additionally claims this makes a fenced report of a completed write safe — resting that on the model always inserting a space before the brace inside the fence. It does not:
"...the payload was:\n```json\ncreate_node {\"content\":\"Buy milk\"}\n```..." → correctly declined (has space)
"...the payload was:\n```json\ncreate_node{\"content\":\"Buy milk\"}\n```..." → WRONGLY detected (no space)
The unspaced form is ordinary, idiomatic JSON formatting. When it fires, the model's entire correct reply is discarded and replaced with a confirmation request — the exact failure class the detector exists to prevent, reachable through the fix meant to close it. The regression test added for this shape (narrated_tool_call_ignores_a_tool_name_starting_a_later_line) pins only the spaced variant, so today there is no failing test for this.
2. The schema-recovery backstop is unbounded and can starve a different mechanism
append_schemas_named_in_query (added in #2257) iterates every non-core schema and appends any whose id or display name is lexically named in the query, with no cap analogous to MAX_SEMANTIC_SCHEMAS. A reproduction against a representative multi-topic sentence naming several common-word schema types produced 9 appends from one message.
This interacts with a pre-existing recency injector in local_agent_service.rs that adds schemas created in the last 5 minutes, gated by remaining_slots = MAX_SCHEMAS.saturating_sub(relevant_schemas.len()). Once the lexical append alone reaches 5, remaining_slots is 0 and the recency injector becomes a complete no-op — even though it targets the same debounce-window gap the new backstop was built for. Concrete failure: define schema A then B inside the embedding debounce window, then send a message naming only A — B is never injected, though the recency mechanism exists specifically for that case.
A comment at local_agent_service.rs:2317-2319 ("Capped at MAX_SEMANTIC_SCHEMAS total...") is now stale — the bound it describes no longer holds for relevant_schemas as a whole.
Proposed Solution
Finding 1: Remove or replace the starts_its_own_line branch's implicit reliance on spacing. Either require an explicit marker (call:, tool:, >>>) for every accepted shape and drop the bare-adjacency own-line case entirely, or add a check that is actually spacing-independent. Add a regression test using the unspaced fenced-JSON shape before changing the code, so the fix is verified against the real failure rather than the documented one.
Finding 2: Give append_schemas_named_in_query a cap, or make remaining_slots derive from the semantic-hit count rather than the post-append relevant_schemas length so the two mechanisms cannot compete for one budget. A cap should not exclude the case that motivated the backstop (a type named outright in the request) — cap the total, not by dropping named-but-unembedded schemas first. Correct the stale comment at local_agent_service.rs:2317-2319 alongside whichever fix is chosen.
Architecture Impact
No relevant ADR or architecture doc found in nodespace-docs for either area (searched decisions/, architecture/, components/ for narrated-call detection, schema-recovery backstops, and retrieval budget mechanisms). No companion nodespace-docs change required.
Acceptance Criteria
-
looks_like_narrated_tool_callno longer discards a correct answer for an unspaced tool-name-then-brace shape following a newline - A regression test covers the unspaced fenced-JSON shape and fails against the current code before the fix
-
append_schemas_named_in_query(or its caller) enforces a bound so it cannot alone exhaust the recency injector's slot budget - The stale
local_agent_service.rs:2317-2319comment is corrected to match the actual bound in force -
bun run test:allpasses with no new failures -
bun run quality:fixpasses
Technical Specifications
Reference Files
packages/agent/src/local_agent/agent_loop.rs—looks_like_narrated_tool_call(~line 1214),ends_with_markerhelper, and its test module (narrated_tool_call_*tests)packages/core/src/ops/context_ops.rs—append_schemas_named_in_query(~line 254)packages/daemon/src/services/local_agent_service.rs— recency injector andremaining_slotscomputation (~line 2321), stale comment (~line 2317-2319)
Lower-severity items, recorded but not required for this issue's acceptance criteria
- Node Creation gained
update_node/update_task_statusin Restore the Stage-2 write-tool surface, and stop a failed write reporting success (closes #2254) #2257 but no target-resolution path (resolve_query/route_clarify); its guidance covers only records already in the current conversation. Worth a design decision — widen the whitelist to match Graph Editing's resolution tools, or tighten the guidance to explicitly punt when the record is not in conversation. get_all_schemas()is still called twice per turn across thecontext_ops/local_agent_servicemodule boundary; Restore the Stage-2 write-tool surface, and stop a failed write reporting success (closes #2254) #2257's dedupe fixed the duplicate call withincontext_opsonly.format_for_prompt's truncation (context_ops.rs, ~line 503) breaks rather than continues on budget exhaustion, and lexical appends land after semantic hits in insertion order — so under real budget pressure the schema the user named outright (the point of the Finding 2 mechanism) is the first thing dropped. Latent at the current 4000-char budget with typical schemas, not currently reachable in practice.
Related Issues
- Stage-2 withholds update_node on read-then-write turns, and the model reports success for the no-op #2254 (parent — the change that introduced both mechanisms)
Activity
malibio commentedon Aug 24, 2026
Baseline: 226/227 test files, 4793/4794 tests passed. One failure is the documented core-plugins viewer flake (5s default timeout under machine load in a fresh worktree) — not a regression.