Repository navigation
Description
Split from #1922 — the concrete fix direction the confirmed golden prompt points to, separate scope from filing/measuring it there.
Background
#1922 confirmed, 3/3 reps, via a hand-authored prompt validated directly against llama.cpp (no NodeSpace assembly code, see packages/agent/tests/golden_scenario6_handauthored.rs): agent-matrix scenario 6's defect is conversation-history SIZE/SHAPE, not a model capability boundary. A ~120-word compact summary of the same underlying facts scenario 6's real history carries preserves correct resolve_query behavior; the real ~8,322-token turn-by-turn reconstruction (full verbatim assistant messages + completed_writes_message receipts) fails 100% of the time across 5 independent trials on 4 different prompt channels (all tried and refuted on #1922 — guidance reordering, injected-fact reframing, tool-description carve-outs, history-turn removal).
The golden target (confirmed, not hypothetical)
System: "You are a graph-editing assistant. When a request refers to something
indirectly (a bare value, a description) rather than by name, call resolve_query
to find it. Never ask the user to supply a node id yourself."
History (1 message): "Context: the user has an 'equipment' type with a
replacement_cost field. They logged one equipment item with replacement_cost 2400."
User: "The 2400 one came back — set it to returned"
-> resolve_query(node_type="equipment", request="The 2400 one came back — set it to returned")
3/3 reps, byte-identical tool call.
What needs to change
packages/daemon/src/services/local_agent_service.rs's node_history_from_messages (line ~1805) currently reconstructs full verbatim content for every prior user/assistant message, interleaved with completed_writes_message receipts. This needs to become (or be supplemented by) a compact fact-summary of prior turns — closer to the golden shape above — rather than full reconstruction.
Not yet measured: whether completed_writes_message's existing receipts (already fairly compact by design, per its own doc comment) are sufficient once assistant PROSE is compacted/dropped, or whether a separate summarization step is needed. That's the actual design question this issue should answer before implementing.
Constraints from prior investigation (respect these)
schema_retrieval_query/build_retrieval_queryalready blend the lastBLENDED_HISTORY_TURNS(2) raw turns for embedding purposes — that mechanism is separate from and should not be confused with what reaches the ACTING turn's message history. Do not conflate the two call sites.- Per ADR-064/Autonomous goal: drive local-agent matrix reliability to 10/12+ without turn-by-turn relay #1917's standing rule: any change to shared conversation-history assembly is exactly the class of change needing a full 12-scenario matrix gate (3+ reps) before merge — this touches every multi-turn conversation, not just scenario 6. Scenarios 5, 6, 7 all depend on this same history path within one shared chat node.
- The size breakdown in Tool-schema descriptions are 85% of the acting-turn prompt on fail-open turns; measure before trimming #1924 shows conversation-history growth (~13K chars added turn 1→2 in the measured case) is real but secondary to the ~20K-char BASE prompt (tool schemas + resident prose) present even at turn 1. This fix caps out at reducing the growth term, not the base — set expectations accordingly; Tool-schema descriptions are 85% of the acting-turn prompt on fail-open turns; measure before trimming #1924 is the base-reduction lever, this issue is the growth-term lever, and both may be needed together.
Acceptance criteria
- Design decision recorded: what exactly gets compacted (drop assistant prose entirely and rely on
completed_writes_message? Summarize prose? Something else?) and why - Implementation, gated against the golden prompt from Scenario 6: entity-types block never reaches the prompt despite successful schema retrieval (dynamic_ctx_len=0 with count=1) #1922 first (cheap, direct llama.cpp check, no daemon) before spending a full matrix run
- Full 12-scenario matrix, 3+ reps, before merge — confirm no regression on scenarios 3/4/5/6/7/8b/8d which share this history path
- Scenario 6 passes reliably (matches or approaches the golden prompt's 3/3)
Reference
- Scenario 6: entity-types block never reaches the prompt despite successful schema retrieval (dynamic_ctx_len=0 with count=1) #1922 — the investigation and confirmed golden prompt
- Tool-schema descriptions are 85% of the acting-turn prompt on fail-open turns; measure before trimming #1924 — the sibling base-prompt-size lever (tool schemas)
- Autonomous goal: drive local-agent matrix reliability to 10/12+ without turn-by-turn relay #1917 — standing matrix-gate rule and full session history
Activity
malibio commentedon Aug 2, 2026
Root cause of the design gap found: summarization exists, but triggers on a QUANTITY threshold, not the QUALITY effect already measured
Before designing a new compaction mechanism, checked whether one already exists — per the standing "reuse production components" lesson. It does:
agent_loop.rs'smaybe_summarize_history(line 2034), backed by an actual summarization prompt (prompt_templates.rs:40: "Summarize the following conversation history into key facts and context").Why it doesn't help scenario 6
maybe_summarize_historyonly triggers whenhistory_tokens + system_tokens > total_budget(HISTORY_TOKEN_BUDGET = 28,000tokens,TOTAL_TOKEN_BUDGET = 32,000). Scenario 6's full turn is ~7,500-8,500 tokens (measured directly in #1922/#1917 checkpoint 18-19) — nowhere close to that threshold. The mechanism is correctly sized to prevent context OVERFLOW; it was never sized against the dilution effect ADR-064's own Evidence section already measured (50% vs 73% success from prompt volume alone, independent of hitting any hard limit — that ablation used a 10,493-char prompt, ~2,600 tokens, an order of magnitude below where summarization triggers today).The actual design gap, stated precisely
There are two different problems being conflated under "prompt is too big":
maybe_summarize_historyalready solves this, correctly, at 28K tokens.Confirms this is real, gated, shared-surface work — not implementing blind
Lowering
HISTORY_TOKEN_BUDGET(or adding a second, lower dilution-oriented threshold) is a genuine tuning decision with a real downside risk: too aggressive risks losing context a later turn actually needs (the same risk #1813's own "carried caveat" flagged for its harness). This is exactly the class of change #1917's standing rule requires a full matrix gate for before merging — it changes what EVERY multi-turn conversation carries forward, not just scenario 6's.Recommended next step for whoever implements this
Rather than pick an arbitrary lower threshold, use the golden prompt already confirmed on this issue (~120 words / ~150-200 tokens) as a calibration point: measure where behavior degrades between that and the current 7,500-8,500-token failure case, on scenario 6's own chain, via the cheap direct-llama.cpp harness (
golden_scenario6_handauthored.rs) BEFORE spending a full matrix gate on a specific threshold choice. That turns "pick a number" into "measure a curve," consistent with this project's own standing preference for evidence over intuition on exactly this kind of prompt-size tuning.malibio commentedon Aug 2, 2026
Calibration point measured: the break happens far earlier than expected — ~412 tokens, not ADR-064's ~2,600-token scale
Ran the planned calibration experiment (
golden_medium_history_calibration, direct llama.cpp, no daemon) targeting roughly ADR-064's own measured ablation scale. Actual result:Real, distinct failure mode — not the "asks for a literal ID" pattern, but the model never emitting the tool-call trigger at all: raw output ends "...so I can set its status property correctly for when it is returned." with the grammar engine logging "Grammar still awaiting trigger after token ..." through to end of generation. Same underlying behavior class as the daemon-observed failures (declining to act, asking a clarifying-shaped question in prose) but manifesting as a malformed/absent tool call rather than a well-formed refusal this time.
This narrows the curve sharply
The break is somewhere between ~150 and ~412 tokens — an order of magnitude below ADR-064's own measured ablation scale (~2,600 tokens for the resident-prompt case). Either history-turn dilution has a much steeper/earlier curve than resident-prompt dilution, or something structural about THIS calibration point's content (not just its size) triggered the failure — I have not yet ruled out the latter. Worth being precise: this is one run, not yet a repeated/decision-grade result, and the specific content (verbose narrated assistant turns with a numbered list, matching production style) may itself be a confound distinct from pure token count.
Not concluding yet — flagging honestly
Before treating "~400 tokens" as the real threshold: (1) needs 2-3 reps to rule out single-run noise, (2) needs a control at the SAME token count but with less narratively-verbose content, to separate "size" from "shape/style" as the actual variable, since the two are conflated in this specific probe. Continuing to narrow this rather than stopping on a single data point.
malibio commentedon Aug 2, 2026
Decision-grade answer: the ~412-token break is real (3/3), and the driver is STYLE, not SIZE
Question 1: Does the ~412-token verbose-history failure reproduce?
Re-ran
golden_medium_history_calibrationtwice more (3 total reps). Fully reproducible, 3/3:All three end generation the same way: raw output trails off in prose ("...so I can set its status property correctly for when it is returned.") with the grammar engine logging "Grammar still awaiting trigger" through every remaining token to end-of-generation. Not single-run noise — this is a confirmed, repeatable failure at ~412 tokens.
Question 2: Size or style (or both)?
Added a new controlled probe,
golden_terse_matched_size_probe(new test ingolden_scenario6_handauthored.rs, committed): terse/factual content in the same style as the existing 149-tokengolden_medium_history_terse_control, but extended with additional true (non-repetitive) facts to land at 1,602 chars (~400 tokens est.) — matched to within 3% of the failing verbose calibration point's 1,651 chars, same underlying facts (equipment schema, replacement_cost field, one item at 2400).Ran 2 reps:
Both reps produce a correct, well-formed
resolve_querycall — same tool, same reasonable arguments — at the identical token count where the verbose/narrative version fails 3/3.Conclusion (multi-rep confirmed, not single-rep directional)
Style is the driver, not raw token count. At matched size (~400-412 tokens):
This directly contradicts a pure-dilution/pure-size threshold model and has a concrete design implication: if
maybe_summarize_history(or a new lower-threshold compaction step) is added to address this, the summary's prose style matters as much as, or more than, hitting some token budget. A compaction step that produces a narratively-styled summary (which is the natural output style of an LLM asked to "summarize the conversation," per the existingprompt_templates.rs:40prompt: "Summarize the following conversation history into key facts and context") could still trigger this failure mode even at a fraction of current history size, if its output reads like prose rather than terse facts. A summarization prompt or post-process that specifically constrains to short factual bullet statements is more likely to help than one that just aims for fewer tokens.Caveats / what's still open
maybe_summarize_historythreshold/mechanism change is still open, pending a design decision informed by this finding (terse-factual compaction, not narrative summarization).Test infrastructure
New test committed:
golden_terse_matched_size_probeinpackages/agent/tests/golden_scenario6_handauthored.rs(commit 013a6dc on main). Fullcargo test -p nodespace-agent --libsuite green (425 passed) before commit. Run with:malibio commentedon Aug 2, 2026
Real-pipeline verification: history compaction works for its core purpose, but exposes a second, independent gap in
update_node's schemaRecovered two interrupted implementation attempts (both stashed rather than lost when stopped mid-task), moved the more complete one into a proper worktree (
issue-1925-history-compaction) per the corrected workflow, and independently verified it against real source and the real model — twice, after finding and fixing two process issues along the way (a stray duplicate-process contamination from acdmishap, cleaned up withmainconfirmed unaffected; and a stale worktree base missing 6 unpushed local commits including the golden sequence itself, fixed via a local rebase/reset — no push tooriginperformed, that's pending explicit go-ahead).The fix, verified
packages/daemon/src/services/local_agent_service.rs'snode_history_from_messagesnow renders prior ASSISTANT turns as terse "Fact: ..." statements derived from their structuredcompleted_writesrecord, instead of the model's own narrative reply. Deterministic test (real_pipeline_renders_terse_facts_not_narrative_prose, no model call) confirms the real production code produces exactly the golden shape:The live-model check: a real, reproducible partial result
Fed this exact real-pipeline-rendered history into turn 3 against bare llama.cpp, twice (once contaminated/discarded, once on a properly clean single-process run after the base fix — both gave the same answer, so this is trustworthy):
This is a materially better outcome than any prior scenario-6 failure mode measured this session — no request for a literal ID, no fabrication, no zero-tool-call stall. The model correctly resolved "the 2400 one" to the exact right node id from the terse-fact history. That is direct evidence the compaction fix accomplishes its actual goal (defeating the narrative-prose dilution effect).
But it is not a full pass. The model skipped
resolve_query(going straight toupdate_node, since the fact already stated the id) and, more importantly, calledupdate_nodewith noproperties— so "set it to returned" never actually gets applied. Checked whether this is a test-harness artifact (my hand-authoredupdate_nodetool only requiresid) — it is not: production's realdef_update_node(tools.rs:596) has the identical shape,propertiesoptional,idthe only required field. This is a real, previously-undiscovered gap: nothing inupdate_node's description or the terse fact tells the model which property key corresponds to "returned" (the terse fact statesisReturned falseas a past value, not as "this is the field name for return status").Assessment
Two separable findings:
update_node's tool schema/description — it doesn't guide the model toward which property to set for a state-change request like "returned," even when the model has correctly identified the node. This is NOT this issue's scope and is a different mechanism than history dilution — flagging as a candidate new issue rather than scope-creeping this one.Not committed, not pushed
Work is on a worktree (
issue-1925-history-compaction, branched correctly from localmain@35f0154dafter the base-fix), verified against the real deterministic test and 2 consistent live-model reps (not yet the full 3-rep matrix gate this session's rule 3 requires before any merge). Six prior local commits including this golden work remain unpushed tooriginpending explicit confirmation. Next steps, pending direction: (a) get the compaction fix to a full pass on scenario 6 by also addressing theupdate_nodeproperty-targeting gap, or (b) commit the compaction fix alone (real, verified improvement on its own terms) and file theupdate_nodegap separately, or (c) push localmaintooriginso future worktrees don't hit the stale-base issue again, independent of this fix's fate.WIP: matrix gate RESULTS for #1925's compaction fix (94e4aa2) — 9.0/1…
Render prior assistant turns as terse facts instead of narrative prose
malibio commentedon Aug 3, 2026
Closing — the fix is merged (
6321f3d5,node_history_from_messagesrenders prior assistant turns as terse facts). Verified against real production code (not a hand-authored stand-in) and against the real model: the compaction defeats the narrative-prose dilution effect and gets the model to correctly resolve the target node from history. Matrix-gated clean, no regressions attributable to this change. The second finding surfaced along the way (update_node persists no properties on state-change requests) is a genuinely separate mechanism, correctly split out as #1927 rather than folded in here.