Skip to content

fix(roadmap): the stage trace gate counts the text that the request gives #5466

Not planned

Description

@dan-petty

Problem or Motivation

The stage planner reads again the files that its request already holds. In the stage comment sample of 2026-11-06 to 2026-11-13 (54 items, 8,213 tool calls), the planner made 383 read_file calls on cited files that the capped context kept, in 42 of 52 items. Two causes can explain the re-reads, and the data does not split them:

  1. The trace gate. TraceFacts.of (src/devops_cli/roadmap/agent_run.py) reads only trace.tool_calls. _was_read and _was_seen (src/devops_cli/roadmap/stage/stage_change.py) accept only the paths and the match lines of tool calls. Line 10 of roadmap_stage_change.md says that Feasibility cites only the tools and the paths that this run used. So a claim about text from context is refused unless the planner reads the file again.
  2. Line numbers. collect_context writes each ### Code: <path> block as raw text, with no line numbers and no range in the heading. The prompt asks for path:line:text citations, and read_file gives numbered lines. Of the 477 read_file calls on files that the body cites whole, 453 read a line range. Only 67 of 557 reads of cited files are in calls 1-10.

The planner also calls read_issue on its own item (14 of 54 items, 19 calls), although body is in the request. It calls read_spec with no capability (19 of 54 items, 26 calls), although capabilities holds all names.

The stage replay cannot see a change of the trace gate: 0 of the 59 cases in tests/fixtures/roadmap_eval/stage/ hold facts.trace, so the gate does not run in the replay.

Proposed Solution & Architectural Design

  1. Number the code lines. Each ### Code: block states its range and gives each line in the read_file format, from the real first line of a sliced range.
  2. Add a separate given field to TraceFacts. Do not merge it into paths:
    • Build it from the final request text, after the cap and after the sections that _request adds (registry places, stage facts).
    • Add a whole path only when the request holds all of its text.
    • For a file that the cap cut, add only the path:N entries of the lines that remain.
    • Never add a path that only a tree entry, an identifier match, an index line or a manifest names. Any path in the set makes every claim on it pass through the suffix match of _same_path.
  3. Accept a separate claim form for given text, such as "the request context holds path". Keep "read" for tool reads. Change line 10 of roadmap_stage_change.md to name both forms.
  4. Store given in PlanFacts and in the kept plan record, so that a revision of a kept plan uses the set of its own commit. Change the record key.
  5. read_issue of the item's own number and read_spec with no capability answer with the name of the request field that holds the text. When the cap cut the body, read_issue gives the full body.

The threshold stays: a claim about text that the request did not hold is still refused. This change lowers no quality threshold (AGENTS.md rule 5).

Target Subsystem

SDLC, Git & PR Governance: src/devops_cli/roadmap/agent_run.py, src/devops_cli/roadmap/stage/stage_change.py, stage.py, stage_plan_record.py, stage_tools.py, src/devops_cli/roadmap/refine/refine.py (collect_context), src/devops_cli/ai/tasks/roadmap_stage_change.md, tests/fixtures/roadmap_eval/stage/.

Existing Tool Considered

No open tool decides which claims of a plan the request and the tool calls support. The gate is project code (#3266, #4495), and this change extends TraceFacts. The numbered lines use the format of the existing read_file tool. Cost to build: about 1.5M tokens and 4 hours (estimate), about 150 lines and 10 tests. Keep cost: one field, one record key, one prompt line.

Acceptance Criteria

  • Test first: unit tests that fail before the change:
    • a true claim on a whole given file passes with no tool read;
    • a false claim on the part of a file that the cap cut is refused;
    • a claim on a path that only the tree or the identifier matches show is refused;
    • a claim to have read an ADR that only an index line names is refused.
  • Replay cases with facts.trace and facts.given for the four cases above. The replay passes trace.lines. Every known-bad plan of the stage eval is still refused.
  • A test: each code block of the context gives the numbered lines of its range, from the real first line.
  • Baseline first: after fix(roadmap): the stage gate log names each refused claim #5433 logs the subject of each refused claim, count for 7 days the refused paths that the capped context held. Record that count in ## Feasibility as the baseline, not 383.
  • Measure: report the re-reads of context paths in two parts: re-reads for line numbers (a ranged read of a given range) and re-reads that the gate forced.
  • Live proof after release: on real Service stage runs for 7 days, give the read_file calls on context paths (sample baseline 383 in 42 of 52 items), the own read_issue and no-argument read_spec calls (baseline 33), and the share of stage_problem_trace_path in the stage gate returns lines (baseline 10 of 60).

Dependencies

Standards Compliance

  • I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 4 blocks, zero bare exceptions, tests that cover the changed lines).

