Runtime Policies and Errors¶
Configuration¶
config ¶
Typed settings and deterministic configuration resolution.
CachePolicy ¶
Bases: str, Enum
Allowed cache read and write behavior.
Settings
dataclass
¶
Settings(home: Path, db_path: Path, cache_dir: Path, artifact_dir: Path, max_trials: int = 25, concurrency: int = 4, sample_concurrency: int = 8, seed: int = 0, max_retries: int = 2, sample_timeout_seconds: float = 60.0, trial_timeout_seconds: float = 300.0, cache_policy: CachePolicy = READ_WRITE)
Resolved core settings with no provider credentials.
cache_policy
class-attribute
instance-attribute
¶
cache_policy: CachePolicy = CachePolicy.READ_WRITE
resolve
classmethod
¶
resolve(*, overrides: Mapping[str, Any] | None = None, config_path: str | Path | None = None, environ: Mapping[str, str] | None = None) -> Settings
Resolve defaults, selected TOML, known environment variables, and overrides.
Source code in src/tunarag/config.py
as_dict ¶
Return a serializable settings view containing no secrets.
Source code in src/tunarag/config.py
Retry policy¶
retry ¶
Deterministic retry and timeout policy.
RetryPolicy
dataclass
¶
RetryPolicy(max_retries: int = 2, sample_timeout_seconds: float | None = 60.0, trial_timeout_seconds: float | None = 300.0, base_delay_seconds: float = 0.5, max_delay_seconds: float = 30.0)
Bound retries, exponential backoff, and execution timeouts.
sample_timeout_seconds
class-attribute
instance-attribute
¶
trial_timeout_seconds
class-attribute
instance-attribute
¶
lease_seconds
property
¶
Return a recovery lease longer than the configured trial timeout.
delay_before_retry ¶
Return deterministic capped exponential backoff.
Source code in src/tunarag/retry.py
is_retryable ¶
Classify known transient failures without parsing messages.
Source code in src/tunarag/retry.py
Stopping rules¶
stopping ¶
Composable stop conditions for study execution.
StopContext
dataclass
¶
StopContext(completed_trials: int, exact_cost: float = 0.0, estimated_cost: float = 0.0, elapsed_seconds: float = 0.0, successful_trials: int = 0, failed_trials: int = 0, objective_scores: tuple[float | None, ...] = ())
Current study totals supplied to stop conditions.
objective_scores
class-attribute
instance-attribute
¶
StopCondition ¶
Bases: Protocol
Return whether execution should stop for the current context.
MaxTrials
dataclass
¶
Stop after a maximum number of completed trials.
should_stop ¶
should_stop(context: StopContext) -> bool
CostBudget
dataclass
¶
Stop when exact cost, or exact plus estimated cost, reaches a budget.
should_stop ¶
should_stop(context: StopContext) -> bool
TimeBudget
dataclass
¶
Stop when elapsed wall-clock execution reaches a limit.
should_stop ¶
should_stop(context: StopContext) -> bool
TargetScore
dataclass
¶
Stop when any successful objective reaches a benefit-oriented target.
should_stop ¶
should_stop(context: StopContext) -> bool
MaxFailures
dataclass
¶
Stop after a total or consecutive number of failed trials.
NoImprovement
dataclass
¶
Stop after completed trials fail to improve the best objective.
should_stop ¶
should_stop(context: StopContext) -> bool
Source code in src/tunarag/stopping.py
Errors¶
errors ¶
Structured public errors with secret-safe diagnostic details.
ErrorCode ¶
Bases: str, Enum
Stable machine-readable error identifiers.
OPTIONAL_DEPENDENCY
class-attribute
instance-attribute
¶
TunaRAGError ¶
TunaRAGError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: Exception
Base class for public package errors.
Source code in src/tunarag/errors.py
as_dict ¶
Return a JSON-compatible diagnostic representation.
Source code in src/tunarag/errors.py
ConfigurationError ¶
ConfigurationError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: TunaRAGError
Configuration could not be parsed or validated.
Source code in src/tunarag/errors.py
SearchSpaceError ¶
SearchSpaceError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: TunaRAGError
A search-space definition or candidate is invalid.
Source code in src/tunarag/errors.py
DatasetError ¶
Bases: TunaRAGError
An evaluation dataset could not be loaded or validated.
Source code in src/tunarag/errors.py
AdapterError ¶
AdapterError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: TunaRAGError
The user-owned RAG adapter failed.
Source code in src/tunarag/errors.py
EvaluationError ¶
EvaluationError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: TunaRAGError
An evaluator failed or returned invalid observations.
Source code in src/tunarag/errors.py
StoreError ¶
StoreError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: TunaRAGError
Durable state could not be read or written.
Source code in src/tunarag/errors.py
ResumeError ¶
ResumeError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: TunaRAGError
A study cannot resume under the supplied semantics.
Source code in src/tunarag/errors.py
BudgetError ¶
BudgetError(message: str, *, stage: str | None = None, retryable: bool = False, details: Mapping[str, Any] | None = None)
Bases: TunaRAGError
A configured scheduling budget has been exhausted.
Source code in src/tunarag/errors.py
MissingOptionalDependencyError ¶
Bases: TunaRAGError
A requested integration extra is not installed.
Source code in src/tunarag/errors.py
SyncInAsyncContextError ¶
Bases: TunaRAGError
A synchronous entry point was called from an active event loop.
Source code in src/tunarag/errors.py
redact ¶
Return a recursively redacted, JSON-compatible diagnostic value.