Add ModelRun.total_cost and total_data_rows#2057
Open
apollonin wants to merge 3 commits into
Open
Conversation
Expose a model run's total cost and processed data-row count, fetched in real time from Model Foundry (modelFoundryModelRunInfo) on property access and cached on the instance -- nothing is persisted on the run. Returns None for runs not backed by a Foundry model job. Requires the matching backend changes that surface totalDataRows on the modelFoundryModelRunInfo GraphQL field.
Catch ResourceNotFoundError/InternalServerError (run has no Foundry model job) and cache the empty result, but let transient errors (network, timeout, rate limit) propagate so they are not permanently cached as None. Addresses Bugbot review feedback.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ff2aadd. Configure here.
execute() returns None (not raises) for a RESOURCE_NOT_FOUND response since raise_return_resource_not_found defaults to False, so index the payload defensively to avoid a TypeError. Addresses Bugbot feedback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Adds two lazy properties to
ModelRun:Why
Model Foundry users (DoubleVerify) currently log cost and dataset size by hand. This lets them pull both straight off the
ModelRunthey already fetch — matching the workflow in their existing scripts (client.get_model_run(...)).How
On first access, a single
modelFoundryModelRunInfoquery is issued (which proxies to model_service's already-computed per-job cost + data-row count) and cached on the instance. Nothing is persisted on the run — it's real-time rehydration. Runs not backed by a Foundry model job returnNone(theLabelboxErroris swallowed).The
get_model_runquery itself is unchanged, so existing fetches stay cheap; the extra round trip only happens when cost/usage is actually read. (A server-sideModelRun.totalCostfield resolver was rejected becauseDbObjectselects all fields on every fetch, which would hit model_service on everyget_model_run.)Part of a 3-PR stack (deploy in order)
total_data_rows(Labelbox/python-monorepo#2502)totalDataRowson GraphQL (Labelbox/intelligence#29662)Test
tests/unit/test_unit_model_run.py— fetch + cache, refresh re-fetch, andNonefor non-Foundry runs. 3 tests passing (pytest tests/unit/test_unit_model_run.py).Note
Low Risk
Read-only additive SDK properties with opt-in GraphQL cost; depends on upstream Model Foundry GraphQL being deployed in the stack.
Overview
Adds lazy, cached
ModelRun.total_cost(USD) andModelRun.total_data_rows, populated on first read via amodelFoundryModelRunInfoGraphQL call (not onget_model_run).refresh_cost_and_usage()clears the cache for a live re-fetch.Non–Model Foundry runs and missing payloads return
None;ResourceNotFoundError/InternalServerErrorand empty responses are treated as no usage data. Transient errors (e.g.NetworkError) are not cached so a later read can retry.Unit tests in
test_unit_model_run.pycover fetch/cache, refresh, non-Foundry/missing payload behavior, and transient error propagation.Reviewed by Cursor Bugbot for commit 9f91a2b. Bugbot is set up for automated code reviews on this repo. Configure here.