Skip to content

Two independent renderers produce the RELEVANT ENTITY TYPES block; converge them on one function #1848

Closed

Description

@malibio

Overview

The RELEVANT ENTITY TYPES block the agent sees is produced by two independent renderers that are concatenated into a single system prompt. #1841 (PR #1847) aligned their output format and content, but they remain separate code reading separate sources — so they will drift again.

Current state

  • packages/core/src/ops/context_ops.rs — WorkspaceContext::format_for_prompt, reads SchemaNode directly
  • packages/agent/src/local_agent/routing.rs — render_schema_metadata, reads the schema_metadata JSON built in skill_ops.rs

agent_loop.rs concatenates both (base_system_content + candidate_block), so one prompt can carry four blocks under the same heading — one from context_ops, one per eligible routing candidate.

Why this matters

This divergence directly caused #1841. The guidance conditioned properties population on field metadata that one renderer emitted and the other did not; the model saw an instruction with no referent and silently dropped every user-supplied value. That cost a full investigation cycle to diagnose.

After PR #1847 both renderers emit name, type, required-ness, enum values, and title_template in the same notation. Nothing enforces that they stay in agreement — there is no shared function and no test asserting equivalence. The next field added to SchemaField will be rendered by whichever renderer its author happens to be looking at.

Prompt drift is invisible to the type system. It surfaces only as nondeterministic model misbehavior, which is the most expensive class of bug to diagnose in this codebase.

Suggested direction

Converge on one renderer. The obstacle is that the two read different sources (SchemaNode vs schema_metadata JSON) and serve different callers, so this is a real refactor rather than a mechanical extraction — which is why PR #1847 deliberately left it out of scope.

Options worth weighing:

  • A shared formatting function taking a common intermediate, with both call sites converting into it
  • Have the routing path carry SchemaNode rather than a JSON projection, removing skill_ops's lossy re-encoding entirely
  • At minimum, a test asserting the two produce identical field descriptors for the same schema

Additional consideration: is the duplication itself wanted?

Worth deciding separately from the refactor. A prompt currently repeats the same entity block up to four times. That is redundant tokens, and per the resident-prompt findings, dilution is a measurable risk. If the routing block's copy is load-bearing (it scopes a candidate's procedure) it should stay; if not, emitting it once would be both cheaper and clearer. Measure before changing — this is the same class of prompt-shape question that has been mis-diagnosed by assumption before.

Acceptance Criteria

  • One code path produces the block, or a test enforces the two agree field-for-field
  • Adding a field to SchemaField cannot land in one renderer and not the other without a test failing
  • Decide, with measurement, whether the block should appear more than once per prompt
  • No regression in bun run eval:agent (current: 9/12)

Activity

  1. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Design decision before implementation

    Investigated the two renderers and the data flow between them. Posting the approach with a recommendation; proceeding as described unless redirected.

    What the chain actually looks like

    SchemaNode ──> context_ops::format_for_prompt          (renders SchemaNode directly)
        │
        └────────> skill_ops (JSON projection) ──> SkillCandidate.schema_metadata: Value
                                                        └──> routing::render_schema_metadata
    

    Constraint the issue's option 2 runs into

    'Have the routing path carry SchemaNode rather than a JSON projection' is not purely internal. That same JSON is the response body of the model-facing search_skills tool, and its shape is pinned by search_skills_response_includes_schema_metadata plus the latency suites. Deleting the projection would change a tool-output contract the model reads — a bigger and riskier change than the drift this issue is about, and one worth its own decision.

    Recommended approach: option 1, shared function over a common intermediate

    Introduce one renderer in nodespace-core taking a small typed descriptor (type id, display name, fields with name/type/enum values/required-ness, title_template). Both call sites convert into it:

    • context_ops converts from SchemaNode — lossless, it already holds the typed value.
    • skill_ops builds the descriptor from SchemaNode and serializes the existing JSON from that same descriptor, so the tool-output contract is preserved and the projection stops being an independent hand-written encoding.
    • routing.rs deserializes the descriptor rather than field-picking untyped JSON.

    That satisfies AC 1 and 2 structurally: one function emits the block, and a new field on SchemaField reaches the prompt only by going through the descriptor, so it cannot land in one renderer and not the other. Plus an equivalence test asserting both paths yield identical field descriptors for the same schema, as belt-and-braces for the conversion seams.

    Crate direction already works — nodespace-agent depends on nodespace-core, so the shared renderer lives in core.

    On AC 3 (should the block appear more than once?)

    Handling this as a measurement, reported as a finding — not a code change in this PR. The issue explicitly says measure before changing, and per the resident-prompt findings this is exactly the class of prompt-shape question that has been mis-diagnosed by assumption. I will report the measured numbers and recommend separately; de-duplication, if warranted, is a follow-up so the refactor here stays behaviour-neutral and independently reviewable.

    AC 4

    bun run eval:agent against the 9/12 baseline, run with the DB purge + daemon rebuild the eval requires (a plain run silently measures stale guidance).

    Not touching the search_skills JSON contract. Say the word if you want option 2's full removal of the projection folded in instead.

  2. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Baseline (worktree issue-1848-converge-entity-block-renderers): Frontend 4113 passed / 171 test files, 0 failures.

  3. self-assigned this
    on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions