fix(agents): attribute virtual-provider cost to the selected backend #204
No reviewers
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
#159 fix(agents): virtual-provider budget cost is priced against the agent-level (provider, model), not the selected backend
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core!204
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bugfix/m1-virtual-provider-cost-attribution"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes #159: a pooled (virtual-provider, ADR-2038)
LLMAgent's budget pre-flightcheck and cost accumulation always resolved pricing/zero-cost status against the
agent-level
(provider, model)anchor, never the backendVirtualChatModelactually selected and invoked for a given call.
VirtualChatModel.select_backend()now surfaces the selected backend's own(provider, model)identity alongside the backend instance and its URL.LLMAgent._resolve_invocation_target()performs that one per-invocationselection up front and threads it through the pre-flight budget check, the
pinned call (
_retry_ainvokeand thestream_message()astream path), andthe post-call cost accumulation, so all three agree on the backend that
actually serves the call.
tool-loop call sites and the no-tools path is consolidated into a new
_invoke_and_track_cost()helper.(self.provider, self.model)).Acceptance criteria (from issue #159)
missing_pricing_entry.nox -s typecheck,nox -s unit_tests, and the coverage threshold stay green.Test plan
nox -s unit_tests— 160 features, 3387 scenarios, 15601 steps, all passed(the two
@tdd_issue_159scenarios from #202 now pass normally with@tdd_expected_failremoved; a third new scenario covers the streaming path)nox -s coverage_report— 97.3% (≥ 97% threshold)nox -s lint,nox -s format -- --check— cleannox -s typecheck— 0 errors (1 pre-existing, unrelated warning)nox -s security_scan— 0 findingsnox -s dead_code— cleannox -s integration_tests— 382/382 Robot tests passedCloses #159
PR Review: !204 (Ticket #159)
Verdict: Request Changes
The core fix is correct and well-constructed: the one-per-invocation selection is now surfaced via
VirtualChatModel.select_backend()and threaded through pre-flight check → pinned call → cost accumulation, the ADR-2032/ADR-2038 pinning rules still hold (retries and streams target the pinned backend; no re-selection), non-virtual agents fall back byte-identically, and the consolidation into_invoke_and_track_cost()removed real duplication across seven call sites. Verified locally:nox -s unit_tests(160 features / 3387 scenarios / 15601 steps, all pass),nox -s typecheck(0 errors, 1 pre-existing unrelated warning),nox -s lint(clean) — all matching the PR's reported results.Request Changes because the PR's checklist marks issue #159's acceptance criterion 3 (zero-cost carve-out evaluates the selected backend's rates) as ✅, but no test exercises it — the changed carve-out parameterization is never executed with a pooled agent.
Critical Issues
None.
Major Issues
Missing test for AC3 — zero-cost carve-out with a selected backend (PR body claims ✅).
features/virtual_provider.feature(lines 243–262) covers AC1 (distinct rates), the streaming path, and AC2 (unpriced anchor). No scenario anywhere drivesLLMAgent._check_budget_before_invoke's carve-out branch (src/cleveractors/agents/llm.py:681–697) with a pooled agent:max_cost_usd = 10.0withaccumulated = 0.0, so the gate never trips and the carve-out is never reached.max_cost_usd = None, so there is no gate at all.features/budget_gate_single_llm.feature,features/execution_limits.feature) exercise the single-LLMPureLangGraph/runtime_dispatchpath, not theLLMAgenttool-loop path changed here.Consequently the code this PR actually changed —
provider/modelkwargs flowing into_is_zero_rated_invocationfor a virtual agent — has zero test coverage, and both directions of AC3's semantics are unverified: (a) a provably-free selected backend passing an exhausted gate while the anchor is non-zero-rated/unpriced, and (b) the consistent converse that a non-zero-rated selected backend now blocks even when the anchor pair is zero-rated (a real behavior change for pooled agents that nothing pins down).Recommendation: add a scenario, e.g. pricing
{deepseek: 0.0/0.0, zai: 5.0/5.0}withaccumulated = 10.0,max_cost_usd = 10.0→ the pooled run completes and accumulated cost stays0.0; ideally add the converse (priced selected backend + zero-rated anchor →budget_exhausted). Until then, please remove the ✅ on AC3 in the PR description or mark it as covered-by-code-review only.Minor Issues
src/cleveractors/agents/llm.py:749–750. For a pooled agent,_run_pruning_pass(llm.py:1004) callsbuild_chat_model(config=self.config, ...), andbuild_chat_model(src/cleveractors/agents/llm_client.py:102–113) returns a freshVirtualChatModelwheneverconfig["backends"]is present. So a pooled agent's pruning pass selects a backend internally (with its own provider/model) while_accumulate_cost_after_invoke(..., "pruning", model=self.model)bills it at the agent-level anchor pair — the same mis-attribution class #159 fixes for the main path, still live for pruning spend (including themissing_pricing_entryraise for an unpriced anchor, swallowed by the tool loop as a per-tool error). This is pre-existing, not a regression of this PR, and out of #159's stated ACs — but the new docstring asserts the opposite and will mislead maintainers.Recommendation: correct the docstring to state that pruning-pass attribution for pooled agents still resolves the anchor pair, and file a follow-up issue to wire selected-backend attribution into the pruning accumulation (or explicitly defer it on #159).
Nits
_resolve_invocation_target(src/cleveractors/agents/llm.py:587–594). It claims init failure "is reported by_retry_ainvoke's own eagerself.chat_modelaccess (unchanged, and still the single place that raises) instead of here" and that the method does "not force construction". In factself._ensure_chat_model()(line 595) constructs the model and propagatesConfigurationErrorfrom here —_retry_ainvokeis never reached when init fails, and a malformedbackendsconfig on an exhausted budget now raisesConfigurationErrorbeforebudget_exhausted(slight error-precedence change; fast-fail outside the retry loop is still preserved). Suggest rewording to describe the actual behavior.docs/adr/ADR-2038-virtual-provider-load-balanced-backend-routing.md:178–189). The non-normative note still describes this repo's implementation as selecting "once per external call and perform[ing] retries against that one backend internally, rather than relying solely on the outer, already-existing retry wrapper" — the new implementation does rely on the outer wrapper, pinning by passingtarget.backendso re-entry cannot re-select (the normative pinning rule still holds). Since the budget-gate ADR got a dated correction, consider a matching one-line note update here._InvocationTarget.backend: Any(src/cleveractors/agents/llm.py:239).BaseChatModelis already imported underTYPE_CHECKINGin this module (lines 35–36) and used in annotations (llm.py:466); withfrom __future__ import annotationsthe field could be typedBaseChatModel | Noneprecisely, per CONTRIBUTING's "Full Annotations".backend_providers/backend_models(src/cleveractors/agents/llm_virtual_provider.py:256–259). A partially populated pair (one list shorter thanbackends) silently mixes a backend provider with the anchor model. Unreachable viabuild_virtual_chat_model(always consistent), but a cheap construction-time check would make the invariant explicit._resolve_invocation_target()selects before_check_budget_before_invoke, abudget_exhaustedblock consumes a round-robin slot even though no call fires (previously selection happened insideainvoke, after the gate). Appears benign for load-balancing fairness (the blocked turn legitimately consumed capacity) and no existing test depends on the sequence, but it is a subtle routing-sequence change worth being aware of; a sentence in the ADR correction would document it.Summary
A high-quality, well-documented fix that resolves the real #159 defect: per-invocation backend selection is surfaced (
SelectedBackend), the pre-flight gate, pinned call, and cost accumulation now agree on the backend that actually serves each call, and the six duplicated check→invoke→extract→accumulate sites are consolidated behind_invoke_and_track_cost()without changing call-site semantics (verified: all seven sites — main, synthesis, synthesis_followup, stuck_model, stuck_model_followup, no-tools, stream — pass equivalent kwargs and labels; pruning builds its own model and is untouched; ADR-2038 pinning holds for retries and streams). Test additions are meaningful (distinct anchor/backend rates make mis-attribution numerically detectable; the unpriced-anchor assertion explicitly guards against a skip-accumulation partial fix; the mock'schunk_position="last"change is verified correct against langchain-core 1.8.5's astream sentinel behavior). Local verification matches the PR report: unit tests 3387/3387, typecheck 0 errors, lint clean.Two things block approval: the claimed-✅ AC3 has no test (Major), and the new "_accumulate_cost_after_invoke" docstring misstates the pruning path for pooled agents (Minor). Both are small, targeted follow-ups on an otherwise solid PR. Per the request, red-tape items (labels, commit footer, branch-name metadata) were excluded; the PR thread contains no prior reviewer comments and nothing was ruled out-of-scope there; the #159 gism0 memory journal was unavailable (no gism0 tools in this session), so the review relied on the ticket, PR description, ADRs, and
docs/index.md(§4.4.7 documents only config surface/routing — no cost content, so no spec edit was required there).PR Review: !204 (Ticket #159)
Verdict: Request Changes
The core fix is correct and well-constructed: the one-per-invocation selection is now surfaced via
VirtualChatModel.select_backend()and threaded through pre-flight check → pinned call → cost accumulation, the ADR-2032/ADR-2038 pinning rules still hold (retries and streams target the pinned backend; no re-selection), non-virtual agents fall back byte-identically, and the consolidation into_invoke_and_track_cost()removed real duplication across seven call sites. Verified locally:nox -s unit_tests(160 features / 3387 scenarios / 15601 steps, all pass),nox -s typecheck(0 errors, 1 pre-existing unrelated warning),nox -s lint(clean) — all matching the PR's reported results.Request Changes because the PR's checklist marks issue #159's acceptance criterion 3 (zero-cost carve-out evaluates the selected backend's rates) as ✅, but no test exercises it — the changed carve-out parameterization is never executed with a pooled agent.
Critical Issues
None.
Major Issues
Missing test for AC3 — zero-cost carve-out with a selected backend (PR body claims ✅).
features/virtual_provider.feature(lines 243–262) covers AC1 (distinct rates), the streaming path, and AC2 (unpriced anchor). No scenario anywhere drivesLLMAgent._check_budget_before_invoke's carve-out branch (src/cleveractors/agents/llm.py:681–697) with a pooled agent:max_cost_usd = 10.0withaccumulated = 0.0, so the gate never trips and the carve-out is never reached.max_cost_usd = None, so there is no gate at all.features/budget_gate_single_llm.feature,features/execution_limits.feature) exercise the single-LLMPureLangGraph/runtime_dispatchpath, not theLLMAgenttool-loop path changed here.Consequently the code this PR actually changed —
provider/modelkwargs flowing into_is_zero_rated_invocationfor a virtual agent — has zero test coverage, and both directions of AC3's semantics are unverified: (a) a provably-free selected backend passing an exhausted gate while the anchor is non-zero-rated/unpriced, and (b) the consistent converse that a non-zero-rated selected backend now blocks even when the anchor pair is zero-rated (a real behavior change for pooled agents that nothing pins down).Recommendation: add a scenario, e.g. pricing
{deepseek: 0.0/0.0, zai: 5.0/5.0}withaccumulated = 10.0,max_cost_usd = 10.0→ the pooled run completes and accumulated cost stays0.0; ideally add the converse (priced selected backend + zero-rated anchor →budget_exhausted). Until then, please remove the ✅ on AC3 in the PR description or mark it as covered-by-code-review only.Minor Issues
src/cleveractors/agents/llm.py:749–750. For a pooled agent,_run_pruning_pass(llm.py:1004) callsbuild_chat_model(config=self.config, ...), andbuild_chat_model(src/cleveractors/agents/llm_client.py:102–113) returns a freshVirtualChatModelwheneverconfig["backends"]is present. So a pooled agent's pruning pass selects a backend internally (with its own provider/model) while_accumulate_cost_after_invoke(..., "pruning", model=self.model)bills it at the agent-level anchor pair — the same mis-attribution class #159 fixes for the main path, still live for pruning spend (including themissing_pricing_entryraise for an unpriced anchor, swallowed by the tool loop as a per-tool error). This is pre-existing, not a regression of this PR, and out of #159's stated ACs — but the new docstring asserts the opposite and will mislead maintainers.Recommendation: correct the docstring to state that pruning-pass attribution for pooled agents still resolves the anchor pair, and file a follow-up issue to wire selected-backend attribution into the pruning accumulation (or explicitly defer it on #159).
Nits
_resolve_invocation_target(src/cleveractors/agents/llm.py:587–594). It claims init failure "is reported by_retry_ainvoke's own eagerself.chat_modelaccess (unchanged, and still the single place that raises) instead of here" and that the method does "not force construction". In factself._ensure_chat_model()(line 595) constructs the model and propagatesConfigurationErrorfrom here —_retry_ainvokeis never reached when init fails, and a malformedbackendsconfig on an exhausted budget now raisesConfigurationErrorbeforebudget_exhausted(slight error-precedence change; fast-fail outside the retry loop is still preserved). Suggest rewording to describe the actual behavior.docs/adr/ADR-2038-virtual-provider-load-balanced-backend-routing.md:178–189). The non-normative note still describes this repo's implementation as selecting "once per external call and perform[ing] retries against that one backend internally, rather than relying solely on the outer, already-existing retry wrapper" — the new implementation does rely on the outer wrapper, pinning by passingtarget.backendso re-entry cannot re-select (the normative pinning rule still holds). Since the budget-gate ADR got a dated correction, consider a matching one-line note update here._InvocationTarget.backend: Any(src/cleveractors/agents/llm.py:239).BaseChatModelis already imported underTYPE_CHECKINGin this module (lines 35–36) and used in annotations (llm.py:466); withfrom __future__ import annotationsthe field could be typedBaseChatModel | Noneprecisely, per CONTRIBUTING's "Full Annotations".backend_providers/backend_models(src/cleveractors/agents/llm_virtual_provider.py:256–259). A partially populated pair (one list shorter thanbackends) silently mixes a backend provider with the anchor model. Unreachable viabuild_virtual_chat_model(always consistent), but a cheap construction-time check would make the invariant explicit._resolve_invocation_target()selects before_check_budget_before_invoke, abudget_exhaustedblock consumes a round-robin slot even though no call fires (previously selection happened insideainvoke, after the gate). Appears benign for load-balancing fairness (the blocked turn legitimately consumed capacity) and no existing test depends on the sequence, but it is a subtle routing-sequence change worth being aware of; a sentence in the ADR correction would document it.Summary
A high-quality, well-documented fix that resolves the real #159 defect: per-invocation backend selection is surfaced (
SelectedBackend), the pre-flight gate, pinned call, and cost accumulation now agree on the backend that actually serves each call, and the six duplicated check→invoke→extract→accumulate sites are consolidated behind_invoke_and_track_cost()without changing call-site semantics (verified: all seven sites — main, synthesis, synthesis_followup, stuck_model, stuck_model_followup, no-tools, stream — pass equivalent kwargs and labels; pruning builds its own model and is untouched; ADR-2038 pinning holds for retries and streams). Test additions are meaningful (distinct anchor/backend rates make mis-attribution numerically detectable; the unpriced-anchor assertion explicitly guards against a skip-accumulation partial fix; the mock'schunk_position="last"change is verified correct against langchain-core 1.8.5's astream sentinel behavior). Local verification matches the PR report: unit tests 3387/3387, typecheck 0 errors, lint clean.Two things block approval: the claimed-✅ AC3 has no test (Major), and the new
_accumulate_cost_after_invokedocstring misstates the pruning path for pooled agents (Minor). Both are small, targeted follow-ups on an otherwise solid PR. Per the request, red-tape items (labels, commit footer, branch-name metadata) were excluded; the PR thread contains no prior reviewer comments and nothing was ruled out-of-scope there; the #159 gism0 memory journal was unavailable (no gism0 tools in this session), so the review relied on the ticket, PR description, ADRs, anddocs/index.md(§4.4.7 documents only config surface/routing — no cost content, so no spec edit was required there).f11060572868f2a2c8b8@hurui200320 Thanks for the thorough review. Before making any change I re-checked each point against issue #159's acceptance criteria,
docs/index.md§4.4.7, anddocs/adr/ADR-2038-virtual-provider-load-balanced-backend-routing.md— all findings below were independently confirmed correct against those sources before being acted on. Pushed as an amendment to the same commit (f110605→68f2a2c), not a new commit, since this PR is still a single-commit TDD/bugfix pair with #202.Major Issues
features/virtual_provider.feature:0.0/0.0, agent-level anchor priced non-zero, accumulated cost already at the limit → the pooled run completes and accumulated cost stays unchanged (verifies_check_budget_before_invoke's carve-out readstarget.provider/target.model, notself.provider/self.model).budget_exhausted(verifies the carve-out can't be satisfied by a coincidentally zero-rated anchor when the backend that will actually serve the call is priced).Kept the PR description's ✅ on AC3 since it's now true, rather than walking it back.
Minor Issues
_run_pruning_pass→build_chat_model(config=self.config, ...)→ confirmed it returns a freshVirtualChatModelwhenever a pooled agent'sconfig["backends"]is present, exactly as you described. Corrected_accumulate_cost_after_invoke's docstring to state that pruning for pooled agents still bills the agent-level anchor pair, not the backend the pruning call actually invokes, and that this is pre-existing and out of #159's ACs — not something this PR fixes. I did not open a follow-up issue for the pruning-attribution gap itself (your recommendation offered it as one of two options, with "explicitly defer it on #159" as the alternative, which the corrected docstring now does); happy to file one if you'd prefer that over the docstring note.Nits
_resolve_invocation_targetdocstring — DONE. Confirmed:_ensure_chat_model()(called directly by this method) propagatesConfigurationErrorfrom construction before_check_budget_before_invokeruns, for every agent that goes through_invoke_and_track_cost/the streaming path — not only pooled ones, since_resolve_invocation_targetis now called unconditionally first at every call site. Reworded the docstring to describe this correctly and scoped the note to "virtual and non-virtual agents alike" rather than pooled-only (my first draft had that wrong too before I traced all the call sites).llm_virtual_provider.pyacross this PR: pre-#159,VirtualChatModel._agenerate/_astreamdid their own internalselect → call_with_retry, matching the old note. Post-#159,LLMAgent._retry_ainvoke/stream_messagecalltarget.backend.ainvoke()/.astream()directly through the existing ADR-2032 outer retry wrapper, bypassingVirtualChatModel's own entry points entirely. Rewrote the note to describe the new design, and keptVirtualChatModel._agenerate/_astream's internal retry logic in place (not dead code — it's required forVirtualChatModelto remain Liskov-substitutable for anyBaseChatModelcaller that invokes it directly rather than throughLLMAgent). Also added your optional one-sentence note on the round-robin-position-advances-on-a-blocked-round observation, as documentation only — no code change, since you already flagged it as benign._InvocationTarget.backend: Any— DONE. Changed toBaseChatModel | None;BaseChatModelwas already imported underTYPE_CHECKINGand used elsewhere in the file, so this was a pure typing tightening with no runtime impact (from __future__ import annotationskeeps the dataclass annotation as a string).backend_providers/backend_models— DONE, with a caveat. Added a pydantic@model_validator(mode="after")onVirtualChatModelrejecting any state other than "both empty" (opted out) or "both exactlylen(backends)" (fully populated) — a partially-populated pair is now a construction-timeValidationErrorinstead of a silent mismatch inselect_backend(). Added a scenario covering the new error path so it isn't uncovered dead code. Caveat: I verifiedbuild_virtual_chat_modelalways populates all four parallel lists in lockstep in one loop, so this path is indeed unreachable through the normal config-driven construction path, exactly as you noted — the guard only protects direct/manual construction (test doubles, library use).Not acted on
VirtualChatModel's internal retry path — both are pre-existing, out of #159's scope, and documented as such; let me know if you'd like either filed separately rather than left as a documented gap.Verification
nox -s unit_tests: 160 features / 3390 scenarios / 15611 steps, all green (3 new scenarios: 2 for AC3, 1 for the new validator).nox -s lint,nox -s typecheck(0 errors, the same 1 pre-existing unrelated warning),nox -s security_scan,nox -s dead_code: all clean. Coverage delta checked by scopingnox -s coverage_reporttofeatures/virtual_provider.featurealone (not the full suite):llm_virtual_provider.pyat 99.57%, with only one pre-existing, unrelated line (llm_virtual_provider.py:510, anexcept ConfigurationError: raise) still uncovered in that scope — not part of this PR's diff.PR Review: !204 (Ticket #159)
Verdict: Approve
Re-review of the amended commit (
68f2a2c) after the author's response to the previous review. All previously blocking findings were verifiably addressed, and a fresh pass over the full change surfaced no new critical or major issues. Verified locally on68f2a2c:nox -s typecheck(0 errors, 1 pre-existing unrelated warning),nox -s lint(clean),nox -s coverage_report(97.3% full-suite, above the 97% standard — run unscoped this time, closing the only gap in the author's own verification), andnox -s unit_tests(160 features / 3390 scenarios / 15611 steps, all pass) — matching the author's reported results.Per the review ground rules, items the author's response decided as out-of-scope or deferred were removed from this review (see Summary), as were process/red-tape items.
Critical Issues
None.
Major Issues
None.
Minor Issues
None.
Nits
features/mocks/fake_backend_chat_model.py:117–131—_build_stream_chunksilently ignores a partially-set token config where_build_response_messageasserts. The non-streaming builder (lines 88–91) assertsprompt_tokens/completion_tokensare set together or bothNone; the streaming builder just skipsusage_metadatawhen only one is set. Harmless today (every scenario sets both or neither), but a future misconfigured mock would silently produce usage-less streaming instead of failing fast. Recommend mirroring the assert (or factoring a shared guard).PR description test-plan numbers are stale for the amended commit. The body reports "3387 scenarios / 15601 steps" (the pre-amendment run); the pushed commit is 3390/15611 — as the author's thread comment states and this review re-verified locally. One-line PR-body update; cosmetic only.
Summary
All issues from the previous review are confirmed fixed in
68f2a2c, each verified against the code rather than the claims:features/virtual_provider.featuredrive the carve-out branch with a pooled agent in both directions — a provably-free selected backend passing an already-tripped gate while the anchor is priced (accumulated cost stays at the limit), and the converse where a priced selected backend still blocks even though the anchor is zero-rated (budget_exhaustedasserted withkind='cost'/reason='budget_exhausted'). Distinct anchor/backend rates make mis-attribution numerically detectable, and both scenarios fail against the pre-fix anchor-resolved carve-out — AC3 is now genuinely pinned, and the PR body's ✅ is accurate._accumulate_cost_after_invoke's docstring now correctly states that pooled-agent pruning spend still bills the agent-level anchor pair, explicitly scoped as pre-existing and outside #159's ACs._resolve_invocation_target's docstring now accurately describes the error-precedence change (ConfigurationError raised there, for virtual and non-virtual agents alike); the ADR-2038 implementation note was rewritten to match the outer-retry pinned-call design while keepingVirtualChatModelLiskov-substitutable, plus the round-robin-advance note;_InvocationTarget.backendis nowBaseChatModel | None; and a pydantic@model_validatorrejects partially populatedbackend_providers/backend_modelsat construction time, with a scenario covering the new error path.Removed from this review per the author's thread decisions: the pruning-pass attribution gap (explicitly deferred — documented as a pre-existing, out-of-scope gap in the docstring; the author offered to file a follow-up issue if preferred, which is a ticket-process decision, not a PR blocker); the blocked-rounds-advance-selection observation (documentation-only, agreed benign, now captured in the ADR); and the phantom "Submitting independent PRs" item (no such comment exists in this thread). The gism0 memory journal for #159 was unavailable in this session (no gism0 tools), so the review relied on the ticket, PR description, ADRs, and
docs/index.md— no behavioral gaps found against them.Spec/subtask check: the issue's subtasks are satisfied — attribution mechanism decided (backend-identity propagation via
select_backend()/SelectedBackend), wired into both_check_budget_before_invokeand_accumulate_cost_after_invoke, and the full test matrix added (AC1 non-streaming + streaming, AC2 unpriced anchor, AC3 both directions, AC4 preserved by the non-virtual fallback plus the untouched pre-existing suite).docs/index.md§4.4.7 carries no cost-attribution content, so no spec edit was needed there (the corrections live in the two ADRs, both dated in their changelog tables).benchmarks/virtual_provider_benchmark.pystill measures the same hot path (_selectnow delegates toselect_backend), so it remains valid without changes. The commit first line matches the issue's Metadata Commit Message and the PR is a single atomic commit on a rebase-clean branch.Ready to merge.
68f2a2c8b80163c37b250163c37b25d4bb0d5e53d4bb0d5e536f15fa48eb@hurui200320 Thanks for the re-review and approval. Before touching anything I re-checked both reviews against issue #159's acceptance criteria,
docs/index.md§4.4.7, and bothdocs/adr/ADR-2038-*documents, then independently re-derived (not just trusted) that the Major/Minor items from the first review were genuinely present in the code — they were, matching your approval. This reply covers the two remaining Nits from your approving review, plus one housekeeping item.Nits from the approving review
_build_stream_chunksilently drops a partially-set token pair — DONE.Confirmed the asymmetry you flagged:
_build_response_message(features/mocks/fake_backend_chat_model.py:88-91) already assertsprompt_tokens/completion_tokensare set together or bothNone, but_build_stream_chunkjust fell through to the no-usage-metadata branch on a partial pair instead of failing fast. Added the identical assert to_build_stream_chunk, immediately before itsis_lastbranch.No scenario currently constructs a partial pair, so this is a pure fail-fast tightening with no behavioral change today — it only prevents a future misconfigured mock from silently producing usage-less streaming. Re-verified scoped:
nox -s unit_tests -- features/virtual_provider.feature→ 1 feature, 49 scenarios, 153 steps, all passed.nox -s lintandnox -s typecheckboth clean (the one typecheck warning is the same pre-existing, unrelatedlangchain_google_genaiimport warning noted in both your reviews). Coverage delta scoped to the same feature:llm_virtual_provider.py99.57%, the same single pre-existing/unrelated uncovered line (llm_virtual_provider.py:510) as before — no regression.PR description test-plan counts are stale — NOT done (tooling restriction on my end, not a disagreement).
You're right that the description still reports the pre-amendment
3387 scenarios / 15601 stepsinstead of3390/15611. I attempted to patch the PR body via the Forgejo API to correct this, but my own tooling's auto-mode permission layer blocked that specific call as an unscoped external-system write (PR-description edits weren't explicitly requested by my operator for this pass). I'm flagging it here rather than silently skipping it: the accurate current counts are 160 features, 3390 scenarios, 15611 steps (unchanged by the nit-1 fix above, since it adds no new scenario — it only tightens an existing step's assertion), and three new scenarios now exist versus the stale description's "one": the streaming-path scenario, the two AC3 carve-out scenarios (counted as one bullet originally), and the backend-list construction-time validator scenario. If you'd like, I can have my operator explicitly authorize the description edit in a follow-up pass, or you/another maintainer can correct it directly — either way it's cosmetic only and doesn't affect mergeability.Housekeeping
d4bb0d5to6f15fa4and force-pushed tobugfix/m1-virtual-provider-cost-attribution. The commit message's trailing paragraph documents the nit-1 change and its scoped re-verification, consistent with how the earlier review-response paragraphs were recorded in the same commit.No other outstanding items from either review remain unaddressed on my side. Let me know if the description edit should be done now or left as-is.
6f15fa48eb11af53405e