Files
CLIProxyAPI/sdk/cliproxy/usage/home_selection.go
hkfires 216f2947fc feat(home): report reused dispatch turns in usage
Add attempt-scoped HomeSelection metadata carrying the reused and
additional flags, scheduling route model, and credential policy
through usage records to the Redis queue. Mark retained executions
and Codex duplex successors as reused so Home can compensate later
turns after completion without redispatching or reacquiring a
concurrency slot.

Mark split additional-model records as additional so they never add
scheduling charges, while preserving independent per-response
execution IDs for deduplication. Document the deferred accounting
and add coverage across conductor, duplex, reporter, and queue.
2026-11-09 22:31:47 +08:00

38 lines
1.2 KiB
Go

package usage
import "context"
// HomeSelection identifies executions associated with a Home dispatch. Dispatch
// charges the first execution; reused executions are charged by primary usage.
// Additional-model records are billing details, not extra scheduling requests.
// Model is the scheduling route, not the upstream model.
type HomeSelection struct {
Reused bool `json:"reused"`
Additional bool `json:"additional,omitempty"`
Model string `json:"model"`
CredentialPolicy string `json:"credential_policy,omitempty"`
}
type homeSelectionContextKey struct{}
// WithHomeSelection captures immutable, attempt-scoped Home accounting metadata.
func WithHomeSelection(ctx context.Context, selection HomeSelection) context.Context {
if ctx == nil {
ctx = context.Background()
}
return context.WithValue(ctx, homeSelectionContextKey{}, selection)
}
// HomeSelectionFromContext returns a copy so follow-up responses cannot change
// the accounting metadata retained by the first response's usage reporter.
func HomeSelectionFromContext(ctx context.Context) *HomeSelection {
if ctx == nil {
return nil
}
selection, ok := ctx.Value(homeSelectionContextKey{}).(HomeSelection)
if !ok {
return nil
}
return &selection
}