Skip to content

fix(quality): derive instruction tokens from parsed frontmatter - #356

Merged
rng1995 merged 5 commits into
NVIDIA:mainfrom
YMuskrat:codex/fix-quality-instruction-tokens
Nov 9, 2026
Merged

rng1995 merged 5 commits into
NVIDIA:mainfrom
YMuskrat:codex/fix-quality-instruction-tokens

Conversation

@YMuskrat

@YMuskrat YMuskrat commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary

The Tier 1 instruction-token estimate finds the first literal --- after the opening delimiter. Valid YAML values or comments containing that text therefore make it count metadata as instructions. A horizontal rule in a document without frontmatter can also produce a spurious estimate.

Use the Markdown-body group from the existing frontmatter parser for the estimate. Tests exercise quoted descriptions, nested metadata, YAML comments, LF/CRLF, body-only separators and unclosed frontmatter. Seven of the eight new cases failed before the change.

Total/frontmatter token estimates, quality deductions and the minimum-score gate retain their existing behavior. The packaged text-analyzer still scores 84.5/B; its instruction estimate changes from 359 to 358 because the closing-delimiter newline is excluded.

Verification

  • Familiar with the contributing guidelines; commit includes DCO sign-off.
  • 430 focused quality, schema, configuration and gate tests passed.
  • Updated the user-visible changelog.
  • make lint and changed-file formatting checks passed.
  • make build produced the wheel and source distribution.
  • Ran make test with two workers and a first-failure limit: 824 passed, 2 skipped, 2 failed before stopping. Both failures also occur on unchanged upstream 55d8b8d: the GitLab template test cannot create its hard-coded /tmp directory in this sandbox, and the standalone provenance test returns no run_dir (cause not diagnosed). Full-suite success is not claimed.
  • No credentials, private datasets or proprietary benchmark content added.

Validated on Python 3.12 with the repository's locked all/dev dependencies; no live model requests.

Release Impact

  • Updated CHANGELOG.md.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed head a16c0591 against main 55d8b8d4.

The fix works for the cases it targets. A --- inside a quoted value, a nested value or a YAML comment no longer inflates the estimate, and 7 of the 8 new cases fail on main. I ran the validator on every tracked SKILL.md on both trees. Only text-analyzer (359 to 358) and tests/fixtures/skills/simple (81 to 80) change; scores, totals, frontmatter tokens and issues are identical. Nothing in scoring, deductions or the gate reads instructions_tokens.

I've left one P3 inline: an unclosed or empty frontmatter block followed by a body --- still produces an estimate, which the new CHANGELOG sentence says no longer happens.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed. Using the parser's body group is the right direction, and the quoted/nested/comment --- cases are covered well.

+1 to the open P3 thread on quality_score.py:882, which I reproduced on the current head (a16c059):

SKILL.md frontmatter_tokens instructions_tokens
unclosed frontmatter, then a body --- thematic break 22 4
empty ---\n---\n block, then a body --- 14 4

Both estimates still come from body text even though no valid frontmatter was parsed, which contradicts the new CHANGELOG sentence. Gating both assignments on a successful parse (if fm_match and _frontmatter:) and adding the "unclosed frontmatter + later body ---" case to test_instruction_tokens_do_not_infer_frontmatter_from_body_separators would close it.

CI has not run on this fork PR yet, so it needs a maintainer to approve the workflow run.

Require successful frontmatter parsing before estimating frontmatter and instruction tokens. Cover unclosed and empty blocks followed by a body separator, plus invalid YAML.

Merge upstream main d136a59 and preserve its changelog while placing this fix under Unreleased.

Signed-off-by: Codex <[email protected]>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM at a2c7b76. My earlier point is addressed: both token estimates are now set only when _parse_frontmatter returned a mapping (if fm_match and _frontmatter:), which matches how has_frontmatter is decided, and the unclosed / empty / invalid-YAML cases with a later body --- are covered and assert zero for both estimates.

Checked locally:

  • tests/validators passes apart from 12 test_plugin_dependencies.py failures that fail identically on the base commit d136a59 in my environment, so they are unrelated to this change.
  • ruff check and ruff format --check are clean on the changed files.

No further concerns from me.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All review comments are addressed. Both token estimates require successfully parsed frontmatter, with regressions for unclosed/empty frontmatter plus a later body separator and invalid YAML. Resolved the CHANGELOG-only conflict with current main while preserving both sets of entries. Fresh verification on the merged tree: 406 quality/schema/frontmatter tests passed; src/tests lint, changed-file formatting and PR whitespace checks passed.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reconfirmed approval after moving the same changelog entry within Fixed to avoid a second conflict with PR #357. Source and test trees are identical to the tested 2b9ab75 revision (406 quality/schema/frontmatter tests passed). Verified the two PRs now merge cleanly in a local squash-merge simulation; whitespace checks pass.

@rng1995
rng1995 disabled auto-merge November 9, 2026 19:16
@rng1995
rng1995 enabled auto-merge (squash) November 9, 2026 19:19

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reconfirmed approval on the new main-merge commit. The PR diff against current main remains the intended three files, and the quality validator and regression tests are byte-for-byte unchanged from the previously approved revision. Fresh validation on this head: 406 quality/schema/frontmatter tests passed; changed-file lint, formatting and PR whitespace checks passed. All review threads remain addressed.

@rng1995
rng1995 merged commit 1af2693 into NVIDIA:main Nov 9, 2026
26 checks passed
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.

3 participants