Replace etcd-backed `known_slot_types` queries with DB-backed equivalent
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 368
Description
Background
Today every consumer of the system-wide "known slot types" map calls `legacy_etcd_config_loader.get_resource_slots()`, which returns `INTRINSIC_SLOTS = {cpu, mem}` merged with whatever is configured under etcd `config/resource_slots`. The same information is already represented in the database via the `resource_slot_types` table (and the registered slot types each agent serves through `agent_resources`), so the etcd path is redundant.
A first version of a DB-backed helper `ScheduleDBSource._fetch_system_wide_slot_inventory()` was prototyped during BA-5967 (the agent_resources joined with agents (status != TERMINATED) and resource_slot_types projection). It was reverted from the BA-5967 PR so the broader migration can be coordinated end-to-end under this single ticket.
Current etcd call sites
- SchedulingController.validate_session_spec — sokovan/scheduling_controller/scheduling_controller.py:374
- SchedulerRepository._get_known_slot_types — repositories/scheduler/repository.py:215
- AgentRegistry (legacy registry.py) — registry.py:491, 1269, 1297, 1325, 1353
Goal
1. Land a public DB-backed equivalent for the system-wide slot inventory (likely on `SchedulerRepository`, e.g. `fetch_system_wide_slot_inventory()`), backed by a `db_source` helper.
2. Replace every `legacy_etcd_config_loader.get_resource_slots()` call site listed above with the new repository method.
3. Re-add the no-RG fallback in `ScheduleDBSource.fetch_session_spec_contexts` so the validator chain still has a slot-type registry to consult when a draft omits `resource_group_name` (the originally-prototyped `else` branch).
4. Decide on the semantic divergence: the etcd loader unconditionally merges `INTRINSIC_SLOTS = {cpu, mem}`, whereas an agent-derived inventory only contains slots actually registered by some non-TERMINATED agent. In practice every cluster has at least one agent serving cpu/mem, but the new path should either guarantee the intrinsic set or document the divergence explicitly.
Open Questions
- Inventory source: stay with `agents joined agent_resources joined resource_slot_types` (active inventory), switch to `resource_slot_types` table directly (pure registry, agent-independent), or union both?
- DI plumbing for `registry.py`: AgentRegistry currently does not hold SchedulerRepository — adding the dependency vs reading directly from the DB needs to be decided.
- Should the etcd loader's `get_resource_slots` itself be removed, or kept as a thin wrapper for non-scheduler use cases?
Out of Scope
BA-5967 itself stays scoped to the per-RG inventory in the enqueue draft path. Everything related to the system-wide registry — including the `_fetch_system_wide_slot_inventory` helper, its public exposure, and the no-RG fallback — is owned by this ticket.
Acceptance
- `legacy_etcd_config_loader.get_resource_slots()` has no remaining callers under `manager/sokovan/`, `manager/repositories/scheduler/`, and `manager/registry.py`.
- Sessions enqueued without an explicit resource group reach the validator chain with a non-empty `known_slot_types` map.
- `pants lint`, `check`, `test` pass on changed files.
- Behavioral parity (or documented divergence) for the intrinsic cpu/mem slots.
JIRA Issue: BA-5984
Contributor guide
Assessment
This issue has not been assessed yet.