The registry: sessions, numbered events and instruction queues in SQLite #8
Loading…
Reference in a new issue
No description provided.
Delete branch "server-registry"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 implementssession.Serviceandsession.Authorizer.Startand 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.Reportignores host frames at or below the stored number; the agent's first frame makes a starting session running (WaitRunning).Instructionsstreams a session's queue from a number and records a prompt asDeliveredwhen it is handed on.Canceldrops the prompts not yet sent.Waitingrecord (the host's report has no way to say it yet), the HostService handler (waits forsessionauth, PR #3/#4), the Kubernetes Job code, the operations, the loader.Assisted-By: Claude noreply@anthropic.com
Review for spec-bb1.33. I ran
go vetandgo test -race ./internal/session/: green. The ticket's points on this part hold: a nudge is stored beforeNudgereturns and comes out ofInstructionsafter the database is opened again; frames come out ofSubscribein 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.
HostFramehas no time, andappendEventstamps every event with the server's clock at the moment of storing. The host reports each frame with the time it passed (Frame.timeinhost.proto) and holds frames while the server is away, up to 200 to a call:"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
HostFrameand 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.
Authorizecompares the hash and never looks atstate. AfterEndthe token of a pod that is gone goes on openingGcService.Run, which runs the real gc in the city's directory. Refuse a session that isEnded, with a test.3.
Runningcomes one answer early."How gc's operations meet the owner's": a start is reported done after the agent has answered
initializeandsession/new. The first frame from the agent is the answer toinitialize; ifsession/newthen fails,WaitRunninghas already returned and gc is told the session started. Make the sessionRunningon the answer tosession/new.Smaller, in the same push:
Reportaccepts a batch with a hole (host_seq2, 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.CREATE TABLE IF NOT EXISTSwith no version. The file will sit on the city's volume from the first start; setPRAGMA user_versionnow and refuse a file of another version, so that the first change of schema has something to migrate from.Deliveredrecord, since the host attaches again past it.Instructions(after)can mark everything at or belowafteras sent.Noted, not changes: a prompt that
Canceldrops gets no closing record in the stream; andDeliveredhere means handed to the host, which queues it, until the host can report what it did with an instruction (roomcity-5e knows).0ad639859f8b98d89ecf8b98d89ecf668bf942a0