fix: use remapped variables in cost calculation - #1505
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughPR refactors cost calculation to use a new request-scoped ChangesCost Calculation Variables Abstraction Refactoring
Sequence Diagram(s)sequenceDiagram
participant ExecutionEngine
participant Request
participant CostCalculator
participant VariablesView
ExecutionEngine->>Request: build request/context
Request->>VariablesView: Context.VariablesView()
ExecutionEngine->>CostCalculator: ValidateSliceArguments(varsView)
CostCalculator->>VariablesView: Get(path...)
VariablesView-->>CostCalculator: value
ExecutionEngine->>CostCalculator: EstimateCost(varsView)
CostCalculator->>VariablesView: Get(path...)
VariablesView-->>CostCalculator: value
ExecutionEngine->>CostCalculator: ActualCost(varsView, ActualListSizes)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
v2/pkg/engine/resolve/context.go (1)
24-24:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winFix typo in documentation.
"Recommented" should be "Recommended".
📝 Proposed fix
- // Recommented read-only use via variables.Set returned by VariableSet(). + // Recommended read-only use via variables.Set returned by VariableSet().🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v2/pkg/engine/resolve/context.go` at line 24, Update the comment containing "Recommented read-only use via variables.Set returned by VariableSet()." to correct the typo: change "Recommented" to "Recommended" so the comment reads "Recommended read-only use via variables.Set returned by VariableSet()." Locate this comment near the VariableSet() reference in resolve/context.go and update the wording accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@v2/pkg/engine/resolve/context.go`:
- Line 24: Update the comment containing "Recommented read-only use via
variables.Set returned by VariableSet()." to correct the typo: change
"Recommented" to "Recommended" so the comment reads "Recommended read-only use
via variables.Set returned by VariableSet()." Locate this comment near the
VariableSet() reference in resolve/context.go and update the wording
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: aa72970e-3b85-47a3-a42a-93ea5fcecd43
📒 Files selected for processing (1)
v2/pkg/engine/resolve/context.go
… yury/eng-9610-cost-calculation-ignores-remapvariables
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
v2/pkg/engine/plan/cost.go (2)
148-160:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftKeep nested variable access inside
VariablesView.Both paths only use
vars.Get()for the top-level variable and then descend through rawastjson.Values. That bypasses the nested/path remapping thatVariablesViewwas introduced to provide, so dotted slicing arguments and weighted input-object fields can still be read from pre-remap keys and fall back to defaults/zero cost. This leaves a remapped-variable hole in cost control.Also applies to: 283-304
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v2/pkg/engine/plan/cost.go` around lines 148 - 160, The current extractSlicingArgValue implementation extracts the top-level variable with vars.Get(arg.varName) then traverses raw astjson.Value fields, bypassing VariablesView remapping; update extractSlicingArgValue to resolve nested paths via VariablesView (not by descending astjson.Value) by repeatedly calling vars.Get on the progressively concatenated path (e.g., arg.varName, arg.varName+"."+segment, ...) or using the VariablesView API for nested access so remapping/defaults apply; apply the same change to the similar logic referenced around the other block (the code at the other occurrence) so both use VariablesView for nested/dotted access instead of manipulating astjson.Value directly.
826-834:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse one source of truth for debug mode.
The header switches on
actualListSizes != nil, but argument rendering switches onvars.IsEmpty(). Those diverge for estimated calls without variables and for actual-cost calls that still carry variables, so the same dump can label itself one way and format args the other way.Also applies to: 899-907
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@v2/pkg/engine/plan/cost.go`:
- Around line 148-160: The current extractSlicingArgValue implementation
extracts the top-level variable with vars.Get(arg.varName) then traverses raw
astjson.Value fields, bypassing VariablesView remapping; update
extractSlicingArgValue to resolve nested paths via VariablesView (not by
descending astjson.Value) by repeatedly calling vars.Get on the progressively
concatenated path (e.g., arg.varName, arg.varName+"."+segment, ...) or using the
VariablesView API for nested access so remapping/defaults apply; apply the same
change to the similar logic referenced around the other block (the code at the
other occurrence) so both use VariablesView for nested/dotted access instead of
manipulating astjson.Value directly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 98ec6368-77fd-413c-b3e6-034589439880
📒 Files selected for processing (6)
execution/engine/execution_engine.goexecution/graphql/request.gov2/pkg/engine/plan/cost.gov2/pkg/engine/resolve/context.gov2/pkg/engine/resolve/inputtemplate.gov2/pkg/engine/resolve/variables_view.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
v2/pkg/engine/plan/cost.go (1)
904-911: 💤 Low valueMisleading comments: condition doesn't distinguish actual vs estimated mode.
The comments say "actual cost" and "estimated cost", but
vars.IsEmpty()doesn't determine the cost mode—that's controlled byactualListSizes != nil(line 830). The condition here determines whether variable values are available for display, not the cost calculation mode.📝 Suggested comment clarification
if arg.hasVariable { if vars.IsEmpty() { - // actual cost + // variables unavailable, show variable name only argStrs = append(argStrs, fmt.Sprintf("%s=$%s", name, arg.varName)) } else { - // estimated cost + // variables available, show resolved value v := vars.Get(arg.varName) argStrs = append(argStrs, fmt.Sprintf("%s=%s($%s)", name, v, arg.varName)) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v2/pkg/engine/plan/cost.go` around lines 904 - 911, The comments are misleading: vars.IsEmpty() checks whether variable values are available for display, not whether we're in "actual" vs "estimated" cost mode (that is governed by actualListSizes != nil); update the comments around the argStrs append in the block using vars.IsEmpty() to state that the branch prints the variable name with either the raw variable value (when vars has no mapping) or the variable's resolved value wrapper (when vars provides a value). Refer to vars.IsEmpty(), vars.Get(arg.varName), arg.varName, actualListSizes and argStrs to locate and clarify the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@v2/pkg/engine/plan/cost.go`:
- Around line 904-911: The comments are misleading: vars.IsEmpty() checks
whether variable values are available for display, not whether we're in "actual"
vs "estimated" cost mode (that is governed by actualListSizes != nil); update
the comments around the argStrs append in the block using vars.IsEmpty() to
state that the branch prints the variable name with either the raw variable
value (when vars has no mapping) or the variable's resolved value wrapper (when
vars provides a value). Refer to vars.IsEmpty(), vars.Get(arg.varName),
arg.varName, actualListSizes and argStrs to locate and clarify the comment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 63e2ce83-c74c-4445-bc7a-5d279dd85248
📒 Files selected for processing (1)
v2/pkg/engine/plan/cost.go
🤖 I have created a release *beep* *boop* --- ## [2.4.0](v2.3.1...v2.4.0) (2026-05-21) ### Features * **grpc_datasource:** introduce RPCTransport abstraction with gRPC implementation ([#1490](#1490)) ([faffd81](faffd81)) ### Bug Fixes * use remapped variables in cost calculation ([#1505](#1505)) ([972ad0f](972ad0f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.15.3](execution/v1.15.2...execution/v1.15.3) (2026-05-21) ### Bug Fixes * use remapped variables in cost calculation ([#1505](#1505)) ([972ad0f](972ad0f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
I have no idea how it slipped but I implemented Cost Control
without any regard to remapped variables.
This PR fixes the situation. It adds an abstraction to deal with remapped
variables. Additionally, I have applied it in the resolver.