Skip to content

Prompt-assembly snapshot gate: assert production reproduces the tuned golden prompt (zero model calls) #2119

Closed

Description

@malibio

Overview

Once a golden prompt is tuned and frozen, assert — with zero model calls — that NodeSpace's assembly line actually produces it. This is the half of the golden-prompt methodology that was specified but never written, and it is what converts a tuned prompt from a finding in a test file into a target the production pipeline is held to.

packages/agent/tests/live_stage1_golden_prompts.rs names the gap in its own header:

separate "does this exact prompt text get the right tool call" (answerable here, in seconds) from "does the real pipeline assemble that exact prompt from real inputs" (a distinct, deterministic, zero-model-call question — the snapshot tests this golden set feeds, not yet written).

Problem Statement

Without this gate, prompt tuning has no teeth. A golden prompt can be hand-authored, validated at N/N against the live model, and checked in — and production can still assemble something materially different, with nothing failing. That is precisely what happened around scenario 6: a hand-authored prompt got the correct resolve_query call 3/3, while production fired it 0/8, and the difference was never pinned down as an assembly divergence because nothing compared the two.

It also makes prompt regressions invisible. Resident prose, tool descriptions, skill guidance, and the Stage-2 candidate block are edited independently across agent_guidance.rs, tools.rs, skill_pipeline.rs, and routing.rs. Any of those edits silently changes what the model receives, and today no test notices.

Proposed design

A deterministic, zero-model-call test that reconstructs the assembled prompt from real production inputs and compares it to a checked-in golden file.

The comparison must cover what the model actually receives, which is assembled at several sites:

  • PromptAssembler::assemble() — the resident system prompt from seeded prompt nodes
  • routing::render_candidates_for_prompt() — the Stage-2 candidate block and its instruction subtrees
  • routing::stage2_tools() — the scoped tool surface (names, descriptions, parameter schemas)
  • STAGE1_SYSTEM_PROMPT + stage1_tool_definitions() — the Stage-1 request
  • The RELEVANT ENTITY TYPES block, which reaches the prompt from two independent sites (Stage-2 candidate block and resident workspace context)

Failure output must be a readable diff. A byte-equality assertion that prints two 8KB blobs is not actionable; the whole point is to show which line of guidance moved.

Fixture inputs, not a live database

Assembly depends on seeded prompt/skill nodes, retrieved candidates, and workspace context. Those must come from committed fixtures so the test is hermetic and deterministic — no DB, no daemon, no embedding service, no model. It should run in the normal test suite, not behind --ignored.

Update workflow

Changing a prompt should be a deliberate two-step: update the golden file, and the test passes. An accidental change to tools.rs or agent_guidance.rs fails the gate and has to be acknowledged. Provide an explicit regeneration path (env var or bin flag) so updating goldens is one command rather than hand-editing, but never auto-update on failure.

Relationship to the tuning loop

The runner issue produces case files that are validated against the live model. The frozen prompt text from a passing case becomes the golden this test asserts against. The two halves close the loop:

  1. Tune the prompt as data against llama.cpp until it reliably does the right thing
  2. Freeze it as a golden
  3. This gate fails until production assembly reproduces it
  4. Fix the assembly line (delete prose the tuned version proved unnecessary, move content to the channel that owns it per ADR-064)

Acceptance Criteria

  • Zero-model-call test asserting production assembly matches a checked-in golden prompt
  • Covers the resident system prompt (PromptAssembler::assemble())
  • Covers the Stage-2 candidate block (render_candidates_for_prompt()) including rendered instruction subtrees
  • Covers the scoped tool surface (stage2_tools()) — tool names, descriptions, and parameter schemas
  • Covers the Stage-1 request (STAGE1_SYSTEM_PROMPT + stage1_tool_definitions())
  • Fixture-driven: no DB, no daemon, no embedding service, no model; runs in the default test suite
  • Failure output is a readable diff identifying which section changed, not a raw blob comparison
  • Explicit golden-regeneration command; goldens never auto-update on failure
  • Editing any model-facing constant (agent_guidance.rs, tools.rs, skill_pipeline.rs, routing render fns) without updating its golden fails the test — verified by an actual edit

Out of scope

  • The live-model tuning runner — separate issue
  • Authoring the dev-domain golden corpus — separate issue
  • Changing production prompt text; this issue only makes drift visible

Notes

  • ADR-064 makes this a standing measurement surface: it fixes which channel owns which category of instruction, and its own evidence shows a shipped contradiction (coreValues in the tool schema vs core_values in resident prose) reaching the model in the same prompt. A diff gate over the assembled prompt is what would have surfaced that.
  • Prompt size is a hardware-requirements input via ADR-062 (context window budgeted against total RAM), so unnoticed prompt growth has consequences beyond token cost.
  • NODESPACE_PROMPT_DUMP captures the real final string at the native-path chokepoint and can be used to verify the reconstruction matches an actual live session.

Activity

  1. malibio commented on Aug 17, 2026

    @malibio
    CollaboratorAuthor

    Paired with #2118 (the live-model tuning runner). #2118 produces the validated prompt text; this issue is what holds production to it.

    Sequencing note: #2119 is independently useful and can land first. Even before any golden is re-tuned, a snapshot of today's assembled prompt turns the four independently-edited model-facing surfaces (agent_guidance.rs, tools.rs, skill_pipeline.rs, routing.rs render fns) into a reviewable diff. That alone would have caught the coreValues/core_values contradiction ADR-064 documents as shipped in production.

  2. malibio commented on Aug 17, 2026

    @malibio
    CollaboratorAuthor

    Sequencing: #2118 → #2120 → #2119 → #1977

    These four are one line of work. Recording the order and the reasoning so it survives a context reset.

    # issue why here
    1 #2118 — golden-prompt runner Nothing else can proceed without a fast tuning loop. No domain decisions, no live-measurement dependency.
    2 #2120 — retarget guidance + trim The substantive manual work. Needs #2118 to be iterable; must precede the eval retarget.
    3 #2119 — assembly snapshot gate Freezes the tuned prompt as production's target. Placed after #2120 so the golden is captured once, not churned through a wholesale rewrite.
    4 #1977 — matrix + routing fixtures Retargeting the eval before the guidance would tune the two in opposite directions — scores would likely drop with nothing actually wrong.

    Why the snapshot gate is third, not first

    It was initially argued for first, on the grounds that snapshotting today's assembly turns four independently-edited surfaces (agent_guidance.rs, tools.rs, skill_pipeline.rs, routing.rs) into a reviewable diff — which is real, and would have caught the coreValues/core_values contradiction ADR-064 records as shipped.

    But the snapshot would capture today's invoice-flavored prompt, and #2120 then rewrites it wholesale. Nearly every diff during that window is intended, so the gate's actual value — catching unintended drift — is thin exactly when it would be running. Capturing the golden once, after the rewrite settles, is cleaner than regenerating it through two rounds of deliberate change.

    The risk this ordering carries, and its mitigation

    The failure mode is the #1917 pattern repeating: tune by hand, get a good result, close the issue, never build the gate. That is not hypothetical — it is what happened, and live_stage1_golden_prompts.rs still carries the header comment saying the snapshot tests are "not yet written."

    Mitigation is in #2120's acceptance criteria rather than in the ordering: every tuned prompt is checked in as a #2118 case file. The work is durable whether or not #2119 lands promptly, and #2119 becomes the step that converts those case files into a production contract rather than the only thing standing between tuning and lost work.

    For reading the current assembled prompt while deciding what to cut, NODESPACE_PROMPT_DUMP already dumps it at the native-path chokepoint — the gate is not needed for that.

    Adjacent, not blocking

  3. malibio commented on Aug 17, 2026

    @malibio
    CollaboratorAuthor

    Goldens must reproduce production's prompt ENVIRONMENT, not just a working prompt

    Clarification from the user on what "golden prompt string" means here, and it tightens the brief:

    we have to provide it the same environment as if NodeSpace is pumping the string

    The distinction

    A hand-authored minimal prompt — short system text, two hand-written tool defs, no candidate block, no entity-types block, no tool-call records in history — answers "can the model do this task under favorable conditions?" That is a useful control, and it is what scenario6-zero-history-control.toml is.

    It is not the string NodeSpace pumps. Production sends, in one request:

    • the assembled resident system prompt (PromptAssembler::assemble() over seeded prompt nodes)
    • the Stage-2 candidate block with rendered skill instruction subtrees (render_candidates_for_prompt())
    • the RELEVANT ENTITY TYPES block (from the candidate block's schema_metadata and/or resident workspace context)
    • the full scoped tool surface with production parameter schemas (stage2_tools())
    • history carrying prior tool-call records, tool results, and write receipts

    That gap is not hypothetical — it is precisely where scenario 6 died. Hand-authored got resolve_query 3/3; production fired it 0/8. The hand-authored prompt was not wrong, it was a different environment.

    The requirement

    A golden must be structurally what production sends — same blocks, same sections, same ordering, same tool surface — with the content of those blocks being what is under tuning. Otherwise:

    The tuning question is "what should the resident prompt SAY, and how short can it be," not "what happens if we delete the resident prompt entirely."

    Two golden tiers, and both are needed

    1. Control goldens (minimal, hand-authored) — diagnostic. Establishes the model can do the task, so a production-shaped failure is attributable to the environment rather than the model. scenario6-zero-history-control.toml is already this, and its own notes call it "the harness's own canary." Keep as-is.
    2. Production-shaped goldens — the actual target. Every block production emits is present and structurally faithful. These are what Prompt-assembly snapshot gate: assert production reproduces the tuned golden prompt (zero model calls) #2119 asserts against and what Generate write-tool field declarations from retrieved schemas, and delete the prose they replace #2120 tunes. This tier does not exist yet.

    The existing "authored fresh, no STAGE1_SYSTEM_PROMPT / no skill_pipeline.rs" discipline still holds for tier 2, and is not in tension with it: fresh content in production's structure. A golden assembled from production's current text cannot be the target production is engineered toward — but a golden missing production's blocks cannot be that target either.

    How to obtain the production shape

    NODESPACE_PROMPT_DUMP captures the exact assembled string at the generate_blocking chokepoint (confirmed working through the golden runner). Run a real session, dump the prompt, and use it as the structural reference for what blocks appear and in what order. Then author fresh content into that structure rather than copying the text.

    Acceptance criteria to add

    • At least one production-shaped golden exists per scenario under tuning: resident prompt, candidate block with instruction subtree, RELEVANT ENTITY TYPES, full scoped tool surface, and realistic history including tool-call records
    • The structural reference is derived from a real NODESPACE_PROMPT_DUMP capture, documented in the case notes, so the shape is verifiable rather than assumed
    • Control (minimal) and production-shaped goldens are distinguishable in the corpus, so a result is never misread as production-representative when it came from the favorable-conditions control
    • Tool definitions in production-shaped goldens carry the real parameter schemas, not simplified stand-ins — the schema is a tuned channel per ADR-064 rule 1
  4. malibio commented on Aug 17, 2026

    @malibio
    CollaboratorAuthor

    Revised sequencing: #2118 → #2122 → #2119 → #2120 → #1977

    Supersedes the earlier sequencing comment. The chain gained a step and #2120 was rescoped, because the previous plan had no issue that actually produced the golden corpus — #2119 would have asserted against goldens nobody authored.

    # issue deliverable touches production source?
    1 #2118 the utility (PR #2121) new bin only
    2 #2122 tuned golden prompt strings no
    3 #2119 snapshot gate test only
    4 #2120 assembly emits the goldens yes
    5 #1977 eval retargeted to match fixtures only

    The split that matters

    #2120 previously mixed what should the prompt say with edit the files that emit it. That is the exact conflation this effort exists to remove — a failure could be a bad prompt or bad plumbing, indistinguishable.

    Now:

    A failure in #2122 is a prompt failure. A failure in #2120 is a plumbing failure. By construction.

    Why #2119 moved ahead of #2120

    The gate is what defines #2120's done condition. "Make plumbing match" has no test without it.

    The governing requirement across all of them

    Goldens must be production-shaped: same blocks, same structure, same tool surface as what NodeSpace actually sends — with the content of those blocks being what is tuned. A minimal hand-authored prompt is a useful control but not a target; scenario 6 is the cautionary case, at 3/3 hand-authored vs 0/8 in production for the same task.

  5. malibio commented on Aug 18, 2026

    @malibio
    CollaboratorAuthor

    The corpus this issue targets now exists — what changed since this issue was written

    #2122 merged as 44ef2f1f. This issue predates it and does not mention any of the findings below, several of which change what "done" means here. Orientation for whoever picks it up.

    Where the target lives, byte-exact

    packages/agent/goldens/ — 8 dev-workflow cases, 2 minimal controls, 3 ablation arms, and PATTERN.toml recording the rule that makes them work. All measured 5/5 byte-identical against the locked native model, with argument values asserted rather than tool names.

    Reproduce any target string without a daemon or DB:

    NODESPACE_PROMPT_DUMP=/tmp/target.jsonl \
      ./target/release/golden_runner --reps 1 packages/agent/goldens/<case>.toml

    dev-status-change-enum is 2681 and 4401 chars post-template across its two turns. Diff assembly output against that directly — no interpretation required.

    Four requirements the corpus establishes that this issue does not mention

    1. Write tools must declare each field as a typed sub-property, enums inline. This is the largest behavioural requirement, not a style preference. dev-instance-creation dropped a user-supplied value 3/3 across eight arms spanning every prose channel ADR-064 defines — candidate instructions, schema descriptions, three shapes of worked example, a content boundary rule, an ordered procedure, and that procedure with its enumeration forced to be printed. Declaring the field closed it immediately.

    The diagnostic is the useful part: with the enumeration printed, the model listed five particulars and the dropped one was not among them. The value was already gone before any instruction could act on it, which is why every wording-level fix was inert — they all operate downstream of the loss. Two further probes bound it: asked directly, the model correctly identifies that no field exists; offered a clarification tool and told to use it, it writes anyway and says nothing.

    Generatable from the same schema data that renders the type line, so no new source of truth.

    2. Delete the prose the declarations replace. An arm carrying both a declared sub-property and the prose telling the model to invent keys failed; the declaration alone passes. Adding structure while leaving the instruction it supersedes is measurably not the same edit.

    3. Two rendering sites, differently scoped. The resident block carries the retrieved schemas; the per-candidate block carries only that candidate's own types (routing.rs renders c.schema_metadata). An early draft of the corpus copied the resident list into the candidate block and reproduced production's structure while violating its scoping — the exact contamination routing.rs documents at that call site. All 15 turns now render the block exactly twice, correctly scoped.

    4. Keep the heading's parenthetical. The corpus heads the block EXISTING SCHEMAS (do not recreate these; …) rather than RELEVANT ENTITY TYPES (…). Read the measurement carefully: production's constant at context_ops.rs:118 is already constraint-framed, so the arms compared two constraint-framed headings differing in noun. Both scored 5/5; the two arms that scored 0/5 dropped the parenthetical and changed the noun together.

    So the supported claim is "keep the parenthetical". The ENTITY → SCHEMAS rename is a consistency fix with no measured cost — ENTITY has no referent in storage (node_type == "schema"), in the 44 node_type tool params, or in the API — but it is not a measured improvement. The isolating arm is recorded as NOT RUN.

    What the ablation says about how much of this is worth reproducing

    On dev-status-change-enum only, at 5 reps:

    arm turn-1 post-template result
    full 2681 correct
    no Stage-2 candidate block 1765 (−34%) identical — inert
    no instruction subtree 2371 identical — inert
    no schemas block 2031 read path degrades

    Two mechanisms bought nothing measurable on that case. One case is not the workload — ablation/README.toml carries that caveat and it should travel with any decision. But if effort has to be prioritised, the schemas block is the one with evidence behind it.

    Note the last row changed after the declared-field pattern landed: with enums declared on the write tool, deleting the schemas block no longer breaks the write, only the read — search_nodes.filters declares no enum. Not-yet-run: declaring enums on a read tool's filter parameter. If that works, the block may be redundant for reads too.

    Blocked on #2123

    Production's value parameter is named properties, which the Gemma-4 template deletes wholesale. Declarations inside a deleted parameter reach the model no better than its description does, so none of requirement 1 is reproducible until that rename lands. The corpus uses field_values for exactly this reason, which is also why it is not production-shaped today — every affected case says so in its own notes.

    Sequencing: #2123 → #2119 → #2120.

    One methodological note, learned twice the hard way

    Measurements transcribed into prose drift from the files they describe. It happened twice in #2122 — caught once in review, once self-caught after a heading change invalidated recorded character counts. Derive them, don't transcribe them. That is directly #2119's problem.

    Relatedly: 3 reps is not enough for heading- or block-level changes. A 3/3 run wrongly cleared a change of causing a regression during #2122; only a 5-rep comparison settled it. The corpus files declare reps = 5.

    🤖 Generated with Claude Code

  6. mstomar125 commented on Aug 18, 2026

    @mstomar125
    Contributor

    Resolved by #2145.

    Added packages/agent/tests/prompt_assembly_snapshot.rs — a deterministic, zero-model-call test covering all 5 assembly sites named in this issue:

    • PromptAssembler::assemble_static (the resident system prompt, via its documented DB-free path for assemble())
    • context_ops::WorkspaceContext::format_for_prompt (RELEVANT ENTITY TYPES site 2, resident workspace context)
    • routing::render_candidates_for_prompt (Stage-2 candidate block + instruction subtrees; RELEVANT ENTITY TYPES site 1)
    • routing::stage2_tools (scoped tool surface — names, descriptions, full parameter schemas)
    • STAGE1_SYSTEM_PROMPT + stage1_tool_definitions() (the Stage-1 request)

    All fixture-driven (no DB, no daemon, no embedding service, no model), runs in the default cargo test -p nodespace-agent suite (~10ms), diffs failures with similar::TextDiff (readable line diff, not a blob comparison), and golden files are only ever written via an explicit UPDATE_GOLDEN=1 env var — never on a bare test failure.

    Proved the drift-detection mechanism with an actual edit (appended a sentence to agent_guidance.rs's SCHEMA_CREATION_RULES, confirmed exactly the resident-system-prompt test failed with a pinpoint diff while the other 4 stayed green, then reverted cleanly).

    Per the issue's own scope, the day-one committed goldens reflect current production assembly output, not the #2122 tuned target — core#2120 is the follow-up that brings production's emitted text in line with that corpus, updating these goldens as part of that work. Full design rationale is in the PR description.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions