feat(realism): operator-tunable planner weights via realism_config
New realism_config table (uuid PK + unique key) + two repo methods (get/set) backs an admin-only GET/PUT /api/v1/realism/config surface. The planner now exposes apply_payload(payload) / current_payload() / reset_to_defaults() and reads its weights through mutable module globals; pick() resolves the live values each call. Validation catches negative weights, zero totals, out-of-range canary_probability, unknown content_class names, and silently drops cross-list entries (canary class on the user list, etc). The orchestrator worker calls _refresh_realism_config(repo) on startup and every 5 ticks (~5min at 60s interval). Operator changes land within one refresh window with no bus signal — the simpler path for a knob whose latency tolerance is minutes.
This commit is contained in:
@@ -78,6 +78,7 @@ from .orchestrator import (
|
||||
OrchestratorEventsResponse,
|
||||
)
|
||||
from .realism import (
|
||||
RealismConfig,
|
||||
SyntheticFile,
|
||||
SyntheticFilesResponse,
|
||||
)
|
||||
@@ -231,6 +232,7 @@ __all__ = [
|
||||
"OrchestratorEvent",
|
||||
"OrchestratorEventsResponse",
|
||||
# realism
|
||||
"RealismConfig",
|
||||
"SyntheticFile",
|
||||
"SyntheticFilesResponse",
|
||||
# logs
|
||||
|
||||
@@ -83,3 +83,25 @@ class SyntheticFilesResponse(BaseModel):
|
||||
limit: int
|
||||
offset: int
|
||||
data: List[dict[str, Any]]
|
||||
|
||||
|
||||
class RealismConfig(SQLModel, table=True):
|
||||
"""Operator-tunable realism knobs.
|
||||
|
||||
Single-row-per-key schema: each row carries one piece of operator
|
||||
config (today: ``key="weights"`` → JSON encoding the planner's
|
||||
user/system/canary weights and canary probability). The planner
|
||||
reads in-memory module globals; the orchestrator worker refreshes
|
||||
those globals from this table on a periodic tick.
|
||||
|
||||
UUID PK + unique key per ``feedback_uuid_over_natural_keys.md``.
|
||||
"""
|
||||
__tablename__ = "realism_config"
|
||||
uuid: str = Field(default_factory=lambda: str(uuid4()), primary_key=True)
|
||||
key: str = Field(max_length=64, unique=True, index=True)
|
||||
value: str = Field(
|
||||
sa_column=Column("value", Text, nullable=False, default="{}"),
|
||||
)
|
||||
updated_at: datetime = Field(
|
||||
default_factory=lambda: datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user