Persistent state schema migration requirements — the one schema, one migration ladder, and the fail-fast host-map membership rule. Use when changing anything that is persisted.
81 stars
0 votes
0 copies
4 views
Added November 9, 2026
databasesgo
Works with
terminal
Security analysis
A100/100
Scanned December 1, 2026
$npx -y skills add juspay/kolu --skill state --agent claude-code
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of State?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/juspay-state)
---
name: state
description: >-
Persistent state schema migration requirements — the one schema, one migration ladder, and the fail-fast host-map membership rule. Use when changing anything that is persisted.
---
## Persistent State (conf)
State is stored via `conf` in `packages/server/src/state.ts`, which opens the store and walks the ladder; the on-disk shape (`PersistedStateSchema`, exported only to its two siblings) lives in `packages/server/src/stateShape.ts` and the migration ladder in `packages/server/src/stateLadder.ts`. Domain modules (`preferences.ts`, `hostPersistence.ts`) read and write their own keys against the shared `store`.
When changing what is persisted (any of the per-domain schemas — `PreferencesSchema` in `packages/common/src/surface.ts`, `PersistedHostsSchema` in `packages/common/src/hostKey.ts`), **you must add a migration** in `stateLadder.ts`'s `CONF_MIGRATIONS` table and bump `SCHEMA_VERSION` (`stateShape.ts`). Without a migration, existing users' state files silently lose or misinterpret data on schema changes.
The disk shape is one schema, one migration ladder, one source of truth. `PersistedStateSchema` is exported only to `state.ts` and `stateLadder.ts`; every other consumer goes through the domain accessors (`getPreferences()`, `getPersistedHosts()`).
**DEPLOYED IS RELEASED — the rule that says when a rung is frozen.** A branch a person has deployed has RELEASED its saved shape onto that person's disk: their `config.json` now carries the ladder number that branch was holding, and conf never runs a rung at or below a file's own number again. So from the FIRST DEPLOY on — the first colleague running the branch, the first time you point your own daemon at your real state root — every change to a persisted shape is a NEW rung with a NEW number, and **a rung that has already run on somebody's store is never edited, never renumbered and never squashed before merge.** The question to ask before touching a rung is not "has this merged?" but "could a store written by an earlier commit of this branch exist?" — and once the answer is yes, that rung's number and body are history, not drafts.
This RETIRES the "renumber until release" licence #2364 took (the story is told in the comment on `stateLadder.ts`'s 1.49.0 rung, which walked one rung's number up through 1.46 → 1.49 as the shape moved under it). That licence read "release" as "merge", and that reading is wrong for a branch being deployed. #2376 is what it cost: commit `910515439` moved a member's watch bookkeeping out of `works[].members[].watch` into the top-level `members` record and gave the member `worktree`, with `SCHEMA_VERSION` still reading 1.50.0 — but a person was already running an earlier commit of the branch, so their store sat at 1.50.0 in the OLD shape, no rung ran, and their Conductor refused to load (`Missing key at [0]["members"][0]["worktree"]`). The repair was a rung written afterwards (1.52.0) and proven against a scrubbed copy of their real file (`packages/server/src/fixtures/deployed-1.50.0-old-members.json`).
**Not every shape change needs a rung — but deciding takes the same audit.** A change a reader accepts unaided covers itself: a literal union GROWING a member (an old file names none of the new ones), and a field with a decoding default (`Schema.withDecodingDefaultKey`, as `Decision.file` and `PrInfo.headSha` carry) which an old file simply omits. A change a reader refuses needs a rung: a required new field, a removed field, a renamed key, changed nesting. Either way the audit is per COMMIT, not per PR — list every commit of the branch that touched a saved shape and say, for each, which rung or which decoding default lets head read what that commit wrote.
**The works ride it too — and the `members` key beside them.** `works` is the `PersistedStateSchema` key holding every piece of work kolu stores (`kolu-work`'s `Work`, unadorned — `kolu-conductor`'s `PersistedWorksSchema`), and `members` is what the watch knows about each MEMBER TERMINAL, keyed by fleet ref (`PersistedMembersSchema`: the name kolu last saw, the agent in it, the level the conversation was told about, how it joined, whether it has been spoken to, whether a command ran). Two keys because they are two things on two clocks — a work is what the Conductor stated and the human decided, a member entry moves every time a host is read — and they are restored TOGETHER (works without their members come back as terminals nobody has read, which rings the conversation about everything again). It is real user data: a work carries the human's decisions, its timeline and the files kolu kept when it ended, and it outlives the conversation that opened it. Same schema, same ladder, same fail-fast as `hosts`. Changing its shape takes a rung and a `SCHEMA_VERSION` bump like anything else.
**One file this store does not own — and it still rides this ladder.** The conductor's transcript rows live in `<KOLU_STATE_DIR>/conductor/transcript.json`, not in `config.json`: they were ~90% of that file's bytes and `conf` rewrites the whole file on every `set`, so a keystroke re-serialized the fleet and the host map with it. The file is `{"version": "<ladder version>", "rows": [...]}`, written atomically at mode 0600 by `packages/server/src/conductor/transcriptFile.ts`.
It gets NO ladder of its own. The rule, in one sentence: **a change to the row shape is a rung in `stateLadder.ts` that rewrites that file, and `TRANSCRIPT_FILE_VERSION` (exported from `stateShape.ts`) moves to that rung's number.** A file stamped with anything else is refused BY NAME on read — never re-shaped on the fly, never read as a guess. The 1.50.0 rung is the worked example: it moved `conductor.rows` out of the store into the file and deleted the key. A rung that stamps a file keeps its own frozen copy of the number it stamped (1.53.0's `TRANSCRIPT_VERSION_1_53_0`), so the live constant moving never changes what a frozen rung writes.
**What the backup ring covers: `config.json`, and nothing else.** The ring (`stateBackups.ts`, `openStateBackupRing` in `state.ts`) snapshots that one file's bytes, so everything in `PersistedStateSchema` — `preferences`, `viewerMode`, `hosts`, `works`, `members`, `memory`, `workCodeViews` — is in a backup and has a restore path. Two neighbours under the same state root are OUTSIDE it, deliberately:
- `conductor/transcript.json` — most of the conversation's bytes, moving on every keystroke. Ringing it would churn the ring for a record whose other half (the agent's own session store) kolu does not back up at all; restoring kolu's rows or session id alone would show a conversation the agent does not remember.
- `works/<work>/…` — the files kolu copied out of a worktree when a work ended. Copies of worktree files, not state. A restored finished work whose kept files were swept since reads them as gone, plainly.
The `conductor` KEY (session id, model) is in the snapshot but has no restore path, for the first reason above. `works`, `members` and `workCodeViews` do have one: `restoreWorks(works, members, workCodeViews)` on the live conductor host, which replaces all three wholesale, drops the asks nobody can answer and the views whose work is not in the snapshot, re-seeds what it knows about each restored member, republishes and re-scopes the watch. `memory` has its own, `restoreMemory(memory)`. The restore dialog says what is covered and what is not — keep those three in step.
**Host-map membership rides this store too — it is not a special case.** The fleet you add via the selector strip persists as the `hosts` field of `PersistedStateSchema`, owned by `hostPersistence.ts` (its `getPersistedHosts()` reader + `savePoolMembership()` persist-hook shaper) and carried by the SAME schema + migration ladder as every other domain. It IS real user data (unlike `preferences`, a silent reset would eat the fleet), so it must never be silently emptied — and `conf` already guarantees that: a corrupt/unparseable store **THROWS on read** (`clearInvalidConfig` is false, conf 15's default), it does NOT reset to defaults. That fail-fast is exactly why `hosts` belongs in this store rather than a hand-rolled file. An invalid-but-parseable value (a hand-edited `local`, a duplicate) additionally fails loud where it's read — `getPersistedHosts` re-validates through `PersistedHostsSchema` (in `kolu-common/hostKey`) and throws, never silently normalizing. Changing the `hosts` shape takes a migration + `SCHEMA_VERSION` bump like any other domain.