Repository navigation
fix(finops): give the Soniox balance pull a command-line entry point - #25188
Conversation
pull_vendor_balance.py defined pull() but nothing called it when the daily job ran the file, so the step exited 0 writing no artifact, the loader treated the missing artifact as dark, and omi_finops.vendor_balance_snapshot was never created. Adds main() and the __main__ guard, and a subprocess test that runs it the way the job does. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08c7de46e4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import subprocess | ||
| import sys | ||
|
|
||
| env = {k: v for k, v in __import__("os").environ.items() if k != "FINOPS_SONIOX_ORG_KEY"} |
There was a problem hiding this comment.
Move the new test imports to module scope
The new test imports subprocess and sys inside the function and dynamically imports os, violating the explicit backend convention in backend/AGENTS.md: “All imports at module top level — never inside functions.” Move all three standard-library imports into the existing module-level import block and use os.environ directly.
AGENTS.md reference: backend/AGENTS.md:L168-L168
Useful? React with 👍 / 👎.
…A-1961) (#25217) ## What The Soniox balance snapshot now renders its money fields to BigQuery's NUMERIC contract before the load, so the daily finops job's first real snapshot no longer fails. ## Why After #25188 gave `pull_vendor_balance.py` a real entry point, the first production run (`finops-unit-cost-job-8fqt6`, 2026-11-13 15:39Z) reached the puller and failed loading `used_usd`: the vendor's decimal has more than nine fractional digits and BigQuery rejected it with `Invalid NUMERIC value`. The job exited 1 after one retry; `omi_finops.vendor_balance_snapshot` was created but holds 0 rows. Tracked as SCA-1961; the Soniox line on Omi TV needs two good snapshots. ## Change - `numeric_usd()` in `pull_vendor_balance.py`: half-up to nine decimals (the policy the derived daily spend already uses and the README documents), plain decimal notation (never exponent), short values keep their digits (`12.5` stays `12.5`), and a value outside NUMERIC's 29 integer digits becomes an `invalid_response` skip instead of a load error. - `parse_balance` uses it for both `used_usd` and `available_usd`. The derived `usd` column already quantized to nine places. - `load_vendor_balance` re-renders the artifact's values through the same function, so an artifact written by an older image cannot reach BigQuery unnormalized. - README: one sentence on the policy. No schema, schedule, secret, IAM or job-config change. ## Tests - `pytest backend/tests/unit/test_finops*.py`: 279 passed, including new parametrized renderings (more than nine digits, half rounding, exponent notation, 29-digit limit, short values unchanged) and a loader regression that checks every money string sent to BigQuery against the NUMERIC text pattern, with 16-digit vendor-like decimals. ## Rollout Needs the finops job image rebuilt through its existing workflow (release request SCA-1895 / SCA-1961). The release owner verifies the first scheduled snapshot; the measured Soniox line needs a second one the next day. Failure-Class: none 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/25217?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/25217?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25217&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
…A-1961) The first real daily run after BasedHardware#25188 reached the Soniox balance puller and failed loading used_usd: the vendor's decimal has more than nine fractional digits and BigQuery rejected it as an invalid NUMERIC (job exit 1). parse_balance now renders balances through numeric_usd: half-up to nine decimals (the policy the derived daily spend already uses), plain decimal notation, short values unchanged, and a value outside the NUMERIC range is an invalid_response skip. The loader re-renders the artifact values too, so an artifact written by an older image cannot reach the table unnormalized. All money fields in the snapshot path are covered (used_usd, available_usd); the derived usd already quantized. Tests: parametrized renderings (more than nine digits, half rounding, exponent notation, range limit) and a loader regression that checks every money string sent to BigQuery against the NUMERIC text pattern. Failure-Class: none Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
What
backend/scripts/finops/pull_vendor_balance.pygets amain()(--raw DIR) and anif __name__ == "__main__"guard, plus a subprocess test.Why
The daily job (
finops-unit-cost-job) runs this file as a subprocess (run_unit_cost.pybalance step). The file definedpull()but nothing called it, so the step logged[balance] ok in 0s, wrote no artifact, andload_vendor_balancereturns{}for a missing artifact.omi_finops.vendor_balance_snapshotwas therefore never created, the Omi TV Soniox line stayed on the dated console constant, and the adminvendorBalanceleg errored every wall refresh (41 errors seen 11-12). Found 2026-11-13 by running the script against the real org key (David approved usingFINOPS_SONIOX_ORG_KEY): it exited 0 and wrote nothing. After the fix the same run writes areadyartifact with exactly the loader's expected keys.The org key itself is valid (balance endpoint HTTP 200) and already mounted on the job; no access change.
Verification
{"status": "skipped", "reason": "key_unavailable"}; with the real key: writes areadyartifact (keys: available_usd, invoice_billing_enabled, status, ts, used_usd, vendor);daily_deltasaccepts it. No values printed or stored.test_script_entry_writes_an_artifact_when_run_as_the_job_runs_it(subprocess, no key). Local pytest is not installed in this worktree; CI runs it.After deploy
The next daily run creates
vendor_balance_snapshotwith its first snapshot; the Omi TV wall shows Soniox as measured once 2 snapshots exist (two daily runs). Needs the finops job image rebuilt through its existing workflow (release queue).Failure-Class: FC-job-step-exits-zero-without-running
🤖 Generated with Claude Code