Skip to content

Fix narrated-call false positive and schema-recovery/recency-injector starvation (closes #2261) - #2266

Merged
malibio merged 4 commits into
mainfrom
issue-2261-narrated-call-schema-cap
Aug 24, 2026
Merged

malibio merged 4 commits into
mainfrom
issue-2261-narrated-call-schema-cap

Conversation

@malibio

@malibio malibio commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two findings from a post-merge audit of #2257 (filed as #2261), both root-caused independently rather than accepted at face value:

  1. Narrated-tool-call detector discards a correct answer. looks_like_narrated_tool_call's own-line admission accepted a tool name immediately followed by { at the start of a line, on the theory that a narrated call writes its arguments flush against the name while documentation puts a space there. That distinction doesn't hold for a model's own honest report of a completed write inside fenced JSON — ordinary formatting omits the space too (create_node{"content":"Buy milk"}), and every existing regression test for the own-line case used the spaced form, so this false positive went undetected through three prior review passes. Removed the admission entirely; only an explicit marker (call:, tool:, >>>) is now accepted.

  2. Lexical schema backstop can starve the recency injector. append_schemas_named_in_query (an unbounded lexical backstop recovering schemas the ~30s embedding debounce hasn't indexed yet) and local_agent_service.rs's recently-created-schema injector both write into WorkspaceContext.relevant_schemas, but the injector computed its remaining budget from the vector's post-append length. A turn naming several existing schemas by name could exhaust that budget before the injector ever ran, silently dropping a type the user just created in the same turn — even when semantic search itself found nothing. Added semantic_schema_count to WorkspaceContext, captured before the lexical append runs, so the injector's budget reflects what semantic retrieval actually returned rather than a total blind to who wrote what.

Test plan

  • cargo test -p nodespace-agent --lib narrated_tool_call — 13/13 pass, including new unspaced-fenced-JSON regression cases
  • cargo test -p nodespace-core --lib context_ops — 40/40 pass, including new lexical_append_does_not_retroactively_inflate_the_semantic_count
  • cargo test -p nodespace-core --lib — 1199/1199 pass
  • cargo test -p nodespace-daemon --lib — 162/162 pass
  • cargo test -p nodespace-agent --lib — 577 pass, 1 pre-existing ignored
  • bun run quality:fix — clean, no unrelated reformatting
  • bun run test:all — 227/227 frontend files, all Rust suites 0 failed (one run hit the known core-plugins.test.ts 5s-timeout flake under machine load; documented in Narrated-call detector still discards a correct answer, and the schema-recovery backstop can starve the recency injector #2261's baseline comment, not a regression — passed clean on retry)
  • Full pre-push gate (scripts/test-gate.ts), including cargo test -p nodespace-app Tauri-seam integration tests

Closes #2261.

🤖 Generated with Claude Code

The own-line admission accepted a tool name immediately followed by
`{` at the start of a line, reasoning that a narrated call writes its
arguments flush against the name while documentation puts a space
there. That distinction doesn't hold for a model's own report of a
completed write inside fenced JSON — ordinary formatting omits the
space too (`create_node{"content":"Buy milk"}`), and every existing
regression test for the own-line case used the spaced form, so this
false positive went undetected. Removed the admission; only an
explicit marker (call:, tool:, >>>) is now accepted.

Found in a post-merge audit of #2257 (#2261).
`append_schemas_named_in_query` (an unbounded lexical backstop for
schemas the embedding debounce hasn't indexed yet) and the recently-
created-schema injector in local_agent_service.rs both write into
WorkspaceContext.relevant_schemas, but the injector computed its
remaining budget from the vector's post-append length. A turn naming
several existing schemas by name could exhaust that budget before the
injector ever ran, silently dropping a type the user had just created
in the same turn — even though semantic search itself found nothing.

Added semantic_schema_count to WorkspaceContext, captured before the
lexical append runs, so the injector's budget is computed against what
semantic retrieval actually returned rather than a total blind to who
wrote what.

Found in a post-merge audit of #2257 (#2261).
Missed by the earlier grep for WorkspaceContext literals, which only
covered context_ops.rs — this construction lives in an integration
test in a different crate.
@malibio

malibio commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type: Initial Review

Requirements Check (issue #2261)

  • looks_like_narrated_tool_call no longer discards a correct answer for an unspaced tool-name-then-brace shape following a newline — agent_loop.rs:1253-55 (in the diff) removes the starts_its_own_line branch entirely; only marker_prefixed (call:, tool:, >>>) gates the own-line/brace-adjacent case now. Verified the unspaced example from the issue (create_node{"content":"Buy milk"} inside a fence, no marker) no longer matches.
  • A regression test covers the unspaced fenced-JSON shape and (per PR description) failed against pre-fix code — narrated_tool_call_ignores_a_tool_documented_at_the_start_of_a_line gains two new assertions, including the exact unspaced-fence case from the issue body.
  • append_schemas_named_in_query (or its caller) enforces a bound so it cannot alone exhaust the recency injector's slot budget — remaining_slots in local_agent_service.rs:2334 now derives from context.semantic_schema_count, captured in context_ops.rs before the lexical backstop runs, rather than from relevant_schemas.len() after it.
  • The stale comment at local_agent_service.rs is corrected — old text ("Capped at MAX_SEMANTIC_SCHEMAS total...") is replaced with an explanation of the actual budget in force. Verified accurate (see findings below).
  • bun run test:all / bun run quality:fix — PR description reports both clean; not independently re-run in this review, taken on the strength of the itemized test plan (13/13, 40/40, 1199/1199, 162/162, 577+1 ignored, full pre-push gate including cargo test -p nodespace-app).

All five stated acceptance criteria are met by the diff.

Code Review Findings

🟢 Finding 1 — narrated-call detector: fix is correct, tradeoff is real but well-reasoned

packages/agent/src/local_agent/agent_loop.rs:1253-1305

Removing the starts_its_own_line branch entirely (rather than trying to patch the adjacency heuristic) is the right call. The issue's own repro shows the heuristic was unfixable with a spacing-based signal — a model's own honest report of a completed write inside fenced JSON uses the exact same "no space before the brace" shape as a genuine narrated call, so there is no local, syntactic way to tell them apart. Falling back to explicit markers (call:, tool:, >>>) trades recall for precision, and the PR's own code comment states the reasoning for that direction explicitly: "Missing a narrated call is the cheaper error... a false positive here discards the model's correct answer outright." That's the right cost asymmetry for this failure mode — a false negative produces visible, recoverable pseudo-code in the reply; a false positive silently destroys a correct answer.

I checked for other call sites depending on the removed branch — ends_with_marker, after.starts_with('{'), and the marker_prefixed check are the only remaining conditions gating this detector, and grepping the whole agent_loop.rs module turns up no other reference to starts_its_own_line or rest.starts_with('{') outside the removed block. The two new test assertions correctly target the exact regression shape from the issue (unspaced single-call and unspaced multi-line "tools listed" variants), not just a paraphrase of it. The updated doc comment on the test above (narrated_tool_call_ignores_a_tool_documented_at_the_start_of_a_line) accurately describes why the admission couldn't be made safe rather than just asserting it's gone — good, since this is exactly the kind of decision a future reader will want to re-litigate without re-discovering the same dead end.

One soft note, not a blocker: the fix intentionally narrows detection to explicit markers, so a narrated call with no marker and no space (e.g. a model literally writing create_node{"content":"Buy milk"} as a fake/hallucinated call rather than a factual report) will now also go undetected and reach the user as pseudo-code. That's the accepted tradeoff, and the PR is explicit about it, but it's worth confirming there isn't a downstream consumer (e.g. an eval or matrix scenario) that specifically pins detection of an unmarked, unspaced narrated call as a still-required behavior — if such a scenario exists it would now silently regress. I did not find one in this diff's scope, but this PR doesn't touch or re-run the eval matrix, so it's outside what this diff can self-verify.

🟢 Finding 2 — semantic_schema_count capture point and injector fix: correct

packages/core/src/ops/context_ops.rs:359-472, packages/daemon/src/services/local_agent_service.rs:2302-2355

Traced the full build_workspace_context body: semantic_schema_count = retrieved_hits.len() is captured immediately after the semantic-search branch and its parse_and_filter_non_core_schemas step, and strictly before append_schemas_named_in_query (the lexical backstop) is called on the next line. No intervening mutation of retrieved_hits or relevant_schemas sits between the capture and the lexical append — the capture point is correct as claimed.

Checked every WorkspaceContext struct-literal site in the workspace (grep -rn "WorkspaceContext {" across all packages): six sites in context_ops.rs (one production, five test) plus one in packages/agent/tests/prompt_assembly_snapshot.rs. All seven now set semantic_schema_count; the third commit in this PR exists specifically to fix the one the earlier grep missed (the integration-test fixture in a different crate), which is a good sign of the author actually re-verifying rather than trusting a first pass.

On the hydration step (related_one_hop_schemas + the filter_map re-resolution against the freshly-fetched all_schemas corpus): this is a real, if narrow, second-order effect not addressed in the PR. retrieved_hits (whose length becomes semantic_schema_count) is built straight from search results via SchemaNode::from_node; the later hydration step re-resolves each hit by id against a separately, freshly fetched all_schemas corpus, using filter_map — so a semantic hit whose id doesn't resolve in that corpus (e.g. deleted between the semantic search call and the corpus fetch a few lines later) is silently dropped from relevant_schemas but still counted in semantic_schema_count. That makes semantic_schema_count an upper bound on the true final semantic-sourced entries in relevant_schemas, not always an exact count. The direction of the error is benign — it can only make remaining_slots too small, causing mild under-injection in a rare corpus-race window, not the starvation bug this PR fixes. Not a blocker, but worth a one-line comment acknowledging the bound is an upper bound rather than an exact count, since the existing doc comment states it more absolutely than the code actually guarantees.

MAX_SCHEMAS in local_agent_service.rs (5) and MAX_SEMANTIC_SCHEMAS in context_ops.rs (5) are two independently-defined constants that happen to share a value with no shared source of truth or comment cross-referencing the other. Not a bug — semantic_schema_count is naturally bounded by MAX_SEMANTIC_SCHEMAS already — but a future change to one without the other could produce confusing behavior (e.g. MAX_SCHEMAS shrinking to 3 while MAX_SEMANTIC_SCHEMAS stays 5 means remaining_slots can legitimately saturate to 0 from semantic hits alone, which is fine, just worth knowing wasn't designed together).

🟡 Test quality: the new context_ops.rs regression test is real but narrow — doesn't exercise the actual starvation path end-to-end

packages/core/src/ops/context_ops.rs:792-212 (lexical_append_does_not_retroactively_inflate_the_semantic_count)

This test is not tautological — it does pin a real invariant (append_schemas_named_in_query must not be able to retroactively change a count captured before it ran), and if a future refactor collapsed the two-step capture-then-append sequence back into one pass, this test would legitimately catch it. So it's not worthless.

But it stops one level short of the bug described in the issue and in this PR's own commit message. The actual failure mode is: recency injector fails to inject a schema it should have, because remaining_slots computed from the wrong count. This test never touches the injector — it only asserts that semantic_schema_count (a local variable computed inline in the test, not read from a WorkspaceContext returned by the function under test) stays equal to 1 after append_schemas_named_in_query runs. It's really testing "does calling this function mutate an unrelated local variable" (which no reasonable implementation would ever fail), not "does the injector, given this exact scenario, correctly inject the schema it was starved from injecting."

There is no test anywhere in this diff (searched local_agent_service.rs for MAX_SCHEMAS/remaining_slots/semantic_schema_count — zero test hits) that constructs a WorkspaceContext-producing scenario through local_agent_service.rs's build_workspace_context wrapper with (a) several schemas named lexically in the query and (b) a recently-created schema that should be injected, and asserts the recently-created schema actually appears in the final formatted output. That's the concrete repro the issue itself describes ("define schema A then B... send a message naming only A — B is never injected"). Given this bug survived three prior review passes specifically because of test-shape gaps (per the issue's own framing), an end-to-end regression test for the injector itself — not just the arithmetic it depends on — would be the stronger investment. Recommend adding one, but given the underlying logic is independently verified correct by tracing (see Finding 2 above) and the existing test does pin something real, this is an Improvement, not a blocker.

🟢 Stale comment fix: accurate

packages/daemon/src/services/local_agent_service.rs:2317-2325

The replacement comment correctly states the injector is now "Budgeted against semantic_schema_count, NOT relevant_schemas.len()" and explains why the old bound was wrong (the lexical backstop's unbounded appends could zero out remaining_slots). This matches the actual code on the next lines. Good improvement over the old comment, which claimed a cap that no longer (and arguably never did, for the full vector) held.

Nitpicks

  • Nit: context_ops.rs — the doc comment on semantic_schema_count (the struct field) states "Count of relevant_schemas entries that came from semantic retrieval" as an unqualified fact; per the hydration-step note above, this is actually an upper bound on that count in the rare case a semantic hit fails to re-resolve against the freshly-fetched corpus. Minor wording tweak would keep the comment fully honest.
  • Nit: Two independently-defined usize = 5 constants (MAX_SCHEMAS, MAX_SEMANTIC_SCHEMAS) in different crates with the same value and no cross-reference comment tying them together — harmless today, but a future one-sided edit could produce a confusing (not incorrect) budget interaction.

Recommendation: APPROVE

Both fixes are correctly targeted at the root causes identified in issue #2261, the reasoning in the code comments and commit messages is unusually thorough and self-auditing (including the third commit fixing the author's own missed call site), and all five acceptance criteria are satisfied. The one substantive gap — the new regression test for Finding 2 pins an arithmetic invariant rather than the end-to-end injector behavior — is a real but non-blocking test-quality improvement, not a correctness issue in the shipped code; the fix itself is independently verified correct by tracing the full data flow. Nothing here should hold up merge.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2266

Review Type: Initial review (no prior reviews or comments on this PR — all three commits reviewed in full)
Scope: fe7756f, 8685dbb, ab4a26f — 4 files, origin/main...HEAD


Requirements Check (issue #2261 acceptance criteria)

# Criterion Status Evidence
1 looks_like_narrated_tool_call no longer discards a correct answer for an unspaced tool-name-then-brace shape following a newline Met agent_loop.rs:1279-1282 — the starts_its_own_line/rest.starts_with('{') disjunct is deleted; the guard is now after.starts_with('{') && marker_prefixed
2 A regression test covers the unspaced fenced-JSON shape and fails against the current code before the fix Met agent_loop.rs:5866-5871. Verified against origin/main's code: for "…was:\n```json\ncreate_node{\"content\":…", before ends with \n and rest.starts_with('{') is true, so the old disjunct fired — the assertion would have failed pre-fix. A second unspaced case ("Tools:\ncreate_node{content}\n…") is added alongside
3 append_schemas_named_in_query (or its caller) enforces a bound so it cannot alone exhaust the recency injector's slot budget Met (via the issue's second option) The issue offered "a cap, or make remaining_slots derive from the semantic-hit count". This PR took the second, which is the better choice — see Finding 3. local_agent_service.rs:2334 now reads MAX_SCHEMAS.saturating_sub(context.semantic_schema_count)
4 The stale local_agent_service.rs:2317-2319 comment is corrected Met local_agent_service.rs:2317-2325 — see Finding 5; the new text is accurate
5 bun run test:all passes with no new failures Not verified by me (main agent's gate) I ran the affected suites: nodespace-agent --lib narrated_tool_call 13/13, nodespace-core --lib context_ops 40/40 plus the new test, nodespace-agent --test prompt_assembly_snapshot 5/5, cargo check -p nodespace-daemon clean
6 bun run quality:fix passes Not verified by me —

The issue's three explicitly-deferred lower-severity items (Node Creation target resolution, the double get_all_schemas() across the module boundary, format_for_prompt truncation dropping named schemas first) are correctly not addressed here — they are out of scope per the issue text.


Code Review Findings

🟢 Finding 1 — Removing the own-line admission does not regress any detected shape (verified)

The brief asked whether any other call site or test relied on starts_its_own_line. It did not. I enumerated every positive assertion in the test module:

  • narrated_tool_call_detects_registered_tool_invocation — all four cases go through the after.starts_with('(') paren branch, untouched
  • narrated_tool_call_detects_a_json_tool_call_emitted_as_text — both cases go through the quoted-name-key branch, untouched
  • narrated_tool_call_detects_a_brace_delimited_call — all three carry an explicit marker (call:, tool:, >>>)
  • the call: create_node {…} case at agent_loop.rs:2516 — marker

Zero positive assertions depended on the removed disjunct, and looks_like_narrated_tool_call has exactly one production call site. All 13 narrated_tool_call_* tests pass. The accepted tradeoff (an unmarked own-line narrated call now slips through) is genuinely the cheaper error, and the comment at agent_loop.rs:1272-1276 states the asymmetry explicitly: a false positive discards the model's correct reply and substitutes a confirmation request, while a miss shows the user visible, recoverable pseudo-code. This is the third admission removed from this function on the same reasoning, and the accumulating pattern is itself evidence the marker-only rule is the right resting point — each broadened heuristic has been shown to fire on a correct answer.

Nit: the detector is now unreachable for any unmarked brace shape, so after.starts_with('{') is only ever evaluated in conjunction with marker_prefixed. Fine as written — reordering to short-circuit on the marker first would be a micro-optimisation on an already-trivial string scan.

🟢 Finding 2 — semantic_schema_count is captured at the correct point

context_ops.rs:395 sits between the semantic-retrieval match (ends line 388) and the lexical all_schemas fetch (line 434). No mutation of retrieved_hits occurs in between — I traced every statement. The three subsequent transformations are all after the capture:

  1. append_schemas_named_in_query (line 447) — the lexical backstop this field exists to be blind to. Correct.
  2. hydration filter_map (line 458) — re-resolves each hit against the full corpus
  3. related_one_hop_schemas (line 462) — writes related_schemas, a different field entirely

I checked every WorkspaceContext struct-literal construction site across the workspace (grep -rn "WorkspaceContext {" --include='*.rs' packages/): one production site (context_ops.rs:472), five in-crate test sites, and one cross-crate integration fixture (prompt_assembly_snapshot.rs:277). All seven are updated — the third commit ab4a26f catching the cross-crate one is the right catch, and there are no others. cargo check -p nodespace-daemon builds the whole graph clean.

There is no Default impl on WorkspaceContext and no #[non_exhaustive], so the compiler genuinely enforces exhaustiveness at every site — the right shape for a field whose whole purpose is a correctness invariant.

🟡 Finding 3 — Hydration can decouple the count from the vector, but the decoupling is benign and errs safe

This is the sharpest question in the brief, so a direct answer: yes, hydration can drop a semantic hit. At context_ops.rs:458-460 each hit is re-resolved via schemas.iter().find(|s| s.id == hit.id), and filter_map silently drops any hit with no corpus match (a schema deleted between the embedding index read and the corpus read — narrow, but real). When that happens semantic_schema_count overstates the number of semantic-sourced entries actually present in relevant_schemas.

This is immaterial, and specifically it errs in the safe direction. An overstated count makes remaining_slots smaller, so the injector injects fewer recently-created schemas than it strictly could. The failure mode is a marginally less complete prompt, not the starvation-to-zero bug being fixed, and the window requires a schema deletion mid-turn. Ordering is not a concern either: filter_map preserves relevance order, and the injector reads only the count, never positions.

Worth noting the converse holds and is worth understanding rather than fixing: semantic_schema_count can never understate the semantic contribution, because nothing between capture and construction adds to the semantic-sourced set. That one-sided error is exactly the property you want from a budget denominator. No change requested — I'd rather this stay a documented characteristic than acquire a defensive recount.

🟢 Suggestion: the doc comment at context_ops.rs:51-59 describes the field as "Count of relevant_schemas entries that came from semantic retrieval, BEFORE append_schemas_named_in_query's lexical backstop ran." Strictly it is the count of hits returned by semantic retrieval, which after hydration is an upper bound on entries present. One clause — "an upper bound after hydration, which can drop a hit whose schema vanished from the corpus mid-turn" — would close the gap between what the name promises and what it guarantees. Optional; the current text is not misleading in any way that would cause a caller to misuse it.

🟡 Finding 4 — The new regression test is weak; it does not exercise the starvation failure mode

Asked plainly, so answered plainly: lexical_append_does_not_retroactively_inflate_the_semantic_count (context_ops.rs:806-826) is close to tautological. It computes semantic_schema_count in the test body (let semantic_schema_count = semantic_hits.len();, line 813) and then asserts that this local — a value the production code never touched — still equals 1 after append_schemas_named_in_query returned. That assertion cannot fail: append_schemas_named_in_query takes semantic_hits by value, so the local was already moved. It is asserting 1 == 1.

The load-bearing assertion is the first one (hits.len() == 3), which pins the real premise: the lexical backstop appends unboundedly and can push the vector past MAX_SCHEMAS on its own. That part is genuine and valuable — it documents why the bug was reachable. But the test as a whole does not pin the bug. Nothing here would fail if someone reverted local_agent_service.rs:2334 back to context.relevant_schemas.len():

  • The capture-point correctness (semantic_schema_count assigned before the append at context_ops.rs:395, not after) is untested — moving that let below line 447 would leave the whole suite green
  • The injector's budget arithmetic is untested — the daemon-side remaining_slots line has no test at all
  • The concrete failure from the issue ("define schema A then B inside the debounce window, send a message naming only A, B is never injected") is not reproduced anywhere

Recommendation (non-blocking): assert against the struct field rather than a test-local — build a WorkspaceContext through build_workspace_context, or at minimum assert ctx.semantic_schema_count < ctx.relevant_schemas.len() on a constructed context so the two are compared to each other rather than to a constant. Better still would be a daemon-side test exercising the injector with a lexically-inflated relevant_schemas and a non-zero recently-created schema, asserting the schema is injected. That is the test that would have caught the original bug and would catch its reintroduction.

I am not blocking on this. The production fix is correct and I verified it by inspection and by tracing every construction site; the shortfall is that the test doesn't defend it, which leaves the fix vulnerable to a future refactor rather than currently broken. But this codebase has a documented history of exactly this failure class — #2261 exists because "every regression test used the same phrasing" — and this is the same shape one layer over: a test that looks like it pins an invariant but asserts around it. Worth fixing before the next change lands on this code.

🟢 Finding 5 — The corrected comment is accurate

The old text claimed "Capped at MAX_SEMANTIC_SCHEMAS total to prevent unbounded context growth" — inaccurate on two counts (the constant is MAX_SCHEMAS, and the cap never bounded relevant_schemas as a whole once the lexical backstop existed). The replacement at local_agent_service.rs:2317-2325 states the actual rule ("Budgeted against semantic_schema_count, NOT relevant_schemas.len()"), names the other writer, and explains the failure it prevents. I verified each claim against the code: the backstop does run inside build_workspace_context before this wrapper (line 447 vs. the wrapper's post-await body), it is unbounded (no cap in append_schemas_named_in_query), and it did previously zero out remaining_slots.

One accuracy point the comment gets right and is easy to miss: relevant_schemas is still not capped in total. MAX_SCHEMAS now bounds only the injector's own contribution relative to the semantic count; the lexical backstop can still push the vector past 5. The comment doesn't claim otherwise, which is precisely why it improves on the old one. The issue's deferred item about format_for_prompt truncation dropping named schemas first is the remaining consequence of that, correctly left for later.

Nit: local_agent_service.rs:2324 references #2261 inline. CLAUDE.md's documentation standard prohibits issue numbers in documentation content; the rule as written scopes to nodespace-docs, and this codebase already carries similar in-code references, so I read this as within existing convention rather than a violation. Flagging only so the call is deliberate — if the intent is that code comments follow the same standalone rule, "found in a post-merge audit" alone carries the same information.

🟢 Finding 6 — Commit hygiene and atomicity

Three commits, each a single coherent change, each with a message that explains why rather than what — including the third, which is honest about being a miss from the earlier grep rather than folding it silently into the second. That is the right call; a reader bisecting this later benefits from seeing the cross-crate fixture was a separate discovery. The two substantive fixes are unrelated to each other but both descend from the same post-merge audit of #2257 and are both named in one issue, so bundling them in one PR is reasonable rather than an atomicity violation.

The comment-to-code ratio in agent_loop.rs is high — roughly 30 lines of comment guarding a two-term boolean. Normally I'd flag that, but here the comments are a decision log recording three separately-disproven heuristics, each existing because someone previously tried the broader rule and it fired on a correct answer. That is load-bearing history, not noise. Keep it.


Recommendation

APPROVE.

Both fixes are correct, minimal, and target the real defect rather than the documented one. Finding 1's tradeoff holds under scrutiny — I verified no positive detection case relied on the removed branch. Finding 2's capture point is correct and every construction site across the workspace is updated. The stale comment is now accurate. No critical or blocking issues.

The one item I'd want followed up is Finding 4: the new regression test asserts a test-local against a constant rather than pinning the production invariant, so a revert of local_agent_service.rs:2334 would leave the suite green. Given this PR exists because a weak test let a defect through three review passes, tightening that assertion — comparing ctx.semantic_schema_count against ctx.relevant_schemas.len() on a real constructed context, or a daemon-side injector test — is worth doing before the next change touches this code. Not a merge blocker: the fix itself is sound and independently verified.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval).

Both fixes are correct and minimal. Verified: no positive narrated-call detection case relied on the removed own-line branch (all use parens, markers, or the quoted JSON name key); semantic_schema_count is captured at the correct point with all seven WorkspaceContext construction sites across the workspace updated; the corrected comment is accurate.

One non-blocking follow-up — the new regression test lexical_append_does_not_retroactively_inflate_the_semantic_count asserts a test-local against a constant rather than pinning the production invariant, so reverting local_agent_service.rs:2334 would leave the suite green. Full findings in the preceding comment.

Two items from the pragmatic-code-review of this PR:

- The prior regression test for the starvation fix pinned arithmetic
  correctness (semantic_schema_count is captured before, and stays
  untouched by, the lexical append) but never drove the actual
  injector code path in local_agent_service.rs. Added
  lexical_backstop_does_not_starve_the_recency_injector, which creates
  six schemas (five named outright in the query, one not), asserts the
  unnamed one still reaches the rendered context, and was confirmed to
  fail against the pre-fix `relevant_schemas.len()` budget before being
  checked in against the fix.
- Clarified semantic_schema_count's doc comment: it is an upper bound
  on the true final semantic-sourced count, not always exact, since
  hydration can drop a retrieval hit that no longer resolves in the
  full schema corpus. Noted the error direction is harmless (more
  conservative, never the starvation this field prevents).

Skipped: cross-referencing MAX_SCHEMAS (local_agent_service.rs) and
MAX_SEMANTIC_SCHEMAS (context_ops.rs), which the review flagged as
sharing a value (5) with no shared definition. Each constant is
already independently justified in its own doc comment for its own
call site; a cross-reference would guard against a coincidence, not a
defect — not worth the coupling for a one-line nit.
@malibio

malibio commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Address-Review Summary

Addressed the findings from the initial pragmatic-code-review.

✅ Addressed

  • 🟡 Test quality gap — added lexical_backstop_does_not_starve_the_recency_injector (packages/daemon/src/services/local_agent_service.rs), an end-to-end test that actually drives the injector code path: 5 schemas named outright in the query (enough to exhaust MAX_SCHEMAS via the lexical backstop alone) plus a 6th, unnamed, freshly-created schema. Asserts the 6th still reaches the rendered context. Confirmed this test fails against the pre-fix context.relevant_schemas.len() budget (the starved schema is dropped) and passes against the current context.semantic_schema_count budget, before checking it in.
  • 🟢 Doc nit — clarified semantic_schema_count's doc comment: it's an upper bound on the true final semantic-sourced count, not always exact (hydration can drop a retrieval hit that no longer resolves in the full corpus), and noted the error direction is harmless — it can only make a caller more conservative, never reproduce the starvation the field exists to prevent.

⏭️ Skipped

  • 🟢 Doc nit — cross-referencing MAX_SCHEMAS (local_agent_service.rs) and MAX_SEMANTIC_SCHEMAS (context_ops.rs), which happen to share a value (5) with no shared definition. Each constant is already independently justified in its own doc comment for its own call site's reasoning. A cross-reference would guard against a coincidence, not a defect — not worth the coupling for a one-line nit.

Verification

  • cargo test -p nodespace-daemon --lib — 163/163 pass (new test included)
  • cargo test -p nodespace-core --lib context_ops — 40/40 pass
  • bun run quality:fix — clean
  • bun run test:all — 227/227 frontend files, all Rust suites 0 failed
  • Full pre-push gate, including cargo test -p nodespace-app Tauri-seam tests — passed clean

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Both changes are additive and low-risk — one new test (verified against both the buggy and fixed code paths to confirm it actually pins the regression) and one doc-comment clarification with no logic change. No production code paths were modified; packages/core/src/ops/context_ops.rs and packages/daemon/src/services/local_agent_service.rs diffs are both purely additive (+72 insertions, 0 deletions). The original review's substantive findings (both fixes' correctness) were already independently re-verified rather than accepted at face value, and nothing in this round touches that logic.

The PR is ready for merge, pending the user's decision.

@malibio
malibio merged commit 30c9fc9 into main Aug 24, 2026
@malibio
malibio deleted the issue-2261-narrated-call-schema-cap branch August 24, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Narrated-call detector still discards a correct answer, and the schema-recovery backstop can starve the recency injector

1 participant