Repository navigation
sminos: the operator writer waits for its upstream's head on a new enrolment (#147) - #425
Conversation
…rolment A machine enrolled under a name its upstream already holds history for (a VM recreated under its old name, `hub enroll --replace`, the endpoint's welcome at a cutover or a rename) forked its own `<name>/human`. An append made before the first `have` and the backlog took seqs from 1 that the upstream held. Those sat at or below the uplink's `sent`, so they were never uploaded, and the machine's log diverged from the hub's. RL10 reaches the same window: the endpoint refuses an own-writer event it never signed and sends its position down as `spent`, around the local event. `hub enroll` and a welcome that cuts over, renames or re-enrols now write daemon/heads.json, naming the enrolment. While that file names the enrolment now, an append to the operator writer in a project of the upstream waits in projects/<id>/queued/ (sminos.waits_for_head, decided under the writer file's locks). The verbs say it waits. Once a `have` has named the head and the log has reached it (the hub's backlog imported on DX2, the positions the endpoint refused spent on RL10), HubLog.release_heads marks the writer known for the enrolment in the project's heads.json. It then appends what waited above the head, in order and with the ts it was said at, and the next upload carries it. A release cut short after its append is finished without a second copy. `daemon owed` counts what waits as `queued`. A machine enrolled before this change has no mark, and nothing of it waits. The fix queues instead of renumbering: a position, once taken, is keyed on by the delivery records, the receipts, RL10's words asks and the delivery outcomes. The queue keeps an event out of the log until it can take a seq that is safe. Tests: test_heads.py (new; DX2's import, RL10's spent positions, the marks of enrol, cutover and rename, owed, the CLI) and test-hub.sh (the enrol's mark). sminos 1.27.2. Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…what waited Review found two gaps. The mark was written after the identity (a welcome) or the credential (`hub enroll`) it names. An appender reading in between saw the new enrolment unmarked and took its seq at once. A mark that failed to write left the cutover done and unmarked, and the next identical welcome skipped the mark for good. Both now write the mark first: an appender that reads the enrolment reads its mark, and a failed mark leaves the identity unwritten for the next welcome to write both. A welcome that renamed the machine while an append waited left that append queued under a former name's writer, which no upload takes. The release under the name now also takes the queues of this machine's operator writer under its former names (never sequenced, so never seen by anyone) and appends them under the name now, in ts order. test_heads.py: the welcome's write order, a failed mark retried by the next welcome, and an append that waited across a rename. All three fail on the previous commit. Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…rain under their own locks The second review found four gaps. - daemon/heads.json held one mark, so publishing a new enrolment unmarked the one still current: an append as it, while it waited, took its seq. The file now keeps the enrolments marked (the last eight), and a new one is added beside the one it replaces. - A release drained a former name's queue under the current writer's lock alone, so an appender still running as the former name could queue between the read and the removal and lose its event. Each queue is now drained under its own writer's locks too. - A queue a cut-short release left behind was deduplicated only against the current writer's log, so after a rename its events were appended again. It is now deduplicated against the log of each writer it drains as well. - `_queue` did not end a fragment an interrupted write had left, so the next queued event joined it and was dropped as unreadable. It now ends the fragment, as `_append` does. test_heads.py: one test each; all four fail on the previous commit. Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
… still found The third review found two gaps. - A `hub enroll` publishing another enrolment under this name while a release ran made the release's own append queue its events again, and the release then removed that queue: the events were lost. The release now appends whatever the enrolment says meanwhile (`_append(..., released=True)`), since it has found the writer's head reached. - Once the enrolment's rule said nothing waits, the uplink stopped looking for queues on that stream, so a command that began before a rename and queued under the former name afterwards stayed stranded until a reconnect. It now caches only the rule's answer and still looks for a queue at each `have`, import and spent position. test-org.sh enrols and has the operator `say` in a hub project with no uplink running. It now asserts that the say waits, releases it as the handshake would, and then reads it with `chat`. test_heads.py: one test each; both fail on the previous commit. Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8ad43c127d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if writer not in (known.get("known") or []): | ||
| known["known"] = sorted(set(known.get("known") or []) | {writer}) | ||
| write_json(project_path(project, HEADS_FILE), known) |
There was a problem hiding this comment.
Mark the writer known only after draining its queue
If the release is interrupted or _append raises after this write but before recording the queued events, heads.json permanently stops subsequent commands from waiting even though the queue remains undrained. A later command therefore takes an earlier sequence number than the messages already waiting: queuing first, failing the release's _append, appending second, and processing another have produces [(1, 'second'), (2, 'first')]. This reverses operator messages in the uploaded and delivered log. Publish the known marker only after the queued append succeeds, while still holding the writer lock, so an interrupted release keeps later appends queued.
Useful? React with 👍 / 👎.
The fourth review: since the last commit keeps looking for queues, an old DX2 uplink that outlived `hub enroll --replace --name <new>` until its supervisor restarted it could drain the new name's queue into its own, former name's writer, which the new uplink never uploads. A release now runs only while the machine is still named as the stream is. test_heads.py: a test that fails on the previous commit. Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
What
A machine enrolled under a name its upstream already holds history for can no longer fork its own operator writer,
<name>/human. Examples: a devcloud VM recreated under its old name,hub enroll --replace, or the endpoint's welcome at a cutover or rename. Its session writers are new UUIDs and never collide. But an append to<name>/humanmade before the firsthaveand the backlog took seqs from 1 that the upstream already held. Those seqs sit at or below the uplink'ssent, so they were never uploaded, and the machine's log silently forked from the hub's.From such an enrolment on, an append to that writer in a project of the upstream waits until the uplink has seen the upstream's head for it and the log has reached that head. It is then appended above the head, in order, with the ts it was said at, and is receipted, uploaded and delivered.
Queue, not renumber
The decision is on the merits:
Renumbering an event after it lands would move a position other parts of the machine already key on:
words?asks and verdicts;Each of these would need a migration under the writer's lock. A position, once taken, has to stay its event's.
The queue keeps the event out of the log until it can take a safe seq, so nothing ever keys on a wrong position. Its cost is the one the ticket names: an operator's
say,sendor line verb on a freshly enrolled machine waits until the hub (or the endpoint) answers. Within a running daemon that is the uplink's firsthavefor the project, a few seconds.The queue is limited to marked enrolments.
hub enrolland a welcome that cuts over, renames or re-enrols writedaemon/heads.json, naming the enrolment's name andenrolled. A machine enrolled before this change has no mark, and nothing of it waits.How
sminos.waits_for_head(project, writer)is true when four things hold: the writer is this machine's operator writer; the project is a hub project of the enrolment's org;daemon/heads.jsonnames the enrolment now; and the project'sheads.jsondoesn't yet list the writer as known for it._appendchecks it under the writer file's locks and puts the events inprojects/<id>/queued/<writer>.jsonl(outsidelog/: never mirrored, never uploaded). It returns them withseq: None.say,saywith a selector,send(aWaitingSend, held like a heldSendDelivery, so--waitstill waits on the message id), and the in-charge and status lines for another machine's member all say it waits and nudge the daemon.HubLog.release_headsruns after ahave, an import and a spent position. Once the log's frontier for the writer (its last seq carried past the spent positions) reaches the head thathavenamed,sminos.release_queueddoes the following under the same locks: it marks the writer known, appends what waited (skipping anything the log already holds, so a release cut short is finished without a second copy), and removes the queue. The uplink's next upload carries it.have. For an own-writer event it never signed, it refuses the event and sends the position down asspent(log-relay.ts), andspend_ownkeeps a position any local event holds as that event's. So an append before thehavetook a seq the hub held, was never uploaded, and the rest of the head was spent around it: the same fork. With the wait, the spent positions bring the frontier to the head, and what waited lands above it.daemon owedcounts what waits asqueued(B2 readsdaemon owedbefore a cutover).hub enrolland a welcome add the enrolment to the marks before they write the credential or identity it names, and the marks file keeps the last eight enrolments. So an appender that reads an enrolment also reads its mark, the enrolment a new one replaces stays marked until it is replaced in fact, and a mark that can't be written leaves the identity unwritten, for the next welcome to write both.have. Each queue is deduplicated against every drained writer's log, so a release cut short after its append isn't appended twice. The release appends what it found the head for, even if an enrolment published meanwhile says otherwise._queueends a fragment an interrupted write left, as_appenddoes.Tests
test_heads.py, new, in thesminosgate:DX2: an append before the
havetakes no seq. After thehavealone it still waits. After the hub's backlog of 1..3 is imported, it lands at 4, is uploaded, is receipted, and no (writer, seq) appears twice.A hub holding nothing of the writer releases it at the
have.A machine enrolled before this change appends at once.
A new enrolment waits again, and a session writer never waits.
A release cut short after its append is finished without a second copy.
daemon owedcounts what waits, with no body. The operator'ssminos saysays it waits.RL10: the cutover's first welcome marks the enrolment. The positions the endpoint spends bring the log to the head, and what waited lands above it and goes up. A renaming welcome holds the new name's writer.
Publication order: the mark is in place when the identity is written, a failed mark is retried by the next welcome, and a renaming welcome keeps the old enrolment marked.
A rename: what waited under the former name lands under the name now. A former queue is drained under its own writer's lock. A late queue from a pre-rename command is drained. A release cut short under a former name is not appended twice. An enrolment published during a release doesn't swallow what the release appends. A queue fragment doesn't swallow the next append.
Each fix-wave test fails on the commit before it.
Also, in the shell suites:
test-hub.sh:hub enrollwrites the mark with hub.json's name andenrolled.test-org.shenrols and has the operatorsayin a hub project with no uplink running. It now asserts that the say waits, releases it as the handshake would, and then reads it withchat. That was the one place the full suite saw the new wait.The conformance replay of O10's RL10 conversation passes unchanged.
Review
doperpowers:reviewer-high ran four rounds. Each round's findings were reproduced, fixed and tested, and each fix's test fails on the commit before it.
Residue (not fixed)
hub leave) before its firsthave. With no upstream, nothing releases them; they stay inprojects/<id>/queued/, butdaemon owedno longer counts them, since it reads only the upstream's projects._append's single write can still leave a partial line, as for any log append.sminos 1.27.3 (after #152's 1.27.1 and #149's 1.27.2).
Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)