Repository navigation
Count sub-runs' and foreach bodies' model usage toward their step - #3332
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Run usage and meter support internal/ir/run_result.go, internal/runtime/modelusage/* |
RunStatus gains a non-serialized ModelUsage field. The meter adds usage, skips empty reports for new sources, and provides child-run source names. |
Foreach body usage aggregation internal/runtime/builtin/foreach/foreach.go, internal/runtime/builtin/foreach/usage_test.go |
Foreach body node usage is merged and added to the parent step context after each body run. The test checks totals across three items. |
Sub-DAG result usage reporting internal/runtime/executor/dag_runner.go, internal/runtime/executor/dag_runner_test.go |
Execute, Reuse, and Retry report child result usage under the child run ID. The test checks that retry usage replaces the earlier report. |
Subflow status usage reporting internal/service/coordinator/subflow/local.go, internal/service/coordinator/subflow/runner.go, internal/service/coordinator/subflow/runner_test.go |
Status polling reports child usage to the parent meter, and returned run status includes the child’s aggregated usage. Local child agents run with a context that has no model-usage meter. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Sequence Diagram(s)
sequenceDiagram
participant ParentSubflowRunner
participant ChildRunStatus
participant ModelUsageMeter
ParentSubflowRunner->>ChildRunStatus: Poll child run status
ChildRunStatus-->>ParentSubflowRunner: Return status with model usage
ParentSubflowRunner->>ModelUsageMeter: Report usage under child run ID
Possibly related PRs
- dagucloud/dagu#3331: Adds model-usage reporting for decision steps and coding-agent sources using the same meter flow.
- dagucloud/dagu#3330: Adds per-step model-usage storage and a meter that records calls across attempts.
- dagucloud/dagu#3329: Expands
llm.Usagewith data that feedsir.ModelUsage.
Merge Risk: 
Minimal · up to 49c26
-
The reviewed usage-accounting paths show no identified issue that needs correction before merging.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description provides a detailed summary, lists the implementation changes, and documents the test plan. It does not include the required Related Issues and Checklist sections, but the main change and validation details are complete.
-
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
af41f8f to
ff360d5
Compare
893e01e to
9a6a537
Compare
05444bf to
96dc039
Compare
9a6a537 to
282746a
Compare
A step that runs a sub-DAG showed nothing of what the child spent on models. The child's total now reaches the step as its latest report, replacing the one before, so a retried or reused child, whose total already covers its earlier attempts, is not counted twice. A distributed child reports on every poll, so the step shows its usage while it runs. An in-process child runs with the parent's meter hidden, so its steps count only toward their own nodes.
A foreach item's body steps run in a nested runner that is not saved with the run, so what they spent on models was lost. Each item's body usage now adds to the foreach step's when the item ends.
282746a to
49c266a
Compare
Summary
Last engine step toward showing a run's model usage. Stacked on #3331.
A step that runs other work showed nothing of what that work spent on models:
Changes
ir.RunStatus.ModelUsage(json:"-", so not part of the step's output) is filled bystatusToRunStatusfrom the child'sModelUsageTotal(). Both the in-process and distributed runners build results through it.SubDAGExecutor.Execute,ReuseandRetrypass their result throughreportSubRunUsage, which callsSetReported("run:<id>", total). That one funnel serves dag, parallel and chat-tool steps.subflow.Runner.waitCompletionreports each polled status.subflow.Local.runAgentruns the child withmodelusage.WithMeter(ctx, nil).foreach.runItemaddsbodyModelUsage(plan)with the newMeter.Addonce the body finishes.Meter.SetReportedignores an empty report for a source it doesn't have yet, so a child that used no model adds no entry.Test plan
TestSubDAGExecutor_ReportsChildModelUsage: a run and then a retry of the same child replace the entry (3 calls, not 5).TestRunnerReportsChildModelUsage: a distributed child's running poll is reported, then replaced by the finished total, which also reaches the result.TestForeachCountsBodyModelUsage: three items' body calls add up on the foreach step.TestMeterAdd: additions merge, and an empty report adds no entry.Summary by CodeRabbit
New Features
Bug Fixes
Tests