routing

package
v0.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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()
	// ReportCodexWorkWaiting says Codex model work is waiting for an account,
	// which may justify spending a reset credit.
	ReportCodexWorkWaiting()
	// ResetCreditComesFirst says a reset credit is about to be spent, so no
	// account may draw its usage credits yet.
	ResetCreditComesFirst() bool
	ExcludeUnsupportedAccountModel(accountKey store.AccountKey, modelSlug string)
	RefreshAccountCredentialsAfterUnauthorized(accountKey store.AccountKey, rejected accounts.Credentials) error
}

AccountRoutingFactsSource isolates selection from account-home discovery.

type AccountUnavailability added in v0.1.11

type AccountUnavailability struct {
	Reason string
	Until  time.Time
	// DrawsCredits means the account can take the work although its included
	// allowance is used up, because OpenAI draws its usage credits for it.
	DrawsCredits bool
}

AccountUnavailability is why an account cannot take new model work, and when that ends if a reset is known. Reason holds no time, so each reader writes Until in its own time zone: the proxy log in UTC, status and the menu in the Mac's current zone. An empty Reason means the account can take the work.

func (AccountUnavailability) LogText added in v0.1.11

func (unavailability AccountUnavailability) LogText() string

LogText is the reason as the proxy log writes it.

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]AccountUnavailability, error)

ReadAccountAvailability uses the same rule as admission.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL