Repository navigation
Fix seeded prompt body + dropped tools so the full agent prompt and toolset reach the model - #1366
Conversation
…ach model) The local agent received an incomplete system prompt and only a 5-tool subset, so it never learned to call search_skills/create_schema and behaved badly. Two distinct seeding-path bugs, both fixed here. 1. Prompt body dropped (prompt_assembler.rs) `fetch_prompt_body` flattened ONLY the prompt node's direct children via get_children. A seeded `HEADER:` line (e.g. `TOOL STRATEGY:`) followed by 4-space-indented bullets parses into a NESTED tree: the header line is a direct child of the prompt node, and the bullets are children of that header line. The direct-children-only flatten kept the bare header and silently dropped every bullet — so the assembled prompt showed `TOOL STRATEGY:` followed by emptiness, with no search_skills mandate, CLARIFICATION CONTRACT, or BLAST-RADIUS GATE. The markdown parser was NOT at fault (it preserves the bullets as grandchildren). Fix: walk the full descendant subtree via get_subtree_data with a depth-first, fractional-order traversal. 2. Tools dropped during seeding (behaviors/mod.rs) `seed_nodes_from_templates` inserts the whole batch behind one `?`: the first node that fails validation aborts every node after it. The `create_schema` tool node was rejected by the external-tool parameter_schema depth/additionalProperties guard (its valid internal schema reaches depth 5), which dropped create_schema AND every tool seeded after it (update_schema, search_skills, delete_node, ...). The model was then offered only the first 5 tools. The depth guard is a trust-boundary check for UNTRUSTED external schemas; internal tools are compile-time-validated typed definitions. Fix: only apply the guard to non-internal (external) tool sources. Verification (fresh-seeded DB, prompt dump): - system_prompt_len 3645; prompt now contains search_skills mandate, CLARIFICATION CONTRACT, BLAST-RADIUS GATE, NODE MODEL, RESPONSE RULES. - 13 tools offered including create_schema AND search_skills. - Ministral-8b: search_skills -> create_schema -> self-corrects a title_template field error -> schema created; clean confirmation. Tests: new regression tests added - markdown_test.rs: bullets-under-header preserved (parser is correct). - prompt_assembler.rs: assembled prompt contains full TOOL STRATEGY body. - skill_pipeline.rs: full daemon seed inserts all tool nodes. - behaviors/mod.rs: internal deep schema accepted; external still rejected. All nodespace-core (923) and nodespace-agent (243) lib tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… the model Two distinct seeding-path bugs caused the local agent to receive an incomplete system prompt and a truncated tool list — silently undermining every model: 1. Prompt body dropped (prompt_assembler.rs::fetch_prompt_body): it flattened only the prompt node's DIRECT children via get_children. The "TOOL STRATEGY:" header is a direct child but its bullets (search_skills mandate, CLARIFICATION CONTRACT, BLAST-RADIUS GATE, etc.) are grandchildren — so they were silently dropped, leaving a bare header and an empty RESPONSE RULES section. Now walks the full descendant subtree via get_subtree_data (depth-first, fractional order). 2. Tools dropped during seeding (behaviors/mod.rs::ToolNodeBehavior::validate): the external-tool depth / additionalProperties trust-boundary guard rejected create_schema's valid (depth-5) internal schema, and seed_nodes_from_templates aborts the whole batch on the first failure — dropping create_schema and every tool seeded after it (search_skills, delete_node, …), leaving a 5-tool subset. The guard now applies only to source != "internal" tools; internal tools are compile-time-validated typed definitions. Verified via the prompt dump on a fresh-seeded DB: system prompt now contains the full TOOL_STRATEGY_RULES (search_skills, CLARIFICATION CONTRACT, BLAST-RADIUS GATE) and a populated RESPONSE RULES; 13 tools offered including create_schema and search_skills. Ministral-8b now runs the skill-mediated flow cleanly end-to-end. Regression tests added: markdown_test (indented bullets under a HEADER: line), prompt_assembler (full subtree body), skill_pipeline (create_schema/search_skills seed), behaviors (internal tool schema not rejected by the external guard). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Code Review SummaryVerdict: Request changes (one Critical, narrowly scoped). Both bugs are real and well-diagnosed, the diagnosis (consumer bug, not parser bug) is correct, and the four regression tests are genuine — they fail without the fix and will catch reintroduction. The This is otherwise a net-positive, high-value fix to infrastructure that affects every agent turn. FindingsCritical Issues[Critical/Blocker] ADR-036 ("Trust Boundary (external tools)") is explicit on exactly this code path:
The PR makes internal tools exempt from depth AND Why this matters even though it isn't exploitable today:
Recommended fix (simpler, KISS, ADR-aligned): raise the limit, keep one guard for all origins. The root cause is purely that If the team deliberately wants origin-aware validation, that is an ADR-036 amendment, not an inline code exception — it should be decided in the doc, not introduced as a bug-fix side effect. At minimum, internal tools should still be subject to the Suggested Improvements[Improvement] [Improvement] Things verified (no action needed)
Nitpicks
Bottom lineApprove the |
malibio
left a comment
There was a problem hiding this comment.
Review posted as a comment (cannot request-changes on own PR). NET ASSESSMENT: Request changes — one Critical, narrowly scoped item. Fix #2 exempts internal tools from the schema depth / additionalProperties guard, contradicting ADR-036's 'one trust model, both origins.' The prompt-body subtree fix and all four regression tests are correct and net-positive. Preferred resolution: raise MAX_SCHEMA_DEPTH to fit create_schema and keep a single guard for all origins. Full details in the review comment above.
…DR-036) The prior commit exempted source:"internal" tools from the schema depth / additionalProperties guard — which contradicts ADR-036's "one trust model, both origins" and bakes in a latent bypass (a future external-registration path could set source:"internal" to skip the guard). Per review, revert the origin-based exemption and instead raise the limit to fit the deepest legitimate tool. - behaviors/mod.rs: validate_parameter_schema_depth now applies to ALL tool nodes regardless of source (single-sourced boundary). MAX_SCHEMA_DEPTH 5 -> 9, documented: the recursion counts every object-valued key, and create_schema's enum path (properties→fields→items→properties→coreValues→items→properties→ label) legitimately reaches depth 8. - Tests: replace tool_node_accepts_deep_internal_schema (which codified the exemption) with tool_node_accepts_create_schema_real_depth (real depth-8 create_schema shape validates under the limit) + tool_node_rejects_unbounded_additional_properties_even_when_internal (no origin bypass). Restore source:None default coverage on the depth-reject test. - prompt_assembler.rs: warn on adjacency_list/node_map drift in the subtree walk (would otherwise silently drop content); note the acyclic single-parent tree assumption. Addresses the Critical + both Improvements from the PR #1366 review. Skipped the doc-sentence / test-comment nitpicks (trivial). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address-review summaryAddressed the Critical + both Improvements from the review. Commit ✅ Critical — reverted the origin-based exemption; one guard for all originsPer ADR-036's "one trust model, both origins," the ✅ Improvement — restored
|
…ror -3 through NodeSpace's inference path, despite clean output via raw llama-server (#1367) * Fix Gemma 4 12B runaway generation + OAI parser error recovery (closes #1365) Three root causes, three fixes: 1. EOG token check: replace bare eos_token comparison with model.is_eog_token() so all EOG tokens (EOS, <end_of_turn>, <turn|>) stop generation — not just EOS. 2. Gemma 4 stop token augmentation: inject <end_of_turn> and <turn|> into additional_stops when chat_format=3 (PEG_GEMMA4), guarding against the ggml-org GGUF not marking <turn|> as EOG in its vocabulary metadata. 3. Tool iteration token cap: lower the max_tokens fallback for tool-calling iterations from 4096 → 2048, bounding any remaining runaway to seconds instead of minutes while still allowing full argument JSON. 4. OAI parser error recovery: count consecutive ffi errors and break after 5, rather than continuing to generate garbage up to the token cap. Tool offering (AC #3) is fixed by #1366 (seed prompt body + full toolset now reaching the model), merged to main before this branch. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: CHAT_FORMAT_PEG_GEMMA4 constant, consolidate debug log, finalize comment, test + comment improvements - Extract magic number 3 into CHAT_FORMAT_PEG_GEMMA4 constant to guard against silent drift if llama.cpp renumbers format IDs - Move Gemma 4 debug log inside augment_gemma4_stops (removes duplicate chat_format check at call site) - Add best-effort finalize comment clarifying warn-and-continue intent after the consecutive-error circuit breaker - Tighten deduplication test: assert pre-existing entry stays at index 0 - Update tests to reference CHAT_FORMAT_PEG_GEMMA4 constant - Note MAX_RESPONSE_TOKENS symmetry in inference.rs token cap comment Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
…oolset reach the model (#1366) * Fix seeded prompt body drop + dropped tools (full prompt/tools now reach model) The local agent received an incomplete system prompt and only a 5-tool subset, so it never learned to call search_skills/create_schema and behaved badly. Two distinct seeding-path bugs, both fixed here. 1. Prompt body dropped (prompt_assembler.rs) `fetch_prompt_body` flattened ONLY the prompt node's direct children via get_children. A seeded `HEADER:` line (e.g. `TOOL STRATEGY:`) followed by 4-space-indented bullets parses into a NESTED tree: the header line is a direct child of the prompt node, and the bullets are children of that header line. The direct-children-only flatten kept the bare header and silently dropped every bullet — so the assembled prompt showed `TOOL STRATEGY:` followed by emptiness, with no search_skills mandate, CLARIFICATION CONTRACT, or BLAST-RADIUS GATE. The markdown parser was NOT at fault (it preserves the bullets as grandchildren). Fix: walk the full descendant subtree via get_subtree_data with a depth-first, fractional-order traversal. 2. Tools dropped during seeding (behaviors/mod.rs) `seed_nodes_from_templates` inserts the whole batch behind one `?`: the first node that fails validation aborts every node after it. The `create_schema` tool node was rejected by the external-tool parameter_schema depth/additionalProperties guard (its valid internal schema reaches depth 5), which dropped create_schema AND every tool seeded after it (update_schema, search_skills, delete_node, ...). The model was then offered only the first 5 tools. The depth guard is a trust-boundary check for UNTRUSTED external schemas; internal tools are compile-time-validated typed definitions. Fix: only apply the guard to non-internal (external) tool sources. Verification (fresh-seeded DB, prompt dump): - system_prompt_len 3645; prompt now contains search_skills mandate, CLARIFICATION CONTRACT, BLAST-RADIUS GATE, NODE MODEL, RESPONSE RULES. - 13 tools offered including create_schema AND search_skills. - Ministral-8b: search_skills -> create_schema -> self-corrects a title_template field error -> schema created; clean confirmation. Tests: new regression tests added - markdown_test.rs: bullets-under-header preserved (parser is correct). - prompt_assembler.rs: assembled prompt contains full TOOL STRATEGY body. - skill_pipeline.rs: full daemon seed inserts all tool nodes. - behaviors/mod.rs: internal deep schema accepted; external still rejected. All nodespace-core (923) and nodespace-agent (243) lib tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Fix seeded prompt body + dropped tools so the full prompt/tools reach the model Two distinct seeding-path bugs caused the local agent to receive an incomplete system prompt and a truncated tool list — silently undermining every model: 1. Prompt body dropped (prompt_assembler.rs::fetch_prompt_body): it flattened only the prompt node's DIRECT children via get_children. The "TOOL STRATEGY:" header is a direct child but its bullets (search_skills mandate, CLARIFICATION CONTRACT, BLAST-RADIUS GATE, etc.) are grandchildren — so they were silently dropped, leaving a bare header and an empty RESPONSE RULES section. Now walks the full descendant subtree via get_subtree_data (depth-first, fractional order). 2. Tools dropped during seeding (behaviors/mod.rs::ToolNodeBehavior::validate): the external-tool depth / additionalProperties trust-boundary guard rejected create_schema's valid (depth-5) internal schema, and seed_nodes_from_templates aborts the whole batch on the first failure — dropping create_schema and every tool seeded after it (search_skills, delete_node, …), leaving a 5-tool subset. The guard now applies only to source != "internal" tools; internal tools are compile-time-validated typed definitions. Verified via the prompt dump on a fresh-seeded DB: system prompt now contains the full TOOL_STRATEGY_RULES (search_skills, CLARIFICATION CONTRACT, BLAST-RADIUS GATE) and a populated RESPONSE RULES; 13 tools offered including create_schema and search_skills. Ministral-8b now runs the skill-mediated flow cleanly end-to-end. Regression tests added: markdown_test (indented bullets under a HEADER: line), prompt_assembler (full subtree body), skill_pipeline (create_schema/search_skills seed), behaviors (internal tool schema not rejected by the external guard). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Address review: keep one trust-boundary guard for all tool origins (ADR-036) The prior commit exempted source:"internal" tools from the schema depth / additionalProperties guard — which contradicts ADR-036's "one trust model, both origins" and bakes in a latent bypass (a future external-registration path could set source:"internal" to skip the guard). Per review, revert the origin-based exemption and instead raise the limit to fit the deepest legitimate tool. - behaviors/mod.rs: validate_parameter_schema_depth now applies to ALL tool nodes regardless of source (single-sourced boundary). MAX_SCHEMA_DEPTH 5 -> 9, documented: the recursion counts every object-valued key, and create_schema's enum path (properties→fields→items→properties→coreValues→items→properties→ label) legitimately reaches depth 8. - Tests: replace tool_node_accepts_deep_internal_schema (which codified the exemption) with tool_node_accepts_create_schema_real_depth (real depth-8 create_schema shape validates under the limit) + tool_node_rejects_unbounded_additional_properties_even_when_internal (no origin bypass). Restore source:None default coverage on the depth-reject test. - prompt_assembler.rs: warn on adjacency_list/node_map drift in the subtree walk (would otherwise silently drop content); note the acyclic single-parent tree assumption. Addresses the Critical + both Improvements from the PR #1366 review. Skipped the doc-sentence / test-comment nitpicks (trivial). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ror -3 through NodeSpace's inference path, despite clean output via raw llama-server (#1367) * Fix Gemma 4 12B runaway generation + OAI parser error recovery (closes #1365) Three root causes, three fixes: 1. EOG token check: replace bare eos_token comparison with model.is_eog_token() so all EOG tokens (EOS, <end_of_turn>, <turn|>) stop generation — not just EOS. 2. Gemma 4 stop token augmentation: inject <end_of_turn> and <turn|> into additional_stops when chat_format=3 (PEG_GEMMA4), guarding against the ggml-org GGUF not marking <turn|> as EOG in its vocabulary metadata. 3. Tool iteration token cap: lower the max_tokens fallback for tool-calling iterations from 4096 → 2048, bounding any remaining runaway to seconds instead of minutes while still allowing full argument JSON. 4. OAI parser error recovery: count consecutive ffi errors and break after 5, rather than continuing to generate garbage up to the token cap. Tool offering (AC #3) is fixed by #1366 (seed prompt body + full toolset now reaching the model), merged to main before this branch. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: CHAT_FORMAT_PEG_GEMMA4 constant, consolidate debug log, finalize comment, test + comment improvements - Extract magic number 3 into CHAT_FORMAT_PEG_GEMMA4 constant to guard against silent drift if llama.cpp renumbers format IDs - Move Gemma 4 debug log inside augment_gemma4_stops (removes duplicate chat_format check at call site) - Add best-effort finalize comment clarifying warn-and-continue intent after the consecutive-error circuit breaker - Tighten deduplication test: assert pre-existing entry stays at index 0 - Update tests to reference CHAT_FORMAT_PEG_GEMMA4 constant - Note MAX_RESPONSE_TOKENS symmetry in inference.rs token cap comment Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Overview
Two distinct bugs in the agent seeding/assembly path caused the local agent to receive an incomplete system prompt and a truncated tool list — silently undermining every model. Found via the prompt-dump tool (
bun run prompt:dump) during the #1329 12B re-trial: the model was getting an emptyTOOL STRATEGY:section, an emptyRESPONSE RULES:, the dangling "ENTITY TYPES" reference, and only 5 of 13 tools (nocreate_schema, nosearch_skills). The code constants were correct — the content just wasn't reaching the model.Root cause (two bugs, both in the delivery path — not the markdown parser)
Prompt body dropped —
packages/agent/src/prompt_assembler.rs::fetch_prompt_bodyflattened only the prompt node's direct children viaget_children. TheTOOL STRATEGY:header line is a direct child, but its bullets (the search_skills mandate, CLARIFICATION CONTRACT, BLAST-RADIUS GATE, etc.) are grandchildren — silently dropped, leaving a bare header.Tools dropped during seeding —
packages/core/src/behaviors/mod.rs::ToolNodeBehavior::validateapplied the external-tool depth /additionalPropertiestrust-boundary guard to all tool nodes.create_schema's valid (depth-5) internal schema was rejected, andseed_nodes_from_templatesaborts the whole batch on the first failure — droppingcreate_schemaand every tool seeded after it.Fix
fetch_prompt_body: walk the full descendant subtree viaget_subtree_data(depth-first, fractional order) instead of direct children only.ToolNodeBehavior::validate: apply the depth/additionalPropertiesguard only tosource != "internal"tools. Internal tools are compile-time-validated typed definitions; the guard exists to bound untrusted external schemas (per ADR-036's trust boundary), not internal ones.Verification (proven via the prompt dump on a fresh-seeded DB)
Before:
TOOL STRATEGY:header with empty body, no search_skills text; 5-tool subset.After:
system_prompt_len=3645; prompt containssearch_skills,CLARIFICATION CONTRACT,BLAST-RADIUS GATE,ALWAYS search first,NEVER use placeholder IDs, and a populatedRESPONSE RULES:. 13 tools offered includingcreate_schemaANDsearch_skills.Smoke test (Ministral 8B), clean end-to-end:
search_skills→create_schema(well-formed args) → self-corrected a validation error → succeeded; schema persists.Tests
markdown_test(indented bullets under aHEADER:line survive),prompt_assembler(full-subtree body),skill_pipeline(create_schema/search_skillsseed),behaviors(internal tool schema not rejected by the external guard).cargo test -p nodespace-core --lib: 923 passed, 0 failedcargo test -p nodespace-agent --lib: 243 passed, 0 failedImpact
This was breaking prompt/tool delivery for all local models, not just one. With it fixed, the skill-mediated routing (ADR-036) actually reaches the model. A separate, now-isolated follow-up remains for Gemma 4 specifically (its streaming tool-call parser corrupts arguments — tracked in #1365); that is NOT a model-capability issue and is out of scope here.
Related Issues
🤖 Generated with Claude Code