Alternatives check of 2026-11-29: none.
Tool: none found.
Reason: Searches found only LLM evaluation frameworks (Ragas, Guardrails AI, DeepEval) that score answers against supplied context; none checks path or path:line claims against a tool-call trace, numbers context code lines, or keeps a given set in a plan record.

Lacks:

  • No check of a claim against the request text or the tool-call trace
  • No path:N line entries for text a cap kept
  • No line-numbered ### Code: blocks in the context
  • No stored given set for a revision of a kept plan
  • Scores a whole answer, not one cited path or line

Proposed design

Problem statement

Hold this item until #6521 delivers. The stage planner reads again the files that its request already holds. The trace gate accepts only tool-call paths and match lines, so it refuses a claim about text from context. The context code blocks carry no line numbers, so the planner reads a line range. This change adds the final request text to the gate, numbers the code lines, and answers own-item and no-capability reads. The measurement of the re-reads is in #6240.

Acceptance criteria

Requirement: Given text passes the gate

The stage trace gate SHALL accept a claim about a path whose whole text the final request holds, with no tool read of that path.

Scenario: A true claim on a whole given file

  • WHEN a plan claims that the request context holds a path whose whole text is in the final request, and the trace holds no read of it
  • THEN the check reports no refusal for that claim

Requirement: A remaining line of a cut file passes

The stage trace gate SHALL accept a claim about a path:N line that the final request holds when the cap cut the file.

Scenario: A claim on a line that remains after the cap

  • WHEN a plan claims that the request context holds path:N, the cap cut the file, and line N remains in the request
  • THEN the check reports no refusal for that claim

Requirement: A cut line stays refused

The stage trace gate MUST refuse a claim about a line of a path that the request cap cut.

Scenario: A claim on the part of a file that the cap cut

  • WHEN a plan claims a line of a file whose text the cap cut, and the request does not hold that line
  • THEN the check refuses the claim

Requirement: A named-only path stays refused

The stage trace gate MUST refuse a claim on a path that only a tree entry, an identifier match, an index line, a manifest, a registry place or a stage fact names.

Scenario: A path that only a tree entry or an identifier match shows

  • WHEN a plan claims text of a path that only a tree entry or an identifier match names, and the request does not hold its text
  • THEN the check refuses the claim

Requirement: An index-only ADR read stays refused

The stage trace gate MUST refuse a claim to have read a path that only an index line names.

Scenario: A read claim on an ADR that only an index line names

  • WHEN a plan claims that it read an ADR path that only an index line names, and the trace holds no read of it
  • THEN the check refuses the claim

Requirement: The record keeps its own given set

A kept plan record SHALL store the given set of its own commit, under a record key that changes with the prompt version.

Scenario: A revision of a kept plan

  • WHEN the trace check runs on a revision of a kept plan record
  • THEN the check uses the given set stored in that record

Requirement: The context code block numbers its lines

Each ### Code: block of the request context SHALL state its range and give each line as &lt;N>: &lt;text>, from the real first line.

Scenario: A sliced code range

  • WHEN collect_context writes a ### Code: block for a range that starts after line 1 of the file
  • THEN the heading states the range and the first numbered line carries the real line number

Requirement: The own item read names the request field

read_issue of the item's own number MUST answer with the name of the request field that holds the text.

Scenario: The planner reads its own item

  • WHEN the planner calls read_issue with the number of its own item
  • THEN the answer names the request field body

Requirement: The own item read gives the full body when cut

read_issue of the item's own number MUST answer with the full body when the request cap cut it.

Scenario: The planner reads its own item whose body the cap cut

  • WHEN the planner calls read_issue with the number of its own item and the request body is shorter than the issue body
  • THEN the answer holds the whole issue body

Requirement: The no-capability spec read names the request field

read_spec with no capability MUST answer with the name of the request field that holds the names.

Scenario: The planner lists the capabilities

  • WHEN the planner calls read_spec with no capability name
  • THEN the answer names the request field capabilities

Requirement: The stage prompt names both claim forms

The stage prompt MUST name the given-text claim form beside the read form.

Scenario: The stage prompt rules

  • WHEN the feasibility rule of src/devops_cli/ai/tasks/roadmap_stage_change.md is read
  • THEN the rule names the read form and the given-text claim form

Requirement: The replay passes the trace lines and given set

The stage eval replay SHALL pass the lines and given facts of each case to the trace gate.

Scenario: The replay of the new cases

  • WHEN uv run devops roadmap eval stage --replay runs over the new cases, whose facts hold trace.lines and trace.given
  • THEN the new cases pass with their trace lines and given sets

Requirement: Every known-bad plan stays refused

The stage eval replay MUST still refuse every known-bad plan.

Scenario: The 3205 zero-call trace case

  • WHEN uv run devops roadmap eval stage --replay runs the 3205 case, whose trace holds no tool call and whose plan claims a read
  • THEN the replay refuses the plan for that read claim

