Skip to content

fix(novelty): the faithfulness check sees the heading and lead-in of the cited spans - #1017

Merged
xaleryb merged 10 commits into
intel:mainfrom
antonwolfy:fix/verify-atom-context
Nov 21, 2026
Merged

xaleryb merged 10 commits into
intel:mainfrom
antonwolfy:fix/verify-atom-context

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

verify_atoms judged each atom against the text of its cited spans alone. On main a list item is judged without its lead-in and a sentence without the sentence that names its subject, so atoms the skill states read as unsupported or distorted. In the report on #1009, 11 of 132 atoms were flagged and a maintainer found none a real distortion. For example the atom "dpnp is recommended for large arrays (>10,000 elements)" was shown only - Large arrays (>10,000 elements) (lead-in Use dpnp for: missing), and "Prefer dpnp over plain NumPy when the arrays are large" only "Prefer this over plain NumPy when the arrays are large ..." (the Purpose sentence that says "this" is dpnp missing).

The fix is the issue's first option: the prompt gets a CONTEXT block holding the heading path of the first cited span and its lead-in (for a list item or table row, the nearest earlier span that is neither; otherwise the span just before it). The block says it only resolves references ("this", "both", a list's lead-in) and never supplies the claim; the prompt also says a changed polarity, number or qualifier stays distorted or unsupported even when the context words it otherwise. SOURCE is still the cited text only. The case in the issue where the needed text comes after the cited span (the code block and the line after "Three commands answer most questions") is not covered, and is tracked in #1016.

Closes #1009

Changes

  • dokimi/dokimi/novelty/verify_context.py (new): the faithfulness prompt with its CONTEXT block, and context_for, which returns Heading: <path>, Lead-in: <text> and, for a table row, Table header: <row> lines, or (none). The header is the row before the nearest delimiter row (|---|---|) of the unbroken run of table rows, because segment drops the blank line between two tables; a row of the second table gets the second table's header, and a header row or a run with no delimiter row gets none. It is a separate module because atoms.py would pass the 800-line cap.
  • dokimi/dokimi/novelty/atoms.py: verify_atoms builds the prompt with the context; the tally, max_atoms, the unchecked handling and the cache rule are unchanged.
  • dokimi/tests/test_novelty_verify_context.py: a fake client captures the prompt (list item with lead-in and heading, sentence with its predecessor, (none), an atom citing no known span, context not duplicating cited spans, SOURCE holding only cited text).
  • Changelog fragment (Fixed).

Risk

The verifier prompt changes, so cached faithfulness verdicts for the old prompt are asked again once (paid calls on the next skill novelty atoms/analyze run). Verdicts of atoms whose cited spans were already self-contained should not change; ones that depended on a heading or lead-in now read supported. The prompt grows by the heading path and one span per atom. The open PR #954 also edits atoms.py, but only --max-tokens wording in docstrings and messages far from verify_atoms, so a merge with it should not conflict.

Testing

On a Linux review host, at e550111d (on main 52160e9):

  • make ci-local: 0 failed, 36 passed, 14 skipped (matrix legs on other Pythons, semgrep, conda-forge, fuzz, jobs not run on a PR). 23973 tests passed, 19 skipped.
  • Two tables in a row (| Flag | Default | then, after a blank line, | Flag | Maximum |), citing --y: before, the context said Table header: | Flag | Default |; now Table header: | Flag | Maximum |. On the previous head the two new two-table tests fail; with the guard that gives a header row no Table header removed, test_the_header_row_of_the_second_table_gets_no_table_header fails.
  • On main's code the new test file fails: 5 failed, on the faithfulness prompt has no CONTEXT block.
  • Mutants, each failing the new tests: returning None instead of (none) when no cited span id is known (the unknown-id test), skipping a run of list items when looking for the lead-in (list item test), dropping the heading line, using the last cited span instead of the first, returning an empty string instead of (none), returning no lead-in, putting extra text in SOURCE.
  • tests/test_novelty_permanent_stop.py and tests/test_novelty_silent_defaults.py, which drive verify_atoms, pass unchanged.
  • Not run: the other Python versions, a real model (the prompt wording is not measured against the verifier of the report).

Open questions

None.

Revert

A plain revert restores the old prompt and the cited-spans-only check. Nothing is stored; saved atoms files keep the faithfulness labels they were written with.

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)

…the cited spans (intel#1009)

verify_atoms judged an atom against its cited spans alone, so a list item lost its lead-in ("Use dpnp for:") and a sentence like "Prefer this over plain NumPy" lost the sentence naming its subject, and supported atoms read as unsupported or distorted.

The prompt now has a CONTEXT block with the heading path of the first cited span and its lead-in: for a list item or table row the nearest earlier span that is neither, otherwise the span just before it. The block is stated as only for resolving references; SOURCE is still the cited text and a changed polarity or number stays distorted or unsupported. The prompt and context helper move to novelty/verify_context.py to keep atoms.py under the 800-line cap. Cached verdicts for the old prompt are asked again.

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

exai-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Found no critical or high issues in this commit.

CI at `28778b0`: 1 failing, 1 still running, 19 passing, 2 skipped
Check Status
Tests (py3.14) failing at step Run tests
Test Linux Wheels Python 3.14 still running

Review limit reached. This PR has had 6 reviews, so it will only be reviewed again when you ask.
To ask: re-request review from exai-bot in the Reviewers list.

Lower-severity findings not shown (1)

1 medium

Review details
  • Commit reviewed: 28778b0 against merge base 52160e9
  • Coverage: 4 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 350k tokens (252k from cache), 1m17s
  • Tool calls: 28 (15 file_read, 7 code_search, 2 local_check_results, 2 pr_comments, 1 ci_status, 1 code_comment)
  • Novelty atom context verification, tests, and changelog: 4 files

@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

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

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.90%. Comparing base (52160e9) to head (28778b0).
⚠️ Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
dokimi/dokimi/novelty/verify_context.py 94.73% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1017    +/-   ##
========================================
  Coverage   95.89%   95.90%            
========================================
  Files         448      450     +2     
  Lines       59289    59485   +196     
  Branches    10224    10256    +32     
========================================
+ Hits        56857    57048   +191     
- Misses       1511     1513     +2     
- Partials      921      924     +3     
Files with missing lines Coverage Δ
dokimi/dokimi/novelty/atoms.py 98.80% <100.00%> (+<0.01%) ⬆️
dokimi/dokimi/novelty/verify_context.py 94.73% <94.73%> (ø)

... and 40 files with indirect coverage changes

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

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

@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.

🟡 Not approved yet · reviewed e11cd64

Next: @antonwolfy: settle 1 open question (below). 1 nit optional.

Blocking

  • Open question for @antonwolfy: A sentence after a list or table takes the last list item or table row as its lead-in. Decide whether a sentence should also walk back over list items and table rows to reach the lead-in.

Verified on e11cd64: ✅ changed tests: 5 passed, fail on main · ✅ full suite with main merged in: 23938 passed · ✅ merges onto main · ⚠️ 9 broken variants of the changed code: 8 caught by the tests, 1 not · 2 mutations tried · 4 edge inputs tried

9 checks behind it, each with its evidence
Area What holds How
List item lead-in The five tests in tests/test_novelty_verify_context.py pass on the head. A list item gets its heading and the lead-in before its list, a sentence gets the span before it, and a span with no predecessor gets (none) tests on the head
Tests on main The same five tests fail on main, where the prompt has no CONTEXT block same tests on main
Merge The PR merges onto main with no conflict merge onto main
Full test run The full test run passes with main merged in: 23900 passed, 85 skipped, no failures full suite, main merged in
Verifier wiring Replacing the context= argument that verify_atoms passes with (none) fails three of the five tests, so the call is pinned broke the code, tests caught it
Crlf and non-ascii A CRLF document with a non-ASCII heading and lead-in gives the lead-in Use ß for: with no stray carriage return ran it, edge input (text)
Span order and duplicates Cited span ids in any order, with a duplicate, give the lead-in of the first span in document order, and an empty list gives (none) ran it, edge input (collections)
Unknown span ids An atom whose span ids match no span is still counted as supported, and its prompt carries (none) as the context ran it, edge input (none)
Response cache The response cache key is a hash of the request text, so a prompt with a new CONTEXT block gets a new key and the old cached verdicts are not replayed ran it

Comment thread dokimi/dokimi/novelty/verify_context.py Resolved
Settles the review thread on context_for: no test passed span ids that match no span, so returning None instead of "(none)" left the suite green. The new test drives verify_atoms with an unknown id and asserts the CONTEXT block is "(none)".

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

Copy link
Copy Markdown
Contributor Author

(commented) 🟡 Not approved yet · reviewed e11cd64

@vchamarthi (#1017 (review)): The open question is whether a sentence after a list or table should walk back to the lead-in before it. It does not: the sentence takes the span right before it (the last item or row), the same rule as any other sentence, and the code is unchanged. The text right before a sentence is the nearest place its "these" or "both" can point, and the lead-in is often a few spans away. The nit is settled in 136f12f.

…ontext

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…tion

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…mparable

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…n after a table

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>

@vlad-perevezentsev vlad-perevezentsev 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.

🟢 LGTM · re-checked 3471f57 · nothing required from @antonwolfy

🔀 Merge: safe now · merges cleanly into current main, 13 commits behind; its tests pass on the merge · no open PR conflicts with it

✅ make ci-local --offline: 23,918 passed · ⚠️ schema_compat fails from main drift (schemas added by #829), not from this PR · ✅ context_for on tables, headings and sections: run by hand

The earlier points are fixed; list, table and "this" spans now get the context they need.

Fixed in this branch, up to 3471f57:

  • A table row had no header row in its context: 9b9c91c adds Table header:, and 3471f57 keeps it to table rows, with tests.
  • The lead-in could be a heading or come from another section: dd23298 skips both, with a test.
  • The changelog did not say old faithfulness counts are not comparable: 13260b9 says so.

Comment thread dokimi/dokimi/novelty/verify_context.py Resolved
…f an earlier one

Settles the review point that the header lookup walked through the blank line between two tables, so a row of the second table got the first table's header. segment drops blank lines, so the table start is now the delimiter row (|---|---|): the header is the row before the nearest delimiter row in the unbroken run of table rows. A header row itself and a run without a delimiter row get no Table header.

Adds a two-table regression test and a header-row test, and names the behaviour in the changelog fragment.

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

Copy link
Copy Markdown
Contributor Author

(approved) 🟢 LGTM · re-checked 3471f57 · nothing required from @antonwolfy

@vlad-perevezentsev (#1017 (review)): Approval that recaps the earlier fixes; it asks for no change. The schema_compat failure it mentions comes from main drift, not this PR. The one open thread (two tables) is answered above.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

Review points answered at e550111; 8 checks still pending (External catalog smoke test (uxlfoundation/skills), Fidelity golden (claude-code 2.1.318), Linux Python 3.14, Linux Wheels Python 3.14, Mutation of changed lines, Package install smoke test (py3.11), Tests (py3.14), mypy); every other check passed.

codecov has not reported on this head yet.

A data row of single dashes (`| - | - |`) was taken for the delimiter
row, so the row after it got the wrong table header and the row before
it none. Delimiter cells now need at least two dashes; a test pins both
neighbours of such a row.

Signed-off-by: vchamarthi <venkata.sai.gireesh.chamarthi@intel.com>
@vchamarthi

Copy link
Copy Markdown
Contributor

🟢 Ready for re-review · 1 commit on fix/verify-atom-context (e550111..28778b0)

Next: a re-review of the new head. Nothing needed from @antonwolfy.

Changes

  • _DELIMITER_ROW in verify_context.py needs two or more dashes per cell, so | - | - | is a data row.

Verified on the new head: ✅ 1/1 tests fail before the fix, pass after · ✅ full suite with main merged in: 24248 passed · ✅ second reader: nothing raised

What each test shows
  • Rows beside a dash-only row get the table's own header: fails before, passes after.
  • Left to GitHub's own checks: agent-quality.yml:external-catalog-smoke, ci.yml:static / pre-commit, ci.yml:static / Install gitleaks, ci.yml:static / Scan commits, ci.yml:fidelity / Install the pinned Claude Code, ci.yml:test-latest, ci.yml:package-smoke, ci.yml:windows-smoke.

@xaleryb xaleryb 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.

Approved on 28778b0. Read the commits after the earlier approvals (e550111, 28778b0) and ran them on a Linux host merged with current main: the 13 tests of test_novelty_verify_context.py fail against main's source and pass on the merged tree (3 runs); 3,403 novelty/verify/context/span tests pass; ruff and mypy are clean. Probed: a row of the second of two tables gets its own header, aligned delimiters work, a dash-only data row (| - | - |) is not taken for a delimiter. Known and accepted: a delimiter row of single dashes (|-|-|) gives no Table header. CI is green, no open threads.

@xaleryb
xaleryb merged commit 36075a0 into intel:main Nov 21, 2026
31 of 32 checks passed
@antonwolfy
antonwolfy deleted the fix/verify-atom-context branch November 21, 2026 10:36
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: the faithfulness check judges a span without its heading or lead-in, so supported atoms read as unsupported

6 participants