Repository navigation
feat(mesh): count in-flight prefill tokens per worker (url@rank) - #3481
Conversation
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
Path scope:
|
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (4)
- Merge this only together with #3406, not on its own. No policy reads
prefill_tokens()in this PR, so landing it alone adds an unread counter plus charge and release work on every PD request (the "land it with its first caller" rule from #3210 and #3406, which the description also states). The decode-first change under idx2idx is the one part that stands alone. It changes prefill selection on the MI350 default path, so please run theci:meshgates once before merge; they were not requested on this head. - Make the idx2idx comments say what the code does.
planner.rs:69-71andhttp_pd_router.rs:449-450say the prefill policy is offered "only" the decode's rank.on_decode_rankalso keeps prefills that idx2idx does not remap, and offers all of them when none is left on that rank. Reword both, as theon_decode_rankdoc atplanner.rs:27-29already does. - Compute the "ATOM backend + idx2idx" check once. The same
matches!(backend, Atom) && matches!(policy, Idx2Idx)appears athttp_pd_router.rs:408-413andingress.rs:650-654. Add oneRouterConfigmethod and call it from both places, so the PD router and ext-proc cannot drift apart. - Small fixes:
- Assert
p.worker.prefill_tokens() == 0incancelling_dispatch_releases_pending_load(http_pd_load_tests.rs:737) andstalled_prefill_error_body_cancels_pending_decode(:866). Today only the streaming success path checks the release. - In the description, drop "CI's current mesh step does not filter in
core::placement...": the first step ofatomesh-mocker-benchmark.yamlruns every--libtest, so these tests already ran on this PR. What CI does not run istests/routing(http_pd_load_tests,http_proxy_body_tests). with_prefill_tokensreleases before it charges, but every caller builds a fresh guard: drop the call or add adebug_assert_eq!(self.prefill_tokens, 0).
- Assert
Reviewed at 1124ee6. From the #3406 review, already done here: decode first under idx2idx with a nonzero idx2idx test, the gauge set from the atomic's value, a warning on release underflow, and non-atomic selection and charge listed as a follow-up. ext-proc single-worker and gRPC charging remain listed follow-ups.
|
ci triage for afd71ca:
|
wanzhenchn
left a comment
There was a problem hiding this comment.
Reviewed at 1124ee6 while re-reviewing #3406. The charge and its release paths look right, and selecting decode first is the right fix for idx2idx. It also changes two other prefill policies:
cache_awaredeletes live tenants (inline, with a failing test). Please fix it here, or select decode first only when the prefill policy isagentic.dp_stickyrecordsrebindwhere it recordedrank_mapping. A session pinned to a prefill on another rank is no longer a candidate, so it is re-pinned to the worker on the decode's rank with the fewest live sessions (dp_sticky.rs L159-L190), instead of keeping its pin and being remapped. Placement improves, butrank_mappingnow fires only when the decode's rank has no healthy prefill. Please update metrics.md L167-L169 and mention it in the description.
1124ee6 to
5b3b2ea
Compare
|
@atom-bot review |
aiter-bot
left a comment
There was a problem hiding this comment.
ATOM PR #3481 — feat(mesh): count in-flight prefill tokens per worker (url@rank)
Charges each request's prompt-token count to the prefilling worker's per-rank atomic counter at placement time and releases it when that prefill finishes (P/D prefill-guard drop, first streamed response frame, or guard drop), exporting the in-flight count as the mesh_worker_prefill_tokens{worker} gauge.
Review:
Coverage: 11 files / 173 added lines -- within one review pass
Validation (deterministic): NOT RUN — ships no test target (the diff is Rust mesh code under atom/mesh; validate-atom-pr defines no target for it) and auto-validation is disabled (REVIEW_AUTO_VALIDATE=0)
load() == 0 but never prefill_tokens() == 0 — only the streaming success path checks the release, so a later refactor of WorkerLoadGuard's Drop or of the P/D guard-drop timing could strand the charge with no failing test, and since nothing but a release ever lowers the counter, the gauge would then drift upward permanently. Author must add the two release assertions valarLip's review named. [verified]
2 finding(s) posted inline, on the lines they are about:
atom/mesh/src/observability/metrics/schema.rs:435— A5: planner.rs:108 charges the prompt only whenreq.streamon Single placements, and the gRPC…atom/mesh/src/core/worker.rs:1007— worker.rs:1007with_prefill_tokenscallsrelease_prefill()before charging, but all three call sites…
_Independent refutation: 3 judged, 0 killed, 3 defended — same-family (claude reviewed its own output). Step 7.6 above
11a04c1 to
73572ba
Compare
73572ba to
a3b86cf
Compare
|
Thanks @valarLip @wanzhenchn. Status at a3b86cf, rebased onto #3493's 521882a:
@wanzhenchn Both items are fixed in #3493: aiter-bot's items are answered inline; its first one is item 4 above. |
a3b86cf to
f9d07c1
Compare
f9d07c1 to
19fac16
Compare
0cf44d1 to
f3f9fa5
Compare
f3f9fa5 to
9e89ad9
Compare
|
@MengqingCao LGTM. items are resolved: the P/D cancel and stalled tests now check the charge is taken (7) and released (0), only thing left is the merge order, this goes in with #3406 rather than alone. mocker benchmark job still running.. |
The last gap of the class ROCm#3481 opened. Eleven of the 54 ids are also this codebase's vocabulary: B1..B7 are the KV-offload chunk groups (atom/kv_transfer/offload/README.md), C1/C2 the MTP4 rows (atom/models/glm52/mono/kernels/op.py) and C3/C4 deepseek_v4's cuda-graph capture topology (atom/models/deepseek_v4/mono/session.py). So a lawful finding -- `B1-B2 stage before B3-B4, breaking the tail-to-head order` -- was read as id-led and refused. RULE-CODE-IN-CARD is fatal, so the only way out is an untrue `-- not reported:`: the trap r41 item 1 closed, reached from the other side. `main` refuses these too; this is the class, not a regression. No shape separates `B1` the rule from `B1` the chunk group -- that is what the word lists of r42-r45 established -- so the diff decides, which is the one thing that is not a guess. It is the rule r45 put on CLAIM_IDENT, applied to the id reader too, and `audit_card` already had `diff_text`. Weighing the two errors: refusing a lawful finding is fatal, shipping an id-led line is cosmetic. So a word the PR uses itself stops being read as an id, and both readers share one vocabulary so they cannot disagree. `.claude/` contributes nothing, on purpose: rules.md names every id, so a PR touching the skill -- this one does -- would otherwise put all 54 in the vocabulary and switch the gate off in exactly the reviews most likely to exercise it. Pinned by its own case. selftest 166 green / 0 red. Dropping the vocabulary check turns "a finding using a word the diff uses" red; dropping the `.claude/` exclusion turns "a diff that only touches the skill contributes no vocabulary" red; neither masks the other. With an empty vocabulary the reader is unchanged over 212,823 real lines. check_prompts 0 drift, ruff clean, SKILL.md 505/505. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Merged with current main (dc6cd23), this no longer compiles: #3698 added a |
Each worker now carries a prefill-token counter next to its request count:
the prompt tokens placed on it whose prefill has not finished, exported as
mesh_worker_prefill_tokens{worker}. DP-aware workers keep one per rank.
The planner charges the prompt's tokens, when the router has them, to the
worker that prefills it, and the load guard holds the charge until the
prefill is done:
- P/D: on the prefill worker's guard, released when the prefill response
completes. Under idx2idx it follows the remapped prefill rank; the idx2idx
reservation test carries a nonzero charge and checks where it lands.
- Regular HTTP, streaming: until the response's first frame.
- Regular HTTP, non-streaming: not charged, since its first frame arrives
only after decoding.
ext-proc single-worker and gRPC placements do not charge yet. A release
larger than the charge saturates at zero and logs a warning.
Ported from #3210 with its review addressed: non-streaming requests are not
charged, with a test, and the charge lives on WorkerLoadGuard rather than a
public PrefillTokenGuard.
Co-authored-by: Jasen2201 <yajizhan@amd.com>
- The cancel and stalled error-body P/D tests check the prefill charge is taken and released, not only the request load. - WorkerLoadGuard::with_prefill_tokens debug-asserts a fresh guard instead of releasing a charge no caller has. - The mesh_worker_prefill_tokens help names the paths that charge it. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Needs ruling from @MengqingCao: can this PR charge the prefill on every path, not only on HTTP P/D and streaming HTTP? A path left at zero shows a worker that is prefilling as idle to Paths and release pointsFor example, worker A is prefilling one non-streaming request with a 32K-token prompt, and worker B two streaming requests of 1,024 tokens each.
The engine side at 659c3ba: the charge, the release at the first sampled token and the gauge. With every path charged, the metric help and |
|
Needs ruling from @MengqingCao: can a non-streaming request's charge follow the engine's count? Leaving it at zero and holding it until the response ends each misplace requests for part of its life. Take worker A with one non-streaming 32K-token request (about 2 s of prefill, then 20 s of decode) and worker B with two streaming 1K-token requests. Uncharged, A scores 512 against B's 1,024 while it prefills. Held to the end, A scores 33,280 through its decode. The timeline
Scores are queued prefill plus 512 per in-flight request; the new request's own uncached tokens are the same on both workers, and B's two prefills are already done. Under P/D this request is charged on its prefill worker until the prefill response returns, so its charge already ends with the prefill. Polled, the engine's count lags, so requests placed since the last poll still need the router's own charge. |
main's LocalPlanner (#3698) builds a PlacementPlan::Single without prefill_tokens. The gRPC pipeline it feeds builds its load guards without the count, so 0 changes nothing. Co-authored-by: Cursor <cursoragent@cursor.com>
9e89ad9 to
afd71ca
Compare
valarLip
left a comment
There was a problem hiding this comment.
✅ LGTM
The code is done. Merge this only together with #3406, as agreed under ask 1: nothing in this PR reads prefill_tokens().
Every earlier ask is fixed here or was moved to #3493, which has merged:
- The decode-first change, the idx2idx comment wording and
RouterConfig::prefill_on_decode_rankare on main through #3493 (config/types.rs:614,http_pd_router.rs:408,ingress.rs:652). This PR no longer touches selection and does not duplicate them. - The cancel and stalled error-body tests now assert the charge (7) and the release (0) (
http_pd_load_tests.rs:747,752,841,864). with_prefill_tokensdebug-asserts a fresh guard (worker.rs:1007).- The description's CI sentence is corrected. The routing tests are compiled into
--libthrough#[path], andrun_atomesh_test_harnessran them on this head. - wanzhenchn's E0063 after #3698 is fixed by
prefill_tokens: 0on theatom_localplan (atom_bridge/mod.rs:240). Main has no mesh commits after this PR's base.
Charge and release: every charge is released exactly once on every path we traced. That covers success, error, abort or cancel, stall, client disconnect, retry, idx2idx remap, streaming and non-streaming. A charge happens only in with_prefill_tokens, and release_prefill zeroes the field before Drop's decrement_load runs. The gauge uses the same url@rank key and removal path as requests_active.
Before merge:
- Resolve the two outdated aiter-bot threads (
schema.rs:435,worker.rs:1007). Both are fixed at this head. - Jasen2201's question about charging every path (gRPC, ext-proc, non-streaming) is a scope ruling for #3406 or a follow-up. It is not a defect in this PR, and the metric help names the paths that are charged.
Reviewed at afd71ca (Deep, re-review; two independent passes, no divergence). Already fixed: asks 2 and 3 via #3493; ask 4 (asserts, CI sentence, debug_assert); the E0063 rebase fix.
|
@wanzhenchn Thanks, that's it. Rebased onto 659c3ba and fixed in afd71ca: the |
Ruling: yes, in follow-up PRs on this stack rather than in this one. For ext-proc and gRPC streaming, the guard carries the plan's
Ruling: it follows the KV events instead, as llm-d-router#3975 does. A non-streaming request on every protocol is charged at routing and released when the selected How each path releases
|
Jasen2201
left a comment
There was a problem hiding this comment.
follow up pr fix my comments
main's #3481 added PlacementPlan::Pair::prefill_tokens; this test's initializer predates it and stopped the lib tests from compiling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
) * review-pr: refuse a finding that opens with an internal rule code SKILL.md says, in as many words, "Do NOT use rule codes (B1, D4, A1...) in output -- they are internal labels only". The card gate then parsed a leading rule code as a valid way to claim a FIRE. So the instruction forbade it and the gate rewarded it, and a model that follows the gate over the prose is behaving correctly. It did: ATOM#3481's published review opens a finding `⚠️ A5: planner.rs:108 charges the prompt only when ...`. The reader of that review has no idea what A5 is; the label is this skill's own bookkeeping, shipped to someone it means nothing to. The id still counts as the claim -- withdrawing that would turn such cards into UNREPORTED-FIRE, which the comment below this one explains was worse -- but the card does not ship with it. Two selftest cases, mutation-verified. Checked against ATOM#3481's actual finding text, which the gate now names. 131 green / 0 red. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: refuse only real rule ids, and let Rust cite itself Review raised two defects in the first version, both confirmed. 1. The shape `([A-Z]+\d+[a-z]?):` is not specific to rule ids. `FP8:`, `TP8:`, `MI300:` and `V4:` all match it and are ordinary ways to open a finding in this repo, so the gate would have refused them carrying a message about an internal rule id that does not exist. Now checked against ALL_RULES. 2. Refusing the id was a dead end for a finding with no citable path, because triage's CITATION covered neither `.rs` nor `.toml` -- while `_publish.py` anchors both, and ATOM#3481's Rust findings did anchor inline. Two citation regexes disagreeing meant a mesh finding's `lookup.rs:185` was invisible to the gate and the rule id was its only remaining claim. Extended, which closes the dead end and the asymmetry at once. Two more selftest cases (an FP8: opening is not refused; a Rust citation counts), and the three branches are mutation-verified. 133 green / 0 red, 43 publisher tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: catch a rule id behind emphasis, at both match sites Review asked for this, with one detail off: it said ATOM#3481 ships `**A5:**` and still would. The bytes of that comment are `⚠️ A5: planner.rs:108` with no emphasis, so the gate did catch it. The evasion is real as a next step, not as an observed case -- SKILL.md's own examples lean on `**`, so `**A5:**` is the shape a model reaches for once the plain one is refused. Both match sites hardened, not just the one that refuses. The other registers a rule id as claimed, so a match pinned to offset 0 loses the claim there and raises a false UNREPORTED-FIRE -- the same regex, two opposite failures. Selftest case with the emphasised literal; mutation-verified. 134 green / 0 red. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: give a path-less FIRE a legal card, and share one citation pattern Review found four defects, all confirmed. The first is the serious one: the previous version left a state with no legal way out. 1. A verdict reason may name only a symbol or a condition, and SKILL.md's format allows that. Then `fire_paths[rule]` is empty, and the card had two moves and both were fatal -- name the id and RULE-CODE-IN-CARD refuses it, drop the id and UNREPORTED-FIRE fires. The only way through was a `-- not reported:` that is untrue, which is exactly the "making a reviewer write something false to satisfy a gate" this file already argues against one function away. A path-less FIRE can now be claimed by the distinctive words of its own reason. 2. The in-card `cited` scan carried its own copy of CITATION's extension list and had drifted from it: no `rs|toml`, so a Rust-only finding read as citing nothing and skipped UNANCHORED and UNBACKED both. It now derives its pattern from CITATION, so they cannot diverge again. 3. The new cases all passed an empty verdicts_text, so none of them exercised the interaction they were about. Six cases now drive real FIRE verdicts: an `A5:` card against an `A5` FIRE, the same card without the id, a path-less FIRE claimed by tokens, the id refused in that case too, a backticked id, and a non-rule `FP8 FIRE` that must stay UNREPORTED rather than be claimed by a lookalike id. 4. Cleanups: the rule-id regex is compiled once as RULE_ID_HEAD and the ALL_RULES membership check is a frozenset, applied once before either reader rather than pasted at both; and RULE-CODE-IN-CARD no longer counts under "findings cannot be traced", which is about tracing, not about how a finding is written. 143 green / 0 red, 43 publisher tests, check_prompts 0 drift. Every branch added here is mutation-verified. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: tighten the token claim, read the id through the tag, stop teaching the shape Review found two defects and three nits. All five were real. 1. One shared four-letter word claimed a FIRE. SKILL.md mandates "**Author must**" on every finding, so `must` alone let any finding claim any path-less FIRE whose reason used it -- silencing the UNREPORTED-FIRE that belonged to another rule. Matching was also case-sensitive against a lower-case stopword list, so `Prefill` missed `prefill` while `This` sailed through, and a shared `1024` counted as agreement. `_claim_tokens` now folds case, drops pure numbers and drops the words SKILL.md mandates, and a claim needs two shared tokens or one identifier. 2. `RULE_ID_HEAD` only looked at offset 0, so `[verified] A5: ...` shipped unrefused -- and `_publish.first_clause` strips that tag, so the published line opened `A5:`, the ATOM#3481 symptom with one token in front of it. The id is now read through `_rule_head`, which strips the leading tag the way `_publish` does and accepts `:`, `—` or `--` after the id. One reader for both callers, so the comment about a single guard is true now rather than aspirational. 3. rules.md was teaching the shape. About fifty `⚠️ A1:` templates reach the worker through `expand`, so the model was shown the opening it would then be refused for -- the same instruction/gate disagreement this PR is about, one level up. The ids are out of the templates, and a selftest asserts no template opens with one. 4. The summary printed a bare `CARD NOT NAILED DOWN: ` when a rule code was the only problem; it now names it. The old test only checked that "cannot be traced" was absent, which an empty line and a crash both satisfy. 5. A comment claimed SKILL.md has a `**A5:**` example. It does not. 153 green / 0 red, 43 publisher tests, check_prompts 0 drift, mapping unchanged. Nine new cases; every branch mutation-verified, including the three that first stayed green because the fixtures shared words for other reasons. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: test the identifier on the spelling it was written with Review found that the previous commit's own fix regressed the case it was for, and the three examples it gives all reproduce. Lower-casing happened before the identifier test, so IDENT's ALL-CAPS branch could never match and `[a-z]+_` rejected anything with a digit in front of the underscore. A path-less `B1 FIRE -- KVCACHE size not updated` then had no claimable token, and neither did `fp8_scale dropped on reload` on its own; a one-word reason like `B1 FIRE -- deadlock` could never reach the two-token threshold at all. Each of those is a fatal UNREPORTED-FIRE whose card has no legal move -- the same dead end this PR set out to remove, reintroduced one commit later. `_claim_tokens` now returns `{folded: spelling}`: folding still decides whether two sides share a word, and the spelling is what the identifier test reads. CLAIM_IDENT is local to this path (IDENT is read by other gates and is not mine to widen) and admits a digit in the first segment. A reason with fewer than two claimable words of its own is claimed by one. Also from review: `rules.md:161`'s `B5-[sub-type]:` was the last id-led template and the template selftest's regex could not see it; `_rule_head` now accepts a sub-type suffix and an en dash, and the test regex matches the placeholder form. A double-dash case was missing -- removing `--` from the separators had turned nothing red. 158 green / 0 red, 43 publisher tests, 0 drift, mapping unchanged. Eight new cases; five mutations verified, including the one that first stayed green because the test regex could not match the placeholder it was meant to catch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: put the HK ids back where expand reads them, and stop GEMM naming things Two regressions, both mine, both from the last two commits. 1. The rules.md rewrite took the only `HKn` out of each Housekeeping row. Those ids are not decoration: `expand_rules` finds the row by `\b(HK\d+[a-z]?)\b`, so a derived HK rule became MISSING-RULE-TEXT, rc 1, and fetch.sh aborted the whole review. A `.sh` file in the diff, a `# TODO`, an `ATOM_` env var or three top-level directories is enough to derive one -- this PR touches selftest.sh, so it would have killed its own review. Verified: `expand` on a diff deriving HK1 and HK4 exits 1 on this branch and 0 on main. The ids now sit in the Check column, which expand reads and no card ever quotes, so the no-id-in-templates test still counts zero. A selftest derives HK rules and asserts expand exits 0; stripping the ids again turns it red. 2. CLAIM_IDENT's ALL-CAPS half is also how this codebase writes ordinary words. GEMM, BF16, CUDA, TODO and MI300 all match it, so `B1 FIRE -- GEMM output cast drops the per-token scale` could be claimed by an unrelated card line saying `BF16 GEMM`, and the UNREPORTED-FIRE that belonged to B1 disappeared. That case was correct on main and at 707fd5a; it broke in b232b03, as a side effect of the previous round's fix. A bare ALL-CAPS word now counts only if it is neither a VALUE (dtypes and architectures are already that) nor one of the spelled-out generic terms -- the distinction is which words are common here, not what shape they have. `KVCACHE`, `fp8_scale` and `w8a8_gemm` still count. 160 green / 0 red, 43 publisher tests, 0 drift, mapping unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: let the basename form SKILL.md teaches claim its own FIRE Two open notes from review, both confirmed here first. A verdict reason writes the path it found, `atom/models/x.py:1`. SKILL.md's good examples write the basename, `x.py:1`. The claim matched the verdict's exact string, so the form the skill teaches could not claim the FIRE it was reporting and the card got a fatal UNREPORTED-FIRE -- the instruction and the gate disagreeing again, with the instruction losing. Paths are compared on segment boundaries now, so `x.py` answers for `atom/models/x.py` while `other/x.py` and `scale.py` (against `kv_scale.py`) still do not. And no case carried an en dash, so removing `–` from the separators turned nothing red. One added. 164 green / 0 red, 43 publisher tests, 0 drift, mapping unchanged. Four new cases, three mutation-verified -- including the segment-boundary one, which first stayed green because both fixtures also failed a bare endswith. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: claim a path-less FIRE by a backticked symbol, not by guessing Review's fifth blocking finding in this heuristic, and its advice was to stop patching it. Confirmed first: verdicts `A5 -- foo.py:3 tuned config missing` and `B1 -- FP32 output cast drops the per-token scale` against the single card line `⚠️ foo.py:3 FP32 tuned config missing` claims B1 silently, and `num_tokens`, `head_dim`, `MI355X`, `GSM8K`, `TTFT` do the same. The word list only ever held the words the previous round named. It was never going to hold. No shape separates a name from this codebase's ordinary vocabulary, so every version guessed and every round found what it guessed wrong. The claim is now the one thing that is not a guess: a symbol the reason itself put in backticks, matched as written. `_GENERIC_CAPS`, `CLAIM_IDENT`, `_claim_tokens` and the template-word and stopword filtering are gone with it. A reason that backticks nothing has no route -- which is where main already was, so nothing regresses; what it costs is one pair of backticks in the ledger. Also from review: `_rule_head` refused only `ALL_RULES`, so the ids in `UNREACHABLE_BY_DESIGN` shipped. `📝 HK3:` is the live case, because SKILL.md's own integration-test checklist told the worker to write exactly that. Both ends fixed -- the gate refuses `RULE_SET | UNREACHABLE_BY_DESIGN`, and the checklist no longer hands out the id. 148 green / 0 red, 43 publisher tests, 0 drift, mapping and expand unchanged. Five cases replace the eleven that tested the guesswork; three mutations verified. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: find the rule id through whatever is standing in front of it The tag strip ran once and only on a bare `[tag]`, so six openings review listed still shipped: `**[verified] B1:**`, `**[verified]** B1:`, `` `[verified]` B1: ``, `[verified] [B1]`, `[verified] (B1):`, `A5/B1:` and `D4 -`. Each verified before the change. `_publish.first_clause` strips the tag on the way out, so every one of them reaches the reader as an id-led line -- the ATOM#3481 symptom with decoration in front of it. ATOM#3481 itself used bold. `_rule_head` now peels leading emphasis and bracketed groups in turn rather than once, and accepts a second id after `/` or `,` and a lone `-` as a separator. A peeled group whose contents are themselves a rule id is the id, not a tag over it, which is what `[verified] [B1]` needs and what a single pass cannot tell. Two selftests: seven decorated forms must all be refused, and five ordinary openings -- `FP8:`, `MI300:`, `[verified] x.py:1`, a plain sentence and `[inferred] planner.rs:108` -- must all be left alone. Five mutations verified. 150 green / 0 red, 43 publisher tests, 0 drift, mapping unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: tell the worker about the backticks, and put back the tests I deleted Three things from review, and the third is the one that matters. 1. The new claim needed a backticked symbol and nothing told the worker so. SKILL.md's verdict format explicitly allowed "symbol, or the condition", and neither it nor the UNREPORTED-FIRE hint mentioned backticks -- so a reason like `B1 FIRE -- the scheduler lock is not held` left the card with no legal form again, which is the trap this PR exists to remove. The format line now reads "file:line, or a `backticked` symbol the card will name" (edited in place; the tree merged with #3494 is at 505/505), and the hint says to add them, and that editing the verdict line to do so is a fix rather than a cheat. 2. The symbol was matched as a plain substring, so a two-character one found itself everywhere: `tp` inside "output", `kv` inside "kv_cache". Identifier boundaries now, with both cases pinned. 3. The commit that replaced the word list deleted 224 lines of selftest, and five of them had nothing to do with the word list: the housekeeping `expand` guard, "no rule template opens with an id", and the three `_same_file` cases. The first of those is the test that catches the regression that aborts a review for any diff with a `.sh` file in it -- a regression this PR introduced two commits earlier. Restored, all five passing. That is the same mistake twice in one branch: removing something whose only job is to fail later. Nits: `D4 violation in …` (SKILL.md's own bad example), `HK3 bug fix without test`, `B1 (silent bypass):` and `[B1/B2]` are refused now; the dead `_claim_tokens`, `RULE_ID_HEAD`, `_FIRE_STOPWORDS` and `_CLAIM_TEMPLATE_WORDS` are gone, and two comments that quoted text this PR removed are fixed. `` `x.py:3`: B1: `` is still not refused, and is listed rather than patched. Chasing shapes one at a time is what the word list did for five rounds before this PR replaced it; the same answer should not be re-derived for the matcher. 157 green / 0 red, 43 publisher tests, 0 drift, mapping and expand unchanged. Four mutations verified. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: close punctuation-symbol and rule-id gaps * review-pr: strip what first_clause strips after a citation `_rule_head`'s citation skip removed only `[\s*`_]*:?`, while `_publish.first_clause` strips `(?:-\d+)?` and `[,:]` as well. So an opening that put the id after a range citation, a comma or a dash -- `foo.py:563-569 A5: …`, `` `foo.py:563`, A5: … ``, `foo.py:563 — A5: …` -- returned None here and still reached the reader as `A5: …`, which is the id-led line this gate exists to refuse. Range citations are common: real bot cards carry 74 of them. The skip now strips the same shapes. `foo.py:3 — the E2E path` and `foo.py:3-5 TP8 x` are still left alone, and both ends are pinned by `_head_forms` (25) and `_head_passes` (9). selftest 163 green / 0 red, check_prompts 0 drift. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: past a citation, read only the id forms first_clause creates The widened citation skip refuses ids this codebase uses as its own words. B1..B7 are the KV-offload chunk groups (kv_transfer/offload/README.md:1084), C1/C2 are the MTP4 rows (models/glm52/mono/kernels/op.py:131), and C3/C4 are deepseek_v4's cuda-graph capture topology (models/deepseek_v4/mono/session.py, a dozen uses). All eleven are in REFUSED_IDS. So a lawful finding, written in the citation-led form SKILL.md teaches, was read as id-led: README.md:1084, B1-B2 stage before B3-B4 ... -> B1 (was: no id) op.py:131 — C1/C2 rows for MTP4 are swapped -> C1 (was: no id) session.py:1527 C3 buffers are updated ... -> C3 (already, before this) RULE-CODE-IN-CARD is fatal, so the worker's only way out is an untrue `-- not reported:` -- the trap this gate's own first round exists to close. Past a citation only the colon forms are read now. `_publish.first_clause` strips `(?:-\d+)?` and `[,:]` and nothing else, so `foo.py:563-569 A5: …` is the shape that reaches the reader id-led; `B1-B2 stage before` and `C1/C2 rows` are not, and never were. An id at offset 0 is still read with the full BARE_ID, so every #3481 form stays refused. Replayed over 212,823 unique real lines (ATOM and aiter PR + issue comments, 3000 main commit messages): 0 results change. That number is not evidence of safety on its own -- a finding the old gate made unwritable cannot appear in a corpus of what the old gate published -- which is why the three forms above are taken from this repo's own files rather than from the corpus. selftest 163 green / 0 red (reverting the tightening turns "an ordinary opening is left alone" red, 162/1), check_prompts 0 drift. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: write the rule-id pattern once CITED_ID pasted BARE_ID's first two lines verbatim -- the id, its sub-type, the `A5/B1` list and the `(silent bypass)` aside. The two readers differ only in what they accept after that, so the shared part is now `_ID_HEAD` and each reader supplies its own tail. This is the nit r41 raised about the rule-id regex, reintroduced by the commit before this one. No behaviour change: replayed over 212,823 unique real lines (ATOM and aiter PR + issue comments, 3000 main commit messages) plus the 14 decorated forms the selftest pins -- 0 differences. selftest 163 green / 0 red, 0 drift, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: a word the diff uses is not a rule id The last gap of the class #3481 opened. Eleven of the 54 ids are also this codebase's vocabulary: B1..B7 are the KV-offload chunk groups (atom/kv_transfer/offload/README.md), C1/C2 the MTP4 rows (atom/models/glm52/mono/kernels/op.py) and C3/C4 deepseek_v4's cuda-graph capture topology (atom/models/deepseek_v4/mono/session.py). So a lawful finding -- `B1-B2 stage before B3-B4, breaking the tail-to-head order` -- was read as id-led and refused. RULE-CODE-IN-CARD is fatal, so the only way out is an untrue `-- not reported:`: the trap r41 item 1 closed, reached from the other side. `main` refuses these too; this is the class, not a regression. No shape separates `B1` the rule from `B1` the chunk group -- that is what the word lists of r42-r45 established -- so the diff decides, which is the one thing that is not a guess. It is the rule r45 put on CLAIM_IDENT, applied to the id reader too, and `audit_card` already had `diff_text`. Weighing the two errors: refusing a lawful finding is fatal, shipping an id-led line is cosmetic. So a word the PR uses itself stops being read as an id, and both readers share one vocabulary so they cannot disagree. `.claude/` contributes nothing, on purpose: rules.md names every id, so a PR touching the skill -- this one does -- would otherwise put all 54 in the vocabulary and switch the gate off in exactly the reviews most likely to exercise it. Pinned by its own case. selftest 166 green / 0 red. Dropping the vocabulary check turns "a finding using a word the diff uses" red; dropping the `.claude/` exclusion turns "a diff that only touches the skill contributes no vocabulary" red; neither masks the other. With an empty vocabulary the reader is unchanged over 212,823 real lines. check_prompts 0 drift, ruff clean, SKILL.md 505/505. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: comments that name things the merged tree has Review finding, and both halves check out. `_diff_vocabulary`'s docstring credited "the rule r45 put on CLAIM_IDENT". CLAIM_IDENT appears exactly once in the tree -- in that sentence. The backtick redesign deleted the symbol, and r41/r45 are this PR's own review rounds, which a reader of the merged tree cannot open. Both now point at `_mentions_symbol`, which is in the tree and answers the neighbouring question the same way. The CITED_ID comment was worse than vague, it was wrong. It said `first_clause` strips `(?:-\d+)?` and `[,:]` "and nothing else, so `foo.py:563-569 A5: …` reaches the reader id-led while `README.md:1084, B1-B2 stage before B3-B4` does not". It does not draw that line. Run on the two: first_clause("atom/foo.py:563-569 A5: guard missing", "atom/foo.py:563") -> "A5: guard missing..." first_clause("README.md:1084, B1-B2 stage before B3-B4...", "README.md:1084") -> "B1-B2 stage before B3-B4..." Both reach the reader with an id-shaped word in front. A maintainer who read that comment and went to "fix" first_clause would have been fixing the wrong half. The real distinction is what the reader sees -- `A5:` is a bare label, `B1-B2 stage before B3-B4` is a sentence starting with one of this codebase's own words -- which is what the comment says now, and why the narrowing still earns its place beside `_diff_vocabulary`: it holds for a word the diff happens not to contain. No behaviour change: comments only. selftest 166 green / 0 red, check_prompts 0 drift, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: guard every id the gate refuses, and stop claiming a clean line Three from review. Two confirmed as written; the third is right that the enumeration was wrong and wrong about what the number is. 1. The template guard counted `RULE_SET` (42 derivable ids) while the gate refuses `REFUSED_IDS` (54). The eight templates this branch stripped ids from -- B3, B4, C3, D1b, D5, D8, D9, F1 -- are UNREACHABLE_BY_DESIGN, so a regression re-adding any of them passed the guard while every card quoting that template got refused. Replayed: with `⚠️ B3:` put back in rules.md the old guard stays 166 green / 0 red; the fixed one is 165/1. 2. The comment justifying the after-citation colon-only read claimed those are "the only ones first_clause turns into an id-led published line". They are not: first_clause("planner.rs:108 A5 charges only on req.stream", "planner.rs:108") -> "A5 charges only on req.stream..." This is the same wrong claim the commit before this one removed from triage.py, left behind in selftest.sh and restated once more. Both now say the real shape of it: a trade, not a line. Refusing the no-colon form would take `B1-B2 stage before B3-B4` with it whenever `_diff_vocabulary` does not hold the word; a refusal is fatal and an id-led index line is cosmetic, so the cosmetic gap is the one left open, named where someone can close it. 3. "Eleven of the 54 ids are also this codebase's vocabulary: B1..B7, C1/C2, C3/C4". C4 is not an id, as the review says -- but the count is not ten either. Measured over atom/ and docs/, nineteen of the 54 appear as ordinary words: the nine the enumeration missed are D6, D10, E1, E2, G1, G2, H2, I1 and N1. Both places now give the measured number, name all of them, say C4 is vocabulary and not an id, and say the count is what the tree says today rather than a constant. selftest 166 green / 0 red, check_prompts 0 drift, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: punctuation on its own is not a symbol Review finding, confirmed. `_claim_symbols` took any backticked span of 2-60 characters, so `==`, `--`, `()` and `::` were claim handles. `_mentions_symbol` cannot put a boundary around an end that is already punctuation -- requiring one would reject `x.cuda()`, because the character before `.cuda()` is `x` -- so a reason backticking `==` was claimed by ANY finding with `==` anywhere in it, and the UNREPORTED-FIRE that exists to force that rule onto the card never fired. Replayed: verdict "B1 FIRE -- the `==` check silently equates None and 0" against the single unrelated finding "foo.py:3 the tuned config lookup uses == on floats" claims the FIRE and reports nothing. A span has to carry a word character now. `.cuda()`, `->data` and `::empty` mix the two and keep their claim; punctuation alone has no claim route, which is where a reason that backticks nothing already was. selftest 167 green / 0 red; dropping the word-character requirement turns the new case red (166/1). check_prompts 0 drift, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: a period and a lone hyphen separate a citation too Three from review, all confirmed. The citation skip's separator class had only colon, comma, em dash, en dash and double dash, so `foo.py:3. A5: guard missing` and `foo.py:3 - A5: broken` reached the reader id-led -- the colon form this branch exists to refuse, wearing a separator the class did not list. Both are refused now. Closing them costs nothing lawful, which the review checked and so did I: what follows the strip still has to be the colon form, so `README.md:1084. B1-B2 stage before B3-B4` and its hyphen twin still pass. Both are in `_head_passes` (12 -> 14) and the two refused forms in `_head_forms` (25 -> 27). `--` precedes `-` in the alternation so the long form wins; a line range is eaten by `(?:-\d+)?` before any of it. selftest.sh:515 still carried the pre-fix "Eleven of the 54 ids ... C3/C4" text. That is the third time in this branch that I fixed one copy of a statement and left another: the wrong first_clause claim lived in triage.py and selftest.sh, and so did this count. Both copies now say nineteen, name all of them, and say C4 is vocabulary rather than an id. The PR description said `150 green / 43 passed`, which was the r48 head. Refreshed to 167. selftest 167 green / 0 red; narrowing the separator class back turns "a rule id hidden behind decoration or a citation is still refused" red (166/1). Over 212,823 real lines the reader is unchanged. check_prompts 0 drift, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: no number in the comment, because every number was wrong Review is right that the enumeration missed ids, and right about which: T1 and D11 label obligations in atom/mesh/tests/*.rs, and the count that produced "nineteen" grepped only py/md/cu/hip, so every .rs was invisible to it. It is wrong that the number is twenty-two. H1 appears nowhere under atom/ or docs/ -- `grep -rnw H1 atom/ docs/` is empty -- and the file credited with it, atom/mono/lm_head/kernel.py, does not exist (atom/mono/ holds __init__.py and device/). Measured across py/md/cu/hip/rs/toml/cpp/h/hpp/sh/yaml/yml/json the answer today is twenty-one. But the number is the wrong thing to carry. Four of them have been written into this comment during review -- eleven, ten, nineteen, twenty-two -- and all four were wrong, two mine and two from the review. It moves with the tree and with which extensions the counter thought to grep, and the comment said so itself in the sentence before stating a constant. So there is no number now, in either copy, and the reason is written down where the next person would otherwise add one back. The examples stay, and every path they name exists. selftest 167 green / 0 red, check_prompts 0 drift, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review-pr: gate the count, since prose could not hold it selftest.sh:697 was a third copy of the same sentence, still saying "19 of the 54". Confirmed, and it is the fourth round in a row that this statement was fixed in one place and left standing in another -- the same shape as the wrong first_clause claim, which also lived in two files. Removing the number a third time would be the same move that failed three times. There is a gate now: no comment in triage.py or selftest.sh may state a count of the ids that are also ATOM words. The comments carry the examples and a pointer to _diff_vocabulary, which says why there is no number. The first version of that gate was dead. Its pattern was lower-case only, so putting "Nineteen of the 54" back left the suite at 168 green / 0 red -- a test that cannot fail, which is the thing this skill's own gates exist to catch, and it slipped into the commit that was adding a gate about exactly that. Caught by mutation, not by reading. With `-i` the same mutation is 167/1. selftest 168 green / 0 red, check_prompts 0 drift, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: zufayu <8138883+zufayu@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Yu <zufayu@amd.com>
Motivation
agentic(#3406) weighs the prefill already queued on each rank, the same term as the engine'sleast_tokensbalancer, but the router counted only in-flight requests per worker, not the prefill tokens they carry. This adds that count perurl@rank. It is ported from #3210 (closed) and has no reader until #3406, so the two merge together.Counts in-flight prefill tokens per worker (
url@rank). Ported from #3210 (closed) with its review addressed.Worker::prefill_tokens(), one counter per DP rank, exported asmesh_worker_prefill_tokens{worker}.WorkerLoadGuardholds the charge:decrement_load.No policy reads the counter in this PR. #3406 adds
agentic, which reads it and replaces the whole-prompt charge with its estimate of the uncached tokens. As the #3210 review asked, this should merge together with #3406 rather than land as an unread counter.Since the last review
cache_awarefix it needed and the reworded comments andRouterConfigmethod from valarLip's review. This PR now holds the accounting only.core::placement. The first step ofatomesh-mocker-benchmark.yamlruns every--libtest, includinghttp_pd_load_testsandhttp_proxy_body_tests, which are compiled into the library through#[path].with_prefill_tokensdebug-asserts a fresh guard instead of releasing first. The metric's help names the paths that charge it; feat(mesh): agentic routing policy on the KV event index #3406'sagentic_cost.mdsays the uncharged requests weigh only through the request term.Follow-ups, not in this PR
apply_policyand handing the charge to the guard would close the gap.Validation (Rust 1.100, CPU host, at
f9d07c15f)cargo test --lib: 1364 passed.test_load_counter_performance, which asserts a millionincrement_loadcalls a second, failed once on the shared host (load average above 120) and passed on three reruns; this PR does not touchincrement_load. Tests cover the planner's charge (streaming and non-streaming, P/D), the release at the first streamed frame, the P/D charge and release, and a nonzero charge on the idx2idx remap.cargo fmt --checkclean;cargo clippy --all-targetsshows no new warnings beyond Rust 1.100's deprecation offetch_update, which the existing code shares.cargo test --testspasses every target exceptproto_vendor_tests, which readsproto/manifest.json(not in git).