Documentation
¶
Overview ¶
Package config defines the sqi-worker runtime configuration and provides layered loading from built-in defaults, a YAML/JSON file, SQI_WORKER_* environment variables, and CLI flag overrides — in that override order.
The WorkerConfig struct is the canonical configuration type. Use Load to obtain a populated, validated instance. Use Default to obtain defaults alone.
Note: This package is the authoritative definition of worker configuration. Fields added here must be mirrored in the example config file at config/sqi-worker.example.yaml.
Index ¶
- Constants
- func LoadOrCreateWorkerID(dataDir string) (string, error)
- type DiagnosticsConfig
- type DiscoveryConfig
- type ExprConfig
- type FlagOverrides
- type IsolationConfig
- type LogConfig
- type LogStreamerConfig
- type MetricsConfig
- type NATSConfig
- type StagingConfig
- type ValidationError
- type WorkerConfig
- type WorkerSettings
Constants ¶
const ( DefaultWorkerExprOperationLimit int64 = 1_000_000 MinWorkerExprOperationLimit int64 = 10_000 MaxWorkerExprOperationLimit int64 = 10_000_000 DefaultWorkerExprMemoryLimit int64 = 20_000_000 MinWorkerExprMemoryLimit int64 = 1_000_000 MaxWorkerExprMemoryLimit int64 = 200_000_000 DefaultWorkerExprAssignmentPositions int64 = 10_000 MinWorkerExprAssignmentPositions int64 = 2_000 MaxWorkerExprAssignmentPositions int64 = 100_000 DefaultWorkerExprAssignmentRetainedBytes int64 = 20_000_000 MinWorkerExprAssignmentRetainedBytes int64 = 2_000_000 MaxWorkerExprAssignmentRetainedBytes int64 = 200_000_000 DefaultWorkerExprLetRetainedBytes int64 = 10_000_000 MinWorkerExprLetRetainedBytes int64 = 1_000_000 MaxWorkerExprLetRetainedBytes int64 = 100_000_000 )
The defaults and the range an operator may configure each expr: key to.
These are deliberate COPIES of internal/worker/fmtres's own constants: this package is the operator-facing configuration layer and fmtres is the enforcement leaf, and the worker's config package does not import it (the same direction internal/config and internal/openjd keep). cmd/sqi-worker is the one place that sees both, and its TestExprLimitsBounds_MatchFmtres fails if a number here ever drifts from the one it bounds.
Which of the five is a CATASTROPHE bound (a tight ceiling, tied to a measured failure) and which is a POLICY bound (wide but finite), and why, is recorded on fmtres.ExprLimits' own fields.
Variables ¶
This section is empty.
Functions ¶
func LoadOrCreateWorkerID ¶
LoadOrCreateWorkerID returns the worker's persistent UUID.
On the first call for a given dataDir the function:
- Creates dataDir (and any missing parents) with mode 0700.
- Generates a new random UUID.
- Writes it to <dataDir>/worker.id (mode 0600).
On subsequent calls the existing file is read and the UUID returned unchanged, so the server can correlate the worker across restarts.
An error is returned if the directory cannot be created, the file cannot be read or written, or the stored value is not a valid UUID.
dataDir holds ONLY worker.id and is NEVER widened for run-as-user traversal: it used to also be the shared ancestor of every session working directory (<dataDir>/sessions/<sessionID>), which forced it to be chmod'd traversable (0711) for isolated tasks to chdir into their own session — Go's forkAndExecInChild sets the child's process credentials BEFORE chdir. That coupling is exactly backwards: worker.id is the worker's persistent, server-correlated identity and must stay private (0700) and byte-for-byte stable, while session scratch is ephemeral and needs to be world-traversable when isolation is in play. Session working directories now live under a separate root (see cmd/sqi-worker's effectiveSessionRoot and session.Manager), created traversable FROM BIRTH where that is needed — never by mutating an existing directory's mode, which is the anti-pattern this split eliminates. dataDir stays exactly 0700, created once and never touched again by anything in this codebase.
Types ¶
type DiagnosticsConfig ¶
type DiagnosticsConfig struct {
// Enabled turns on diagnostic-log publishing. When true (the default) the
// worker's slog records are mirrored to sqi-server in addition to stderr.
// Env: SQI_DIAGNOSTICS_ENABLED
Enabled bool `yaml:"enabled"`
}
DiagnosticsConfig controls the diagnostic-log sink that ships the worker's own slog output to sqi-server over core NATS (worker.diag.<workerID>), where it is surfaced in the web UI.
type DiscoveryConfig ¶
type DiscoveryConfig struct {
// EnableMDNS enables mDNS browsing for "_sqi._tcp" services on the local
// network. When true and NATS.URL is empty, the worker uses the first
// discovered server address.
// Env: SQI_WORKER_DISCOVERY_ENABLE_MDNS
EnableMDNS bool `yaml:"enable_mdns"`
// MDNSTimeout is the maximum duration to wait for mDNS discovery results
// before falling back to an error.
// Env: SQI_WORKER_DISCOVERY_MDNS_TIMEOUT
MDNSTimeout time.Duration `yaml:"mdns_timeout"`
}
DiscoveryConfig controls mDNS-based sqi-server auto-discovery.
type ExprConfig ¶ added in v0.3.0
type ExprConfig struct {
// OperationLimit is the specification section 1.3.10 operation budget
// for ONE phase-3 expression evaluation.
// Default: 1000000 Range: 10000-10000000
// Env: SQI_WORKER_EXPR_OPERATION_LIMIT
OperationLimit int64 `yaml:"operation_limit"`
// MemoryLimit is the specification section 1.3.9 live-byte budget for
// ONE phase-3 expression evaluation. The per-let-block structural ceiling
// is 50x this number, which is the figure to size host RAM against.
// Default: 20000000 Range: 1000000-200000000
// Env: SQI_WORKER_EXPR_MEMORY_LIMIT
MemoryLimit int64 `yaml:"memory_limit"`
// AssignmentPositions is how many expression positions (a command, one
// args entry, one embedded file, one variable value) one assignment may
// resolve, summed across the task's own symbol table and every environment
// the session enters.
//
// MUST NOT BE LOWER THAN THE SERVER'S openjd.expr_template_positions. An
// assignment's positions are a subset of its template's, so a lower value
// here rejects, on this host and once per task, a job the server already
// accepted -- naming a budget the submitter never saw. Nothing checks that
// across the two processes today.
// Default: 10000 Range: 2000-100000
// Env: SQI_WORKER_EXPR_ASSIGNMENT_POSITIONS
AssignmentPositions int64 `yaml:"assignment_positions"`
// AssignmentRetainedBytes is the cumulative size of every let-bound
// value every phase-3 symbol table one assignment builds retains. See
// caveat 3 above: this is allocation across the session's entry phase, not
// simultaneously live memory.
// Default: 20000000 Range: 2000000-200000000
// Env: SQI_WORKER_EXPR_ASSIGNMENT_RETAINED_BYTES
AssignmentRetainedBytes int64 `yaml:"assignment_retained_bytes"`
// LetRetainedBytes is what ONE phase-3 symbol table may hold live.
// Note that it measures the WHOLE table, so a job whose own parameters are
// large spends budget its let: block never asked for.
// Default: 10000000 Range: 1000000-100000000
// Env: SQI_WORKER_EXPR_LET_RETAINED_BYTES
LetRetainedBytes int64 `yaml:"let_retained_bytes"`
}
ExprConfig is the operator-facing form of internal/worker/fmtres's ExprLimits: the five numbers that bound phase-3 (task-execution-time) OpenJD expression evaluation on THIS host.
Each worker reads its own file, which is what lets a heterogeneous farm size these to each host's real memory. The server has its own, separate set (internal/config's openjd.expr_* keys) covering submission-time evaluation; the two are independent, with one relation between them that configuration can break -- see AssignmentPositions.
THREE THINGS TO KNOW BEFORE RAISING ANY OF THEM, none of which is obvious from the numbers:
- NONE OF THESE BOUNDS WALL CLOCK. Specification section 1.3.10 prices 256 bytes at one operation, so an operation's real cost varies by orders of magnitude. Raising a limit lengthens the worst assignment this host can be asked to resolve, roughly in proportion; no setting makes a slow resolution impossible.
- expr.operation_limit AND expr.assignment_positions MULTIPLY. The cumulative operation ceiling for one assignment is their product, so raising both raises it twice over.
- THE BYTE DIMENSIONS COUNT CUMULATIVE ALLOCATION, NOT PEAK LIVE RETENTION. A session that never holds more than a few MB at once is still charged the sum of every environment it enters, so sizing host RAM against expr.assignment_retained_bytes over-provisions, and sizing that number against an observed RSS under-bounds it.
An out-of-range value is a startup failure, not a clamp (see Validate).
type FlagOverrides ¶
type FlagOverrides struct {
// LogLevel overrides Log.Level when non-empty.
LogLevel string
// LogFormat overrides Log.Format when non-empty.
LogFormat string
// DryRun, when true, makes the start command print resolved config and exit.
DryRun bool
// NATSInsecureSkipVerify overrides NATS.InsecureSkipVerify when true.
// Corresponds to --nats-insecure-skip-verify on the start subcommand.
NATSInsecureSkipVerify bool
}
FlagOverrides carries values from CLI flags that take highest precedence during config loading. Only non-empty / non-zero values override the lower layers.
type IsolationConfig ¶ added in v0.3.0
type IsolationConfig struct {
// Required makes the worker exit at boot when it cannot assume another
// identity. Default false, preserving pre-isolation behavior: a worker
// with no isolation capability keeps running ordinary queues.
// Env: SQI_WORKER_ISOLATION_REQUIRED
Required bool `yaml:"required"`
// Provider selects the Windows credential mechanism. "logon_user" (the
// default) is the only supported value.
//
// "s4u" is refused. An S4U logon needs no password, but the token it
// produces carries no NETWORK credentials: any UNC path, mapped drive, or
// authenticated license server fails as ANONYMOUS from inside the task.
// On a render farm, where scene files and outputs live on a share, that
// disqualifies it as a general-purpose provider, and no driver exists for
// a worker whose jobs touch local scratch exclusively. Adding it later is
// additive.
// Env: SQI_WORKER_ISOLATION_PROVIDER
Provider string `yaml:"provider"`
// EnvPassthrough lists daemon environment variable NAME patterns inherited
// by isolated tasks, in addition to the minimal base. filepath.Match
// globs. Render farms depend on inherited licensing variables, so a pure
// allowlist with no escape hatch would break real jobs on day one.
// Env: SQI_WORKER_ISOLATION_ENV_PASSTHROUGH (comma-separated)
EnvPassthrough []string `yaml:"env_passthrough"`
}
IsolationConfig controls running tasks as a queue-configured OS user.
type LogConfig ¶
type LogConfig struct {
// Level is the minimum log level: debug, info, warn, error.
// Env: SQI_WORKER_LOG_LEVEL
Level string `yaml:"level"`
// Format is the log output format: json or text.
// Env: SQI_WORKER_LOG_FORMAT
Format string `yaml:"format"`
}
LogConfig controls structured logging output.
type LogStreamerConfig ¶
type LogStreamerConfig struct {
// MaxLinesPerChunk is the maximum number of output lines batched into a
// single NATS message. A flush is triggered immediately when the buffer
// reaches this count. Increase for verbose processes; decrease for more
// granular live log updates.
// Default: 50
// Env: SQI_WORKER_LOG_STREAMER_MAX_LINES_PER_CHUNK
MaxLinesPerChunk int `yaml:"max_lines_per_chunk"`
// MaxBytesPerChunk is the maximum total byte count of line content in a
// single NATS message. A flush is triggered when the accumulated bytes
// reach this limit after adding a line.
// Default: 16384 (16 KB)
// Env: SQI_WORKER_LOG_STREAMER_MAX_BYTES_PER_CHUNK
MaxBytesPerChunk int `yaml:"max_bytes_per_chunk"`
// FlushInterval is the maximum time a line may sit in the buffer before
// being flushed by the background goroutine regardless of chunk thresholds.
// Smaller values make the web UI log viewer feel more live at the cost of
// more frequent small NATS publishes.
// Default: 500ms
// Env: SQI_WORKER_LOG_STREAMER_FLUSH_INTERVAL
FlushInterval time.Duration `yaml:"flush_interval"`
}
LogStreamerConfig controls the log-chunk publisher that streams task process stdout/stderr to sqi-server.
type MetricsConfig ¶
type MetricsConfig struct {
// Addr is the TCP address the local HTTP server listens on.
// Env: SQI_WORKER_METRICS_ADDR
Addr string `yaml:"addr"`
// EnablePprof exposes Go runtime profiling endpoints at /debug/pprof/.
// Env: SQI_WORKER_METRICS_ENABLE_PPROF
EnablePprof bool `yaml:"enable_pprof"`
}
MetricsConfig controls the local HTTP server for health probes and metrics.
type NATSConfig ¶
type NATSConfig struct {
// URL is the NATS server URL, e.g. "nats://localhost:4222".
// Env: SQI_WORKER_NATS_URL
URL string `yaml:"url"`
// TLSCertFile is the path to the client TLS certificate (PEM).
// Env: SQI_WORKER_NATS_TLS_CERT_FILE
TLSCertFile string `yaml:"tls_cert_file"`
// TLSKeyFile is the path to the client TLS key (PEM).
// Env: SQI_WORKER_NATS_TLS_KEY_FILE
TLSKeyFile string `yaml:"tls_key_file"`
// TLSCAFile is the path to the CA certificate used to verify the NATS
// server certificate (PEM).
// Env: SQI_WORKER_NATS_TLS_CA_FILE
TLSCAFile string `yaml:"tls_ca_file"`
// InsecureSkipVerify disables TLS certificate verification. For
// development environments only.
// Env: SQI_WORKER_NATS_INSECURE_SKIP_VERIFY
InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
// MaxReconnectAttempts is the maximum number of reconnection attempts
// before giving up. -1 means retry indefinitely.
// Env: SQI_WORKER_NATS_MAX_RECONNECT_ATTEMPTS
MaxReconnectAttempts int `yaml:"max_reconnect_attempts"`
// ReconnectWait is the base wait duration between reconnection attempts.
// Actual wait uses exponential backoff with jitter.
// Env: SQI_WORKER_NATS_RECONNECT_WAIT
ReconnectWait time.Duration `yaml:"reconnect_wait"`
}
NATSConfig is the connection configuration for the remote NATS server.
type StagingConfig ¶ added in v0.2.0
type StagingConfig struct {
// ScratchDir is the base directory for per-attempt staged copies.
ScratchDir string `yaml:"scratch_dir"`
// SyncCommand is the command template invoked per path, with {src}, {dest},
// and optional {object_type} placeholders, e.g. "rsync -a {src} {dest}".
SyncCommand string `yaml:"sync_command"`
// Defaults enables the built-in copy + TEMP scratch when staging is
// otherwise unconfigured. Default true; set false to make an unconfigured
// stage_locally job fail hard instead.
// Env: SQI_STAGING_DEFAULTS
Defaults bool `yaml:"defaults"`
}
StagingConfig is the operator-owned configuration for the stage_locally path delivery. sqi never copies bytes itself: it invokes SyncCommand per path.
type ValidationError ¶
ValidationError describes a single configuration problem.
func Validate ¶
func Validate(cfg WorkerConfig) []ValidationError
Validate returns a list of validation errors for cfg. An empty slice means the configuration is valid.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type WorkerConfig ¶
type WorkerConfig struct {
// NATS is the connection configuration for the remote NATS instance
// embedded in sqi-server.
NATS NATSConfig `yaml:"nats"`
// Worker contains identity and runtime behavior settings.
Worker WorkerSettings `yaml:"worker"`
// Log controls structured logging output.
Log LogConfig `yaml:"log"`
// Metrics controls the local HTTP server used for health probes and
// Prometheus metrics.
Metrics MetricsConfig `yaml:"metrics"`
// Discovery controls mDNS-based server auto-discovery.
Discovery DiscoveryConfig `yaml:"discovery"`
// LogStreamer controls the log-chunk publisher that batches task process
// output and streams it to sqi-server via NATS.
LogStreamer LogStreamerConfig `yaml:"log_streamer"`
// Diagnostics controls publishing the worker's own slog output to
// sqi-server for display in the web UI.
Diagnostics DiagnosticsConfig `yaml:"diagnostics"`
// Staging configures local input/output staging for the stage_locally path
// delivery. Both fields must be set for staging to function.
Staging StagingConfig `yaml:"staging"`
// Capabilities configures software capability auto-detection (built-in DCC
// detectors plus custom detectors and a disable list).
Capabilities capabilities.CapabilitiesConfig `yaml:"capabilities"`
// Isolation controls running tasks as a queue-configured OS user
// (protocol.AssignMsg.Isolation). Auth/isolation is opt-in: a worker with
// a zero-value IsolationConfig behaves exactly as before this feature
// existed.
Isolation IsolationConfig `yaml:"isolation"`
// Expr bounds what one assignment may spend evaluating OpenJD EXPR
// expressions on this host. Defaults reproduce the fixed limits every
// release before EXPR sub-project E4d compiled in.
Expr ExprConfig `yaml:"expr"`
}
WorkerConfig is the complete runtime configuration for sqi-worker. Zero values are not valid; use Default or Load to obtain a populated instance.
func Default ¶
func Default() WorkerConfig
Default returns a WorkerConfig populated with built-in defaults.
func Load ¶
func Load(configFile string, flags FlagOverrides) (WorkerConfig, error)
Load returns the effective WorkerConfig by merging layers in override order: built-in defaults → YAML/JSON file → SQI_WORKER_* env vars → CLI flags.
configFile may be empty, in which case Load searches the default paths.
type WorkerSettings ¶
type WorkerSettings struct {
// Name is a human-readable label for this worker shown in the web UI.
// Defaults to the hostname.
// Env: SQI_WORKER_NAME
Name string `yaml:"name"`
// FarmID is the farm this worker belongs to. When set, the worker only
// receives tasks belonging to that farm. When empty (the default), the
// worker is unaffiliated and accepts tasks from any farm — suitable for
// single-farm or development setups.
// Env: SQI_WORKER_FARM_ID
FarmID string `yaml:"farm_id"`
// DataDir is the directory used to persist the worker ID file
// (worker.id) — the worker's stable, server-correlated identity. It is
// NEVER shared with session working directories (see SessionDir) and is
// never widened for run-as-user traversal: it stays private (0700) for
// as long as the worker exists.
// Env: SQI_WORKER_DATA_DIR
DataDir string `yaml:"data_dir"`
// SessionDir is the directory under which session working directories
// (<SessionDir>/<sessionID>/) are created. Deliberately separate from
// DataDir: session scratch is ephemeral and, when isolation is in use,
// must be traversable by whichever run-as-user identity a session
// resolves to, while DataDir holds the persistent worker-id and must stay
// private. Left empty (the default), the effective value is resolved at
// startup (see cmd/sqi-worker's effectiveSessionRoot):
// - running as root: /var/lib/sqi-worker-sessions (a SIBLING of, never
// a descendant of, this package's own data_dir default — see
// cmd/sqi-worker's defaultRootSessionDir doc for why the two must
// never nest; its ancestors, /var and /var/lib, are 0755 on every
// real distribution, so nothing needs to be created or widened
// specifically for this)
// - otherwise: <DataDir>/sessions, the same location used before this
// split existed — real run-as-user isolation cannot function without
// root regardless of directory permissions, so there is nothing to
// protect by moving it.
// Env: SQI_WORKER_SESSION_DIR
SessionDir string `yaml:"session_dir"`
// ComputeLocation is the named location (matching a storage location in
// sqi-server) where this worker's filesystem lives. Used for resolved-mode
// path mapping.
// Env: SQI_WORKER_COMPUTE_LOCATION
ComputeLocation string `yaml:"compute_location"`
// CapabilityTags is a list of arbitrary capability tags merged with
// auto-detected capabilities at registration time, e.g. ["maya-2025",
// "gpu", "highram"].
// Env: SQI_WORKER_CAPABILITY_TAGS (comma-separated)
CapabilityTags []string `yaml:"capability_tags"`
// HeartbeatInterval is how often the worker publishes a heartbeat to the
// server. Should be shorter than the server's heartbeat sweep interval.
// Env: SQI_WORKER_HEARTBEAT_INTERVAL
HeartbeatInterval time.Duration `yaml:"heartbeat_interval"`
// ShutdownGracePeriod is the maximum time the worker waits for in-flight
// tasks to finish before force-killing them on shutdown.
// Env: SQI_WORKER_SHUTDOWN_GRACE_PERIOD
ShutdownGracePeriod time.Duration `yaml:"shutdown_grace_period"`
// AllowRoot permits the worker to run as the root user on Linux/macOS.
// Disabled by default because executing render processes as root is a
// security risk (see docs/worker-configuration.md, "worker.allow_root").
// Env: SQI_WORKER_ALLOW_ROOT
AllowRoot bool `yaml:"allow_root"`
// KeepFailedSessions retains a session's working directory after the
// session ends in failure (task cancellation, non-zero exit code, or
// environment setup error). Useful for post-mortem inspection of partial
// outputs and environment state. Disabled by default to avoid filling the
// data directory on busy workers.
// Env: SQI_WORKER_KEEP_FAILED_SESSIONS
KeepFailedSessions bool `yaml:"keep_failed_sessions"`
// QueueIDs restricts this worker to serving the listed queue IDs. An empty
// list means the worker accepts assignments from all queues via a wildcard
// JetStream consumer. Set this when running a heterogeneous farm where
// some workers specialise in a subset of queues.
// Env: SQI_WORKER_QUEUE_IDS (comma-separated)
QueueIDs []string `yaml:"queue_ids"`
// PullIdleBackoff is the wait duration between pull attempts when the
// work queue is empty. Prevents tight polling on idle queues.
// Resets to zero immediately when a task is received.
// Default: 2s
// Env: SQI_WORKER_PULL_IDLE_BACKOFF
PullIdleBackoff time.Duration `yaml:"pull_idle_backoff"`
// PullNackDelay is the redelivery delay applied to an assignment when
// pre-execution validation fails. The delay gives other workers
// a chance to pick it up before NATS redelivers to this one.
// Default: 5s
// Env: SQI_WORKER_PULL_NACK_DELAY
PullNackDelay time.Duration `yaml:"pull_nack_delay"`
}
WorkerSettings controls the worker's identity and runtime behavior.