Expand description
Session identity on the redb sessions table.
One row per (org, project, label), holding the claude session id
forge spawns or resumes that session under. The label carries the
role: LEAD_LABEL for a project’s lead, the worker’s own label
otherwise, so no separate kind column is needed. The value is stored
as serde-json and the worker-only fields are absent on a lead’s row.
A worker row written by migrate_from_dynamic_workers gets its
spawn args from dynamic_workers, which never stored an id. A worker
that has no row yet therefore starts fresh under a newly minted id; one
that already has a row keeps the occupant that row names.
Re-exports§
use anyhow::Context;🔒use redb::ReadableTable;🔒use redb::TableDefinition;🔒use serde::Deserialize;🔒use serde::Deserialize;🔒use serde::Serialize;🔒use serde::Serialize;🔒use super::Db;🔒use super::dynamic_workers;🔒
Structs§
- Project
Identity - A configured project as the migration needs it: its catalog key, and
the org and name its session rows are keyed by.
dynamic_workersis keyed by the catalog key alone, so the caller supplies the mapping. - RowStart 🔒
- What
WorkerRowIndexreads out of a row’s body. Deserialising into this rather thanSessionRecordis the point: serde skips what it is not asked for, so the charter - kilobytes on a project’s lead row - is never allocated. The identity is not here because it is not in the body: the key carries it, and this reader takes it from there. - Session
Record - One session’s identity, plus the worker fields a re-spawn needs.
session_idis absent on a worker row the sweep creates, becausedynamic_workersnever stored one; every other field is worker-only, so a lead’s row carries none of them. - Sweep
Outcome - What a sweep of
dynamic_workersaccounted for. The retired table is only safe to drop whenSelf::drained, and everything else holds it for a later boot. - Worker
RowIndex - One persisted row, without its body: what a caller needs to decide whether that row’s worker can still start.
Enums§
- Seat
State - What a seat was doing when forge last had a say: whether it is open at all, and whether a turn was in flight. The boot wave reads it to reopen the seats that were open and kick only the ones whose turn was cut off.
Constants§
- LEAD_
LABEL - The label a project’s lead is stored under. A worker stores its own label, so the label alone says which role holds the row.
- SESSIONS 🔒
Functions§
- clear_
session_ id - Drop the id a row pinned, keeping everything else it carries.
- decode 🔒
- delete
- Delete the row at
(org, project, label). Returns whether one existed. This is what stops a despawned worker coming back: the row is the only thing a boot re-spawns from. - get
- The record for
(org, project, label), if the store holds one. - list_
all - Every session row, in key order.
- list_
for_ project - Every row for
(org, project), in label order. What a project’s lead reads to re-spawn its persisted workers. - migrate_
from_ dynamic_ workers - Move any
dynamic_workersrows ontosessions, and take each one out of the retired table as it lands. - put
- Write
record, replacing any prior row for the same identity. - restore_
seat_ state - Put a row’s seat state back to what it held before a refused spawn,
but only while the row still holds
expected- the state that spawn wrote. A newer decision (a close landing mid-spawn) stands: the restore undoes the spawn’s own write, never the reader’s. - seat_
state - The state the row at
(org, project, label)holds, orNonewhen the row is absent or was written before the field existed. - seed_
seat_ state - Seed every row written before
seat_stateexisted withIdle, so the first boot on this build reads an explicit state instead of absence. Returns how many rows it seeded; a second run writes nothing. - set_
seat_ state - Move the row at
(org, project, label)tostate, keeping every other field. - update
- Merge
fieldsonto the row at(org, project, label), leaving an absent field at its stored value. Returns whether a row existed; this never creates one, because the row is what makes a worker re-spawn on the next lead connect. - worker_
row_ index - Every row’s identity plus the fields that say whether its worker can still start, in key order.