Repository navigation
fix(novelty): the faithfulness check sees the span after a cited lead-in that ends in a colon - #1072
Conversation
…-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>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 4 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
napetrov
left a comment
There was a problem hiding this comment.
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.
…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>
@napetrov (#1072 (review)): The review body only points at its inline thread (4654563810), answered above. |
vchamarthi
left a comment
There was a problem hiding this comment.
@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 theFollowing: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): |
There was a problem hiding this comment.
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.
…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>
Summary
On
main, the faithfulness check ofskill noveltyatoms 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.\nwith only the sentence cited, the CONTEXT block of theverify_atomsprompt isHeading: 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 readdistorted.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_forappendsFollowing: <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:## Setuptwice). 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. Theatoms.pymodule docstring says the same.dokimi/tests/test_novelty_verify_context.py: the repro (prompt captured fromverify_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_blockssplits onthe 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: Usedpnpfor:andHeading: dpnp > When to use) are unchanged: their last cited span is a list item without a colon.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
distortedorunsupportedtosupportedfor 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 editsatoms.py, but only the--max-tokenswording inExtractionReportandparsemessages, other lines than the module docstring this PR touches, so the two merge cleanly.Testing
On a Linux review host, at
d50b7cb9(onmain36075a08):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).main's codetest_a_colon_ended_lead_in_gets_the_code_block_after_itandtest_the_last_cited_span_in_document_order_decides_the_following_spanfail (2 failed, 15 passed; the first onHeading: T > Hwithout theFollowing:line); here all 18 tests in the file pass. With## Setuptwice andDo the following:ending the first, the earlier code gaveHeading: Intro > Setup\nFollowing: ## Setup; now it givesHeading: Intro > Setup.test_a_repeated_sibling_heading_after_a_colon_ended_span_is_not_addedfails).ruff,mypy, the comment-block and duplicate checks pass.Open questions
None.
Revert
A plain revert restores the old context and prompt wording. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)