Skip to content

docs: the citation guard cannot see a stale pin, accepts :0, and lets a ../ citation escape the repo #1265

Done

Description

@HugoXK

Implementation: AgentDescent (ours) — do not pick up; this is queued behind the #1259 card, not a second slice of it.

tests/test_docs_citations.py (added in #1264, reviewed head 58ab248e980acdd3a8958bd3fea721e541218e41) walks docs/**/*.md and README.md, reads every backticked path:line / path:line-line citation, and requires the cited file to exist and the last cited line to be inside it. Citations into the upstream Elixir/DGM trees are pinned in _EXTERNAL as exact (page, path, first, last) coordinates.

Three gaps, each reachable only by writing a citation we do not have today. They were left out of #1264 deliberately: none of them can fail on the current docs, and pushing a fourth file would have restarted five CI legs for test hygiene.

  1. A pin is never checked for staleness. If a page stops citing a pinned path, or moves the citation to another line, the pin stays and the coordinates it names become permanently allowed. A future citation at exactly those coordinates — the wrong line in a quoted upstream file — would pass silently. Fix: while walking, collect the external citations actually seen and assert _EXTERNAL - seen == set(), naming every stale pin.
  2. :0 passes. _CITATION takes (\d+), and end = 0 never exceeds a line count, so agentdescent/cli.py:0 is accepted. Fix: reject first < 1, and reject last < first.
  3. ../ escapes REPO_ROOT. The path class allows dots, and the guard tests REPO_ROOT / path, so ../../etc/hostname:1 is read (a line count, never contents) and accepted when the target exists. Fix: reject any citation whose path has a .. segment, or resolve and require the result to stay under REPO_ROOT.

Acceptance: each fix lands with an assertion that fails first on the guard as merged — one entry added to _EXTERNAL whose citation is not in the page (stale pin, must be named), one page citing path:0 (must be named), one page citing a ../ path (must be named); today all three pass, after the change all three fail. python -m pytest tests/test_docs_citations.py -q green; the failure message keeps naming the page, the citation and the file's length; no page prose touched; python -m tools.changelog_fragments check decides whether a fragment is needed.

Activity

  1. added
    documentation
    area:docs
    risk:T1
    on Nov 24, 2026
  2. HugoXK commented on Nov 24, 2026

    @HugoXK
    CollaboratorAuthor

    Fourth gap, added from a security read of the guard at 58ab248e980acdd3a8958bd3fea721e541218e41 — same four lines as gap 3, so it rides with it rather than getting its own card.

    target = REPO_ROOT / path (tests/test_docs_citations.py:66) accepts .. segments and absolute paths, and the guard then counts lines on whatever resolves. Today that is cosmetic: _line_count (:52) returns only an integer, the failure message carries page:line -> citation plus that integer (:70) or (file does not exist) (:72), and there is no write, no network and no file content anywhere in the guard.

    The sharp edge is a citation whose target is a FIFO or a character device (/dev/zero-style): read_text would block or read without bound, and on CI that is bounded only by the job's timeout-minutes, i.e. it burns a leg rather than failing with a message.

    Fix, in the same place as gap 3: reject any citation path with a .. segment or an absolute path, resolve, require stat.S_ISREG on the result, and only then count lines. Acceptance unchanged: an injected citation at such a path is named today and refused after the change.

  3. HugoXK commented on Nov 24, 2026

    @HugoXK
    CollaboratorAuthor

    Fifth point, and it decides what the list actually means: all 11 _EXTERNAL entries are carried from the pages' prose; none was checked against an upstream file. The author never fetched agents/*.ex, runtime/genesis.ex, evolution.py, DGM_outer.py, adapters/git.ex or agent/subagent_processing.ex, so 0 of 11 are confirmed upstream.

    That does not make the guard wrong — those citations predate it, and the guard's real value is separating "resolves in this repository" from "asserted to live upstream". But the comment above _EXTERNAL currently reads as if the entries were facts, and a later reader will take them that way. Fix, either: verify the nine distinct coordinates once by hand against the upstream trees and record the sha you read them at, or state in that comment that they are prose-derived and unverified. The second is honest and costs nothing.

    Mechanically: 11 entries over 9 distinct (path, first, last) pairs, because runtime/genesis.ex:152 and agents/manager.ex:58 each appear on two pages — worth keeping that shape when the staleness check is added, since collapsing to 9 would lose the per-page fact.

    Measured on main 441ac2bd with the guard and the #1264 doc line: the guard walks 151 pages, sees 17 citations, of which 4 resolve in-repo and 13 occurrences (the 9 distinct upstream coordinates, some repeated on a page) are pinned. With #1264's one-line fix applied the guard passes at 0 problems, and main's only offender is exactly that one citation.

  4. HugoXK commented on Nov 24, 2026

    @HugoXK
    CollaboratorAuthor

    Three more from a QA pass that ran the guard on 58ab248e rather than reading it. None is live — measured on docs/ + README.md at that head: 0 backticked :line tokens the pattern misses and 0 reversed ranges — so they ride here rather than in the PR.

    1. A reversed range passes. _problems compares only the range's last number (end), so agentdescent/cli.py:999-7 is accepted while its first line is past the end of the file. Fix: also reject start > end and check first against the count.
    2. Extensionless tokens are never read. _CITATION requires a dotted extension, so a Makefile:3 or Dockerfile:12 citation is invisible. Fix: loosen the token pattern, or state in the docstring that only dotted paths are covered. Zero instances today, so the documentation option is legitimate.
    3. The walk has a declared edge that a reader will miss. The guard covers docs/**/*.md + README.md; three tracked markdown files outside that carry citations today — CHANGELOG.md (2), the #1259 changelog fragment (1), and examples/genesis/README.md (2, both external agents/manager.ex rows). Fix: either extend _pages() to every tracked *.md, or say explicitly in the docstring which files are out of scope, so "every citation" is not read as the whole repo.

    Acceptance for all three is the same shape as the rest of this issue: a failing-first injection per item, then the guard green at python -m pytest tests/test_docs_citations.py -q.

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

    area:docsdocumentationrisk:T1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions