The registry: sessions, numbered events and instruction queues in SQLite #8

Merged
mikluko merged 3 commits from server-registry into main 2026-11-16 04:58:54 +00:00
Owner

The registry of spec-bb1.33: sessions, numbered events and the queue of instructions, in one SQLite database (modernc.org/sqlite, pure Go, since the image builds with CGO off). It implements session.Service and session.Authorizer.

  • A session's token is made by Start and kept hashed; a start afresh replaces it, empties the queue and restarts the host's frame count and the instruction numbers. The event numbering goes on.
  • Report ignores host frames at or below the stored number; the agent's first frame makes a starting session running (WaitRunning).
  • Instructions streams a session's queue from a number and records a prompt as Delivered when it is handed on. Cancel drops the prompts not yet sent.
  • Not here: the Waiting record (the host's report has no way to say it yet), the HostService handler (waits for sessionauth, PR #3/#4), the Kubernetes Job code, the operations, the loader.

Assisted-By: Claude noreply@anthropic.com

The registry of spec-bb1.33: sessions, numbered events and the queue of instructions, in one SQLite database (`modernc.org/sqlite`, pure Go, since the image builds with CGO off). It implements `session.Service` and `session.Authorizer`. - A session's token is made by `Start` and kept hashed; a start afresh replaces it, empties the queue and restarts the host's frame count and the instruction numbers. The event numbering goes on. - `Report` ignores host frames at or below the stored number; the agent's first frame makes a starting session running (`WaitRunning`). - `Instructions` streams a session's queue from a number and records a prompt as `Delivered` when it is handed on. `Cancel` drops the prompts not yet sent. - Not here: the `Waiting` record (the host's report has no way to say it yet), the HostService handler (waits for `sessionauth`, PR #3/#4), the Kubernetes Job code, the operations, the loader. Assisted-By: Claude <noreply@anthropic.com>
Keep the sessions, their events and their queues in SQLite
All checks were successful
test / changelog (pull_request) Successful in 4s
image / image (pull_request) Successful in 8s
test / go (pull_request) Successful in 59s
e4ce92bf65
The registry implements session.Service and Authorizer over one SQLite
database (modernc.org/sqlite, pure Go: the image builds with CGO off), so
a queued nudge and the numbered events survive a restart of the server.
The transcripts of "Where transcripts are kept" are these events, in the
same database.

Instructions restart from 1 and the queue is emptied when a session is
started afresh; the event numbering goes on.

Assisted-By: Claude <noreply@anthropic.com>
Pin down an empty Report and what Delivered means
All checks were successful
image / image (pull_request) Successful in 5s
test / changelog (pull_request) Successful in 6s
test / go (pull_request) Successful in 36s
0ad639859f
An empty Report returns the stored host number, which is how a host
restarted in the same pod finds where to number its frames from.

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

Review for spec-bb1.33. I ran go vet and go test -race ./internal/session/: green. The ticket's points on this part hold: a nudge is stored before Nudge returns and comes out of Instructions after the database is opened again; frames come out of Subscribe in the order they were stored; and frames the host sends again after a lost acknowledgement are skipped by their host number, so they take no new number in the events. The token is kept hashed and compared in constant time, and an empty one is refused. Not merged yet; three changes.

1. The frame's own time is dropped.
HostFrame has no time, and appendEvent stamps every event with the server's clock at the moment of storing. The host reports each frame with the time it passed (Frame.time in host.proto) and holds frames while the server is away, up to 200 to a call:

the server is away for ten minutes, the host reports on its return
stored: ten minutes of the session, every frame at the same instant

"Where transcripts are kept" has a transcript hold each message with its time, and this table is where the transcript lands. Carry the time in HostFrame and store it for a frame; the server's clock stays right for prompts and lifecycle, which the server makes.

2. An ended session's token still authorizes.
Authorize compares the hash and never looks at state. After End the token of a pod that is gone goes on opening GcService.Run, which runs the real gc in the city's directory. Refuse a session that is Ended, with a test.

3. Running comes one answer early.
"How gc's operations meet the owner's": a start is reported done after the agent has answered initialize and session/new. The first frame from the agent is the answer to initialize; if session/new then fails, WaitRunning has already returned and gc is told the session started. Make the session Running on the answer to session/new.

Smaller, in the same push:

  • Report accepts a batch with a hole (host_seq 2, then a frame 5) and acknowledges past it, losing 3 and 4 for good. The host never sends one, but the server is where the invariant can be held: refuse a frame that is not the next.
  • The schema is CREATE TABLE IF NOT EXISTS with no version. The file will sit on the city's volume from the first start; set PRAGMA user_version now and refuse a file of another version, so that the first change of schema has something to migrate from.
  • An instruction handed to the host just before the server dies is never marked sent and gets no Delivered record, since the host attaches again past it. Instructions(after) can mark everything at or below after as sent.

Noted, not changes: a prompt that Cancel drops gets no closing record in the stream; and Delivered here means handed to the host, which queues it, until the host can report what it did with an instruction (roomcity-5e knows).

Review for spec-bb1.33. I ran `go vet` and `go test -race ./internal/session/`: green. The ticket's points on this part hold: a nudge is stored before `Nudge` returns and comes out of `Instructions` after the database is opened again; frames come out of `Subscribe` in the order they were stored; and frames the host sends again after a lost acknowledgement are skipped by their host number, so they take no new number in the events. The token is kept hashed and compared in constant time, and an empty one is refused. Not merged yet; three changes. **1. The frame's own time is dropped.** `HostFrame` has no time, and `appendEvent` stamps every event with the server's clock at the moment of storing. The host reports each frame with the time it passed (`Frame.time` in `host.proto`) and holds frames while the server is away, up to 200 to a call: the server is away for ten minutes, the host reports on its return stored: ten minutes of the session, every frame at the same instant "Where transcripts are kept" has a transcript hold each message with its time, and this table is where the transcript lands. Carry the time in `HostFrame` and store it for a frame; the server's clock stays right for prompts and lifecycle, which the server makes. **2. An ended session's token still authorizes.** `Authorize` compares the hash and never looks at `state`. After `End` the token of a pod that is gone goes on opening `GcService.Run`, which runs the real gc in the city's directory. Refuse a session that is `Ended`, with a test. **3. `Running` comes one answer early.** "How gc's operations meet the owner's": a start is reported done after the agent has answered `initialize` and `session/new`. The first frame from the agent is the answer to `initialize`; if `session/new` then fails, `WaitRunning` has already returned and gc is told the session started. Make the session `Running` on the answer to `session/new`. Smaller, in the same push: - `Report` accepts a batch with a hole (`host_seq` 2, then a frame 5) and acknowledges past it, losing 3 and 4 for good. The host never sends one, but the server is where the invariant can be held: refuse a frame that is not the next. - The schema is `CREATE TABLE IF NOT EXISTS` with no version. The file will sit on the city's volume from the first start; set `PRAGMA user_version` now and refuse a file of another version, so that the first change of schema has something to migrate from. - An instruction handed to the host just before the server dies is never marked sent and gets no `Delivered` record, since the host attaches again past it. `Instructions(after)` can mark everything at or below `after` as sent. Noted, not changes: a prompt that `Cancel` drops gets no closing record in the stream; and `Delivered` here means handed to the host, which queues it, until the host can report what it did with an instruction (roomcity-5e knows).
mikluko force-pushed server-registry from 0ad639859f
All checks were successful
image / image (pull_request) Successful in 5s
test / changelog (pull_request) Successful in 6s
test / go (pull_request) Successful in 36s
to 8b98d89ecf
Some checks failed
test / changelog (pull_request) Failing after 4s
image / image (pull_request) Successful in 8s
test / go (pull_request) Successful in 40s
2026-11-16 04:55:54 +00:00
Compare
mikluko force-pushed server-registry from 8b98d89ecf
Some checks failed
test / changelog (pull_request) Failing after 4s
image / image (pull_request) Successful in 8s
test / go (pull_request) Successful in 40s
to 668bf942a0
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 10s
test / go (pull_request) Successful in 56s
2026-11-16 04:56:59 +00:00
Compare
mikluko deleted branch server-registry 2026-11-16 04:58:54 +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!8
No description provided.