flip_api.db.seed.fl_kit_slots

Attributes

_FL_KIT_SLOT_NAMES_PARAMETER

_SLOT_NUMBER_RE

_NON_NUMERIC_SLOT_NUMBER

Functions

_slot_number(→ int)

Extract the trailing integer from a slot name (Trust_0077).

resolve_fl_kit_slot_names(→ list[str])

Resolve the configured FL kit-slot names from their environment's single source.

insert_missing_slots(→ list[str])

Insert a row for each slot name not already in the fl_kit_slot pool.

seed_fl_kit_slots(→ None)

Populate the fl_kit_slot pool from the resolved slot names.

Module Contents

flip_api.db.seed.fl_kit_slots._FL_KIT_SLOT_NAMES_PARAMETER = '/flip/fl_kit_slot_names'
flip_api.db.seed.fl_kit_slots._SLOT_NUMBER_RE
flip_api.db.seed.fl_kit_slots._NON_NUMERIC_SLOT_NUMBER = 10000
flip_api.db.seed.fl_kit_slots._slot_number(slot_name: str) int

Extract the trailing integer from a slot name (Trust_0077).

Slots are conventionally named with a trailing _<N> so the Flower side can pick a per-supernode key with the matching supernode_credentials_<N> suffix. Returns _NON_NUMERIC_SLOT_NUMBER for names without a trailing integer so they sort after all conventional Trust_N slots in the free-slot claim queue.

flip_api.db.seed.fl_kit_slots.resolve_fl_kit_slot_names() list[str]

Resolve the configured FL kit-slot names from their environment’s single source.

In production the source is the /flip/fl_kit_slot_names SSM parameter (a JSON list string, rendered by Terraform from the env file’s FL_KIT_SLOT_NAMES), so the pool can grow via a targeted apply of just that parameter without a task-definition change or restart. In development the source is the FL_KIT_SLOT_NAMES env var (a DevSettings-only field).

Deliberately no prod fallback: a failure to fetch or parse the parameter returns an empty list — the boot seed and the registration reconcile are additive, so existing pool rows and assignments are untouched; the pool simply cannot grow until the parameter is fixed, and nothing stale masks that. The log level splits the two situations: a missing parameter is a not-yet-provisioned source (WARNING); any other AWS error or a malformed value means the source of truth is broken (ERROR).

Note the pre-activation state is ERROR, not WARNING: make apply-fl-kit-slots creates the parameter and grants the task role’s ssm:GetParameter, so an image deployed before that apply gets AccessDeniedException (ERROR) rather than ParameterNotFound — observed on stag 2026-07-14. Either way the pool is intact and the log names the fix.

Returns:

The configured slot names; empty when none are configured or the parameter is unreadable.

Return type:

list[str]

flip_api.db.seed.fl_kit_slots.insert_missing_slots(session: sqlmodel.Session, slot_names: list[str]) list[str]

Insert a row for each slot name not already in the fl_kit_slot pool.

Additive only — never deletes, re-assigns, or un-assigns rows; operators rely on the assignment table to be stable. Does not commit: the caller owns the transaction (boot seeding commits; register_trust’s reconcile shares the registration transaction).

Parameters:
  • session (Session) – The SQLModel session used for reads and inserts.

  • slot_names (list[str]) – The configured slot names to ensure exist.

Returns:

The slot names that were newly inserted.

Return type:

list[str]

flip_api.db.seed.fl_kit_slots.seed_fl_kit_slots(session: sqlmodel.Session) None

Populate the fl_kit_slot pool from the resolved slot names.

Inserts one row per configured slot name if not already present. Never deletes, re-assigns, or un-assigns rows — operators rely on the assignment table to be stable across restarts. register_trust claims a free slot atomically when a trust is registered, so the seed has no slot→trust binding to do.

Parameters:

session (Session) – The SQLModel session used for reads and inserts.