The registry keeps each start, a shown cursor, and Reset; schema version 2 #64

Merged
mikluko merged 3 commits from server-starts into main 2026-11-16 09:12:58 +00:00
Owner

The registry part of the two owner amendments (spec-bb1.16: one transcript per start; spec-bb1.10/.25: !reset) and roomcity-ee's shown cursor, in the one schema change specs-18 asked for, with the first real migration.

  • Schema 2, migration from 1. user_version 1 databases are migrated at Open, in one transaction: sessions.gc_id and sessions.shown (existing rows at their last event, so nothing shown is shown again), and the new table starts with a row for each Started/StartedAfresh event of the stream, closed by the Stopped after it, as lost when a start follows it, open when it is the last. A database of a later version is refused. Test: a v1 database built by hand with a lost-and-restarted session and a stopped one.
  • starts. Registry.Starts(ctx, name) ([]Start, error), Start{N, Began, Ended, How, Room, GCID, FirstSeq, LastSeq}; StartWith opens the next (the plain Start stays); End closes the open one as stop; a start that finds one open closes it as lost (a pod lost without a stop) with LastSeq the event before its own; SetRoom writes the room of the current start. One Seq per name still runs across the starts. The purge removes a purged session's starts.
  • Reset. On session.Service and Registry: marks the open start, runs gc session reset <gc_id> in the city's directory through a hook the server sets (serve.resetter, with gc's output in the error); a stop or a start that follows closes the start as reset, not stop/lost. A gc that refuses unmarks it. ErrNotRunning for an ended session, ErrNotFound for none, an error saying why for a session whose start gave no GC_SESSION_ID. operate's start passes it. Not verified in the cluster: that gc's session reset ends in the runtime's stop then start (roomcity-ee read gc's source for it, spec-bb1.25).
  • shown, as roomcity-ee asked, with their two refinements. Info.Shown, filled by List, Get, Watch; Service.Shown(ctx, name, seq): advances, never back, ErrNotFound for an unknown name. A start leaves the cursor where it is (new rows start at 0); a change does not bump rev. Prompt and Lifecycle carry Time, as Frame does.
  • Breaks for others, fixed here: session.Service has two methods more (the chat side's fake in chattest has them), and two tests compare events without their time (untimed in the session tests).

Not here: the room and page side (!reset, /-/<name>/<n>, the card) and per-start Purge and Transcript(name, n), which are roomcity-ee's on top of Starts.

Assisted-By: Claude noreply@anthropic.com

The registry part of the two owner amendments (spec-bb1.16: one transcript per start; spec-bb1.10/.25: `!reset`) and roomcity-ee's `shown` cursor, in the one schema change specs-18 asked for, with the first real migration. - **Schema 2, migration from 1.** `user_version` 1 databases are migrated at `Open`, in one transaction: `sessions.gc_id` and `sessions.shown` (existing rows at their last event, so nothing shown is shown again), and the new table `starts` with a row for each Started/StartedAfresh event of the stream, closed by the Stopped after it, as `lost` when a start follows it, open when it is the last. A database of a later version is refused. Test: a v1 database built by hand with a lost-and-restarted session and a stopped one. - **`starts`.** `Registry.Starts(ctx, name) ([]Start, error)`, `Start{N, Began, Ended, How, Room, GCID, FirstSeq, LastSeq}`; `StartWith` opens the next (the plain `Start` stays); `End` closes the open one as `stop`; a start that finds one open closes it as `lost` (a pod lost without a stop) with `LastSeq` the event before its own; `SetRoom` writes the room of the current start. One `Seq` per name still runs across the starts. The purge removes a purged session's starts. - **`Reset`.** On `session.Service` and `Registry`: marks the open start, runs `gc session reset <gc_id>` in the city's directory through a hook the server sets (`serve.resetter`, with gc's output in the error); a stop or a start that follows closes the start as `reset`, not `stop`/`lost`. A gc that refuses unmarks it. `ErrNotRunning` for an ended session, `ErrNotFound` for none, an error saying why for a session whose start gave no `GC_SESSION_ID`. `operate`'s start passes it. Not verified in the cluster: that gc's `session reset` ends in the runtime's `stop` then `start` (roomcity-ee read gc's source for it, spec-bb1.25). - **`shown`, as roomcity-ee asked, with their two refinements.** `Info.Shown`, filled by `List`, `Get`, `Watch`; `Service.Shown(ctx, name, seq)`: advances, never back, `ErrNotFound` for an unknown name. A start leaves the cursor where it is (new rows start at 0); a change does not bump `rev`. `Prompt` and `Lifecycle` carry `Time`, as `Frame` does. - Breaks for others, fixed here: `session.Service` has two methods more (the chat side's fake in `chattest` has them), and two tests compare events without their time (`untimed` in the session tests). Not here: the room and page side (`!reset`, `/-/<name>/<n>`, the card) and per-start `Purge` and `Transcript(name, n)`, which are roomcity-ee's on top of `Starts`. Assisted-By: Claude <noreply@anthropic.com>
Keep each start of a session, its shown cursor, and ask gc to reset it
Some checks failed
test / changelog (pull_request) Failing after 4s
image / image (pull_request) Successful in 15s
test / go (pull_request) Successful in 40s
778949df95
One schema bump, version 2, with a migration of version 1 in one
transaction. starts holds each start of a name (number, times, how it
ended, room, the id of gc's session bead, first and last Seq); the one
numbering of events goes on across them. Reset marks the open start and
runs "gc session reset <bead id>" in the city's directory; the stop and
the start gc then makes end the start as "reset" and open the next. A
start that the next start finds open was lost.

Info.Shown and Service.Shown are the chat side's cursor of what it has
shown: it advances and never goes back, a start leaves it where it is.
Prompt and Lifecycle carry the time they were recorded, as Frame does.

Assisted-By: Claude <noreply@anthropic.com>
mikluko force-pushed server-starts from 778949df95
Some checks failed
test / changelog (pull_request) Failing after 4s
image / image (pull_request) Successful in 15s
test / go (pull_request) Successful in 40s
to 2940508331
Some checks failed
image / image (pull_request) Successful in 16s
test / changelog (pull_request) Failing after 4s
test / go (pull_request) Failing after 34s
2026-11-16 08:52:51 +00:00
Compare
mikluko force-pushed server-starts from 2940508331
Some checks failed
image / image (pull_request) Successful in 16s
test / changelog (pull_request) Failing after 4s
test / go (pull_request) Failing after 34s
to 11a3e9d078
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 16s
test / go (pull_request) Successful in 39s
2026-11-16 09:02:38 +00:00
Compare
Copy the database as it was before migrating it
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 15s
test / go (pull_request) Successful in 41s
e1959d6453
A server of the earlier version refuses a migrated database, so the way
back must be a copy the server made itself, not a step of a roll-out. Before
the migration's transaction Open writes SQLite's own consistent copy
(VACUUM INTO, to a temporary name, renamed when whole) beside the database
under a name that carries the old version: roomcity.v1.db. It logs the path
and keeps the copy until an operator removes it. It does not overwrite a
copy that exists: it refuses to migrate and says so. A migration that
fails removes the copy it made, so that the next try is not blocked by it.
The README says what the copy is and how a rollback uses it.

Assisted-By: Claude <noreply@anthropic.com>
Author
Owner

Read at e1959d6 (11a3e9d and the copy on top). The suite is green here under -race, internal/session and internal/serve ten times with GOMAXPROCS=1.

I built a schema-1 database with the v0.5.0 registry in the city's shape and opened it with this code: host with one start never stopped and frames after it; guest with twelve starts each ended at once, then one that ran and was stopped, one that ran and was followed by a start with no stop, and the last open; a task that ended. What came out:

host      1 start, open, shown=4 (its last event)
guest     15 starts: 1..13 "stop", 14 "lost" (last_seq the event before 15's), 15 open; shown=34
worker-1  1 start, "stop"
events    40 before and after
a `starts` table of another shape put in its way: the open fails, user_version stays 1, no column added

So the migration does what it says on that shape, and one that fails leaves the database as it was. Four changes before it merges, and they are about what the new table says and about the city having nobody to lend a hand.

  1. The copy must not be able to stop the server from starting. A server killed between the copy and the migration's commit leaves the database at version 1 and the copy in place; the next start finds the copy, refuses to migrate and exits, and goes on doing so until someone removes a file from the city's volume, which nobody can do today. The same after a rollback that copied the copy back. Give the copy a name that cannot be taken already (the time in it, beside the version), never refuse on one that exists, and say in the README that copies are kept until removed. The copy before the migration and its removal when the migration fails stay as they are.

  2. A start that never got its agent is closed "stop". End has three callers: gc's stop, the cleanup of a start that failed (operate.go, fail), and kill-object on a box gc found dead (observe.go, remove). All three write "stop", so guest's twelve failed starts read as stops that someone asked for, and "lost" is left to the one case of a start that finds the earlier one open, which gc's own stop after a failed or cut-off start usually prevents. Let the three callers say which they are: "stop", "failed" for the start's own cleanup, "lost" for the box found dead as for the start found open. how is text, so no column changes; the migrated starts cannot be told apart and stay "stop", which the README's section may say.

  3. The migration can give the running sessions their gc id. Reset of a session that was running when the database was migrated answers "gc did not tell the id of its session bead at the start", for host and guest in the city until each is started again, and the reason it gives is not the true one. The id is in the database: the start kept GC_SESSION_ID among the session's marks (identityKeys). Set sessions.gc_id and the open start's gc_id from that mark in the migration, with it in the migration's test; and word the error for a start that has none as what the server lacks, not as what gc did not do.

  4. Info.Shown's doc says "a start begins it at the Seq before the event that opens the start"; the code, openStart's own comment and TestShownAdvancesNeverBackAndAStartLeavesItWhereItIs say a start leaves it where it is. Make the doc say what the code does.

For the README, no change to the code asked: a Reset that gc accepts leaves the open start marked, and if gc then does not stop the session (its reference names a case where reset rolls a session back instead of restarting it), the next stop of that start, whoever asks for it, is recorded "reset".

On the coordinator's other points. The cursor under two writers: UPDATE ... SET shown = ? WHERE name = ? AND shown < ? is one statement, so it cannot go back whichever lands first. A start cut off by a server roll: the registry has its start and no end; gc's stop after the failed start then closes it "stop", or, if gc starts again first, the next start closes it "lost"; with change 2 the first of these still reads "stop", since by then nothing tells the server why gc stops it.

Read at e1959d6 (11a3e9d and the copy on top). The suite is green here under `-race`, `internal/session` and `internal/serve` ten times with `GOMAXPROCS=1`. I built a schema-1 database with the v0.5.0 registry in the city's shape and opened it with this code: `host` with one start never stopped and frames after it; `guest` with twelve starts each ended at once, then one that ran and was stopped, one that ran and was followed by a start with no stop, and the last open; a task that ended. What came out: host 1 start, open, shown=4 (its last event) guest 15 starts: 1..13 "stop", 14 "lost" (last_seq the event before 15's), 15 open; shown=34 worker-1 1 start, "stop" events 40 before and after a `starts` table of another shape put in its way: the open fails, user_version stays 1, no column added So the migration does what it says on that shape, and one that fails leaves the database as it was. Four changes before it merges, and they are about what the new table says and about the city having nobody to lend a hand. 1. The copy must not be able to stop the server from starting. A server killed between the copy and the migration's commit leaves the database at version 1 and the copy in place; the next start finds the copy, refuses to migrate and exits, and goes on doing so until someone removes a file from the city's volume, which nobody can do today. The same after a rollback that copied the copy back. Give the copy a name that cannot be taken already (the time in it, beside the version), never refuse on one that exists, and say in the README that copies are kept until removed. The copy before the migration and its removal when the migration fails stay as they are. 2. A start that never got its agent is closed "stop". `End` has three callers: gc's `stop`, the cleanup of a `start` that failed (operate.go, `fail`), and `kill-object` on a box gc found dead (observe.go, `remove`). All three write "stop", so guest's twelve failed starts read as stops that someone asked for, and "lost" is left to the one case of a start that finds the earlier one open, which gc's own stop after a failed or cut-off start usually prevents. Let the three callers say which they are: "stop", "failed" for the start's own cleanup, "lost" for the box found dead as for the start found open. `how` is text, so no column changes; the migrated starts cannot be told apart and stay "stop", which the README's section may say. 3. The migration can give the running sessions their gc id. `Reset` of a session that was running when the database was migrated answers "gc did not tell the id of its session bead at the start", for `host` and `guest` in the city until each is started again, and the reason it gives is not the true one. The id is in the database: the start kept `GC_SESSION_ID` among the session's marks (`identityKeys`). Set `sessions.gc_id` and the open start's `gc_id` from that mark in the migration, with it in the migration's test; and word the error for a start that has none as what the server lacks, not as what gc did not do. 4. `Info.Shown`'s doc says "a start begins it at the Seq before the event that opens the start"; the code, `openStart`'s own comment and `TestShownAdvancesNeverBackAndAStartLeavesItWhereItIs` say a start leaves it where it is. Make the doc say what the code does. For the README, no change to the code asked: a `Reset` that gc accepts leaves the open start marked, and if gc then does not stop the session (its reference names a case where reset rolls a session back instead of restarting it), the next stop of that start, whoever asks for it, is recorded "reset". On the coordinator's other points. The cursor under two writers: `UPDATE ... SET shown = ? WHERE name = ? AND shown < ?` is one statement, so it cannot go back whichever lands first. A start cut off by a server roll: the registry has its start and no end; gc's `stop` after the failed `start` then closes it "stop", or, if gc starts again first, the next start closes it "lost"; with change 2 the first of these still reads "stop", since by then nothing tells the server why gc stops it.
Answer the review of the migration
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 16s
test / go (pull_request) Successful in 42s
063f74b1a2
The copy of the database is named with the time as well as the version,
takes a number when the second is taken, and is never the reason the
server will not start: a server killed between the copy and the commit
leaves version 1 and a copy, and the next start copies again.

The callers say how a start ended: EndAs with HowStop, HowFailed (operate's
failed start) or HowLost (a box found dead by kill-object); End is a stop.
A start that Reset marked is a reset when it is stopped or lost.

The migration takes gc's session id of a running session from its
GC_SESSION_ID mark, so that Reset does not refuse the sessions running when
the server is upgraded; for a start that has none the error says what the
server lacks. Info.Shown's doc says a start leaves the cursor.

Assisted-By: Claude <noreply@anthropic.com>
mikluko deleted branch server-starts 2026-11-16 09:12:58 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/roomcity!64
No description provided.