Skip to content

fix: granite33 citation spans wrong for duplicate sentences (find() first-occurrence) #851

Closed

Description

@planetf1

Spotted during review of #845.

In _add_citation_response_spans (mellea/formatters/granite/granite3/granite33/output.py), spans are located with:

index = response_text_without_citations.find(response_text)

str.find() returns the first occurrence. If the same sentence appears more than once (e.g. two different citations on "The sky is blue." repeated in the response), every citation after the first gets response_begin/response_end pointing at the first occurrence. Consumers slicing response[begin:end] get the wrong span.

Granite 3.2 uses explicit match indices and doesn't have this issue.

Fix direction: find(text, offset) advancing past consumed positions, with care for the multiple-citations-per-sentence case (same sentence → same span, offset should advance only when the sentence changes).

Test needed: two identical sentences with different citations — assert span 0 covers the first occurrence, span 1 the second.

Activity

  1. added
    bug
    on Apr 14, 2026
  2. self-assigned this
    on Apr 14, 2026
  3. planetf1 commented on Apr 15, 2026

    @planetf1
    ContributorAuthor

    Proposing to not implement this until #845 is merged as this hits the same file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions