Skip to content

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

@planetf1

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions