plannerapi

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 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 plannerapi defines the Console-facing surface of the AIBrix planner: the Planner interface, the request/response shapes Enqueue / GetJob / ListJobs / GetQueueStats / GetProvisionResourceStats carry, and the typed errors Console handlers route on.

Anything Console (or any other consumer outside the planner module) imports lives here. The planner -> MDS adapter is rooted at the sibling package .../planner/client; the synchronous reference implementation lives at .../planner/impl. Worker / store / scheduler packages will join when the async Scheduler lands.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidJob indicates the EnqueueRequest failed validation
	// (missing required fields, etc.).
	ErrInvalidJob = errors.New("planner: invalid job")

	// ErrInsufficientResources indicates the RM could not satisfy a
	// capacity request right now. The RM's typed error (from the adjacent
	// RM package) is wrapped with this sentinel so the planner stays
	// decoupled from the concrete RM error vocabulary.
	ErrInsufficientResources = errors.New("planner: insufficient resources")

	// ErrJobNotFound indicates the JobID passed to GetJob/Cancel is not
	// known to the planner. With the in-memory Scheduler this fires for
	// jobs created before the process started; the durable-store
	// follow-up will narrow this to "truly unknown JobID" cases.
	ErrJobNotFound = errors.New("planner: job not found")
)

Sentinel errors returned by the Planner interface. Implementations should wrap with %w so callers can use errors.Is without parsing transport- or storage-specific error strings.

Functions

This section is empty.

Types

type ClientConfig added in v0.8.0

type ClientConfig struct {
	MaxConcurrency           *int32             `json:"max_concurrency,omitempty"`
	AdaptiveConcurrency      *bool              `json:"adaptive_concurrency,omitempty"`
	AdaptiveMaxFactor        *float64           `json:"adaptive_max_factor,omitempty"`
	AdaptiveHealthyWindow    *int32             `json:"adaptive_healthy_window,omitempty"`
	AdaptiveAdditiveIncrease *int32             `json:"adaptive_additive_increase,omitempty"`
	RetryPolicy              *ClientRetryPolicy `json:"retry_policy,omitempty"`
}

ClientConfig is the Console-supplied per-job smart-client control block. The planner projects it verbatim into extra_body.aibrix.client; MDS reads it back as BatchSpec.aibrix.client. Pointer fields carry proto3 presence so an unset field falls back to the metadata-service env defaults rather than overriding with a zero value.

type ClientRetryPolicy added in v0.8.0

type ClientRetryPolicy struct {
	MaxRetries           *int32   `json:"max_retries,omitempty"`
	BaseDelaySeconds     *float64 `json:"base_delay_seconds,omitempty"`
	MaxDelaySeconds      *float64 `json:"max_delay_seconds,omitempty"`
	NoEndpointMaxRetries *int32   `json:"no_endpoint_max_retries,omitempty"`
}

ClientRetryPolicy mirrors the metadata-service aibrix.client.retry_policy block.

type EnqueueRequest

type EnqueueRequest struct {
	// JobID is the user-visible Console job identifier. Console generates
	// it (typically as a UUID) and the planner uses it as the primary
	// correlation key — Planner.GetJob and ListJobs surface it back to
	// Console as pb.Job.Id, distinct from the MDS-side batch ID.
	JobID string `json:"job_id"`
	// Model identifies which model the job will run against, UI provided.
	Model string `json:"model,omitempty"`
	// ModelTemplate is the authoritative Console-selected
	// ModelDeploymentTemplate reference. The planner projects it into
	// extra_body.aibrix.model_template when submitting to MDS.
	ModelTemplate *ModelTemplateRef `json:"model_template,omitempty"`
	// BatchParams is the OpenAI-batch-format submission MDS will execute,
	// in the openai-go SDK's native shape. Console-owned attribution
	// (created_by, display_name, ...) rides on BatchParams.Metadata under
	// the aibrix.console.* namespace and is the single source of truth
	// for read-back via GetJob.
	BatchParams openai.BatchNewParams `json:"batch_params"`
	// RequestCountTotal is the frontend-computed request count (e.g., JSONL line count).
	// The planner persists it to the store for display before MDS reports back.
	RequestCountTotal int32 `json:"request_count_total,omitempty"`
	// ResourceRequest is the Console-supplied resource intent. The planner uses
	// it for resource-manager requests; the final allocation is recorded on
	// extra_body.aibrix.resource_allocation.
	ResourceRequest *ResourceRequest `json:"resource_request,omitempty"`
	// Client is the Console-supplied smart-client control block, projected
	// verbatim into extra_body.aibrix.client.
	Client *ClientConfig `json:"client,omitempty"`
	// InjectionConfig is the error injection configuration for this job.
	InjectionConfig *error_injection.InjectionConfig `json:"injection_config,omitempty"`
}

type Job

type Job struct {
	JobID string        `json:"job_id"`
	Batch *openai.Batch `json:"batch,omitempty"`
	State *JobState     `json:"state,omitempty"`
}

Job is the planner's JobID-keyed result, returned from Enqueue, GetJob, Cancel, and each entry of ListJobs.

JobID is the Console-generated correlation key and the only id that crosses the planner boundary upward. The MDS-side batch.ID is an internal implementation detail of the planner and is not exposed here; callers above the planner read job.Batch.ID only for rendering MDS-native fields, never for lookups.

Batch is the MDS-side openai.Batch when the planner has submitted to MDS. Future asynchronous planners that defer the MDS submit may return Batch == nil on Enqueue and rely on the caller polling GetJob.

type JobState

type JobState struct {
	BatchID             string    `json:"batch_id,omitempty"`
	ProvisionID         string    `json:"provision_id,omitempty"`
	ErrorMessage        string    `json:"error_message,omitempty"`
	QueuedAt            time.Time `json:"queued_at,omitempty"`
	ResourcePreparingAt time.Time `json:"resource_preparing_at,omitempty"`
	SubmittingAt        time.Time `json:"submitting_at,omitempty"`
	ResourceFailedAt    time.Time `json:"resource_failed_at,omitempty"`
	SubmitFailedAt      time.Time `json:"submit_failed_at,omitempty"`
	CancelRequestedAt   time.Time `json:"cancel_requested_at,omitempty"`
	CancelledAt         time.Time `json:"cancelled_at,omitempty"`
}

JobState is the planner-owned lifecycle data that does not exist on the OpenAI Batch object. It is persisted in Console's store and lets the BFF expose pre-MDS events such as resource provisioning and submit failures.

type JobStatus

type JobStatus string

JobStatus is the authoritative user-facing lifecycle status for a Job.

const (
	JobStatusQueued            JobStatus = "queued"
	JobStatusPlanned           JobStatus = "planned"
	JobStatusResourcePreparing JobStatus = "resource_preparing"
	JobStatusSubmitting        JobStatus = "submitting"

	JobStatusScheduling JobStatus = "scheduling"
	JobStatusValidating JobStatus = "validating"
	JobStatusInProgress JobStatus = "in_progress"
	JobStatusFinalizing JobStatus = "finalizing"
	JobStatusCancelling JobStatus = "cancelling"

	JobStatusCompleted      JobStatus = "completed"
	JobStatusFailed         JobStatus = "failed"
	JobStatusExpired        JobStatus = "expired"
	JobStatusCancelled      JobStatus = "cancelled"
	JobStatusResourceFailed JobStatus = "resource_failed"
	JobStatusSubmitFailed   JobStatus = "submit_failed"
)

func (JobStatus) IsTerminal

func (s JobStatus) IsTerminal() bool

IsTerminal reports whether the job will not transition further.

func (JobStatus) ToBatchStatus

func (s JobStatus) ToBatchStatus() openai.BatchStatus

type ListJobsRequest

type ListJobsRequest struct {
	Limit int    `json:"limit,omitempty"`
	After string `json:"after,omitempty"`
}

ListJobsRequest queries the planner-merged job list using the same cursor semantics as the OpenAI Batches list API: Limit controls page size and After carries the trailing batch ID from the previous page.

Keep this request shape aligned with the upstream list contract unless the planner grows planner-owned filters that cannot be expressed at the MDS / OpenAI layer.

type ListJobsResponse

type ListJobsResponse struct {
	Data    []*Job `json:"data"`
	HasMore bool   `json:"has_more"`
}

ListJobsResponse is the planner-facing paginated read result.

Each entry is a Job so the JobID rides alongside the MDS batch view; HasMore mirrors the OpenAI SDK's batch list page semantics.

type ModelTemplateRef

type ModelTemplateRef struct {
	Name    string          `json:"name"`
	Version string          `json:"version,omitempty"`
	Spec    json.RawMessage `json:"spec,omitempty"`
}

ModelTemplateRef identifies the ModelDeploymentTemplate MDS should use when rendering the batch worker job. Empty Version means "latest active version". Spec is the resolved full template spec inlined for cross-cluster delivery; MDS uses Spec directly when present and skips its local registry lookup.

type Planner

type Planner interface {
	Start(ctx context.Context) error
	Enqueue(ctx context.Context, req *EnqueueRequest) (*Job, error)
	GetJob(ctx context.Context, jobID string) (*Job, error)
	ListJobs(ctx context.Context, req *ListJobsRequest) (*ListJobsResponse, error)
	Cancel(ctx context.Context, jobID string) (*Job, error)
	// Recover replays persisted in-flight state at startup; nil for stateless impls.
	Recover(ctx context.Context) error
	Close() error
}

Planner is the Console BFF -> planner boundary.

Console.CreateJob builds an EnqueueRequest and calls Enqueue. All reads (GetJob, ListJobs, Cancel) take the Console-generated JobID and return a Job; the MDS batch.ID never crosses this boundary upward. The planner owns the JobID -> batch.ID translation (in-memory today; durable when the persistence follow-up lands).

Either Start or Recover must be called before any other methods.

Close stops background workers and releases resources; callers (e.g. Server.Shutdown) invoke it on shutdown without a runtime type assertion.

type ResourceRequest added in v0.8.0

type ResourceRequest struct {
	Replicas int `json:"replicas,omitempty"`
	// ProviderConfig contains opaque provider-specific resource settings.
	ProviderConfig map[string]any `json:"provider_config,omitempty"`
}

ResourceRequest captures user resource intent before planner/RM resolution.

type RuntimeRef

type RuntimeRef struct {
	Target  string         `json:"target,omitempty"`
	Options map[string]any `json:"options,omitempty"`
}

RuntimeRef selects the metadata-service Runtime used to materialize the job. Options is intentionally free-form for runtime-specific fields such as Kubernetes namespace, region, or provisioner-specific switches.

Jump to

Keyboard shortcuts

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