samagotchi 0.190.1 → 0.192.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -1
- data/docs/architecture.md +13 -11
- data/docs/bundles.md +1 -1
- data/docs/cli.md +17 -6
- data/docs/configuration.md +6 -1
- data/docs/context.md +8 -1
- data/docs/internals/attached-context.md +3 -1
- data/docs/internals/inline-widgets.md +2 -1
- data/docs/internals/participants.md +1 -5
- data/docs/internals/peers.md +15 -3
- data/docs/internals/remote-sessions.md +5 -2
- data/docs/internals/session-lifecycle.md +233 -18
- data/docs/internals/web-frontend.md +107 -9
- data/docs/peers.md +3 -1
- data/docs/plugins.md +2 -1
- data/docs/scheduling.md +31 -7
- data/docs/sessions.md +12 -12
- data/docs/sub-agent.md +1 -1
- data/docs/testing.md +1 -2
- data/docs/thin-clients.md +98 -12
- data/lib/samagotchi/bridge.rb +3 -4
- data/lib/samagotchi/bundles/mcp/manifest.yml +4 -2
- data/lib/samagotchi/bundles/mcp/plugin.rb +7 -398
- data/lib/samagotchi/bundles/mcp/server_config.rb +158 -0
- data/lib/samagotchi/bundles/mcp/sign_in.rb +261 -0
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +2 -19
- data/lib/samagotchi/compat.rb +1 -7
- data/lib/samagotchi/config.rb +3 -0
- data/lib/samagotchi/context_command.rb +5 -1
- data/lib/samagotchi/context_sources.rb +28 -0
- data/lib/samagotchi/continue_intent.rb +23 -43
- data/lib/samagotchi/delivery.rb +1 -5
- data/lib/samagotchi/hold_stop.rb +5 -2
- data/lib/samagotchi/participants.rb +13 -5
- data/lib/samagotchi/peer_say.rb +29 -14
- data/lib/samagotchi/plugin/sessions.rb +9 -5
- data/lib/samagotchi/schedule_command.rb +6 -1
- data/lib/samagotchi/schedules/prune_part.rb +162 -41
- data/lib/samagotchi/schedules.rb +32 -15
- data/lib/samagotchi/send_command.rb +6 -6
- data/lib/samagotchi/session.rb +7 -0
- data/lib/samagotchi/session_access/ask.rb +9 -3
- data/lib/samagotchi/session_access/exchange.rb +6 -2
- data/lib/samagotchi/session_access/local.rb +103 -32
- data/lib/samagotchi/session_access/remote.rb +10 -9
- data/lib/samagotchi/session_access/remote_peers.rb +2 -2
- data/lib/samagotchi/session_access.rb +17 -7
- data/lib/samagotchi/session_chain/delete.rb +100 -47
- data/lib/samagotchi/session_chain/delete_preview.rb +9 -5
- data/lib/samagotchi/session_chain/successor.rb +78 -0
- data/lib/samagotchi/session_continue.rb +112 -42
- data/lib/samagotchi/session_inbox.rb +1 -1
- data/lib/samagotchi/session_inbox_delivery.rb +111 -25
- data/lib/samagotchi/session_lifecycle/allowed.rb +20 -1
- data/lib/samagotchi/session_lifecycle/reading.rb +9 -3
- data/lib/samagotchi/session_lifecycle.rb +17 -2
- data/lib/samagotchi/session_manager/delivery.rb +61 -29
- data/lib/samagotchi/session_manager/emptiness.rb +5 -2
- data/lib/samagotchi/session_manager/lifecycle.rb +68 -19
- data/lib/samagotchi/session_manager/listing.rb +2 -1
- data/lib/samagotchi/session_manager/removal.rb +67 -13
- data/lib/samagotchi/session_manager/spawn.rb +16 -9
- data/lib/samagotchi/session_manager.rb +4 -0
- data/lib/samagotchi/session_retention.rb +28 -7
- data/lib/samagotchi/session_row.rb +2 -0
- data/lib/samagotchi/session_transition.rb +361 -0
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/tools/cancel_schedule.rb +10 -6
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +13 -3
- data/lib/samagotchi/web/ask_create.rb +138 -0
- data/lib/samagotchi/web/ask_routes.rb +56 -9
- data/lib/samagotchi/web/last_ask.rb +78 -0
- data/lib/samagotchi/web/peer_routes.rb +5 -2
- data/lib/samagotchi/web/public/answer_refs.js +3 -9
- data/lib/samagotchi/web/public/answer_write.js +28 -0
- data/lib/samagotchi/web/public/app.js +72 -96
- data/lib/samagotchi/web/public/block_fix.js +30 -12
- data/lib/samagotchi/web/public/chains.js +3 -1
- data/lib/samagotchi/web/public/command_list.js +5 -3
- data/lib/samagotchi/web/public/composer.js +9 -6
- data/lib/samagotchi/web/public/composer_mount.js +18 -11
- data/lib/samagotchi/web/public/draft_keys.js +10 -0
- data/lib/samagotchi/web/public/drafts.js +278 -0
- data/lib/samagotchi/web/public/owner_claim.js +7 -12
- data/lib/samagotchi/web/public/prompt_history.js +6 -0
- data/lib/samagotchi/web/public/send_turn.js +51 -20
- data/lib/samagotchi/web/public/session_actions.js +80 -16
- data/lib/samagotchi/web/public/session_prefs.js +9 -3
- data/lib/samagotchi/web/public/session_view.js +7 -2
- data/lib/samagotchi/web/public/turn_events.js +0 -2
- data/lib/samagotchi/web/public/unqueue.js +22 -9
- data/lib/samagotchi/web/public/viewer_self.js +1 -6
- data/lib/samagotchi/web/public/views.js +12 -1
- data/lib/samagotchi/web/session_access_routes.rb +11 -5
- data/lib/samagotchi/web/session_control.rb +8 -1
- data/lib/samagotchi/web/session_create.rb +51 -34
- data/lib/samagotchi/web/session_hub.rb +52 -36
- data/lib/samagotchi/web/session_summary.rb +45 -7
- data/lib/samagotchi/web/start_dir.rb +6 -4
- data/lib/samagotchi/worker_boot.rb +28 -6
- data/lib/samagotchi/worker_presence.rb +22 -6
- metadata +10 -1
|
@@ -14,14 +14,14 @@ SessionManager boundaries are in [Architecture](../architecture.md) and [Engine
|
|
|
14
14
|
|
|
15
15
|
| Fact | Writer and removal | Cross-process readers and how they see change |
|
|
16
16
|
|---|---|---|
|
|
17
|
-
| `<id>.json` `status` | `Session#save` writes the session snapshot; the owner is the normal writer. `Session#load` overlays `stopped` as `stopped` without rewriting the file. | `SessionRow` and `SessionAccess::Local` read saved turn status; stop cancellation, restart fallback, and archive refusal also use it as a busy hint. Readers reload the file; the hub refreshes rows on its tick. It is turn state, not proof of liveness. |
|
|
17
|
+
| `<id>.json` `status` | `Session#save` writes the session snapshot; the owner is the normal writer. `Session#load` (and `summary_from_file`) overlays `stopped` as `stopped` without rewriting the file; the file's status is kept in `Session#loaded_status` (not saved, nil for a session built in memory). | `SessionRow` and `SessionAccess::Local` read saved turn status; stop cancellation, restart fallback, and archive refusal also use it as a busy hint. Readers reload the file; the hub refreshes rows on its tick. It is turn state, not proof of liveness. The session hub shows `stopped` only in a stopped state (`STOPPED_STATES`): `Web::SessionSummary.shown` derives the state from the facts, and a restored file whose own status says `stopped` stays stopped everywhere. |
|
|
18
18
|
| `starting` (`{pid, at}`) | `SpawnPart#spawn_session` marks before the first session file; `#spawn_worker_for_session` marks around `Process.spawn`; `#claim_start` claims with `StartingMarker.claim`. Failures clear it; `Worker#start` clears it after acquiring `owner.lock`. A stale/dead marker is taken over after 60 seconds or when its pid is gone. | `WorkerPresence`, resume, archive, delete, and retention read it directly; `WorkerPresence` checks age and pid. The session hub also refreshes presence. The atomic hard-link claim arbitrates competing starters; there is no event notification. |
|
|
19
19
|
| `owner.lock` and `leaving_at` | `OwnerLock.acquire` creates the file, takes its exclusive flock, and writes `{pid, kind, started_at}`; `OwnerLock#mark_leaving` adds `leaving_at` and `leave_wait`; `#release` unlocks and closes but leaves the file. Deletion removes it with the session directory. | `OwnerLock.owner` probes the kernel flock, then reads the record. The kernel releases the lock on process death; the record alone does not establish ownership. Presence and `WorkerLink` decisions probe it; hub presence refreshes poll it. `leaving_at` marks a worker that closed its Bridge but still holds the lock for leave work. |
|
|
20
20
|
| `bridge.json` | `Bridge#write_sidecar` publishes the worker endpoint; `Bridge#remove_sidecar` removes its own sidecar when stopping. A crash can leave it behind. | `WorkerLink.resolve` combines the sidecar with `owner.lock` and pid; a sidecar alone is stale. Readers waiting for a worker poll `WorkerLink.resolve`; a stale unlink rechecks the owner and removes only the unchanged file. Live clients see worker events over Bridge SSE. |
|
|
21
21
|
| In-memory exit claim | `Worker#exit_request` uses `WorkerExitClaim#claim`, `#accept`, `#release` and `#forget`; `#stopped!` records the last stop-all. It dies with that Worker. | Only that worker's threads read it; the Bridge's `/exit` and the loop coordinate through the Engine event lock, not a cross-process file. |
|
|
22
|
-
| `stopped` | `SessionManager#stop_session` calls `Session.mark_stopped
|
|
22
|
+
| `stopped` | `SessionManager#stop_session` calls `Session.mark_stopped` under the session's transition lock (kind `stop`, "Stops, archives and the ring wake"); `SpawnPart#resume` and delivery's `#start_for_send` clear it with `Session.clear_stopped` when starting for a person. Session-directory deletion removes it. | `WorkerPresence`, the worker startup/signal paths, and `Session#load` check the marker. It is read from disk on a decision (and on the hub refresh); no worker event is required. Its timestamp is compared with `starting.at` so a stop cancels an older start, not a later resume. |
|
|
23
23
|
| `archived` | `ArchiveStore.archive` is called by `SessionManager#archive_session`; `ArchiveStore.unarchive` is called by `#unarchive_session`, `SessionContinue#undo_failed_continue`, and the chain-delete undo/revival paths. Session-directory deletion removes it. | Lists, chain resolution, delivery, schedules, retention, and `WorkerPresence` call `ArchiveStore.archived?` against the file; changes are seen by the next read or list refresh. |
|
|
24
|
-
| `continue.lock` and `continue.json` | `SessionContinue#with_lock` takes the
|
|
24
|
+
| `continue.lock` and `continue.json` | `SessionTransition` is the only code that flocks `continue.lock`: a continue takes it exclusively after its recap, for the previous link and the new link's reserved id at once (`SessionContinue#with_lock`: `exclusive`, `LOCK_WAIT` 10 s a try, then `Refused :transition_busy`), a user's link or chain delete takes it exclusively for its whole run (`SessionChain::Delete`, kind `delete`, `LOCK_WAIT` 10 s), the schedule prune, the retention sweep and a leaving worker's empty or scratch delete try it once (kind `delete`), a stop takes it for its turn cancel, mark and TERM (kind `stop`, `STOP_LOCK_WAIT` 10 s for a short hold, a continue naming its new link, a delete or an archive refused at once; a worker stopping its delegates tries once), an archive for its task stop and markers (kind `archive`, `ARCHIVE_LOCK_WAIT` 10 s), a ring's wake holds it shared across its check and resume, crash repair tries it once (`try_exclusive`), an exclusive holder records its kind in the file while it holds it (`holder`, which `Busy.held` reads), arrivals and readers that must exclude a continue take a nonblocking shared hold (`shared`: each `WakePolicy` row's `hold`, taken in the seats), and previews probe it (`held?`). `ContinueIntent#write` records the successor before archive and updates the archived ids after; failed-continue cleanup removes the intent. The lock file remains until session-directory deletion; a continue that ends before its new link is saved removes that link's reserved folder, and the previous link's lock when the link was deleted meanwhile (`SessionTransition.forget`). | Every `:shared` delivery (sends, every turn sender, pushes, peer says), peer pairs, context adds/removes/pushes, invites, schedules, the delete preview, `SessionLifecycle.read` (`transitioning`) and `ContinueIntent.in_flight` (through `SessionChain::Successor`) inspect the lock and intent. flock coordinates the live transition; readers reload the JSON. An intent without a held lock is a crashed continue, not an active one; so is one whose successor is neither saved nor held (a continue holds both), and one under another kind's hold (a delete, a stop, an archive: `SessionTransition.other_than_continue?`). |
|
|
25
25
|
| `parent.json` | `Session#reparent` writes the override when `ChildMove` moves a child. Session-directory deletion removes it. | `ChildReports` resolves the current parent when routing a ring; the worker reads the override when loading its parent. Readers reload the file; it is not an event stream. |
|
|
26
26
|
| `reminders.json` | `Worker::LeavePart#carry_reminders` writes it for an asked restart, or removes it when stopped/no successor; stop, archive, and a stopped restart also remove it. `ReminderCarry#take` reads and removes it at worker start. | Only the next worker restores it into its Engine. It is a one-shot hand-off, not polled state; the session id, 120-second window, and stop marker are checked before restore. |
|
|
27
27
|
| Pending `input/`, `children/`, and `notes/` | `SessionInbox.write_input`, `#write_ring`, and `#write_note` write the files. A worker claims input and notes by atomic rename to `.processing`, then removes or settles them; rings are consumed by `ChildReports`. Session-directory deletion removes all three. | The worker checks input around turns and on its idle loop; rings and notes are checked by worker wake/absorption paths. The file is the durable queue; Bridge SSE can announce a live turn, but the worker's file scan is the fallback and recovery path. |
|
|
@@ -59,7 +59,8 @@ These are reader labels, not stored values:
|
|
|
59
59
|
The compound states exist because the deciders disagree on precedence: owner first (WakePolicy, resume, archive,
|
|
60
60
|
delete) or stop first (a schedule's busy check, a terminal's attach); WakePolicy reads archived before starting. Facts
|
|
61
61
|
that are not states: `continuing` (`continue.json` names a successor and `continue.lock` is held: only a send's and a
|
|
62
|
-
schedule's link resolution reads it),
|
|
62
|
+
schedule's link resolution reads it), `transitioning` (`continue.lock` held by anyone: `SessionTransition.held?`;
|
|
63
|
+
any state can be held, so it is a fact beside the state, and `SessionLifecycle::TRANSITIONING` holds its cells), a stale sidecar (`WorkerLink::Stale`: a crashed worker's leftover, reads as
|
|
63
64
|
the no-owner state), and the other crashed leftovers (a checkpoint, a `.processing` file, an unlocked continue intent).
|
|
64
65
|
`SessionLifecycle::CANONICAL` holds the fewest facts per state, each deriving back to it; `stopping` is a worker whose
|
|
65
66
|
Bridge answers, with a stop, and `stopped_starting` a start marked before the stop.
|
|
@@ -86,6 +87,14 @@ state. A cell is `:go`, `:wait` or the decider's own refusal reason; `SessionLif
|
|
|
86
87
|
back); a ring, a push and a fresh verdict are refused before their write as for a gone parent (a push records to
|
|
87
88
|
its source's folder as for a gone session), and `wake_for_report` answers `:deleting`; a leave's respawn drops
|
|
88
89
|
(`why: deleting`).
|
|
90
|
+
- **While a transition holds the lock** (`SessionLifecycle::TRANSITIONING`, read by `allowed(op, state,
|
|
91
|
+
transitioning: true)`): every delivery whose row holds `:shared` is `:busy` in every state (refused before its own
|
|
92
|
+
checks, nothing written; `:continued` instead when the holder is a continue naming its new link, a resolution fact
|
|
93
|
+
as `continuing` is); a `:none` row answers its state's cell. Generated from the rows' `hold`, plus
|
|
94
|
+
`TAKES_LOCK`: a stop takes the lock itself (`stop_session`, exclusive: `:busy`, nothing marked) and so does the
|
|
95
|
+
ring's column, which is a ring's wake (`wake_for_report`, shared: `:busy`, the ring left on disk; the ring's own
|
|
96
|
+
write, a `:none` row, still goes in). The other literal operations read none (archive's column is `archivable!`,
|
|
97
|
+
its checks; `archive_session` takes the lock after them).
|
|
89
98
|
- **Literal columns** (`LITERAL`): resume (`resume_session`), restart (`restart_session`: `stop_marked` in every
|
|
90
99
|
state with the stop marked: stopping, stopped, stopped_starting), stop (`stop_session`),
|
|
91
100
|
archive (`archivable!`), delete (`release_for_delete!`, without a stop), sched_chain and sched_same
|
|
@@ -127,31 +136,36 @@ SIGSTOP, features and Bridge reply do. The other deciders don't read `ALLOWED` y
|
|
|
127
136
|
combination as real files: owner/link pairs (none, stale sidecar, tui, tui with a stale sidecar, deleting, a worker
|
|
128
137
|
Live, Starting, stuck, Leaving, Skew, an owner of unknown kind) × stop × starting × archived, one absent session, a
|
|
129
138
|
continue in flight on each archived no-owner row, and a start marked after the stop on each no-owner row with both
|
|
130
|
-
(the order is a row fact: `StartingMarker.claim` takes over only a start at or before `stopped_at`)
|
|
139
|
+
(the order is a row fact: `StartingMarker.claim` takes over only a start at or before `stopped_at`), and four rows
|
|
140
|
+
(idle, archived, stopped, a live worker's) with the transition lock held for real by another thread
|
|
141
|
+
(`transitioning`): their deliveries go through the seats (`SessionInbox.deliver`, `deliver_turn`) and must answer
|
|
142
|
+
`TRANSITIONING`'s busy for a `:shared` row, the state's cell for a `:none` one. The owner lock's
|
|
131
143
|
holder, `ContinueIntent.in_flight`, `Process.spawn`, TERM/CONT, the Bridge and the restart fallback are stubbed; no
|
|
132
144
|
process starts. Each row checks that `SessionLifecycle.read` names the state its facts derive, then drives every
|
|
133
145
|
operation (one driver each, every private reach in that one file) and projects its answer into a cell. A row the
|
|
134
146
|
code can't make (a one-turn run's lock with a stop) is marked `reachable: false` with its note and still asserted.
|
|
135
147
|
|
|
136
148
|
Every answer must equal `ALLOWED[op][state]` (for the session hub, `SHOWN[state]`: `Web::SessionSummary.build`'s
|
|
137
|
-
status and bridge_up, its `
|
|
149
|
+
status and bridge_up, the live its summary gates the open question on (`SessionSummary.shown`)), or be named by exactly one `KNOWN_DIFFERENCES` entry (op, a `when`
|
|
138
150
|
over the row, a plain reason); an entry that names no mismatch fails as stale. The entries are the findings for the
|
|
139
151
|
owner, not fixed: stop-first schedule checks under a one-turn run's or an unknown owner's lock (`#busy_cell`'s stop override), and attach's under a
|
|
140
152
|
one-turn run's, a deleter's or an unknown owner's; chain mode's starting check before any one-turn-run check (`#busy_cell`'s F1b override); a start
|
|
141
153
|
marked after the stop holding a resume off;
|
|
142
|
-
`wake_for_report` reporting a worker's `:live` as `:owned
|
|
143
|
-
never reading the stop, the restart and schedule reading a deleter as starting, the schedule's Skew words,
|
|
144
|
-
`busy_reason`'s live branch falling through to the starting check
|
|
145
|
-
removed.) The delivery columns are
|
|
154
|
+
`wake_for_report` reporting a worker's `:live` as `:owned`. (Restart
|
|
155
|
+
never reading the stop, the restart and schedule reading a deleter as starting, the schedule's Skew words,
|
|
156
|
+
`busy_reason`'s live branch falling through to the starting check, and the hub's bridge_up, live and status overlay (F3/(c))
|
|
157
|
+
were fixed: their entries went stale and were removed.) The delivery columns are
|
|
146
158
|
generated from `WakePolicy::ROWS`, so for deliveries the matrix proves the states are drawn right (decide is a function
|
|
147
159
|
of the state), not what WakePolicy does; the literal columns and `SHOWN` are goldens.
|
|
148
160
|
|
|
149
161
|
## Locks and crash repair
|
|
150
162
|
|
|
151
163
|
`owner.lock` is the single-owner boundary for an Engine; its flock is released by process death. A starting claim uses
|
|
152
|
-
an atomic link rather than a long-held lock. A continue holds its exclusive `continue.lock`
|
|
153
|
-
|
|
154
|
-
|
|
164
|
+
an atomic link rather than a long-held lock. A continue holds its exclusive `continue.lock` (and its new link's) from after the recap to the end;
|
|
165
|
+
a user's delete holds them exclusively for its whole run, and the prune, the retention sweep and a leaving worker's
|
|
166
|
+
delete for each removal ("Deletes, the prune and retention"); a stop holds it exclusively for its mark and TERM, an
|
|
167
|
+
archive for its task stop and markers, and a ring's wake shared across its check and resume ("Stops, archives and
|
|
168
|
+
the ring wake"); shared holds protect every `:shared` arrival (the seats, "Arrivals declare their hold"). Every delete takes its transition locks before the `owner.lock` deletion locks. Inside a worker, the lock order is Engine event lock, then
|
|
155
169
|
`WorkerExitClaim`'s mutex. Session saves serialize through their per-session save lock. These locks protect separate
|
|
156
170
|
facts; there is no global lifecycle lock or atomic snapshot across all markers.
|
|
157
171
|
|
|
@@ -160,19 +174,209 @@ worker; under its owner lock, startup settles a turn checkpoint and stale runnin
|
|
|
160
174
|
dead turn. Interrupted continue intents are repaired separately by session listing/the web hub or before another
|
|
161
175
|
continue (`SessionContinue.repair_interrupted`), not by worker startup.
|
|
162
176
|
|
|
177
|
+
### The transition lock (`SessionTransition`)
|
|
178
|
+
|
|
179
|
+
`continue.lock` is a session's transition lock, and `SessionTransition` (`session_transition.rb`) is the only code
|
|
180
|
+
in lib that flocks or probes it (`spec/session_transition_lock_spec.rb`). The file keeps its name: an older chi's
|
|
181
|
+
continue, followed send and delete honour it.
|
|
182
|
+
|
|
183
|
+
- `exclusive(ids, kind:, state_dir:, deadline:, refuse_transitions: false)` takes each id's lock in sorted order,
|
|
184
|
+
creating a missing folder; `deadline: nil` blocks (no caller since the continue took a deadline), seconds retry
|
|
185
|
+
until then (`0`: one try) and raise `SessionTransition::Busy`, which owns its refusal text and names the id. With
|
|
186
|
+
`refuse_transitions` (a stop's; a deadline required, else `ArgumentError`) each failed try reads the holder again
|
|
187
|
+
(`Busy.held(id, taker: kind)`) and raises at once when it is a transition (`Busy#transition?`: a delete, an
|
|
188
|
+
archive, a continue whose intent names its new link); a stop, a repair, a holder that names nothing (an older
|
|
189
|
+
chi's, a continue before its intent, the new link's own hold) and every shared hold are waited out to the
|
|
190
|
+
deadline. Re-reading each try catches a delete that takes the lock while the stop waits behind a send. Ids taken
|
|
191
|
+
before a busy one are let go. While it holds a lock it writes its `kind` into the file (cleared on release, never from a lock another
|
|
192
|
+
holds; `try_exclusive` too).
|
|
193
|
+
- `holder(id, state_dir:)` is that kind (`:continue`, `:delete`), read only behind a failed shared try: a shared
|
|
194
|
+
holder (a send), an older chi's continue, a raw flock and a crash's leftover name none. `Busy.held(id, state_dir:)`
|
|
195
|
+
is the one place that says who holds a lock: a delete is "being deleted" whatever else is on disk; else a continue
|
|
196
|
+
in flight (`ContinueIntent.in_flight`) is "being continued as <new id>" (`SessionChain::Continued`'s words), a
|
|
197
|
+
continue before its intent "being continued", anything else "busy with another change" (each "; try again in a
|
|
198
|
+
moment"). A stop is "being stopped" and an archive "being archived", said as a delete is: a non-continue holder
|
|
199
|
+
(`other_than_continue?`) names no new link, and `in_flight` reads no continue under it, whatever intent a crashed
|
|
200
|
+
continue left. `exclusive`'s own Busy, the seats' busy refusal (`deliver_turn`), the continue's `transition_busy`
|
|
201
|
+
(its detail, which `--remote` reads back), `ContextSources.changing`, `Participants.invite`, the delete's refusal
|
|
202
|
+
(`DeleteRefused.held`) and the delete preview take their words from it; a delete holding the lock makes the seats
|
|
203
|
+
name no successor (`Hold.under`). The peer say/pair and the context push answer a status, `:busy`, whose words
|
|
204
|
+
are the plain ones. Those are `Busy#retry_message`, `#message` for every taker but a stop: a stop's Busy
|
|
205
|
+
(`taker: :stop`) that met a transition says what to do instead ("session ab12cd34 is being deleted", "… being
|
|
206
|
+
archived", "… being continued as <new id>: stop that one"). `DeleteRefused.held` and `ArchiveRefused.held` keep
|
|
207
|
+
the retry words (`retry_message`) for a stop they wrap.
|
|
208
|
+
- `try_exclusive(id, …)` is one try that creates no folder, crash repair's (`repair_intent`): a lock this thread
|
|
209
|
+
holds counts as taken, so a repair reached inside a continue never undoes it.
|
|
210
|
+
- `shared(id, state_dir:)` is a non-blocking shared hold (an invalid id is `false`; the lock file is created, the
|
|
211
|
+
folder only for a session whose file is there: a deleted session's folder is never made again, nothing is held and
|
|
212
|
+
the caller's own gone refusal follows; a lock file it made for a session gone by the block's end is taken back),
|
|
213
|
+
around every arrival's check and write (the seats, below), a peer say's, a peer pair's and a context push's
|
|
214
|
+
continued check and write (`SessionAccess::Local#moved_on`), a context add or remove (`ContextSources.changing`),
|
|
215
|
+
and an invite (`Participants.invite`). A caller that can't write the session folder
|
|
216
|
+
(a peer's chi behind the mailbox door) holds an existing lock file read-only, and holds nothing when there is none
|
|
217
|
+
(no transition holds a file that isn't there; one starting after it is not held off).
|
|
218
|
+
- `held?(id, state_dir:)` is a kernel probe (`in_flight`, `DeletePreview`, `holder`): it creates nothing and ignores the
|
|
219
|
+
registry, so it answers the same inside this thread's own hold.
|
|
220
|
+
- `forget(id, state_dir:)` takes back the lock file `exclusive` left for a session with no session file (one try
|
|
221
|
+
EX|NB; held, or this thread's, it stays) and its folder when that empties it.
|
|
222
|
+
|
|
223
|
+
**Order:** transition locks (several ids sorted) before any `owner.lock`. A taker that holds an `owner.lock` (a worker:
|
|
224
|
+
a delegate follow-up, an ask, a plugin's send, a ring, its own objectives note) only ever takes a transition lock
|
|
225
|
+
non-blocking: shared, or, for a stop of its delegates (`HoldStop#stop_delegates`, `Plugin::Sessions#stop`:
|
|
226
|
+
`stop_session(lock_wait: 0)`), exclusive in one try; so no owner-then-transition path waits. **Token per thread:** an exclusive hold is
|
|
227
|
+
the current thread's (`Thread#thread_variable_*`, not per process: chi web is multi-threaded, and not fiber-local);
|
|
228
|
+
that thread passes through `exclusive` and `shared` of a held id without touching the file (a second flock on the
|
|
229
|
+
held descriptor, or a dup, would convert it). Work handed to another thread doesn't carry the hold: it takes it again
|
|
230
|
+
or is refused. Before the registry, a shared hold inside a continue's own lock was refused; nothing a continue runs
|
|
231
|
+
under its lock takes one of its own id or reaches `follow_guard`, `Delete.link` or `Delete.chain`
|
|
232
|
+
(`spec/session_continue_spec.rb` records any), but the undo's ring wake (`wake_for_rings` → `wake_for_report`), whose
|
|
233
|
+
shared hold passes through on the token by design. **No fork while held:** a forked child keeps the flock; workers
|
|
234
|
+
start through `Process.spawn`, whose descriptors are close-on-exec.
|
|
235
|
+
|
|
236
|
+
**A continue's hold** (`SessionContinue.run` → `continue_once`, `spec/session_continue_spec.rb` "the transition
|
|
237
|
+
lock"). Unlocked: the refusals known before anything changes (`check!`, `archivable!`) and the recap wait (up to
|
|
238
|
+
`RECAP_WAIT` 30 s), so a send during the wait goes in (the archive then refuses it as before) and a delete may take the
|
|
239
|
+
link (its exclusive hold then makes the continue's wait for the lock end busy, "being deleted"). Then one `exclusive([previous, reserved successor id])`, sorted, `LOCK_WAIT` (10 s) a try: under it the previous
|
|
240
|
+
link is loaded and `check!`ed again (continued meanwhile → `Refused :continued`; deleted → not found; the delegate
|
|
241
|
+
plan made again), then the intent, the archive (`archive_session` → `stop_session`, nested), the new link's spawn and
|
|
242
|
+
carry (notes, peers, context, objectives, `ChildMove` notes and rings), or the undo (`return_rings`,
|
|
243
|
+
`NoteMove.give_back`, unarchive, `wake_for_rings` → `wake_for_report` → `resume_session`, `discard_failed_link`'s
|
|
244
|
+
stop and delete of the new link). All of it runs on the continue's thread under its token: a shared hold or a nested
|
|
245
|
+
exclusive of either id passes through, so no step refuses itself (`exclusive` skips held ids). Busy: a plain id is
|
|
246
|
+
refused `:transition_busy` (`SessionTransition::Busy.held`'s words naming the holder, a 409 of that name from chi
|
|
247
|
+
web; a schedule's chain firing counts it a skip, `Schedules::SKIP_REASONS`); a `last:<id>` continue with tries left
|
|
248
|
+
resolves again and waits again, so a second firing of the same chain follows the first one's new link. Any sender's turn
|
|
249
|
+
that meets the hold is refused naming the successor from the intent (`follow_guard`, "Arrivals declare their hold"
|
|
250
|
+
below: `SessionChain::Successor.in_flight`), else `transition_busy`; so are a peer say, a peer pair and a context push into the link's own source
|
|
251
|
+
(`:continued` with `in_flight`), or `:busy` in `SessionTransition::Busy`'s words when the holder names none. Who
|
|
252
|
+
continues a link is one answer, `SessionChain::Successor.of(id, state_dir:, in_flight:)` (`via` `:next`, `:anchor`
|
|
253
|
+
or `:in_flight`), and the refusal one wording, `SessionChain::Continued` ("session X was continued as Y", "is being
|
|
254
|
+
continued as" in flight), each site adding only what to do next. The new link's worker starts inside the hold, in its own process: its boot writes into its
|
|
255
|
+
own session (`ChildMove.adopt`, `NoteMove.adoption`, its objectives notes) take no transition hold, and must not (they
|
|
256
|
+
would be refused by the continue's exclusive). The reserved folder (`exclusive` makes it) goes whatever way a continue
|
|
257
|
+
ends before the new link is saved, with any note left there given back to the previous link; crash repair drops a
|
|
258
|
+
crashed continue's the same way. `Schedules::FIRING_TIMEOUT` (70 s) covers the recap, a lock wait per try and the
|
|
259
|
+
archive.
|
|
260
|
+
|
|
261
|
+
### Deletes, the prune and retention
|
|
262
|
+
|
|
263
|
+
- **A user's delete** (`SessionChain::Delete.link` / `.chain`, from `delete_session` with the chain keywords and
|
|
264
|
+
`delete_chain`: the CLI, chi web, `/exit --delete`) takes `exclusive(ids, kind: :delete, deadline:)` of every
|
|
265
|
+
session it takes or brings back (a link: it, the previous link it would revive, its delegates that go; a chain:
|
|
266
|
+
every link and their delegates), only ids still on disk (a gone one's folder is never made again), sorted, within
|
|
267
|
+
`LOCK_WAIT` (10 s) from the start. The plan is made (a chain's checks run) again under them; ids it adds then (late)
|
|
268
|
+
are a nested `exclusive` with the time left (held ids pass through). The stop (`release_for_delete!` →
|
|
269
|
+
`stop_session`), the task stop, the owner locks (`locked`, kind deleting), the removal, the undo
|
|
270
|
+
(`undo_deleted_link`) and the revival all run under the token. A lock not taken in time is
|
|
271
|
+
`DeleteRefused.held(busy)`: `:continuing` when a continue holds it, else `:transition_held` (chi web's 409 of that
|
|
272
|
+
name, which `--remote` reads back as `DeleteRefused`), Busy's words either way. A continue holding one of the ids
|
|
273
|
+
when the delete looks refuses it at once (`:continuing`, no wait: its end would change what the delete takes), and a
|
|
274
|
+
link continued while the delete waited for the locks is refused `:continuing` naming the new link rather than
|
|
275
|
+
deleted as a middle link. `refuse_continuing:` no longer
|
|
276
|
+
changes anything inside: either keyword takes `Delete.link`, which always refuses a held lock.
|
|
277
|
+
- **The schedule prune** (`Schedules::PrunePart`) takes `exclusive([link, next link], kind: :delete, deadline: 0)` per
|
|
278
|
+
link, oldest first, and checks the link's hold (`prune_hold`: archived, a protector, a worker, an open descendant)
|
|
279
|
+
before and again under it. Busy or a hold stops the prune below the link: never skipped past. The entry records it
|
|
280
|
+
(`extra["prune_waiting"]`, `PrunePart.waiting`; `chi schedule list`/`show`), the log says `prune_waiting` once per
|
|
281
|
+
link, and every tick tries a waiting entry again (`prunes_due`). The deletes inside are plain (`delete_ids`).
|
|
282
|
+
- **The retention sweep** (`SessionRetention.apply`, `prune_orphan_dirs`) and **a leaving worker's delete**
|
|
283
|
+
(`WorkerBoot#discard_left_session`, `#delete_left_scratch`, after the worker let go of its owner lock) take
|
|
284
|
+
`exclusive([id], kind: :delete, deadline: 0)` around the removal: held → kept (the sweep's `kept`; the worker's
|
|
285
|
+
`kept_session` / `scratch_kept`), and a later sweep takes it.
|
|
286
|
+
- The automatic deletes inside a transition (a continue's `discard_failed_link`) and `delete_resolved` /
|
|
287
|
+
`remove_files` themselves take no transition lock: the callers above hold it, so a continue's undo never refuses
|
|
288
|
+
itself.
|
|
289
|
+
|
|
290
|
+
### Stops, archives and the ring wake
|
|
291
|
+
|
|
292
|
+
- **A stop** (`SessionManager.stop_session`) takes `exclusive([id], kind: :stop, deadline: lock_wait,
|
|
293
|
+
refuse_transitions: true)` (`STOP_LOCK_WAIT` 10 s for a short hold; a continue naming its new link, a delete or an
|
|
294
|
+
archive refused at once) for the turn cancel, the owner read, the stop marker, the reminders hand-off and the
|
|
295
|
+
TERM/CONT; the owner wait after it (`wait:`) runs unheld. The turn cancel (a Bridge call whose read timeout is
|
|
296
|
+
`STOP_CANCEL_WAIT`, then up to `STOP_CANCEL_WAIT` for the worker's save) is the one deliberate, bounded exception
|
|
297
|
+
to "never a Bridge wait under a hold": a refused stop leaves the turn running, and no deadlock follows, because
|
|
298
|
+
every shared taker refuses at once on a held lock, a worker's own exclusive takes are one try, and the canceled
|
|
299
|
+
worker saves its turn without the transition lock. Only
|
|
300
|
+
a saved session's lock is taken (a gone one's folder is never made again; `Session.mark_stopped`'s not found
|
|
301
|
+
follows). A hold this thread has passes through: a continue's archive (`archive_session` → `stop_session`), its
|
|
302
|
+
`discard_failed_link`, a delete's `release_for_delete!`; a plain delete with a stop (no chain keywords, a scratch's
|
|
303
|
+
end: `delete_resolved` takes no transition lock) turns a held one into its own refusal (`stop_held` →
|
|
304
|
+
`DeleteRefused.held`). Not taken in time, or held by a transition → `SessionTransition::Busy` (`taker: :stop`),
|
|
305
|
+
nothing canceled or marked: chi web's 409 `stop_held` (`kind`, `successor_id`: `--remote` builds the same Busy), `chi sessions
|
|
306
|
+
stop` prints it and exits 1. A worker stopping its delegates (the exit ask's stop-all, a plugin's
|
|
307
|
+
`ctx.sessions.stop`) tries once (`lock_wait: 0`): it holds its own `owner.lock`; a held child is left running
|
|
308
|
+
(logged / the plugin's `Error`, Busy's words).
|
|
309
|
+
- **An archive** (`archive_session`) stops the tree's live workers first (each stop its own hold, as above), then
|
|
310
|
+
takes `exclusive(tree on disk, kind: :archive, deadline: ARCHIVE_LOCK_WAIT)` (10 s) for the background-task stop
|
|
311
|
+
and the archived markers; a delegate its stopping worker discarded gets no folder again. Inside a continue the
|
|
312
|
+
previous link passes through and its delegates are taken. A lock not taken in time, its own or a stop's, is
|
|
313
|
+
`ArchiveRefused.held` (`:transition_held`, Busy's words; chi web's 409 `busy` with that reason, `--remote` keeps the
|
|
314
|
+
words). Its checks (`archivable!`) come before any lock, as before.
|
|
315
|
+
- **A ring's wake** (`wake_for_report`: `SessionInbox.wake(:ring, hold: :shared)`, on the resolved link) holds the
|
|
316
|
+
lock shared across the decide and the resume, so a stop lands before the check or after the start (its marker then
|
|
317
|
+
stays and the new worker exits on it, or the TERM reaches it): never between them. A transition holding it now →
|
|
318
|
+
`:busy` (`:continued` with a continue's new link), the ring left on disk. The ring's own write and its first wake
|
|
319
|
+
(`ChildReports.ring` → `SessionInbox.deliver(:ring)`, a `:none` row, its start on another thread) hold none:
|
|
320
|
+
still open (Open windows).
|
|
321
|
+
- **A restart** stays outside the lock (D3): it spans two processes (the old worker's leave, the new one's spawn).
|
|
322
|
+
Open windows has its row.
|
|
323
|
+
|
|
324
|
+
### Arrivals declare their hold
|
|
325
|
+
|
|
326
|
+
Every `SessionInbox::WakePolicy::ROWS` row names `hold:` (a required keyword: a row without it doesn't load), pinned
|
|
327
|
+
by `spec/session_lifecycle/allowed_spec.rb`. The hold is taken once, in the three seats, by `SessionInbox::Hold.under`:
|
|
328
|
+
`Dispatch.deliver` (around the refusal check, the write and the wake), `Dispatch.wake` (around the wake) and
|
|
329
|
+
`SessionManager.deliver_turn` (`follow_guard`, around all of the delivery: the resume, the Bridge's wait and post, the
|
|
330
|
+
file and the second liveness check). Not in `resume_session` / `start_for_inbox`: a continue's undo reaches them on its
|
|
331
|
+
own token. A seat met by a held lock refuses, nothing written: a continue naming its new link (`Successor.in_flight`,
|
|
332
|
+
else a saved one) → `:continued` / 409 `link_continued` with `successor_id`; else `:busy` / 409 `transition_busy`
|
|
333
|
+
(`DeliverResult::BUSY`, `SessionTransition::Busy`'s words). chi send, an ask and the Exchange under them retry busy as
|
|
334
|
+
they follow a continue (`Exchange#relocate busy:`: the same link again, within `CONTINUING_WAIT`); a same-mode schedule
|
|
335
|
+
firing counts it a skip; the web composer, a delegate follow-up, a plugin's send and a participant's turn report it.
|
|
336
|
+
|
|
337
|
+
| Row / arrival | Hold | Why |
|
|
338
|
+
|---|---|---|
|
|
339
|
+
| send, push, peer, schedule, plugin, delegate, participant, agent, automatic | `:shared` | A turn or a push landing in a link being continued would be un-archived beside the new link or never read. |
|
|
340
|
+
| note (chi note, `send_note`, a broadcast, objectives) | `:none` | `NoteMove` moves a note written during a continue, the new link adopts one after (`NoteMove.adoption`), a failed continue gives them back; the new link's boot writes its own inside the continue's hold. |
|
|
341
|
+
| ring | `:none` | `ChildReports` rings once, no retry; `ChildMove` moves rings (`return_rings` gives them back); a continue's undo wakes for them on its own token. |
|
|
342
|
+
| fresh_verdict | `:none` | `VerifyFresh.forward` writes once, no retry; the verdict is for the card in the parent it names, continued or not; it starts no worker. |
|
|
343
|
+
| leave (respawn) | `:none` | After the worker's own release, spanning two processes (outside the lock); a refusal would drop a restart or queued input's start with no retry; a continue stops the worker first and the stop wins. |
|
|
344
|
+
| context add / remove (`Local#context_add`/`#context_remove`, chi web's URL add and detach) | shared | `ContextSources.changing`: a continue copies the session's own sources. Refused `ContextSources::Held` (423 `context_busy`). |
|
|
345
|
+
| context push, peer say, peer pair | shared | Phase 1 (`Local#moved_on`); the say's delivery seat holds again (shared beside shared). |
|
|
346
|
+
| invite (`Participants.invite`) | shared | A continue archives the link and ends its grants; refused `Grants::Invalid` with Busy's words. |
|
|
347
|
+
| revoke, peer unpair | none | Removals: a continue ends every grant at the archive, and the new link's pairing is the peer's to make (`Plugin::Peer#tell_moved`); refusing them would only make the owner retry. |
|
|
348
|
+
| `Local#answer` / `#dismiss`, cancel (cut), the attached TUI's `post_turn`, `Bridge#enqueue_turn` (the input fallback) | worker-side | Bridge-only: the live worker's own session (a continue's archive stops that worker and `archivable!` refuses it busy or queued). Over `--remote` the TUI's turn is chi web's turn route, `deliver_turn`'s seat. |
|
|
349
|
+
| The new link's boot (`ChildMove.adopt`, `NoteMove.adoption`, its objectives notes) | worker-side, none | Runs inside its creator's exclusive hold of the new link: a hold there would be refused until the continue ends. |
|
|
350
|
+
|
|
351
|
+
The raw `SessionInbox.write_*` sites are pinned with their hold in `spec/session_lifecycle_writers_spec.rb`. An older
|
|
352
|
+
chi's (0.190.x) worker or chi web takes no hold: its arrivals go in as before, and the tolerance paths stay
|
|
353
|
+
(`archivable!` refusing queued/busy, `NoteMove`, `ChildMove`'s movers).
|
|
354
|
+
|
|
163
355
|
## Open windows
|
|
164
356
|
|
|
165
357
|
These are documented race boundaries, not promises of an atomic lifecycle transition:
|
|
166
358
|
|
|
167
359
|
| Window | Code comment / current behavior | Pin |
|
|
168
360
|
|---|---|---|
|
|
169
|
-
| A ring wake decides to start, then a stop lands before resume. | `SpawnPart#wake_for_report` (`session_manager/spawn.rb`)
|
|
170
|
-
|
|
|
361
|
+
| A ring wake decides to start, then a stop lands before resume (closed). | Before: `SpawnPart#wake_for_report` (`session_manager/spawn.rb`) checked, then `resume_session` cleared a stop that landed meanwhile and started the worker. Now the wake holds the session's transition lock shared across the check and the resume and the stop takes it exclusively for its mark and TERM: the stop comes after the start, whole (its marker stays), or the wake meets the stop's hold and leaves the ring on disk (`:busy`). | `spec/session_manager/spawn_spec.rb` ".wake_for_report" (a stop from another thread in the start callback is held off and its marker stays; a held lock answers `:busy`, nothing started). |
|
|
362
|
+
| A ring's own delivery wakes the parent while a stop lands. | `ChildReports.ring` → `SessionInbox.deliver(:ring)` (a `:none` row: its write must never be refused) decides, then starts the parent on another thread (`ChildReports#starter`, `start_for_inbox`): the hold of `wake_for_report` does not cover it, so a stop between the decide and the start can be cleared by it as before. | No pin (declared); a shared hold around the start alone, on the starter's thread, would close it. |
|
|
363
|
+
| A restart outside the transition lock. | `restart_session` asks the worker to leave and its successor to start (or the fallback TERMs and resumes); it spans two processes, so it takes no transition lock (D3): a continue, a delete, a stop or an archive may interleave with it, each with its own checks (the restart precheck reads `SessionLifecycle`). | No pin (declared). |
|
|
364
|
+
| A stop's owner wait is unheld (its turn cancel: closed). | `stop_session` waits for the owner after it lets go of the lock: a send in that wait may go in (and a new worker start after the wait, as before). The turn cancel now runs under the stop's hold (its Bridge read bounded by `STOP_CANCEL_WAIT`), so a stop refused busy no longer ends the turn. | `spec/session_manager/lifecycle_spec.rb` "under the transition lock" (held for the mark and TERM, not the owner wait) and "mid-turn" (the cancel under the stop's hold, its read timeout; a refused stop cancels nothing). |
|
|
365
|
+
| Empty-session discard races a delivery (closed for turns and notes). | `WorkerBoot#discard_left_session` (`worker_boot.rb`) checks emptiness after releasing the worker lock and again under the deletion lock (`delete_session`'s `still:`): a send or note that went in before the lock keeps the session. One that reads the session during the lock is refused (`DeliverResult::DELETING`, a note as gone); one that read it before the lock and wrote after it reads it again after its write and takes its file back (`SessionInbox.withdraw`), so no turn or note is reported delivered and then removed. No new lock for that: the write-then-reread and the recheck under the existing deletion lock close it (the discard also tries the session's transition lock once, kind `delete`: a send or a transition holding it keeps the session). What remains: a ring or fresh verdict that read the session before the lock and wrote after it is not taken back: it goes with the directory, or stays for the next worker if the delete gives up; neither is reported to a person. | `run_session_loop_spec.rb`: a send at deletion-lock acquisition is refused; one just before the lock keeps the session. `delivery_spec.rb` / `note_delivery_spec.rb`: the lock (or the removal) between the check and the write, deterministic through the bridge / writer seam. |
|
|
171
366
|
| Stop reads an owner pid, then sends TERM. | `LifecyclePart#stop_session` (`session_manager/lifecycle.rb`): the pid can be reused between the owner read and `Process.kill`; protecting that requires a real pid-reuse scenario. | No unit pin: pid reuse/process signaling is not reliably representable without real processes. |
|
|
172
367
|
| Saved `status` is used as a lifecycle hint. | `LifecyclePart#restart_fallback_holds` and `RemovalPart#archive_refusal` (`session_manager/lifecycle.rb`, `session_manager/removal.rb`) use saved `running` status as a busy hint; status is not a lock or proof that a worker is alive. | Unit spec: pin fallback refusal from saved status without a live Bridge. |
|
|
173
368
|
| Stop/start ordering depends on wall-clock `at`. | `SpawnPart#claim_start` and `StartingMarker#claim` (`session_manager/spawn.rb`, `starting_marker.rb`) compare `starting.at` with `Session.stopped_at`; same-time starts are treated as before the stop. Clock adjustments across processes are not serialized. | Unit spec: pin the inclusive `at <= over_before` takeover boundary. |
|
|
174
369
|
| A delete stops a session's background tasks. | `RemovalPart#remove_session_files` (`session_manager/removal.rb`): with `running_tasks:` a stop, `RunningTasks.stop!` runs under the DELETING owner lock, after the `StartingMarker.fresh?` re-check and `still`, for up to ~4 s; meanwhile a send, a schedule or a resume is refused as deleting. With `REFUSE` the same seat lists the final file again and refuses a task started since the op's check (`worker_stopped` set when the op stopped the worker; `stopped_worker` names whose). `SessionChain::Delete` lists a whole batch (a link and its D7 delegates) once under the batch's locks, before any of it goes (`refuse_tasks!`), and its removals then skip the per-id re-check (`RunningTasks.after_check`), so no refusal comes after part of the batch went. A chain with `--stop-tasks` stops link by link inside each `locked(batch)`, serially: up to ~4.5 s per link, N links N times that, with that batch's locks held; a link refused part-way keeps its tasks running. A stop that outlives the join's deadline (`unconfirmed`) is reported as not stopped and may still finish after the files are gone (its thread goes on writing the record under the session's working directory, not the session dir). | `removal_spec.rb` (a worker's `OwnerLock.acquire` during the stop fails; the re-check refuses a new task), `session_chain/delete_spec.rb` (link by link, part-way; a task started after the up-front check keeps the link, its delegate and the chain whole). |
|
|
175
|
-
| An archive stops a session's background tasks without a lock. | `RemovalPart#archive_session`: the stop runs after the tree's workers were stopped and waited for (`stop_session(wait:)`), before the marker; a worker that outlives the wait records the stop itself from the `stop_requested_by` flag on disk (`record_exit_status` / `correct_finished_record`).
|
|
370
|
+
| An archive stops a session's background tasks without a lock (closed for transitions and sends). | `RemovalPart#archive_session`: the stop runs after the tree's workers were stopped and waited for (`stop_session(wait:)`), before the marker; a worker that outlives the wait records the stop itself from the `stop_requested_by` flag on disk (`record_exit_status` / `correct_finished_record`). The task stop and the markers now run under the tree's transition locks (kind `archive`): a send, a continue or a delete doesn't interleave with them. Still open: a task started after the listing isn't stopped (archive refuses `busy` up front), and a send between the workers' stop and the archive's hold goes in (the archive then hides it, as before). | `removal_spec.rb` (the stop sees no owner left); `session_archive_spec.rb` "under the transition locks" (held as an archive for the markers, Busy → `transition_held`). |
|
|
371
|
+
| A peer say, peer pair or context push during a continue (closed, N1). | Before: `Local#peer_say` checked `continued_as` (archived with a saved successor) and posted through `SessionInbox.deliver(:peer)`, a pinned row that skips Head's in-flight look and `follow_guard`; between the archive and the new link's save a say went into the old mailbox after `PeerContinue` had read it, and was never read (its line said "it reads this if you reopen it"). Now each takes `SessionTransition.shared` across the continued check and the write (`Local#moved_on`), never across the Bridge feature probe or the receipt wait: a continue holding the lock refuses it `:continued` naming its new link (in flight), else `:busy`. A say that holds the lock first goes in and the continue's carry takes it. | `session_access_local_spec.rb` "while a transition holds the session's lock" (say, pair, push refused naming the successor, Busy without one, mailbox and source unchanged); `session_continue_spec.rb` "refuses a peer say during the transition" (a real continue, the say made between its archive and the new link's save). |
|
|
372
|
+
| A send between a continue's exclusive hold and its archive marker (closed). | Before: `follow_guard` held only for a followed send to an archived link, so a send (any sender) to a link a continue held but had not archived yet went in, and the archive then refused the continue as busy or queued. Now every `:shared` row's delivery takes the hold in its seat: refused naming the new link (`link_continued`), else `transition_busy`. | `spec/session_inbox/hold_spec.rb` (each sender busy under a really held lock; a send to a link not archived yet refused naming the new link); the matrix's transitioning rows. |
|
|
373
|
+
| A frozen worker's Bridge post under a send's hold. | `deliver_turn` holds the session's lock shared across the Bridge's post (up to `BridgeClient::READ_TIMEOUT` 30 s for a worker that doesn't answer); a continue of that session waits `LOCK_WAIT` per try and is refused `transition_busy`, and a stop or an archive waits its 10 s and is refused (`stop_held` / `transition_held`, "busy with another change"): stopping that frozen worker can take a second try. | No unit pin: a frozen worker's post is a timing case. |
|
|
374
|
+
| A delete or a send during a continue's recap. | `SessionContinue.continue_once` waits for the recap before it takes the transition lock: in that window a link delete and the delete preview no longer see a continue (`:continuing`): the delete may take the link's lock exclusively, and the continue's lock wait then ends busy ("being deleted"); a followed send to the link goes in. Under the lock the continue checks the link again: deleted → not found (its folder not brought back), continued by another → `Refused :continued`, a turn queued → the archive's refusal. | `session_continue_spec.rb` "the transition lock": the lock not held during the recap, a send then accepted, a link deleted or continued during the recap refused under the lock. |
|
|
375
|
+
| The new link's worker boots inside the continue's hold. | `SessionContinue.spawn_continuation` spawns it while the continue holds the new link's transition lock exclusively; its boot writes (`Worker#start` → `ChildMove.adopt`, `WorkerInbound` → `NoteMove.adoption`, its objectives notes through the note row, `:none`) take no transition hold. A hold added on that path would be refused until the continue ends (drop the new link's hold before the spawn instead). A send or a peer pair to the new link from outside is `transition_busy` until the continue lets go (milliseconds after the spawn): the senders retry. | `session_continue_spec.rb`: the boot's adoption on another thread makes no `SessionTransition` call, adopts the note, and a note through `NoteDelivery` goes in. |
|
|
376
|
+
| An unpair or a revoke during a continue. | `:none` (above): an unpair of the old link while the new worker's `tell_moved` re-pairs the peer may leave the peer paired with the new link. | No pin (declared). |
|
|
377
|
+
| Sends to a session a delete holds (open, by design). | `SessionChain::Delete` holds the transition locks from before its stop to the end: a send, a push, a peer say or a context change to the link, its previous link or a delegate that goes is refused `transition_busy` "being deleted" for the stop (up to the delete's wait, 10 s from the CLI), the task stop (about 4 s a link) and the removal; a chain delete holds every link's for the whole chain (N links × stop + tasks: minutes for a long chain with `--stop-tasks`). chi send and an ask retry within their wait; the web composer, a delegate, a plugin and a participant report it. Before, those sends went in and the delete stopped or removed them. | `session_chain/delete_spec.rb` "under the transition locks" (a send during the stop refused as being deleted, both locks the delete's). |
|
|
378
|
+
| A delete meets a send's or another change's hold (closed). | Before: `Delete.link`, `hold_all` took `SH\|NB`, so a continue was refused but another delete, a prune or the retention sweep could run beside it, and a send held nothing off. Now a user's delete waits up to `LOCK_WAIT` for the locks exclusively, then refuses (`continuing` / `transition_held`, the holder named); the prune, the sweep and a leaving worker's delete try once and keep the session. | `session_chain/delete_spec.rb` (a short shared hold waited out, a long one refused, a held delegate refuses), `session_retention_spec.rb`, `session_discardable_spec.rb` (held → kept). |
|
|
379
|
+
| A prune at a link it can't delete (closed: visible, never skipped). | Before: a link another enabled schedule protects (its anchor inside the chain, a stale head) was refused `prune_stopped` at every firing, after the link's delegates were already deleted, and the chain grew silently. Now the hold is checked before anything in the subtree goes and the prune stops there with a record (`prune_waiting`, list/show) and one log line; a held transition lock on the link or the next does the same, and every tick retries. Still open: the chain grows behind such a link until the other schedule is cancelled (re-linking the chain around it is held, D6). | `schedules_spec.rb` "a prune held at a link" (held link: kept with every later link, resumed next tick; next link held; the mid-chain schedule: one log, list/show lines, nothing deleted around it, gone after cancel). |
|
|
176
380
|
| Several methods write or remove the same marker. | The definitions/callers in `session.rb`, `starting_marker.rb`, `archive_store.rb`, `bridge.rb`, and `reminder_carry.rb` are the source of truth; these APIs have multiple call sites. | `spec/session_lifecycle_writers_spec.rb` pins the call-site allow-lists; it does not claim their operations are one transaction. |
|
|
177
381
|
|
|
178
382
|
## Adding a transition
|
|
@@ -183,7 +387,18 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
|
|
|
183
387
|
3. Identify every decider that reads the fact and how it observes the change (lock probe, direct read, poll, or SSE).
|
|
184
388
|
4. If the change touches an open window above, extend its pin in the corresponding unit spec; don't hide a race with a
|
|
185
389
|
sleep or a process-wide integration test.
|
|
186
|
-
5.
|
|
390
|
+
5. A new arrival (a `WakePolicy` row, a delivery outside the seats) declares its hold: `hold: :shared` (the seat
|
|
391
|
+
takes it) or `hold: :none` with its reason; a raw `SessionInbox.write_*` site is listed with its hold in
|
|
392
|
+
`spec/session_lifecycle_writers_spec.rb`; one outside the inbox that changes what a transition carries takes
|
|
393
|
+
`SessionTransition.shared` around its check and write (see "Arrivals declare their hold").
|
|
394
|
+
6. If the fact changes a state, update `SessionLifecycle::STATES`/`Reading.derive` and `CANONICAL`, then the
|
|
187
395
|
`ALLOWED` cells (the literal ones by hand; the delivery ones follow `WakePolicy::ROWS`) and the matrix's rows; a
|
|
188
396
|
decider that answers otherwise is a `KNOWN_DIFFERENCES` entry with its reason, never a silent cell change.
|
|
189
|
-
|
|
397
|
+
7. A new multi-step transition takes `SessionTransition.exclusive` with its own `kind` (add its words to
|
|
398
|
+
`Busy::WORDS` so `Busy.held` names it; any kind but `continue` names no new link; a long one a stop should not
|
|
399
|
+
wait for goes in `Busy::TRANSITIONS`, and a stop meeting it is refused at once), with a deadline, before any
|
|
400
|
+
`owner.lock`; an automatic one tries once (`deadline: 0`) and leaves the session for later, and so does one a
|
|
401
|
+
worker runs (it holds an `owner.lock`). A literal operation that takes the lock gets its `TAKES_LOCK` cell.
|
|
402
|
+
8. Recheck lock order, crash cleanup, and the existing file-format/compatibility specs before changing runtime behavior.
|
|
403
|
+
A transition that must exclude a continue or an arrival takes the transition lock through `SessionTransition`,
|
|
404
|
+
never its own flock of `continue.lock`.
|