Skip to content

fix: granite33 response_end span uses sentence length not full respon…#845

Open
planetf1 wants to merge 5 commits intogenerative-computing:mainfrom
planetf1:cs/issue-843
Open

fix: granite33 response_end span uses sentence length not full respon…#845
planetf1 wants to merge 5 commits intogenerative-computing:mainfrom
planetf1:cs/issue-843

Conversation

@planetf1
Copy link
Copy Markdown
Contributor

@planetf1 planetf1 commented Apr 13, 2026

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

One-line fix: response_end in granite 3.3 citation spans was computed as index + len(response_text_without_citations) (the full response length) instead of index + len(response_text) (the cited sentence length). Every citation span therefore overshot its end index — potentially beyond the end of the string — meaning any consumer slicing response[begin:end] would get far more text than intended.

Granite 3.2 already does this correctly (see granite32/output.py:291–293).

Branch rebased on main (clean; #818 has merged).

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code was added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Three regression tests added in TestAddCitationResponseSpans (test/formatters/granite/test_granite33_output.py):

  • test_response_end_uses_sentence_length_not_full_response — direct regression for Bug: response_end span in granite33 uses full response length instead of sentence length #843: multi-sentence response where the cited sentence is shorter than the full response; pins begin == 0 and end == len(sent1). Fails against the old code.
  • test_multiple_citations_each_span_correct — two citations across two sentences; asserts both spans are correct and non-overlapping.
  • test_single_sentence_response — baseline: single sentence, span covers it exactly.

Coverage on granite33/output.py: 81.64% → 82.77% (+1.1pp). The remaining uncovered lines are error/warning paths (e.g. citation-not-found, sentence-splitting edge cases) that require malformed model output to trigger.

Follow-up

#851str.find() first-occurrence issue: if the same sentence appears more than once in a response, citations after the first get the wrong span. Spotted during review of this PR; out of scope here.

@github-actions github-actions bot added the bug Something isn't working label Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The PR description has been updated. Please fill out the template for your PR to be reviewed.

…se length

_add_citation_response_spans computed response_end as index + len(response_text_without_citations),
which is the length of the entire stripped response rather than the cited sentence. This caused
every citation span to overshoot, potentially past the end of the string.

Fixes generative-computing#843
…issue generative-computing#843)

Adds TestAddCitationResponseSpans covering:
- multi-sentence response where cited sentence is shorter than full response
  (the exact scenario that triggered the bug: response_end overshot)
- multiple citations each getting a correct, non-overlapping span
- single-sentence response as baseline

Fixes generative-computing#843
@planetf1 planetf1 marked this pull request as ready for review April 14, 2026 10:12
@planetf1 planetf1 requested a review from a team as a code owner April 14, 2026 10:12
Remove misleading doc_id parameter from _make_citation (citations are matched
positionally, the value was never read by the function under test). Add comment
clarifying positional matching. Remove issue number from class docstring.
@planetf1 planetf1 enabled auto-merge April 14, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: response_end span in granite33 uses full response length instead of sentence length

1 participant