Skip to content

feat(roadmap): re-anchor a stale citation that matches one line #4479

Closed

Description

@dan-petty

Problem or Motivation

The stage citation gate refuses a Feasibility citation path:N:text when line N of the staged file does not hold text ("The feasibility of the plan cites X, and the staged file holds no such text there."). Most of these citations are stale, not false: the planner copies a line number from another commit, and the text is still in the file at another line.

The study of the stage refusals of 2026-11-11 counted 41 stale citations. In 33 of them, the cited text matches exactly one line of the file at the staged commit. The gate refuses these plans and asks for a second reply, and the second reply often fails again.

This issue is out of scope of #4463, which fixes the citation forms that the trace gate reads.

Proposed Solution & Architectural Design

  • When the text of a path:N:text citation is not at line N but matches exactly one line of the staged file, accept the citation as that line (re-anchor it), and do not refuse the plan.
  • When the text matches zero lines or more than one line, refuse the citation as now.
  • Record how many citations the gate re-anchored, so a person can see the rate.

Target Subsystem

The roadmap stage job: the citation gate (_plan_citation_problems in src/devops_cli/roadmap/stage/stage_change.py).

Existing Tool Considered

The gate already reads the staged file (read_text) and already accepts path:def name at any line. No outside tool is needed: the change is a lookup of one line in a text that the gate already reads.

Standards Compliance

  • I confirm this proposal aligns with AGENTS.md engineering principles.
  • I am willing to submit a pull request implementing this feature with accompanying tests.

Proposed design

Problem statement

The stage citation gate refuses a path:N:text citation when line N does not hold text. In 33 of 41 stale citations, the text matches exactly one line of the staged file. These refusals are mostly stale line numbers, not false evidence. The change re-anchors a unique match, refuses zero or multiple matches, and records the re-anchor count.

Acceptance criteria

Requirement: Unique line match re-anchors

The citation gate SHALL accept a path:N:text citation when the text is absent at line N and matches exactly one line of the staged file.

Scenario: Unique match is accepted

  • WHEN a plan cites src/app.py:12:return value and return value occurs only at line 40 of src/app.py at the staged commit
  • THEN _plan_citation_problems returns no citation problem for that citation

Requirement: No unique line match refuses

The citation gate SHALL refuse a path:N:text citation when the text is absent at line N and matches zero lines or more than one line of the staged file.

Scenario: Zero or multiple matches are refused

  • WHEN a plan cites src/app.py:12:return value and return value occurs at no line or at two lines of src/app.py at the staged commit
  • THEN _plan_citation_problems returns the stale-citation problem for that citation

Requirement: Line N match stays accepted

The citation gate SHALL accept a path:N:text citation when line N of the staged file holds the text, even when another line also holds it.

Scenario: Line N wins

  • WHEN a plan cites src/app.py:12:return value and line 12 and line 40 both hold return value at the staged commit
  • THEN _plan_citation_problems returns no citation problem and records no re-anchor

Requirement: Match keeps the current line test

The citation gate MUST count a line as a match when the normalized cited text occurs in the normalized line, as the current line check does.

Scenario: Partial line text is re-anchored

  • WHEN a plan cites src/app.py:12:return value and only line 40 of src/app.py holds return value = compute() at the staged commit
  • THEN _plan_citation_problems accepts the citation as line 40

Requirement: Short text stays refused

The citation gate MUST apply the minimum cited-text length before it tries to re-anchor a citation.

Scenario: Short text is refused

  • WHEN a plan cites src/app.py:12:ab and ab occurs at exactly one line of src/app.py at the staged commit
  • THEN _plan_citation_problems returns the short-citation problem and records no re-anchor

Requirement: Re-anchor count is recorded

The citation gate SHALL write one log line for each plan run with the number of citations it re-anchored.

Scenario: Count is written

  • WHEN a plan has two citations that each match exactly one other line of their staged file
  • THEN the stage job log holds one line with the count 2

Existing Tool Considered

No alternatives check has run. The gate already reads the staged file through read_text and accepts path:def name at any line. No open, maintained tool or library covers a re-anchor inside this gate. The change builds on the existing reader. Written cost: about 25k tokens to build, 8k tokens to keep and fix, and about 3 hours.

