Skip to content

Compact conversation history in the acting-turn prompt toward the confirmed scenario-6 golden shape #1925

Closed

Description

@malibio

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)

Acceptance criteria

Reference

Activity

  1. malibio commented on Aug 2, 2026

    @malibio
    CollaboratorAuthor

    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's maybe_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_history only triggers when history_tokens + system_tokens > total_budget (HISTORY_TOKEN_BUDGET = 28,000 tokens, 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":

    1. Context overflow — maybe_summarize_history already solves this, correctly, at 28K tokens.
    2. Dilution-driven behavior degradation — ADR-064 measured this kicks in far earlier (order of magnitude smaller), and nothing currently guards against it. Scenario 6 sits in this gap: too big to avoid dilution, nowhere near big enough to trigger the existing safety valve.

    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.

  2. malibio commented on Aug 2, 2026

    @malibio
    CollaboratorAuthor

    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:

    history char count: 1,651 (~412 tokens, well short of the ~2,000-2,500 target due to a padding-verbosity miscalibration on my part)
    GOLDEN[medium-history]: no tool call parsed
    

    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

    ~150 tokens (compact golden, #1922):  PASSES 3/3, correct resolve_query call
    ~412 tokens (this calibration point): FAILS (no tool call at all)
    ~7,500-8,500 tokens (real scenario):  FAILS 3/3, asks for literal ID
    

    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.

  3. malibio commented on Aug 2, 2026

    @malibio
    CollaboratorAuthor

    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_calibration twice more (3 total reps). Fully reproducible, 3/3:

    Rep 1 (prior comment): 1,651 chars (~412 tokens) -> no tool call parsed
    Rep 2 (this session):  1,651 chars (~412 tokens) -> no tool call parsed
    Rep 3 (this session):  1,651 chars (~412 tokens) -> no tool call parsed
    

    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 in golden_scenario6_handauthored.rs, committed): terse/factual content in the same style as the existing 149-token golden_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:

    Rep 1: 1,602 chars (~400 tokens) -> resolve_query({"node_type":"equipment_item","request":"The 2400 one"})  [PASS]
    Rep 2: 1,602 chars (~400 tokens) -> resolve_query({"node_type":"equipment_item","request":"The 2400 one"})  [PASS]
    

    Both reps produce a correct, well-formed resolve_query call — 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):

    • Narrative/verbose history (paragraphs, numbered lists, questions back to the user — the actual production assistant-turn style): fails 3/3
    • Terse/factual history (short declarative "Fact: ..." statements, same content): passes 2/2

    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 existing prompt_templates.rs:40 prompt: "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

    • n=2 on the terse-matched probe (both pass) vs n=3 on the verbose calibration (all fail) — asymmetric rep counts, but 2/2 clean passes against a robust 3/3 fail at the identical size is a strong enough contrast to call this confirmed rather than directional, per the bounded-calibration scope of this task.
    • Have not run the optional cross-check (verbose-style at ~150-200 tokens, matched to the passing terse control's size) — the terse-matched-size probe alone already cleanly separates the two variables, and running it would mostly confirm the same direction rather than add new discriminating information. Left out of scope for this bounded round; flagging in case a future round wants full symmetric coverage of the 2x2 (size x style) grid.
    • This still doesn't explain why the real ~7,500-8,500 token production history fails in a different way (asks for a literal ID, rather than emitting no tool call at all) — the two failure modes may sit on different parts of the same curve, or may be qualitatively different problems. Not addressed by this round.
    • No fix implemented here, per scope — this is measurement only. The maybe_summarize_history threshold/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_probe in packages/agent/tests/golden_scenario6_handauthored.rs (commit 013a6dc on main). Full cargo test -p nodespace-agent --lib suite green (425 passed) before commit. Run with:

    cargo test -p nodespace-agent --test golden_scenario6_handauthored golden_terse_matched_size_probe -- --ignored --nocapture --test-threads=1
    
  4. malibio commented on Aug 2, 2026

    @malibio
    CollaboratorAuthor

    Real-pipeline verification: history compaction works for its core purpose, but exposes a second, independent gap in update_node's schema

    Recovered 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 a cd mishap, cleaned up with main confirmed unaffected; and a stale worktree base missing 6 unpushed local commits including the golden sequence itself, fixed via a local rebase/reset — no push to origin performed, that's pending explicit go-ahead).

    The fix, verified

    packages/daemon/src/services/local_agent_service.rs's node_history_from_messages now renders prior ASSISTANT turns as terse "Fact: ..." statements derived from their structured completed_writes record, 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:

    [1] Assistant: Fact: a schema with id 'equipment_checkout_record' ('Equipment Checkout Record') was created, with fields isReturned (boolean), replacementCost (number).
    [4] Assistant: Fact: a equipment_checkout_record node was created with title 'Laser Cutter' and properties isReturned false, replacementCost 2400 (id nodespace://laser-cutter-node).
    

    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):

    REAL-PIPELINE[turn3]: update_node({"id":"nodespace://laser-cutter-node"})
    

    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 to update_node, since the fact already stated the id) and, more importantly, called update_node with no properties — so "set it to returned" never actually gets applied. Checked whether this is a test-harness artifact (my hand-authored update_node tool only requires id) — it is not: production's real def_update_node (tools.rs:596) has the identical shape, properties optional, id the only required field. This is a real, previously-undiscovered gap: nothing in update_node's description or the terse fact tells the model which property key corresponds to "returned" (the terse fact states isReturned false as a past value, not as "this is the field name for return status").

    Assessment

    Two separable findings:

    1. The compaction fix (this issue's actual scope) works — it defeats the dilution effect and gets the model to correctly identify the target node from real production history. This is real progress.
    2. A second, independent gap exists in 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 local main @ 35f0154d after 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 to origin pending explicit confirmation. Next steps, pending direction: (a) get the compaction fix to a full pass on scenario 6 by also addressing the update_node property-targeting gap, or (b) commit the compaction fix alone (real, verified improvement on its own terms) and file the update_node gap separately, or (c) push local main to origin so future worktrees don't hit the stale-base issue again, independent of this fix's fate.

  5. malibio commented on Aug 3, 2026

    @malibio
    CollaboratorAuthor

    Closing — the fix is merged (6321f3d5, node_history_from_messages renders 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions