Skip to content

sminos: the operator writer waits for its upstream's head on a new enrolment (#147) - #425

Merged
SSFSKIM merged 7 commits into
mainfrom
sminos-own-writer-seq
Oct 28, 2026
Merged

SSFSKIM merged 7 commits into
mainfrom
sminos-own-writer-seq

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

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>/human made before the first have and the backlog took seqs from 1 that the upstream already held. Those seqs sit at or below the uplink's sent, 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:

    • the local delivery records' settled cursors, which would then re-deliver the moved event or skip the imported history;
    • the append receipts, keyed by seq;
    • RL10's words? asks and verdicts;
    • the delivery outcomes.

    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, send or line verb on a freshly enrolled machine waits until the hub (or the endpoint) answers. Within a running daemon that is the uplink's first have for the project, a few seconds.

  • The queue is limited to marked enrolments. hub enroll and a welcome that cuts over, renames or re-enrols write daemon/heads.json, naming the enrolment's name and enrolled. 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.json names the enrolment now; and the project's heads.json doesn't yet list the writer as known for it.
  • While it is true, _append checks it under the writer file's locks and puts the events in projects/<id>/queued/<writer>.jsonl (outside log/: never mirrored, never uploaded). It returns them with seq: None. say, say with a selector, send (a WaitingSend, held like a held SendDelivery, so --wait still 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_heads runs after a have, 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 that have named, sminos.release_queued does 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.
  • DX2: the hub's backlog brings the writer's events past the machine's vector, and they are imported as they are now.
  • RL10 reaches the same window. The endpoint relays the hub's have. For an own-writer event it never signed, it refuses the event and sends the position down as spent (log-relay.ts), and spend_own keeps a position any local event holds as that event's. So an append before the have took 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 owed counts what waits as queued (B2 reads daemon owed before a cutover).
  • Publication. hub enroll and 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.
  • A rename while an append waits. The release under the name now also drains this machine's operator queues under its former names, each under its own writer's locks. A queue made late, by a command that began before the rename, is still found at the next 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.
  • _queue ends a fragment an interrupted write left, as _append does.

Tests

test_heads.py, new, in the sminos gate:

  • DX2: an append before the have takes no seq. After the have alone 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 owed counts what waits, with no body. The operator's sminos say says 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 enroll writes the mark with hub.json's name and enrolled.
  • 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. 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.

  1. On efad5d0. The mark was published after the identity it names, and a failed mark write left the writer unprotected for good. An append that waited across a rename was abandoned. Fixed in 11ece4a.
  2. On 11ece4a. Replacing the single mark unmarked the enrolment still current. A former name's queue was drained under the wrong lock. Recovery deduplicated against one log only. A trailing fragment in a queue swallowed the next append. Fixed in 9e488e6.
  3. On 9e488e6, two P2s, each needing an enrolment or a rename to overlap a release. An enrolment published mid-release re-queued and then removed what the release appended. A late former-name queue stayed stranded until a reconnect. Fixed in 256e2e3.
  4. On 256e2e3, one P2 the previous fix introduced: an old DX2 uplink that outlived a re-enrolment under a new name could drain the new name's queue into its own writer. Fixed in 3b5cdd3, with a one-line check that the stream still runs under the machine's current name. I stopped the loop there: the findings had narrowed from P1s to a single overlap case, and this last check wasn't reviewed again.

Residue (not fixed)

  • An operator append made before enrolment, under the host's name, in a hub checkout is not covered. If the machine then enrols under that same name and the hub already holds history for it, the old window remains. Covering it would mean holding operator words on any machine that isn't enrolled.
  • Queued events are not appended if the machine leaves the hub (hub leave) before its first have. With no upstream, nothing releases them; they stay in projects/<id>/queued/, but daemon owed no longer counts them, since it reads only the upstream's projects.
  • A crash in the release, after its append and before the queue's removal, is finished by the next release without a second copy. A crash in the middle of _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)

…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)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T09:50:59.077573Z 8ad43c1 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1983 to +1985
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant