Skip to content

fix: count unpriced paid fires against the budget and refuse userinfo in a local endpoint - #3

Merged
agent-kit-startup merged 1 commit into
mainfrom
fix/budget-fail-closed-loopback-userinfo
Nov 30, 2026
Merged

agent-kit-startup merged 1 commit into
mainfrom
fix/budget-fail-closed-loopback-userinfo

Conversation

@agent-kit-startup

Copy link
Copy Markdown
Contributor

Spend sums fail closed

Since Agent Kit 6.26.0, a fire on a model claude cannot price records cost_usd: null with cost_usd_reported and cost_basis: "unknown". The spend sums read only cost_usd, so such a paid fire counted as 0.

  • lib/common.sh: ns_spend and ns_repo_spend count each ledger line at cost_usd_reported when it is a number, else cost_usd, else 0 (shared NS_JQ_COST). This covers the night and month budgets, --budget-remaining, --check and the report's Spend table. Lines from fires listed in local-fires.tsv are still skipped, so local fires count 0. Ledger lines in the older format still count.
  • bin/night-shift: the per-fire cost in runs.tsv uses the same rule from the AGENT_KIT_RESULT line. It stays empty in local mode.
  • bin/night-shift-report: a note under Spend gives the number of tonight's fires with an unknown cost basis.

Stricter loopback check

ns_is_loopback_url now requires the authority (from :// to the first /) to be exactly 127.0.0.1, localhost or [::1], in any case, with an optional numeric port. Anything else counts as remote: userinfo, a percent-encoded @, a trailing dot, a longer host name, an empty or non-numeric port, or ? or # after the host. ns_endpoint_label prints a label only for a URL that passes this check, so it never prints userinfo.

Tests

  • tests/test_cost.sh (new): an unpriced fire stops an api-key night whose ceiling it exceeds. --check and the report count it. The month sum counts unpriced, old-format and priced lines once each. An unpriced local fire still counts 0.
  • tests/test_local.sh: a table of accepted and refused endpoint URLs, plus end-to-end checks that a userinfo endpoint is refused and, when vouched for, is never printed.
  • tests/fake/agent-kit: optional priced:X and unknown:X cost tokens emit the 6.26.0 fields. The default output keeps the older format.

bash tests/run.sh: 227 passed, 0 failed. scripts/hygiene-scan.sh: clean.

README ("Local model", "Cost comes from the backend") and docs/config.md describe both changes.

… in a local endpoint

Spend sums now count cost_usd_reported when the kit records one (6.26.0 and
later), else cost_usd. A paid fire on a model claude cannot price
(cost_usd null, cost_basis "unknown") now counts at the reported figure in
the night and month budgets, --budget-remaining, --check, the run log and
the morning report, which also notes such fires. Fires listed in
local-fires.tsv still count 0, and older ledger lines keep working.

ns_is_loopback_url now requires the authority to be exactly 127.0.0.1,
localhost or [::1] (any case) with an optional numeric port, so a URL with
userinfo, a percent-encoded @, a trailing dot, a longer host or a
non-numeric port is treated as remote.
@agent-kit-startup
agent-kit-startup merged commit 9478e59 into main Nov 30, 2026
2 checks passed
@agent-kit-startup
agent-kit-startup deleted the fix/budget-fail-closed-loopback-userinfo branch November 30, 2026 19:03
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