Skip to content

BUG-73: doc-citations --relocate crashes when two lines cite the same code line, and --write then records the wrong text #292

Open

Description

@ephico2real2

Part of #178.

What is wrong. On PR #288 (after the review fixes), F3 added one line at cmapi/src/cmapi/routers/requests.py:111, so five citations in docs/14-authorization.md moved down by one. docs/14 cites requests.py:128 twice, at lines 177 and 192.

python scripts/doc-citations.py --relocate raised:

File "scripts/doc-citations.py", line 172, in relocate
    lock[f"{c.doc}|{c.path}|{new_start}-{new_end}"] = lock.pop(c.key)
KeyError: 'docs/14-authorization.md|cmapi/src/cmapi/routers/requests.py|128-128'

The lock key has no document line, so two citations of one code line share one key, and the second pop fails.

Worse. The check's message for an ambiguous move says to run --write. Run after the crash, --write re-recorded the five keys with the new text at the old line numbers (row = repo.get(request_id) in place of requests:approve), and --check then reported 0 problems. So the check can be made to pass while every citation points at the wrong line. The coordinator caught it by reading the lock's diff and corrected the citations by hand.

Fix to research. Make the lock key unique per citation (include the document line, or de-duplicate before relocating). Make --write refuse to record a text that differs from the recorded one for a key unless the citation's line number changed, so it cannot hide a move.

How to prove it. A test with one document that cites the same code line twice, then a one-line insertion above it. --relocate moves both citations, and a --write with no citation change leaves the lock's text unchanged. It fails on main.

Activity

  1. added
    bug
    status:open
    sev:medium
    Backlog
    on Nov 15, 2026
  2. added a commit that references this issue on Nov 15, 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

    Backlogbugsev:mediumstatus:open

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions