Skip to content

fix(novelty): refit the dry-run token profile on measured runs, one least_sure_role rule - #1371

Merged
napetrov merged 2 commits into
intel:mainfrom
antonwolfy:fix/novelty-token-refit
Nov 29, 2026
Merged

napetrov merged 2 commits into
intel:mainfrom
antonwolfy:fix/novelty-token-refit

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Summary

skill novelty analyze --dry-run prices each call from a per-role token profile that was fitted on October runs, and #1217 asks for a refit on measured paid runs per tier. Those runs now exist: 17 paid runs of 2026-11-28 at 26e3083, on seven skill entry points of 640 to 5,954 tokens (their numbers are in tests/test_novelty_token_profile.py). On main the profile misprices them, and the least-sure rule names a role no measurement backs:

Run (from the 17) What main does Measured
n15, triage, 4,003 tokens, priced from its own 7 extractor, 50 answerer and 50 judge calls the profile prices it 22% low, its extractor 25% low: a flat 2,359 output tokens per call the extractor writes 3,115 per call here (2,154 at 640 tokens, 3,705 at 5,954)
n08, triage, 5,954 tokens, --dry-run expected_usd is 0.337 against 0.570 billed (-41%)
--dry-run --tier study (or no tier) stderr says Least sure of: extractor (...): the extractor's token profile is the standard tier's, borrowed, since no run of this tier was measured study and untiered were measured: the extractor does the same work per call as at standard

For least_sure_role the issue asked to revisit the rule once per-role error data exists. Pricing each of the 17 runs at its own --dry-run call counts with the refit profile, the role with the largest estimated dollars had the largest dollar error in 15 of 17. The other two (n05 and n11) are triage runs where every role was off by under $0.01. At standard, study and untiered the role furthest off was always the extractor, mostly through its call count, not its tokens (see #1370). So the borrowed branch, which this refutes, is gone: one rule at every tier, the role with the largest dollars.

Closes #1217

The off-by-call-count part is not this profile: on the November runs the atom estimate over-counts at standard and study (+168% on expected_usd for a 1,278-token artifact whose runs kept 27 and 33 atoms). It is tracked in #1370.

Changes

  • dokimi/dokimi/novelty/tiers.py: every entry of CALL_TOKENS and EXTRACTOR_TOKENS is now (input base, input per artifact token, output base, output per artifact token), and call_tokens returns (max(0, round(in_base + in_per * n_tokens)), max(0, round(out_base + out_per * n_tokens))). The answerer's input term keeps its context_share / MEASURED_CONTEXT_SHARE scaling; output is not scaled.
  • Values are the least-squares fit of the 10 fit-half runs (x is the artifact's tokens, y a role's tokens per call, input and output fitted separately): triage extractor (841, 0.186, 1908, 0.251) from the four triage runs, with an output slope; standard (452, 0.54, 225, 0.0) pooled over the six standard, study and untiered runs, since they do the same work per call; answerer (-104, 0.946, 350, 0.0) and judge (481, 0.014, 95, 0.0) over every fit run. The study and untiered fallback to the standard extractor profile stays; its comment now says those runs were measured.
  • TOKENS_PER_ATOM, ESCALATION_SHARE and MEASURED_CONTEXT_SHARE are untouched (fitted on the October runs). FITTED_TOKENS_MAX stays 6723 (the largest October run); its comment now reads -2% at 1,153 tokens and -14% at 6,723, recomputed with the refit.
  • dokimi/dokimi/novelty/cost.py: least_sure_role takes the role with the largest dollars at every tier, a tie going to the first of extractor, answerer, judge, with the reason "the has the most dollars, so an error in its call count or its token profile moves the figure most". Its unused tier parameter and the borrowed branch are dropped, and add_role_usd calls it without a tier.
  • tests/test_novelty_token_profile.py (new): the 17 rows; the constants equal a closed-form least-squares fit of the fit rows; the 7 held runs, priced from their own calls at the pinned list prices, land within 15% per run (worst 11%) and within 20% per role (worst 16%).
  • tests/test_novelty_tiers.py: pins the new 4-tuples and call_tokens("extractor", 1000, "triage") == (1027, 2159) / "standard") == (992, 225); the answerer scaling test uses the new constants and checks output is not scaled; the October whole-projection dollar check is renamed test_held_out_dollars_within_55_percent with its own tolerance (held-01, a 198-token standard run below the refit's smallest artifact of 640 tokens, lands +51%: 47 projected extractor calls against 34 measured, +22% priced from the 34). Calls and atoms checks and the triage dollar check keep 35% (worst triage 24%).
  • tests/test_novelty_estimate_roles.py: the borrowed-extractor test and BORROWED are removed; every tier (and no tier) names the role with the largest dollars with the new reason, a unit test pins the rule on hand-made splits (judge largest, a tie going to the first role), and the stderr-line test expects the new reason. Both tests pinned the behaviour this reverses.
  • docs/skill-novelty.md (the estimate paragraph only): the one rule and its evidence, the profile's fit and its held-out figures (11% per run, 16% per role), study and untiered sharing the standard extractor profile, the October figures restated (dollars within 51%, high on 6 runs up to +51%, low on 6 down to -14%, triage -2% at 1,153 tokens and -14% at 6,723), and the note on the atom count. docs/skill-novelty-walkthrough.md line 79: "up to 14% low".
  • Changelog fragment (Changed). novelty_budget.py and tests/test_novelty_estimate_roles.py docstrings name --dry-run, not the old --estimate-only.

Risk

expected_usd changes at the same call counts. On the 17 runs' own --dry-run call counts it rises on 13 and falls on 4 (n01 triage 640 tokens -1.2%, n09 -3.5%, n10 -2.4%, n16 -0.4%), so it is not higher everywhere. The rises are largest on triage with large artifacts and on standard and study at small ones:

Run Old estimate vs billed New estimate vs billed
n08, triage, 5,954 tokens -41% -22%
n15, triage, 4,003 tokens -22% -7%
n07, triage, 4,234 tokens -5% +16%
n02, standard, 640 tokens +32% +49%
n13, standard, 1,278 tokens +146% +168%
n14, study, 1,278 tokens +88% +104%

Where the atom count is already over-counted (n13, n14, n02) the overshoot grows; that cause is #1370. Triage on large artifacts runs less low. Artifacts above 6,723 tokens still extrapolate and are still flagged (usd_extrapolated). The least_sure_role reason text changes at every tier, and study and an untiered run no longer say "borrowed" or always name the extractor; a script that matches the old text breaks.

Open PRs on the same files: #1197, #1325 and #1366 edit other lines of docs/skill-novelty.md, the walkthrough and the two estimate test files, and #1190 and #1247 edit novelty/cost.py and commands/novelty_budget.py. A test merge of each with this branch merges every file they share cleanly. The conflicts #1197, #1190 and #1247 show are all in files this branch does not change.

Testing

On Linux, at b8a473db (on main 52f9de6):

  • make ci-local: 38 passed, 0 failed, 16 skipped (the external-catalog smoke needing docker and network, the Claude Code install, conda-forge deps, the Atheris fuzz, semgrep, the cross-platform matrix legs, and jobs that need a PR or a deploy). 30828 tests passed, 27 skipped; changed-line coverage 100% (8 lines); mutation of changed lines: 28 mutants, 27 killed, 1 waived (max(0, ...) on the output never binds, since every output base is at least 95 and no output slope is negative). A first run had one failure, a 60 s timeout in tests/test_unclosed_openers.py (a test this change does not touch); that file alone passes (346 passed) and the second full run is the one above.
  • On main's code the new and changed tests fail: test_novelty_token_profile.py 3 failed (the constants; n11's answerer 24% low per role; n15 at -22% in the 15% check), test_novelty_estimate_roles.py 6 failed, 8 passed (the old reason text; study and untiered name the extractor, not the largest dollars), test_novelty_tiers.py 3 failed, 54 passed (the old constants and (1016, 2359)).
  • 12 mutants, each failing the test that pins it: no output slope, triage and standard profiles swapped, the borrowed branch put back, max turned into min, the tie order reversed, 0.0 for the answerer's output base, the answerer's output scaled with the arms, the reason without "call count", the judge's input slope off by one digit, the standard extractor output at 195, no floor on the input, and study borrowing the triage profile.
  • Not run: the matrix legs on Python 3.11, 3.12 and 3.14. No paid run and no model call: the figures come from the 17 rows as given.

Open questions

None.

Revert

A plain revert restores the old 3-tuple profile, the borrowed rule and the old docs and tests. Nothing is stored: expected_usd, usd_by_role and least_sure_role are printed by --dry-run, not written to a record.

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)

…east_sure_role rule (intel#1217)

`skill novelty analyze --dry-run` priced each call from a flat output profile and a per-tier input line fitted on the October runs. Against 17 paid runs of 2026-11-28 the triage extractor's output grows with the artifact (2,154 tokens per call at 640 tokens, 3,705 at 5,954) where the profile said 2,359, so large triage artifacts priced low (n15, 4,003 tokens: -22% priced from its own calls).

Every `CALL_TOKENS` and `EXTRACTOR_TOKENS` entry is now (input base, input per artifact token, output base, output per artifact token), least-squares fitted on 10 of the 17 runs: the triage extractor on its own with an output slope, standard, study and untiered pooled (they do the same work per call), the answerer and the judge on every fit row. Priced from their own calls, the other 7 runs land within 11% per run and 16% per role. `FITTED_TOKENS_MAX` stays 6723 and its comment gives the refit's figures for the two October runs.

`least_sure_role` takes the role with the largest dollars at every tier, with a reason that names the call count too. The study and untiered branch that called the extractor profile borrowed is gone: in 15 of the 17 runs the role with the largest estimated dollars had the largest dollar error, and the other two are triage runs where every role was off by under $0.01. Its `tier` parameter is dropped.

Tests: a new module holds the 17 rows and checks the constants against a closed-form fit and the held-out runs against the pinned prices; the October dollar check has its own 55% tolerance for the 198-token run below the refit's smallest artifact. The estimate paragraph of skill-novelty.md and the walkthrough's "up to 14% low" follow the refit.

Test-narrowed: test_a_tier_without_an_extractor_profile_names_the_extractor_as_borrowed is removed with the borrowed branch it pinned, and test_triage_and_standard_name_the_role_with_the_largest_dollars is renamed and widened to every tier (intel#1217); test_held_out_dollars_within_35_percent is renamed test_held_out_dollars_within_55_percent for the 198-token held-01 run (+51%), below the refit's smallest artifact (640 tokens), with its calls and atoms checks unchanged at 35% (intel#1217)
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…#1217)

The estimate paragraph of skill-novelty.md carried a literal issue placeholder, which is filled in the PR description only; it now states the fact without a link.

The changelog fragment said every role's output term grows with the artifact, but only the triage extractor's slope is non-zero; it now says so, and states the 13 of 17 runs figure plainly.

The waiver comment in call_tokens said every output base is above 95, but the judge's is exactly 95; it now says at least 95 with no negative slope.

Two sentences with a plural subject and "its own" are rephrased, and two docstrings (the estimate roles test and novelty_budget.py) name --dry-run instead of the old --estimate-only flag.

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

exai-bot commented Nov 28, 2026 •

Copy link
Copy Markdown

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

CI at b8a473d: 21 passing, 4 skipped.

Review details
  • Commit reviewed: b8a473d against merge base 52f9de6
  • Coverage: 9 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 117k tokens (54k from cache), 30s
  • Tool calls: 8 (5 file_read, 1 ci_status, 1 code_search, 1 local_check_results)
  • Novelty token profile refit, cost estimation, tiers, and documentation: 9 files

@codecov-commenter

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 96.21%. Comparing base (52f9de6) to head (b8a473d).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1371      +/-   ##
==========================================
- Coverage   96.22%   96.21%   -0.02%     
==========================================
  Files         509      509              
  Lines       67762    67759       -3     
  Branches    11766    11765       -1     
==========================================
- Hits        65203    65191      -12     
- Misses       1576     1581       +5     
- Partials      983      987       +4     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/novelty_budget.py 97.03% <ø> (ø)
dokimi/dokimi/novelty/cost.py 96.39% <100.00%> (-0.10%) ⬇️
dokimi/dokimi/novelty/tiers.py 100.00% <100.00%> (ø)

... 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: CONTRACT (head b8a473d)

  • Contract: changed (count signal only, no file:line)
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The fit and held-out pricing checks pass using the recorded measurements. The October fixture below the new fit range remains 51% high at whole-run level, as disclosed. I did not repeat the paid runs.

Coverage: 74 passed in 3.07s. Hosted checks on the reviewed head passed or skipped. The combined #1371 and #1374 tree also passed 86 targeted tests.

@napetrov
napetrov merged commit 26e816b into intel:main Nov 29, 2026
25 checks passed
@antonwolfy
antonwolfy deleted the fix/novelty-token-refit branch November 29, 2026 10:27
@xaleryb

xaleryb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

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 analyze --estimate-only: refit the per-role token profile against measured runs per tier

5 participants