Documentation
¶
Overview ¶
Package routing keeps model turns on durable task pins and moves new requests away from unavailable accounts. It does not retry or replay model work.
Index ¶
- Variables
- type AccountRoutingFactsSource
- type ClaudePoolExhaustedError
- type RouteDecision
- type TaskRouter
- func (router *TaskRouter) ClaudePoolCapacity(modelSlug string) (accountFree bool, availableAgainAt time.Time, limitClaim string, err error)
- func (router *TaskRouter) ReadAccountAvailability(modelSlug string) ([]accounts.AccountRoutingFact, map[store.AccountKey]string, error)
- func (router *TaskRouter) ReportExhaustedTurn(taskID store.TaskID, servedAccountKey store.AccountKey, resetsAt time.Time) string
- func (router *TaskRouter) ReportUnauthorizedTurn(servedAccountKey store.AccountKey, rejectedCredentials accounts.Credentials)
- func (router *TaskRouter) ReportUnsupportedModel(taskID store.TaskID, accountKey store.AccountKey, modelSlug string) bool
- func (router *TaskRouter) RouteForModelCatalogue() (RouteDecision, error)
- func (router *TaskRouter) RouteForProviderTask(taskID store.TaskID, workKind store.WorkKind, modelSlug string, ...) (RouteDecision, error)
- func (router *TaskRouter) RouteForTask(taskID store.TaskID, workKind store.WorkKind, modelSlug string) (RouteDecision, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNoAvailableAccount = errors.New("no account can take this work")
ErrNoAvailableAccount means new work must wait for account capacity.
Functions ¶
This section is empty.
Types ¶
type AccountRoutingFactsSource ¶
type AccountRoutingFactsSource interface {
ReadAccountRoutingFacts() ([]accounts.AccountRoutingFact, error)
RequestAccountRoutingFactsRefresh()
ExcludeUnsupportedAccountModel(accountKey store.AccountKey, modelSlug string)
}
AccountRoutingFactsSource isolates selection from account-home discovery.
type ClaudePoolExhaustedError ¶ added in v0.1.7
type ClaudePoolExhaustedError struct {
AccountProblems string
AvailableAgainAt time.Time
// LimitClaim is Anthropic's name for the limit that ends at AvailableAgainAt,
// such as five_hour or seven_day.
LimitClaim string
}
ClaudePoolExhaustedError is ErrNoAvailableAccount for Claude model work. It says when an allowance reset next frees an account; AvailableAgainAt is zero when no reset will, for example when every account is signed out.
func (*ClaudePoolExhaustedError) Error ¶ added in v0.1.7
func (exhausted *ClaudePoolExhaustedError) Error() string
func (*ClaudePoolExhaustedError) Unwrap ¶ added in v0.1.7
func (exhausted *ClaudePoolExhaustedError) Unwrap() error
type RouteDecision ¶
type RouteDecision struct {
AccountKey store.AccountKey
DisplayName string
Credentials accounts.Credentials
// Assignment is empty when model work stays on its pinned account. Otherwise it
// says, in product terms, which account now serves the work and why; the relay
// logs it with the client that sent the request.
Assignment string
}
RouteDecision carries credentials with the account identity so the relay cannot mix accounts.
type TaskRouter ¶
type TaskRouter struct {
// contains filtered or unexported fields
}
TaskRouter reads every pin decision from SQLite so external repairs are visible without restart.
func CreateTaskRouter ¶
func CreateTaskRouter(storeDatabase *store.StoreDatabase, accountFacts AccountRoutingFactsSource) *TaskRouter
CreateTaskRouter keeps allowance refresh ownership outside routing's single selection rule.
func (*TaskRouter) ClaudePoolCapacity ¶ added in v0.1.7
func (router *TaskRouter) ClaudePoolCapacity(modelSlug string) (accountFree bool, availableAgainAt time.Time, limitClaim string, err error)
ClaudePoolCapacity says whether a Claude account can take modelSlug now. If none can, it says when an allowance reset next frees one, and Anthropic's name for the limit that ends then.
func (*TaskRouter) ReadAccountAvailability ¶
func (router *TaskRouter) ReadAccountAvailability(modelSlug string) ([]accounts.AccountRoutingFact, map[store.AccountKey]string, error)
ReadAccountAvailability uses the same rule as admission. An empty reason means the account can take new work for modelSlug.
func (*TaskRouter) ReportExhaustedTurn ¶
func (router *TaskRouter) ReportExhaustedTurn(taskID store.TaskID, servedAccountKey store.AccountKey, resetsAt time.Time) string
ReportExhaustedTurn changes the account for the next client request; routing never resends work. It returns what happened to the task, for the proxy log.
func (*TaskRouter) ReportUnauthorizedTurn ¶
func (router *TaskRouter) ReportUnauthorizedTurn(servedAccountKey store.AccountKey, rejectedCredentials accounts.Credentials)
ReportUnauthorizedTurn refreshes rejected credentials for the client's next request without replaying the failed turn.
func (*TaskRouter) ReportUnsupportedModel ¶
func (router *TaskRouter) ReportUnsupportedModel(taskID store.TaskID, accountKey store.AccountKey, modelSlug string) bool
ReportUnsupportedModel prepares the next client request without resending rejected work.
func (*TaskRouter) RouteForModelCatalogue ¶
func (router *TaskRouter) RouteForModelCatalogue() (RouteDecision, error)
RouteForModelCatalogue reads model metadata from the widest observed account catalogue. Inference allowance does not restrict this read, and task pins are untouched.
func (*TaskRouter) RouteForProviderTask ¶
func (router *TaskRouter) RouteForProviderTask(taskID store.TaskID, workKind store.WorkKind, modelSlug string, provider accounts.Provider, parentTaskID store.TaskID) (RouteDecision, error)
RouteForProviderTask uses the same placement rule for each provider. A new fork first inherits its parent account when that account can serve this model.
func (*TaskRouter) RouteForTask ¶
func (router *TaskRouter) RouteForTask(taskID store.TaskID, workKind store.WorkKind, modelSlug string) (RouteDecision, error)
RouteForTask keeps model work on its task's account while that account is available and gives new work the account selectAccountForNewWork ranks first. Work without a task ID gets the same choice as a new task but is never pinned. Metadata requests never create or move a pin.