Skip to content

feat(budget): bound what agents report spent by the providers' own figures - #96

Open
mrgoonie wants to merge 3 commits into
mainfrom
feat/provider-cost-floor
Open

mrgoonie wants to merge 3 commits into
mainfrom
feat/provider-cost-floor

Conversation

@mrgoonie

Copy link
Copy Markdown
Contributor

Why

The agent zone meters its own runs, so a capped budget was only as hard as the reported costs are honest. ADR 0007 states this limit. This PR proposes ADR 0027: the providers' own billing figure bounds what the agents report. ADR 0027 is proposed and needs the Owner's acceptance.

What

  • Owner setting. budget.set takes provider_cost_sources (anthropic, openai). Only a capped budget with a period accepts it, and budget.set warns when a source is removed.
  • Read by the control zone only.
    • The control zone reads each provider's admin cost API for the factory's own workspace or project, every 15 minutes, or a minute after a failed read.
    • It stores the figure at install/provider_spend. Only the control zone writes that key; the agent zone can read it but not write it, in the store and in the PostgreSQL row policies. No migration is needed.
    • Admin keys are SISF_ANTHROPIC_ADMIN_KEY and SISF_OPENAI_ADMIN_KEY. Each must be set with its scope, SISF_ANTHROPIC_COST_WORKSPACE or SISF_OPENAI_COST_PROJECT. No agent environment accepts a SISF_ variable.
  • Floor in the gate. The gate counts a period as having spent the larger of the agents' reports and the providers' figures, then adds reservations. budget.get shows provider_spent_micros and warns when the providers report more than the agents.
  • Fails closed. A named provider whose figure is missing, damaged or more than 2 hours old holds new capped runs with BUDGET_EXCEEDED. A rollback is never held.
  • Exact money. Amounts are parsed as decimals and rounded up to the micro; only USD is accepted. No redirect is followed with an admin key, and response bodies are never quoted in errors.

Limits

  • The adapters are written from the providers' published API references and tested against fakes only. Nothing has been proven against the live APIs.
  • The figures lag by hours, so runs claimed inside that window are admitted on the agents' word.
  • The gate runs in the agent zone's dispatcher. The floor corrects wrong reported costs, but cannot stop an agent zone that is taken over as a whole. In that case, budget.get (fed by the control zone's figure) is how the Owner sees what was really spent.
  • OAuth and subscription sign-ins have no billing figure, so this check does not apply to them.

Files outside the feature

  • ADR 0007's limit paragraph now points to ADR 0027.
  • tests/docs/brief_parity_test.go now counts 27 ADRs and lists 0027 as proposed, as earlier ADRs did.
  • Docs updated: operations guide, capability matrix (experimental), threat model (TM-12), acceptance matrix (SISF-14) and release notes.
  • Proposed for FEATURES.md (not edited here): "Budget bounded by the providers' reported spend (Anthropic, OpenAI), experimental, fakes-only."

Verification

  • go generate leaves no diff; gofmt, go vet and golangci-lint are clean (0 issues).
  • go test ./... passes.
  • -race passes on internal/budget/..., cmd/factoryd/..., internal/testkit/..., internal/dispatcher/... and tests/docs.
  • -race passes on internal/budget against PostgreSQL. On PostgreSQL, the agent role cannot change the figure over plain SQL.
  • Negative tests cover:
    • the agent zone cannot write the figure;
    • a missing, stale, future-dated, partial or damaged figure holds runs but not a rollback;
    • a missing key or a failed source stores nothing;
    • no retry within a minute of a failure;
    • redirects do not carry the key;
    • non-USD currencies are refused.

…gures

The agent zone meters its own runs, so a capped budget was only as hard
as that zone is honest. An Owner can now name Anthropic or OpenAI as
cost sources for a capped budget with a period. The control zone reads
each provider's admin cost API for the factory's own workspace or
project every 15 minutes and stores the figure where only it can write.
The gate counts a period as having spent the larger of the agents'
reports and the providers' figures.

A named provider whose figure is missing, damaged or read more than two
hours ago holds new capped runs and never a rollback, so a missing key
or an outage fails closed. Amounts are parsed as exact decimals, only
USD is accepted, and no redirect is followed with an admin key.

Signed-off-by: Goon <duy@wearetopgroup.com>
…r a failed read

A damaged figure answered TAMPERED, which stopped a rollback and did not
hold every claim; it now holds capped runs like a missing one. The
control pass runs every second, so a failed read is now retried after a
minute instead of on every pass. State plainly that the gate runs in the
agent zone, so the floor corrects wrong reports but cannot stop an agent
zone taken over as a whole.

Signed-off-by: Goon <duy@wearetopgroup.com>
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