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:
2026-04-27 18:00:08 -04:00
parent da3c35c6a4
commit 2cc60bd677
12 changed files with 711 additions and 9 deletions

View File

@@ -152,6 +152,29 @@ async def test_get_synthetic_file_returns_none_when_missing(repo):
assert await repo.get_synthetic_file("does-not-exist") is None
@pytest.mark.asyncio
async def test_realism_config_get_returns_none_when_unset(repo):
assert await repo.get_realism_config("weights") is None
@pytest.mark.asyncio
async def test_realism_config_set_then_get_roundtrips(repo):
await repo.set_realism_config("weights", '{"canary_probability": 0.07}')
row = await repo.get_realism_config("weights")
assert row is not None
assert row["key"] == "weights"
assert row["value"] == '{"canary_probability": 0.07}'
@pytest.mark.asyncio
async def test_realism_config_set_is_upsert(repo):
await repo.set_realism_config("weights", '{"a": 1}')
await repo.set_realism_config("weights", '{"a": 2}')
row = await repo.get_realism_config("weights")
assert row is not None
assert row["value"] == '{"a": 2}'
def test_path_max_length_fits_mysql_utf8mb4_index_limit():
"""The unique (decky_uuid, path) index has to fit MySQL's 3072-byte
utf8mb4 cap: (decky_uuid_len + path_len) * 4 <= 3072. A regression