Skip to content

fix(finops): give the Soniox balance pull a command-line entry point - #25188

Merged
Git-on-my-level merged 1 commit into
mainfrom
lane/finops-balance-main-1113
Nov 13, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
lane/finops-balance-main-1113

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What

backend/scripts/finops/pull_vendor_balance.py gets a main() (--raw DIR) and an if __name__ == "__main__" guard, plus a subprocess test.

Why

The daily job (finops-unit-cost-job) runs this file as a subprocess (run_unit_cost.py balance step). The file defined pull() but nothing called it, so the step logged [balance] ok in 0s, wrote no artifact, and load_vendor_balance returns {} for a missing artifact. omi_finops.vendor_balance_snapshot was therefore never created, the Omi TV Soniox line stayed on the dated console constant, and the admin vendorBalance leg errored every wall refresh (41 errors seen 11-12). Found 2026-11-13 by running the script against the real org key (David approved using FINOPS_SONIOX_ORG_KEY): it exited 0 and wrote nothing. After the fix the same run writes a ready artifact 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

  • Ran the fixed script locally with no key: writes {"status": "skipped", "reason": "key_unavailable"}; with the real key: writes a ready artifact (keys: available_usd, invoice_billing_enabled, status, ts, used_usd, vendor); daily_deltas accepts it. No values printed or stored.
  • New test 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_snapshot with 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

View guided diff Turn on auto-fix

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T10:54:52.677106Z 08c7de4 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +285 to +288
import subprocess
import sys

env = {k: v for k, v in __import__("os").environ.items() if k != "FINOPS_SONIOX_ORG_KEY"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 46599b0 into main Nov 13, 2026
67 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/finops-balance-main-1113 branch November 13, 2026 11:11
Git-on-my-level added a commit that referenced this pull request Nov 13, 2026
…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. -->
sauranshbhardwaj pushed a commit to sauranshbhardwaj/omi that referenced this pull request Nov 13, 2026
…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]>
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.

1 participant