Existing Tool Considered

The alternatives check of 2026-11-23 records the verdict none and names no tool that covers the need; its Tools considered and Lacks: list are in the alternatives block in the issue body. A further search found no open, maintained tool that decides which path and path:line claims the final request text and the tool-call trace support, numbers the context code lines, or keeps a given set in the plan record. The stage trace gate stays project code (#3266, #4495), and this change extends TraceFacts. Cost to build: about 150 lines and 10 tests, about 1.5M tokens and 4 hours. Cost to keep: one field, one record key, one prompt line.

Key questions

  • Is the given set a separate field of TraceFacts, or part of paths?: A separate given field. _same_path accepts any path of a set by suffix. A path that only a tree entry, an identifier match, an index line, a manifest, a registry place or a stage fact names would let every claim on it pass. The read evidence stays in paths. A whole path entry supports a claim on the path and on any path:N of it. A path:N entry supports only that line. (best practice) [sources: src/devops_cli/roadmap/agent_run.py:649, src/devops_cli/roadmap/stage/stage_change.py:2442, src/devops_cli/roadmap/stage/stage_change.py:2448, src/devops_cli/roadmap/stage/stage_change.py:2454]
    • Chosen: A separate given field on TraceFacts. The gate keeps the text of the final request apart from the read evidence. A claim on given text passes. A claim on a cut line stays refused.
    • Rejected: Merge the given paths into paths. _same_path accepts any path of the set by suffix. A path from a tree entry, an identifier match, an index line, a manifest, a registry place or a stage fact would let every claim on it pass.
  • From which text is the given set built?: The final context text of the request, after the cap and after _request appends the registry places and the stage facts. A section that holds a file's whole text adds the path. For a file that the cap cut, only the path:N entries of the numbered lines that remain join. A tree entry, an identifier match, an index line, a manifest, a registry place or a stage fact only names a path and adds none. (best practice) [sources: src/devops_cli/roadmap/refine/refine.py:1174, src/devops_cli/roadmap/refine/refine.py:1190, src/devops_cli/roadmap/stage/stage.py]
    • Chosen: The final request context after the cap and the added sections. The set matches what the model can read. A claim on a line that the cap cut stays refused. A registry place or a stage fact adds no path.
    • Rejected: The context before the cap. A claim on a line that the cap cut would pass. A registry place or a stage fact would not count.
  • Which claim form does the gate accept for given text?: A separate form, the request context holds path``, beside the read form. Line 10 of src/devops_cli/ai/tasks/roadmap_stage_change.md names both forms. (best practice) [sources: src/devops_cli/ai/tasks/roadmap_stage_change.md:10, src/devops_cli/roadmap/stage/stage_change.py:2454]
    • Chosen: A separate given-text form beside the read form. A claim on given text is true and needs no read. The read form keeps its meaning of a tool call.
    • Rejected: Use the read form for given text. It would state a tool read that the run never made. The audit of the trace would be false.
  • Where does a kept plan record keep its given set?: In PlanFacts and in the kept plan record. PlanFacts.of keeps only the entries that the feasibility text cites, as it does for paths and lines. The record key already holds the prompt version. This change edits the prompt, so a record of the old gate is not reused. A revision of a kept plan uses the given set of its own commit. (best practice) [sources: src/devops_cli/roadmap/stage/stage_plan_record.py:53, src/devops_cli/roadmap/stage/stage_plan_record.py:69, src/devops_cli/roadmap/stage/stage_plan_record.py:79]
    • Chosen: Store the set in PlanFacts and the record, under the key that holds the prompt version. A revision reads the set of the commit that the plan judged. The prompt edit changes the key, so an old record is not reused.
    • Rejected: Recompute the set from the current request at each revision. A revision would judge the old claims against a different request.
  • How does a context code block give its line numbers?: Each ### Code: block states its range in the heading and gives each line as &lt;N>: &lt;text>, the format of read_file, from the real first line of the sliced range. (best practice) [sources: src/devops_cli/roadmap/refine/refine.py:1174, src/devops_cli/roadmap/refine/refine_investigation.py:346, src/devops_cli/roadmap/refine/refine_investigation.py:368]
    • Chosen: Numbered lines in the read_file format, with the range in the heading. The planner can cite path:line:text from the request and needs no second read.
    • Rejected: Keep the raw text with no numbers. The planner reads a line range again for the numbers. That is the cost this change removes.
  • What do read_issue of the own item and read_spec with no capability answer?: The name of the request field that holds the text: body for the own item, and capabilities for a read_spec with no capability. When the cap cut the body, read_issue gives the full body from issue_body. The stage tools need the own item number and the request body held for the item. (best practice) [sources: src/devops_cli/roadmap/stage/stage_tools.py:343, src/devops_cli/roadmap/stage/stage_tools.py:406, src/devops_cli/roadmap/stage/stage.py]
    • Chosen: Name the request field that holds the text. The text is already in the request. The call returns no new text and costs no tokens.
    • Rejected: Keep reading the issue or the registry. The call repeats text that the request holds. The sample shows 33 such calls.
  • Which open items must deliver before this change starts?: chore(roadmap): hold incremental stage and implement work #6521 must close first: it is an open hold issue with no sub-issue and no type/epic label, so the dependency rule of the roadmap holds this item back while it is open. The reply of 2026-11-20 freezes this item for the re-architecture tracker refactor(roadmap): re-architect stage and implement on Coder #6519, and a person closes chore(roadmap): hold incremental stage and implement work #6521 when the experiments decide, or closes this item as not planned. fix(roadmap): the stage gate log names each refused claim #5433 has merged. fix(roadmap): the plan context lists the ADRs in force, not ADR 0001-0005 #5465 and feat(roadmap): planners and implement read the target AGENTS.md #4650 change collect_context, so their pull requests must not stack with this one, but neither must merge first. [sources: docs/roadmap/refine.md:24, openspec/specs/roadmap-refine/waits/spec.md:229]
  • Does the stage eval replay see the trace gate today?: Yes, for one case, but it drops the match lines and the given set. stage_eval_cases.py loads trace.json into facts.trace when a case folder holds it. The 3205 case holds trace.json with empty tools and paths, and its plan claims a read_file of src/devops_cli/commands/roadmap.py. The replay refuses that claim. stage_eval_gates.py builds TraceFacts from tools and paths only, and TraceFact holds no lines or given, so no case passes a line or a given set. [sources: tests/fixtures/roadmap_eval/stage/3205-a-plan-that-cites-a-read-its-run/trace.json, tests/fixtures/roadmap_eval/stage/3205-a-plan-that-cites-a-read-its-run/plan.json, src/devops_cli/roadmap/stage/stage_eval_cases.py:169, src/devops_cli/roadmap/stage/stage_eval_gates.py:133]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#6521

Moved to new items

#6240

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 13, 2026
  2. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 13, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches found only general LLM-output evaluation libraries, RAGAS and DeepEval, which score whether an answer's claims are supported by retrieved context with a model judge. None of them decides which path/path:line claims the final request text and the tool-call trace support, numbers the context code lines, or keeps a given set in the plan record, so the stage trace gate stays project code as the issue states.

    Tool: none found

    Lacks:

    • a deterministic check of which path and path:line claims a run's request text and tool calls support
    • a separate given set built from the final request text after the cap and the added sections
    • line numbering of each context ### Code: block in the read_file format
    • a claim form for given text beside the read form, in the stage prompt and the gate
    • storage of the given set in PlanFacts and the kept plan record
    • answers to own read_issue and no-capability read_spec naming the request field
    • replay fixtures that carry facts.trace and facts.given

    Tools considered:

    Searches run:

    • library check agent tool calls cite files read evidence gate hallucinated file paths, results: 5
    • open source tool verify LLM citations claims grounded in provided context faithfulness, results: 5
    • RAGAS faithfulness metric verify answer claims supported by context, results: 5
    • "citation verification" tool LLM output file line references validator, results: 5
    • DeepEval faithfulness metric github, results: 5
    • RAGAS, results: 5
    • TruLens groundedness feedback function, results: 5
    • python package verify claims against source documents evidence checking, results: 5

    Sources:

    Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  6. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 9be129e (see proposed design in issue body).

    Moved to new items: #6240.

  7. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Frozen on 2026-11-20. The stage, implement and fix-checks jobs grade under 60%, so the owner rule asks for a re-architecture before more fixes inside the current design (tracker #6519). This item is incremental work on those jobs, so its Dependencies section now names #6521 first. Stage and implement leave this item while #6521 is open. When the experiments of #6519 decide, a person closes #6521 (this item can then continue) or closes this item as not planned.

  8. added
    status/new
    and removed
    status/ready
    on Nov 27, 2026
  9. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  10. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor

    Triage under #6519 (owner instruction of 2026-11-30), before the hold #6521 closes. This item adds or extends a gate, refusal, screen, cap, limit, retry, result line, shell allowlist, tool catalog or plan-shape rule of the stage, implement or fix-checks job. #6519 found that 263 of about 900 issues in four weeks added such rules and none replaced the engine. Stage now runs on stock Coder (grade 60 on 30 graded attempts), where the agent reads the repository, runs the checks in its loop and has a real shell; implement follows (#6527). The code paths that this item names have also moved. If the failure class still shows in graded attempts, file a new item from that evidence. Closed as not planned; a person may reopen it.

  11. removed
    status/new
    on Nov 30, 2026
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

    effort/mediumpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions