Documentation
¶
Overview ¶
Package bench runs one project once per provider and compares the runs.
Each run happens on a throwaway copy of the project whose router sends every task to one provider, so the user's files and database are never touched. The dispatch itself is the caller's (`orch bench` hands in `orch run`'s own code path); this package prepares the copies, watches the spend cap while a run is going, and reads the finished copy's database into a Result.
Index ¶
- Constants
- Variables
- func Prepare(src, dst, provider string, models map[string]string) error
- func SpentUSD(ctx context.Context, db receipt.Reader, runID string, prices pricing.Table) (float64, error)
- func WatchCap(ctx context.Context, ticks <-chan time.Time, max float64, ...) error
- type Report
- type Result
Constants ¶
const Version = 1
Version is the results schema's version. Bump it when a field changes meaning or goes away; adding one does not need it.
Variables ¶
var ErrOverCap = errors.New("max-usd reached")
ErrOverCap is what WatchCap reports when a run crossed its cap.
var Providers = []string{ string(model.BackendClaude), string(model.BackendCodex), string(model.BackendOpencode), string(model.BackendGemini), string(model.BackendAgy), string(model.BackendMuse), }
Providers are the backends a bench can run, in the order the flag help lists them.
Functions ¶
func Prepare ¶
Prepare copies the project at src to dst for one provider's run: without its runtime state, every task not in the backlog back to todo, and the router rewritten so each route dispatches to provider.
models maps a provider to the cli_model every route should use; without an entry, each route takes the cli_model of a route that already targets the provider, same tier first.
func SpentUSD ¶
func SpentUSD(ctx context.Context, db receipt.Reader, runID string, prices pricing.Table) (float64, error)
SpentUSD is the cap watch's running total: the run's receipt so far, so the cap and the reported cost are the same number.
func WatchCap ¶
func WatchCap(ctx context.Context, ticks <-chan time.Time, max float64, spent func(context.Context) (float64, error), stop func()) error
WatchCap calls spent on every tick and calls stop once it reaches max, then returns ErrOverCap. It returns nil when ctx ends first. A read error is not a reason to stop a run; the next tick tries again.
The cap is checked between dispatches, not inside one: a dispatch already running when the total crosses it finishes, so a run can end a dispatch's cost above max.
Types ¶
type Report ¶
type Report struct {
BenchVersion int `json:"bench_version"`
OrchVersion string `json:"orch_version"`
Date string `json:"date"`
OS string `json:"os"`
Arch string `json:"arch"`
Project string `json:"project"`
MaxUSD float64 `json:"max_usd"`
Results []Result `json:"results"`
}
Report is the whole bench: where and when it ran, and one Result per run.
type Result ¶
type Result struct {
Provider string `json:"provider"`
CLIVersion string `json:"cli_version"`
Run int `json:"run"`
// Outcome is "finished", "stopped: max-usd", "exit N" or "error: <message>".
Outcome string `json:"outcome"`
// Tasks is every task in the project; Done and Blocked are tasks by
// their last outcome in the run, as its receipt counts them; Unfinished
// is the rest, backlog included.
Tasks int `json:"tasks"`
Done int `json:"done"`
Blocked int `json:"blocked"`
Unfinished int `json:"unfinished"`
Dispatches int `json:"dispatches"`
// FailedAttempts counts fail and timeout events; Retries counts retry
// events. Both are the receipt's.
FailedAttempts int `json:"failed_attempts"`
Retries int `json:"retries"`
WallS float64 `json:"wall_s"`
AgentS float64 `json:"agent_s"`
// CostUSD is what the CLI reported plus the pricing.yaml estimate for
// rows it did not price, EstimatedCostUSD the estimated part, and
// CostSource the receipt's label for it (reported, estimated, no_data).
CostUSD float64 `json:"cost_usd"`
EstimatedCostUSD float64 `json:"estimated_cost_usd"`
CostSource string `json:"cost_source"`
// TokensIn/TokensOut are as the CLI reported them, cache included;
// WeightedTokens is what the budget window counts.
TokensIn int `json:"tokens_in"`
TokensOut int `json:"tokens_out"`
WeightedTokens int `json:"weighted_tokens"`
}
Result is one provider's run.
func Collect ¶
func Collect(ctx context.Context, db receipt.Reader, runID string, prices pricing.Table) (Result, error)
Collect reads one run of a copy into a Result: the counts, time and spend come from the run's receipt (internal/receipt, the same builder `orch report receipt` and the dashboard use), plus the task totals the receipt does not carry. Provider, CLIVersion, Run and Outcome are the caller's to fill.