Skip to content

fix(agent): fold structured-output repair usage into delivery totals (#207) - #366

Merged
yuluo-yx merged 3 commits into
agentic-ai-java:mainfrom
XianReallyHot-ZZH:feat/issue-207-repair-usage
Nov 12, 2026
Merged

yuluo-yx merged 3 commits into
agentic-ai-java:mainfrom
XianReallyHot-ZZH:feat/issue-207-repair-usage

Conversation

@XianReallyHot-ZZH

Copy link
Copy Markdown
Contributor

确认 (Acknowledged) contribution to ARGI: the structured-output repair re-ask now folds its reported token usage into the delivered AgentResult total via per-field null-propagating aggregation (Usage.plus, matching UsageAccumulator/NodeUsage semantics, so unknown fields stay unknown and are never summed as zero, including a null main usage), with a new repairUsage result segment distinguishing main-call from repair consumption (null = no repair issued, all-unknown = repair issued with unreported usage, the old 5-arg AgentResult constructor kept for source compatibility), counting every issued-and-answered call exactly once across successful repair, repaired-still-invalid and response-without-assistant-message paths while a client failure before any response counts nothing guessed, and the independent ReAct finish() backfills the merged total into the Finished outcome plus one cumulative UsageUpdate so event consumers and callResult/streamResult deliveries agree on the same invocation totals, for #207. Consumer impact: AgentResult (opt-in strict-delivery type) gains one record component and Usage gains one additive method, both unreleased post-2.1.0-RC1 surface; Finished/UsageUpdate now carry repair-inclusive totals on repaired runs, which is the intended fix; no estimation path is introduced — unreported consumption stays unknown.

@yuluo-yx yuluo-yx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two reproduced usage gaps:

  • Repair timeout: repairUsage is unknown, but total usage remains (1,2,3). A missing response does not prove zero consumption; keep the delivery total unknown.
  • Repair responds with usage but invalid output: finish() throws before emitting the merged UsageUpdate. Both model modes leave event consumers at (1,2,3), while the exception result reports (11,22,33). Emit the merged usage before propagating validation failure.

@XianReallyHot-ZZH

Copy link
Copy Markdown
Contributor Author

Thanks @yuluo-yx — both reproduced gaps are fixed in 548a9e5 (TDD: failing assertions first, then the two production changes):

  1. Repair timeout / no response: the no-response branch now returns an all-unknown delivery total instead of the pre-repair (1,2,3) — no response proves what the issued call consumed, so neither the total nor the segment may claim it spent zero. Both usage and repairUsage stay Usage.unknown() (finalizer test repairClientFailureBeforeResponseKeepsTotalUnknown, executor test failedRepairKeepsDeliveryTotalUnknown asserts the last visible UsageUpdate is unknown too, both model modes).

  2. Merged usage before failure propagation: finish() now emits the cumulative UsageUpdate(result.usage()) immediately when the finalizer reports a repair segment — before the COMPLETED check, so a repaired-but-still-invalid run publishes (11,22,33) to event consumers first and the thrown AgentExecutionException result then carries the same totals (test repairedButInvalidRunPublishesMergedUsageBeforeFailing, both model modes, asserting event view == result.usage() == result.repairUsage()).

agent-core 250/250 and the graph callResult/streamResult suites stay green; the graph path needs no production change since its strict-delivery results come from the same finalizer.

@yuluo-yx yuluo-yx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@yuluo-yx
yuluo-yx merged commit efd12ae into agentic-ai-java:main Nov 12, 2026
7 checks passed
@XianReallyHot-ZZH
XianReallyHot-ZZH deleted the feat/issue-207-repair-usage branch November 13, 2026 00:18
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.

2 participants