Skip to main content

Module sessions

Module sessions 

Source
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§

ProjectIdentity
A configured project as the migration needs it: its catalog key, and the org and name its session rows are keyed by. dynamic_workers is keyed by the catalog key alone, so the caller supplies the mapping.
RowStart 🔒
What WorkerRowIndex reads out of a row’s body. Deserialising into this rather than SessionRecord is 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.
SessionRecord
One session’s identity, plus the worker fields a re-spawn needs. session_id is absent on a worker row the sweep creates, because dynamic_workers never stored one; every other field is worker-only, so a lead’s row carries none of them.
SweepOutcome
What a sweep of dynamic_workers accounted for. The retired table is only safe to drop when Self::drained, and everything else holds it for a later boot.
WorkerRowIndex
One persisted row, without its body: what a caller needs to decide whether that row’s worker can still start.

Enums§

SeatState
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_workers rows onto sessions, 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, or None when the row is absent or was written before the field existed.
seed_seat_state
Seed every row written before seat_state existed with Idle, 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) to state, keeping every other field.
update
Merge fields onto 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.