Skip to content

fix: citation-placement bugs from the PR #403 review - #410

Merged
neuromechanist merged 5 commits into
developfrom
fix/citation-placement-bugs
Sep 19, 2026
Merged

neuromechanist merged 5 commits into
developfrom
fix/citation-placement-bugs

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses the citation-placement/marker-logic findings from the PR #403 review:

Design history on Important #7 (three rounds, ended in a different design than started):

  1. First fix: a fixed "titles always skip forward, everything else forward-skips only if the next character is lowercase" heuristic.
  2. Independent review reproduced a regression: etc./e.g./et al. frequently do end a sentence, and the lowercase-character proxy got it wrong in both directions (relocated a marker into an unrelated sentence, or left it stuck one sentence too early).
  3. A second independent review reproduced further misplacements against round 2's fix, in both directions again — including against the seemingly-reliable "title + capitalized word" signal ("she became a Dr. Her family..." has a capitalized word after the period too, and it is not a name).

Final design: stop guessing. Never relocate a marker across an abbreviation's period into a different sentence. A marker left right after Dr. or et al. is imprecisely placed but still within (or immediately adjacent to) the sentence it supports — a bounded, honest degradation, not a misattribution to the wrong claim, in keeping with this project's "precision over features" principle. vs. is the sole exception: across two review passes nobody could construct natural prose where it genuinely ends a sentence, so it still skips forward to the real end. Test matrix (TestNormalizeCitationMarkersAbbreviations) covers both directions for each abbreviation family (title, et al., etc., e.g.) plus the title-as-standalone-noun edge case, using domain-flavored HED/BIDS/EEGLAB-style prose (lowercase filenames, capitalized tool names, CLI flags) since that's where this project's actual risk concentrates.

Reviewer note (not a blocker): there's a negligible residual risk that the frontend fix (Important #5) mis-migrates un-backticked word[N] array-index-shaped text. Checked against the real HED docs corpus and this shape does not actually occur there — accepted as a documented limitation rather than fixed further.

Test plan

  • uv run pytest tests/test_agents/test_content.py tests/test_frontend/ -v - 91 passed
  • bun frontend/test-streaming.js - 69 passed
  • bun frontend/test-citation-markers.js - 10 passed
  • Verified directly against every reproduction string from both review rounds (original two + four from the second pass)
  • uv run ruff check / ruff format clean

…ntext

The precedingIdentifier heuristic in migrateLegacyCitationMarkers fired for
any word directly followed by [n], which is also the shape of a normal,
unlinked citation marker (e.g. "documentation[1] explains"). Rely on the
existing backtick-based inline-code check instead; array-index-style text
now needs backticks to be preserved as code.
_SENTENCE_END_PATTERN was punctuation-only, so a marker landed right after
a title or 'et al.' (e.g. "Dr.[1] Smith") instead of the real sentence
end. Add a fixed abbreviation-exception list (Dr., Mr., Mrs., Ms., Prof.,
vs., etc., i.e., e.g., et al.) applied everywhere the pattern is used to
find a sentence boundary.
PR #403 added a frontend-tests CI job (test.yml and tests.yml) that runs
frontend/test-citation-markers.js and frontend/test-streaming.js with Bun.
Update comments that still claimed no JS runtime is available in CI.
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://fix-citation-placement-bugs-demo.osc.earth
Branch fix/citation-placement-bugs
Commit 753a6a3

This preview will be updated automatically when you push new commits.

@neuromechanist
neuromechanist removed the request for review from yarikoptic September 19, 2026 19:21
The abbreviation exception treated every listed abbreviation as never
sentence-final, forward-searching past it unconditionally. That's right
for titles (Dr., Mr., ...), which are always followed by a name in the
same sentence, but wrong for etc./e.g./et al., which frequently do end a
sentence -- especially in enumerative technical prose (HED/BIDS/EEGLAB
docs list features, tags, etc.). A marker after one of those was silently
relocated into the next, unrelated sentence.

Split the exception into two kinds: titles always skip forward; etc./al/
e.g./i.e. only skip forward when the text right after the period is
lowercase, the signal that the same sentence continues. Otherwise their
own boundary is accepted.
…cross one

Two rounds of heuristic each fixed the reported misplacement while causing
the opposite one: a marker relocated into a different, unrelated sentence.
Even the seemingly reliable 'title + capitalized word' signal fails ('she
became a Dr. Her family...' has a capitalized word after the period too,
and it is not a name). No cheap local signal reliably distinguishes an
abbreviation's period from a real sentence end in both directions.

Replace the heuristic with a conservative default: never relocate a marker
across an abbreviation's period into a different sentence. A marker left
right after 'Dr.' or 'et al.' is imprecisely placed but still within (or
adjacent to) the sentence it supports -- an accepted, bounded degradation,
not a misattribution to the wrong claim. 'vs.' is the sole exception,
confirmed across two review passes to not occur as a genuine sentence end
in natural prose, so it still skips forward.

Test matrix covers both directions for each abbreviation family (title,
et al., etc., e.g.) plus the title-as-standalone-noun edge case, using
domain-flavored HED/BIDS/EEGLAB-style prose.
@neuromechanist
neuromechanist merged commit dff0f74 into develop Sep 19, 2026
9 checks passed
@neuromechanist
neuromechanist deleted the fix/citation-placement-bugs branch September 19, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant