Skip to content

fix(novelty): the faithfulness check sees the span after a cited lead-in that ends in a colon - #1072

Merged
napetrov merged 2 commits into
intel:mainfrom
antonwolfy:fix/verify-context-following-span
Nov 22, 2026
Merged

napetrov merged 2 commits into
intel:mainfrom
antonwolfy:fix/verify-context-following-span

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On main, the faithfulness check of skill novelty atoms gets the heading path and the span before the first cited span, but never a span after the cited ones. For # T\n\n## H\n\nThree commands answer most questions before any code changes:\n\n```bash\npython -V\nsycl-ls\n```\n\nThen go on.\n with only the sentence cited, the CONTEXT block of the verify_atoms prompt is Heading: T > H: the code block that names the commands is absent, so an atom such as "The three diagnostic commands (version, visible devices, array device) should be run before any code changes" is judged without it and can read distorted.

Of the options in the issue, this takes the first, narrowed: when the last cited span in document order ends in a colon, the very next span is added as one Following: line. The option of the next N characters of the section is not taken: N is arbitrary and it would let the context supply claims, not only resolve references, which the prompt forbids. For a lead-in followed by list items only the first item is added; further items are the claim itself.

Closes #1016

Changes

  • dokimi/dokimi/novelty/verify_context.py: context_for appends Following: <text of the next span> after the Lead-in and Table header parts when the last cited span ends in : and the next span is in the same section (a heading is not, including a sibling heading that repeats the section's title: ## Setup twice). Output for a last cited span without a colon, (none) for nothing cited, and the first-cited-span rules are unchanged.
  • VERIFY_PROMPT's CONTEXT sentence names the span after a lead-in that ends in a colon, and still says the context never supplies the claim. The atoms.py module docstring says the same.
  • dokimi/tests/test_novelty_verify_context.py: the repro (prompt captured from verify_atoms), a next heading (omitted), a repeated sibling heading ## Setup (omitted), no colon (unchanged), and a colon-ended last span of several cited spans (the last in document order decides). The helper _blocks splits on the claim, so judge the SOURCE alone): because the sentence now wraps one line earlier. The two pinned strings (Heading: dpnp > When to use\nLead-in: Use dpnp for: and Heading: dpnp > When to use) are unchanged: their last cited span is a list item without a colon.
  • Changelog fragment (Fixed).

Risk

Prompts of atoms whose last cited span ends in a colon and is followed by a span of the same section carry one more line, so a verdict can move from distorted or unsupported to supported for such atoms. The cached verdicts of an earlier run are not rewritten. Other prompts are byte-identical except the reworded CONTEXT sentence. Open #954 also edits atoms.py, but only the --max-tokens wording in ExtractionReport and parse messages, other lines than the module docstring this PR touches, so the two merge cleanly.

Testing

On a Linux review host, at d50b7cb9 (on main 36075a08):

  • make ci-local: 36 passed, 0 failed, 14 skipped (steps needing micromamba, semgrep, the Intel matrix, the fuzz job, the docs deploy and the CLI-surface package step).
  • The repro: on main's code test_a_colon_ended_lead_in_gets_the_code_block_after_it and test_the_last_cited_span_in_document_order_decides_the_following_span fail (2 failed, 15 passed; the first on Heading: T > H without the Following: line); here all 18 tests in the file pass. With ## Setup twice and Do the following: ending the first, the earlier code gave Heading: Intro > Setup\nFollowing: ## Setup; now it gives Heading: Intro > Setup.
  • Mutants, each failing a test: dropping the colon condition, taking the first instead of the last cited span, dropping the same-section condition, taking the span two after, and dropping the not-a-heading condition (test_a_repeated_sibling_heading_after_a_colon_ended_span_is_not_added fails).
  • Guard tests (docs code refs, growth ratchet, test-quality audit, import architecture), ruff, mypy, the comment-block and duplicate checks pass.
  • Not run: the other Python versions (3.11, 3.12, 3.14) and a real model call.

Open questions

None.

Revert

A plain revert restores the old context and prompt wording. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…-in that ends in a colon (intel#1016)

The faithfulness context held the heading path and the span before the first cited span, never a span after the cited ones. A sentence such as "Three commands answer most questions before any code changes:" is followed by the code block that names the commands, so an atom naming them was judged without it and could read `distorted`.

When the last cited span in document order ends in a colon, `context_for` now adds one `Following:` line with the very next span, unless that span is a heading, in another section or itself cited. Only that one span is taken, so the context still resolves references and does not supply the claim; the CONTEXT sentence of `VERIFY_PROMPT` says so. Output for a last cited span without a colon is unchanged.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 21, 2026 12:14
@antonwolfy antonwolfy self-assigned this Nov 21, 2026
@exai-bot

exai-bot commented Nov 21, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 4 selected item(s).

CI at d50b7cb: 21 passing, 3 skipped.

Review details
  • Commit reviewed: d50b7cb against merge base 36075a0
  • Coverage: 4 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 68k tokens (40k from cache), 10s
  • Tool calls: 9 (6 file_read, 2 code_search, 1 local_check_results)
  • Novelty following-span context verification and tests: 4 files

@codecov-commenter

codecov-commenter commented Nov 21, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.91%. Comparing base (36075a0) to head (d50b7cb).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1072      +/-   ##
==========================================
- Coverage   95.92%   95.91%   -0.01%     
==========================================
  Files         450      450              
  Lines       59527    59533       +6     
  Branches    10265    10267       +2     
==========================================
+ Hits        57101    57104       +3     
  Misses       1507     1507              
- Partials      919      922       +3     
Files with missing lines Coverage Δ
dokimi/dokimi/novelty/atoms.py 98.80% <ø> (ø)
dokimi/dokimi/novelty/verify_context.py 95.45% <100.00%> (+0.71%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change class: LOCAL (head 441b206)

  • Contract: none
  • Responsibility: none
  • Dependency: none
  • Review depth: skim: local change, check diff + tests
  • Coverage gaps: none

See the inline finding. Checked the captured verification prompt, citation order and section boundaries. Focused tests on 441b2061c: 17 passed.

Comment thread dokimi/dokimi/novelty/verify_context.py Resolved
…section's title

Settles the review point on intel#1072 (context_for): a colon-ended last cited span followed by a sibling heading with the same title (`## Setup` twice) had the same heading_path as the section, so `Following: ## Setup` leaked into the verification prompt.

The following span is now added only when its kind is not a heading, as the lead-in check already does. A test covers the repeated sibling title.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) ### Change class: LOCAL (head 441b206)

@napetrov (#1072 (review)): The review body only points at its inline thread (4654563810), answered above.

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antonwolfy: fix the 1 must-fix item in the line comments and settle 1 open question, then push for a re-review. 1 nit in line comments is optional.

Open threads and questions:

  • Open question for antonwolfy: Whether a lead-in ending in the full-width colon : gets the Following: line. State in the PR description that only the ASCII colon counts, or accept : in the check.

Reviewed at d50b7cb: changed tests: 18 passed, fail on main; full suite with main merged in: 24521 passed, its only failures are main's too; merges onto main; 3 broken variants of the changed code, all caught by the tests; 4 mutations and 10 edge inputs tried.

parts.append("Table header: " + spans[header].text)
last = max(cited, key=order.__getitem__)
after = order[last] + 1
if by_id[last].text.rstrip().endswith(":") and after < len(spans):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must fix: Input # T then Lead: as the last span: with after <= len(spans) the call raises IndexError, and the tests still pass.
Input: segment("# T\n\nLead:\n") with Lead: cited.
Got: The head returns Heading: T.
Expected: a case that fails under that change.

Suggestion: Add a test that segments # T and Lead: with nothing after Lead:, cites Lead:, and asserts the context is Heading: T.

Patch, run on d50b7cb: the tests now catch the broken variant; tests and lint are no worse.

Patch
--- a/dokimi/tests/test_novelty_verify_context.py
+++ b/dokimi/tests/test_novelty_verify_context.py
@@ -179,6 +179,12 @@
     assert context.splitlines()[-1] == "Following: - one"
 
 
+def test_a_colon_ended_last_span_of_the_document_gets_no_following_span():
+    spans = segment("# T\n\nLead:\n")
+    _, context = _check(_atom(spans, "Lead:"), spans)
+    assert context == "Heading: T"
+
+
 def test_rows_beside_a_dash_only_row_get_their_own_table_header():
     spans = segment("## Flags\n\n| Option | Default |\n|---|---|\n| --a | 10 |\n| - | - |\n| --b | 20 |\n")
     for row in ("--a", "--b"):
Details

With after <= len(spans) the same call raises IndexError at spans[after], and verify_atoms builds the prompt outside its try, so the whole verification stops. Changing after < len(spans) to after <= len(spans) still passes the suite: no test in test_novelty_verify_context.py cites a colon-ended span that is the last span of a document.

@napetrov
napetrov merged commit cf610c7 into intel:main Nov 22, 2026
24 checks passed
@antonwolfy
antonwolfy deleted the fix/verify-context-following-span branch November 22, 2026 10:14
antonwolfy added a commit that referenced this pull request Nov 22, 2026
…Following line (#1098)

Settles the open point on #1072 (discussion_r4655519764): no test put a colon-ended cited span last in the document, so changing `after < len(spans)` to `after <= len(spans)` in `context_for` left all tests green.

The new test cites `# T\n\nLead:\n` with `Lead:` and asserts the context is exactly `Heading: T`; with the looser guard `context_for` raises IndexError and the test fails. No production code changes.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
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.

novelty atoms: faithfulness context ignores spans after the cited one

5 participants