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.
Spotted during review of #845.
In
_add_citation_response_spans(mellea/formatters/granite/granite3/granite33/output.py), spans are located with: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 getsresponse_begin/response_endpointing at the first occurrence. Consumers slicingresponse[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.