Key questions

  • Does the citation gate already read the staged file?: Yes. _plan_citation_problems receives a read_text callable, and _citation_problems reads each cited path through it. [sources: src/devops_cli/roadmap/stage/stage_change.py:1362, src/devops_cli/roadmap/stage/stage_change.py]
  • Should the gate re-anchor a line citation that matches exactly one other line?: Yes. The gate accepts the citation as the unique matching line and records a re-anchor. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py, AGENTS.md]
    • Chosen: Re-anchor a unique match. The text is in the staged file, so the evidence is stale, not false. The gate already reads the file.
    • Rejected: Refuse as now. It costs a second reply and often fails again, as the issue reports.
    • Rejected: Fuzzy match several lines. It can accept the wrong line and weakens the gate.
  • How does the gate decide that a line matches the cited text?: Use the current normalized containment test: the normalized cited text occurs in the normalized line. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py]
    • Chosen: Normalized containment. It preserves the current line check and changes only the line that the gate looks at.
    • Rejected: Exact line equality. It would refuse a citation that quotes part of a longer line, which the current gate accepts.
    • Rejected: Fuzzy text distance. It can accept a wrong line and adds a dependency.
  • What does the gate do when zero lines or more than one line match?: Refuse the citation with the current stale-citation problem. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py]
    • Chosen: Refuse zero or multiple matches. Only one line gives an unambiguous target for the stale citation.
    • Rejected: Re-anchor the first match. The first line is arbitrary and can cite the wrong code.
    • Rejected: Re-anchor the closest line. Distance from the stale line is no evidence of the correct line.
  • Where does the gate record the re-anchor count?: The gate writes one log line with the count for each plan run. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py, AGENTS.md]
    • Chosen: One log line from the gate. It keeps the count in the job log and needs no new return type or comment.
    • Rejected: Stage comment. It changes the staged item comment and needs a wider change in the stage job.
    • Rejected: Metric counter. It adds telemetry for a diagnostic count.
  • Does the change need an outside tool or library?: No. The gate compares the cited text with lines of a file it already holds. A fuzzy-match library adds a dependency for no need. (best practice) [sources: AGENTS.md, src/devops_cli/roadmap/stage/stage_change.py]
    • Chosen: Use the existing reader and text search. The gate already has the file text and the normalized cited text.
    • Rejected: Add a fuzzy-match library. It adds a dependency and can accept a wrong line.
    • Rejected: Build a separate citation index. It duplicates the file read and adds state for no need.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-11: none.
Tool: none found.

Activity

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

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It reduces false refusals in the stage gate but does not block any pipeline; 41 of 41 stale cases are recoverable by re-anchoring.
    • Value: Medium. It removes a repeated failure mode that forces a second (often failing) reply from the planner.
    • Effort: Medium. The gate already reads the staged file; the work is a linear scan for a unique match plus a counter and tests.
    • Related: fix(roadmap): the plan check fails a citation of a line that moved #3422, which asks for a different change. Both target stale line citations in the stage plan check, but #3422 fixed a specific failed citation while the candidate adds a general re-anchoring rule and a re-anchor counter.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

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

  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches for a library that re-anchors or verifies path:N:text code citations returned no relevant tool, only unrelated documentation pages. The need is a linear scan for a unique line inside file text that the gate already reads through read_text, so no open, maintained tool or library covers it.

    Tool: none found

    Lacks:

    • No searched tool accepts a stale path:N:text citation as the unique matching line of the staged file.
    • No searched tool refuses a citation when the text matches zero lines or more than one line.
    • No searched tool keeps the existing normalized containment line test and minimum cited-text length.
    • No searched tool records a per-run re-anchor count for the stage job log.

    Searches run:

    • code citation line number re-anchoring tool verify file citation, results: 5
    • python library find line number of text in file unique match, results: 5
    • verify LLM source code citations file line numbers open source tool, results: 5

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

  7. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Scope from the content freshness plan (2026-11-11)

    This issue is child 14 of #4880, the content freshness tracker. The scope grows from one stage-gate rule to one shared citation module.

    Why

    This issue adds a re-anchor rule only inside the stage gate (_plan_citation_problems in src/devops_cli/roadmap/stage/stage_change.py). The question resolver (#4808), brain add (#4671) and brain repair (#4687) also verify citations. Without one module, 4 copies of the parse, verify and re-anchor logic drift apart. The stage study counted 41 stale citations, and 33 of them match exactly one line.

    New scope

    Build the rule as one citation module:

    1. Parse a path:N:text citation and the structured citation of docs(adr): keep reference docs in git as cited brain sources #4884: {path, commit, lines, span_hash, doc_class, generated_from?, adr_status?, as_of}.
    2. Render a permalink at a commit.
    3. Verify at a SHA: git show <sha>:<path> with 0 GitHub requests, else 1 contents GET.
    4. Compute the span hash: SHA-256, the first CONST_KB_SHA_DIGEST_LENGTH (16) hex characters.
    5. Re-anchor a span that matches exactly one place.

    The stage gate uses the module first. Post one comment on #4808, #4671 and #4687 that names the module.

    Acceptance added

    Depends on: None (start now).

  8. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 12, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 12, 2026
  10. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor
  11. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 15:46 UTC

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/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions