samagotchi 0.190.1 → 0.191.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 +22 -1
- data/docs/architecture.md +8 -7
- data/docs/cli.md +6 -3
- data/docs/context.md +8 -1
- data/docs/internals/attached-context.md +3 -1
- data/docs/internals/peers.md +15 -3
- data/docs/internals/remote-sessions.md +2 -2
- data/docs/internals/session-lifecycle.md +213 -12
- data/docs/peers.md +3 -1
- data/docs/plugins.md +2 -1
- data/docs/scheduling.md +24 -6
- data/docs/sessions.md +10 -10
- data/docs/sub-agent.md +1 -1
- data/lib/samagotchi/bridge.rb +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- 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/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 +5 -1
- data/lib/samagotchi/schedules/prune_part.rb +130 -41
- data/lib/samagotchi/schedules.rb +18 -6
- data/lib/samagotchi/send_command.rb +6 -6
- 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 +105 -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 +13 -2
- data/lib/samagotchi/session_manager/delivery.rb +61 -23
- data/lib/samagotchi/session_manager/emptiness.rb +5 -2
- data/lib/samagotchi/session_manager/lifecycle.rb +50 -14
- data/lib/samagotchi/session_manager/removal.rb +65 -13
- data/lib/samagotchi/session_manager/spawn.rb +14 -6
- data/lib/samagotchi/session_retention.rb +28 -7
- data/lib/samagotchi/session_transition.rb +315 -0
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +10 -2
- data/lib/samagotchi/web/peer_routes.rb +5 -2
- data/lib/samagotchi/web/session_access_routes.rb +5 -2
- data/lib/samagotchi/web/session_control.rb +6 -1
- data/lib/samagotchi/web/session_create.rb +1 -1
- data/lib/samagotchi/worker_boot.rb +28 -6
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a2e3f365d9e072d6e62259794b8b820eadfbad98191b52950bd500c3a719cdc6
|
|
4
|
+
data.tar.gz: 8f464ea54361dd666264cd430fe51d7f9af6cad6fac31612a1c3fe2f80aacbd1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c0ff226bcf7c80d9a2c7d1838da6c456fb971c9f681c4480837908c95abe5e7c82411342f4738864eb8a31411eb6c6ba93f96e2078d72cb48e0aa3ffeebdf60c
|
|
7
|
+
data.tar.gz: 1192fbb01bd6a56d59269430db8a3aa0da8523a6ac566c687ad37b0a14c7243dfb60935d134dcc4d9b0bee4b4613efb551ffca238667f71138d26c24d127cc30
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,26 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.191.0] - 2026-11-27
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Continuing, deleting, pruning, stopping and archiving a session no longer race each other: each waits briefly for
|
|
16
|
+
the other change to finish, then goes on or is refused, naming what holds the session ("session ab12cd34 is being
|
|
17
|
+
deleted; try again in a moment").
|
|
18
|
+
- A message sent while its session is being continued is no longer lost: `chi send` and thin-client asks retry and
|
|
19
|
+
reach the new link; a schedule's firing skips that tick; `chi peer say`/`pair` and `chi context push` are refused,
|
|
20
|
+
naming the new link to send to.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Schedule pruning no longer stalls partway down a chain when one session can't go yet: it stops there, shows
|
|
25
|
+
`pruning held at …` in `chi schedule list` (and why in `show`), and tries again on the next tick.
|
|
26
|
+
- A child's report waking its parent no longer undoes a stop of that parent that is in progress.
|
|
27
|
+
- A stop or an archive no longer slips into the middle of a continue or a delete: `chi sessions stop`, the web's
|
|
28
|
+
stop and an archive wait (up to 10 s) for the change to finish, then go on or are refused in its words.
|
|
29
|
+
- Retention and a scratch session's cleanup no longer delete a session in the middle of a continue.
|
|
30
|
+
|
|
11
31
|
## [0.190.1] - 2026-11-26
|
|
12
32
|
|
|
13
33
|
### Fixed
|
|
@@ -6966,7 +6986,8 @@ and long-lived sessions.
|
|
|
6966
6986
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6967
6987
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6968
6988
|
|
|
6969
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
6989
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.191.0...HEAD
|
|
6990
|
+
[0.191.0]: https://github.com/dm1try/samagotchi/compare/v0.190.1...v0.191.0
|
|
6970
6991
|
[0.190.1]: https://github.com/dm1try/samagotchi/compare/v0.190.0...v0.190.1
|
|
6971
6992
|
[0.190.0]: https://github.com/dm1try/samagotchi/compare/v0.189.0...v0.190.0
|
|
6972
6993
|
[0.189.0]: https://github.com/dm1try/samagotchi/compare/v0.188.0...v0.189.0
|
data/docs/architecture.md
CHANGED
|
@@ -508,7 +508,7 @@ model: [internals/remote-sessions.md](internals/remote-sessions.md).
|
|
|
508
508
|
| `GET /api/projects?dir=` | owner | optional page-scope folder | 200: project rows (`Web::ProjectList`: the hub's projects plus the start project and current project, even without sessions) with counts, roots, default/current marks; no `dir`: no current project | 400 `invalid_dir`; 503 `no_hub` |
|
|
509
509
|
| `POST /api/projects` | owner | `{dir}` (absolute folder; `~` and `~/` expand against the server's home) | 200 `{outcome, root, dir}` (`created`, `already_marked`, or `git`) | 400 `invalid_json`, `invalid_dir`; 422 `above_home`, `write_failed` |
|
|
510
510
|
| `POST /api/sessions` (more fields) | owner | `toolkit`, `tools`, `no_tools`, `parent_answers`; `driver` (`agent:<name>`, the new session's driver); `client_id` (`cli:send`/`cli:answer`/`agent:<name>`: the first line is checked as chi send checks it); `check_vision: true` (images follow) | 201 adds `model_warning`, `parent_answers_warning` (a level looser than config.yml's, capped) and `first_turn_id` (the id the prompt it starts with gets for its turn; null for an `idle` create); with a `first_turn_id`, a wait `token` for that turn (none for an `idle` create) | 400 `invalid_toolkit`, `invalid_parent_answers`, `invalid_continues` (beside `continues`); 403 `parent_answers_refused`, `parent_continue_refused`; 422 `no_vision` |
|
|
511
|
-
| `POST /api/sessions/:id/turn` (more fields) | owner | `client_id` as above; `check_vision: true` with `images` | as before | 403 `parent_answers_refused`, `parent_continue_refused`; 422 `no_vision` |
|
|
511
|
+
| `POST /api/sessions/:id/turn` (more fields) | owner | `client_id` as above; `check_vision: true` with `images` | as before | 403 `parent_answers_refused`, `parent_continue_refused`; 422 `no_vision`; 409 `link_continued` (`successor_id`) or `transition_busy` while a transition holds the session's lock (every sender: `SessionInbox::Hold`, internals/session-lifecycle.md) |
|
|
512
512
|
| `POST /api/sessions/:id/wait/prepare` | owner | `question_id` (absent: the pending one; `null`: none), `turn`, `created`, `busy` (+ `queue`) | 200 `{session_id, cursor, baseline: {messages, question_id, last_turn}, own_turn, known_turn, running, live, settled, last_turn_id}` (`WaitStart`) | 409 `busy`, `waiting` (`SendCommand::Busy`'s words, and its fields: `question`, `parent_strategy`) |
|
|
513
513
|
| `POST /api/sessions/:id/wait` | owner | `cursor`, `baseline`, `turn`, `queued`, `ended_before`, `owner_grace`, `timeout` (capped at 30 s); or `{token, timeout}` (a wait token, `SessionAccess::Exchange::Token`: the answer adds `session_id`, and `token` again while the status is `timeout`; a token beside the other fields, another session's, one that isn't one or a participant's: 400 `invalid_wait`) | 200: `ReplyWait::Result`'s fields (`status`: `done`, `waiting_for_answer`, `no_reply`, `error`, `stopped`, `worker_gone`, or `timeout`: ask again; `text`, `file`, `question` as `PendingQuestion#to_file`, `outcome`, `limit`, `error_kind`, `retryable`, `cancel_reason`, `stopped_by`, `kept_steps`, `turn_id`, `origin`; never the session) and `parent_strategy` `{name, allowed, origin}` (`ParentReport.strategy_for`, this server's config.yml) | 400 `invalid_wait`; 503 `server_stopping` |
|
|
514
514
|
| `POST /api/sessions/:id/ask` | owner | `prompt` (16 KiB), `timeout` (default and most 30 s), `queue` (default `true`: a running session queues it as its own turn; `false` refuses it), `client_id` (absent: `web:unnamed`; `cli:send`'s `/continue yes` goes in as `cli:answer` and is parent-gated as on `…/turn`), `request_id` (optional, 1-128 printable ASCII, messages only: a retry with it answers the first ask's turn, `SessionInbox.enqueued_id_for`) | 200: the wait's fields + `session_id` (where it ran), `asked` (the id given, when another link ran it), `token` when the status is `timeout`, `request_id` echoed when given; 200 `{status: command, session_id}` for a session command (`/continue yes` with an offer standing answers the continued turn's fields instead). The whole call answers within `AskRoutes::ASK_MAX_SECONDS` (35) (`Web::AskRoutes`, `SessionAccess::Ask`, [thin-clients.md](thin-clients.md)) | 404 `not_found`; 400 `ambiguous_id`, `missing_fields`, `invalid_prompt`, `local_command`, `invalid_ask` (also a `request_id` on a session command); 403 `parent_continue_refused`, `parent_answers_refused`; 409 `busy`, `waiting` (neutral words, Busy's fields), `continuing`, `owned_by_tui`, `enqueued_id_conflict` (the same `request_id`, another prompt, a turn the session no longer names but the worker remembers), the turn route's delivery refusals (`queue_unavailable`, …); 504 `worker_timeout`; 503 `server_stopping` |
|
|
@@ -516,11 +516,11 @@ model: [internals/remote-sessions.md](internals/remote-sessions.md).
|
|
|
516
516
|
| `POST /api/sessions/:id/answer` (`wait`) | owner | `wait: N` (seconds, at most 30) beside `id`, `selected`, `freeform` | 200 `{status: answered, session_id, id, reply: {the wait's fields, token while it is timeout}}`; a question answered elsewhere first: 200 `{status: not_pending, answered_here: false, …, reply}` (as `chi answer` still waits); a wait that fails after the answer went in: 200 with that `status` and `wait_error` `{error: server_stopping \| not_found \| wait_failed, detail}` in place of `reply`; without `wait` every answer is as before | 400 `invalid_wait`; 404 |
|
|
517
517
|
| `POST /api/sessions/:id/notes` | owner | `text`, `source` (default `cli`, never `broadcast`) | 200 `{status: queued \| waits, session_id, queued}` (`NoteDelivery`) | 409 `owned_by_tui` (`status: refused`); 400 `note_rejected`, `missing_fields`, `invalid_source` |
|
|
518
518
|
| `POST /api/sessions/:id/context` (more bodies) | owner | `{name, push: true, why, hint}` or `{name, cmd, every, why, hint}` beside the page's `{url, why, hint}`; `added_by` `cli`/`agent` (else `web`); `movable` (any body) | 201 `{status: attached, name, movable}` | 400 `invalid_source`; 409 `exists` |
|
|
519
|
-
| `POST /api/sessions/:id/context/:name/push` | owner | `text`, `summary`, `wake`, `hint` (a source's JSON output, checked the same way) | 200 `{status: pushed, name, before, revision, changed}` | 404 `not_found`; 409 `not_push`; 410 `context_continued` (`next_id`); 400 `invalid_text` |
|
|
519
|
+
| `POST /api/sessions/:id/context/:name/push` | owner | `text`, `summary`, `wake`, `hint` (a source's JSON output, checked the same way) | 200 `{status: pushed, name, before, revision, changed}` | 404 `not_found`; 409 `not_push`; 410 `context_continued` (`next_id`, `in_flight` while its continue runs); 423 `context_busy` (another change holds its transition lock); 400 `invalid_text` |
|
|
520
520
|
| `GET /api/sessions/:id/peers` | owner | | 200 `{peers: [{name, label, paired_at, from, address, can_send, messages, exchanges}]}`: one row per mailbox folder, its newest 20 messages with their receipts and `words`, last 20 joined exchanges, newest first; no text; files only ([internals/peers.md](internals/peers.md)) | 404 `not_found` |
|
|
521
521
|
| `GET /api/sessions/:id/peers/:name/messages/:serial` | owner | | 200 the message (its text) and its receipt | 404 `no_message`; 400 `invalid_peer` |
|
|
522
522
|
| `DELETE /api/sessions/:id/peers/:name` | owner | | 200 `{unpaired}`: the pairing ends, its messages stay | 400 `invalid_peer` |
|
|
523
|
-
| `POST /api/sessions/:id/peers/:name/pair`, `…/say` | owner | pair: `address`, `from`; say: `text`, `summary`, `wake`, `re`, `wait` (≤ 30: the server waits for the receipt) | pair 200 `{status: paired, link}`; say 200 `PeerSay` and its `line` | 409 refused (`continued` + `next_id
|
|
523
|
+
| `POST /api/sessions/:id/peers/:name/pair`, `…/say` | owner | pair: `address`, `from`; say: `text`, `summary`, `wake`, `re`, `wait` (≤ 30: the server waits for the receipt) | pair 200 `{status: paired, link}`; say 200 `PeerSay` and its `line` | 409 refused (`continued` + `next_id` and `in_flight` while its continue runs, `busy` (a say adds `detail`), `old_worker`, …, the same shape); 400 bad name, text or wait |
|
|
524
524
|
| `DELETE /api/sessions/:id/context/:name?own=1` | owner | | 200 `{status: detached}`: the session's own only | 409 `project_source` (chi context rm's words); 404 |
|
|
525
525
|
| `POST /api/sessions/:id/stop` | owner | `wait?` (seconds, capped at `SessionManager::STOP_WAIT`, 10: `chi --remote NAME sessions stop` sends it) | 200 `{status: stopped, session_id, released}`: `released`, whether the worker let go within the wait (without one `STOP_WAIT_SECONDS`, 2 s: the page's Stop) | 409 `owned_by_tui` |
|
|
526
526
|
| `DELETE /api/sessions/:id?force=` | owner | `force=true` stops a live worker first (the page sends it) | as before | 409 `worker_running` without it |
|
|
@@ -551,10 +551,11 @@ past its deadline) is sent once more, as `SessionAccess::Local#answer` does, and
|
|
|
551
551
|
|
|
552
552
|
A refusal an exception raises carries, next to `error` and `detail` (the page's words), `message` (the exception's own,
|
|
553
553
|
verbatim) and the fields its class is built from, so a remote client raises the same class with the same text:
|
|
554
|
-
`owned_by_tui` (`session_id`), `worker_running`/`still_stopping` (`DeleteRefused`: `session_id`, `reason`), `busy`/
|
|
555
|
-
`scratch` (`ArchiveRefused`: `session_id`, `reason`, `busy_id`), a
|
|
556
|
-
`
|
|
557
|
-
(`
|
|
554
|
+
`owned_by_tui` (`session_id`), `worker_running`/`still_stopping`/`transition_held` (`DeleteRefused`: `session_id`, `reason`), `busy`/
|
|
555
|
+
`scratch` (`ArchiveRefused`: `session_id`, `reason`, `busy_id`; reason `transition_held`'s `message` names the holder), a stop's
|
|
556
|
+
`stop_held` (`SessionTransition::Busy`: `session_id`, `kind`, `successor_id`), a restart's `held`/`not_running`/`unsupported`/
|
|
557
|
+
`failed` (`RestartRefused`: `session_id`, `reason`, `version`), a continue's `continued`/`open_children`/`folder_gone`/`transition_busy`
|
|
558
|
+
(`SessionContinue::Refused`: `session_id`, `reason`, `ids`; `transition_busy`'s `message` names the holder) and `ambiguous_id` (`Session::AmbiguousId`: `ids`).
|
|
558
559
|
A session an id names none of is `404 not_found` with `Session::NotFound`'s words (`no session X`, `#session_not_found`):
|
|
559
560
|
every lookup goes through `Session.resolve!` (an id or a unique prefix), and every surface shows that one message.
|
|
560
561
|
|
data/docs/cli.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
- `chi context <add|push|ls|show|refresh|rm|mute|unmute> …` — attach live external text to sessions (a command chi runs every so often, or text pushed in); the model gets a short note when it changes and reads it with `context_read`; `chi context add <URL>` attaches a GitHub PR with the github-pr bundle; `chi context push NAME -m TEXT` (the long form is `--message TEXT`) gives a `--push` source its new text, read from stdin when no `-m` is given (see [Attached context](context.md))
|
|
25
25
|
- `chi peer pair|unpair|say|ls …` — a peer agent's side of a session (a Claude Code or Codex session paired with it; see [Peers](peers.md)): `pair NAME ID [--address ADDR] [--from TEXT]` pairs (refused for a continued session, naming its next id, and for a live worker older than the mailbox: restart it), `unpair NAME ID` ends the pairing (its messages stay), `say NAME ID (--wake|--nowake) [--summary TEXT] [--re REF] [-m TEXT] [--wait SECONDS]` leaves a message and prints what chi did with it (`#12 received · woke chi`, `held: … · waits for the user's next message`, `noted`, or why it can't say yet), `ls ID [--format json]` the session's peers, their messages and receipts. A refusal exits 1 (nothing written), a usage error 2; `--remote` runs it through that machine's chi web, which waits for the say
|
|
26
26
|
- `chi context report [--days N]` — the candidate judge's counts from `context_candidates.jsonl`: candidates proposed, mentioned, attached or declined by you; the judge's asks; what it would attach per threshold, and how that agrees with what you did (this machine only; see [The log and the report](context.md#the-log-and-the-report))
|
|
27
|
-
- `chi send [-m TEXT] [--image PATH]... [--cut | --queue] [--as NAME] (ID|PREFIX)...` — send a message to sessions as if typed there (from an agent, as that agent: `--as NAME` or its marker, see [An agent's messages](sub-agent.md#an-agents-messages-driver-and-visitor); `--new --driver NAME` names a new session's driver): a turn starts (or a running one takes it at its next step; `--cut` asks it to cut long thinking for it; `--queue` runs it as a turn of its own after the running one, and `--queue --wait` waits for that turn's own answer); piped stdin goes above `-m` as quoted context, and `--image` attaches images (see [Sessions: Sending a message](sessions.md#sending-a-message)); to a session that was continued it goes to its chain's newest link (`3f9a1c2e → 7b2d41aa (continued) sent`; the old link stays archived; one being continued right now waits up to 10 s for its new link, then `refused: being continued as 7b2d41aa
|
|
27
|
+
- `chi send [-m TEXT] [--image PATH]... [--cut | --queue] [--as NAME] (ID|PREFIX)...` — send a message to sessions as if typed there (from an agent, as that agent: `--as NAME` or its marker, see [An agent's messages](sub-agent.md#an-agents-messages-driver-and-visitor); `--new --driver NAME` names a new session's driver): a turn starts (or a running one takes it at its next step; `--cut` asks it to cut long thinking for it; `--queue` runs it as a turn of its own after the running one, and `--queue --wait` waits for that turn's own answer); piped stdin goes above `-m` as quoted context, and `--image` attaches images (see [Sessions: Sending a message](sessions.md#sending-a-message)); to a session that was continued it goes to its chain's newest link (`3f9a1c2e → 7b2d41aa (continued) sent`; the old link stays archived; one being continued right now waits up to 10 s for its new link, then `refused: session 3f9a1c2e is being continued as 7b2d41aa-…; send again in a moment`), so a chain's first id is a stable address; `--new` starts a session with it instead (`--new --continues ID|last:ID` the next link of that session's chain, see [Session chains](sessions.md#session-chains)), and `--wait` prints the answer (`--wait ID` with no message waits for the next reply without sending — to an idle session whose last turn already ended, that ended turn's reply or end comes back; `--wait --turn T ID` with no message waits for exactly turn T, whether running, queued or last ended; `--format json` includes its `turn_id` when known, for waiting again after exit 3 or 4; exit 3 a question waits, its options on stderr; exit 4 `--timeout` passed with the turn still running; see [Starting a session](sessions.md#starting-a-session))
|
|
28
28
|
- `chi answer ID --question QID (--option N|LABEL)... [--text T] [--timeout S] [--format json]` (or `--dismiss`) — answer the question a session waits on (the one `chi send --wait` exited 3 with), then wait and print what comes next as `chi send --wait` does: the reply (0), the next question (3), still running after `--timeout` (4). `--option` is 1-based or the label, repeated on a multi-select question; `--text` is free text, or a Deny's reason; `--dismiss` leaves it unanswered and the model finishes its reply. A question no longer open (the web answered first) isn't answered again: it waits for that turn's reply. An option the question doesn't offer exits 2; a worker that is gone exits 1 (`send the task again: chi send --wait -m "…" ID`). What a parent may pick follows `guardrails.parent_answers`, or the session's own `parent_answers` when stricter (`soft`, the default: a deny, a plain answer, Continue and "Allow once"; `standard`: no allow; `hard`: no Continue either), never a wider scope or an allow on chi's own config; a refused pick exits 1 with what to answer instead (a convention, not a security boundary; see [Guardrails](guardrails.md#answers-from-a-parent-agent))
|
|
29
29
|
- `chi schedule <add|edit|list|show|tick|run-now|enable|disable|cancel>` — durable schedules on this machine: a prompt with a clock that fires out of no worker (cron, systemd, or chi web's hub with `schedule.auto_tick`), as the next link of a session's chain or as a turn in the session itself (see [Scheduling](scheduling.md) and [Durable schedules](#durable-schedules-chi-schedule)). A usage error exits 2, an unknown session or schedule 1; `chi --remote X schedule list` exits 2
|
|
30
30
|
- `chi remote add NAME URL [--token-file F | --token-stdin]`, `chi remote ls`, `chi remote rm NAME` — the other machines whose chi web the session commands reach with `--remote NAME` (see [Remote sessions](#remote-sessions))
|
|
@@ -457,7 +457,7 @@ chi schedule add --continues 3f9a1c2e --every 30m --mode same -m "Check the buil
|
|
|
457
457
|
|
|
458
458
|
chi schedule list # id name mode recurrence next due target [skips 3 of 12 (≈1 h at a 5 min tick)]
|
|
459
459
|
chi schedule list --all --format json # the disabled ones and the fired one-offs too
|
|
460
|
-
chi schedule show 4b7e9a # the entry in full: anchor, head, prompt, counters, its last 20 outcomes
|
|
460
|
+
chi schedule show 4b7e9a # the entry in full: anchor, head, prompt, counters, where its prune waits, its last 20 outcomes
|
|
461
461
|
chi schedule tick # fire everything due; quiet when nothing is
|
|
462
462
|
chi schedule tick --dry-run # print what would fire, change nothing
|
|
463
463
|
chi schedule run-now 4b7e9a # fire it now, whatever its next_due says
|
|
@@ -764,7 +764,10 @@ note or image) is deleted as its worker exits, and `/exit` says so; set
|
|
|
764
764
|
[Sessions](sessions.md).
|
|
765
765
|
|
|
766
766
|
`chi sessions stop ID...` stops each session's worker and waits for it to exit, so
|
|
767
|
-
a `chi --resume ID` after it starts a fresh one.
|
|
767
|
+
a `chi --resume ID` after it starts a fresh one. While another change holds the
|
|
768
|
+
session (a continue, a delete, an archive) for longer than 10 s, the stop is
|
|
769
|
+
refused in its words ("session ab12cd34 is being deleted; try again in a
|
|
770
|
+
moment") and that id exits 1. A worker still running an
|
|
768
771
|
older chi (from before an upgrade) takes turns, but not commands, or not the
|
|
769
772
|
ones newer than it (`/llm-context`, `--llm-context` on `--attach`); the attached
|
|
770
773
|
terminal and the Web UI say so, with that restart line.
|
data/docs/context.md
CHANGED
|
@@ -331,9 +331,16 @@ link's id (`chi context push` exits 1; chi web answers 410
|
|
|
331
331
|
`context_continued`):
|
|
332
332
|
|
|
333
333
|
```
|
|
334
|
-
chi context push: 3f2a9c1e was continued as 7b1d…: notes stays with the session it was attached to; attach it to 7b1d… (or pair again with 7b1d…) and push there
|
|
334
|
+
chi context push: session 3f2a9c1e was continued as 7b1d…: notes stays with the session it was attached to; attach it to 7b1d… (or pair again with 7b1d…) and push there
|
|
335
335
|
```
|
|
336
336
|
|
|
337
|
+
A session being continued right now (its new link not saved yet) is refused the same way, `is being continued as`
|
|
338
|
+
and `… push there in a moment`; one busy with another change (its transition lock held) is refused with `chi context
|
|
339
|
+
push: session 3f2a9c1e is busy with another change; try again in a moment` (chi web answers 423 `context_busy`).
|
|
340
|
+
`chi context add` and `chi context rm` of a session's own source (and the page's attach and ×) are refused the same
|
|
341
|
+
way while a transition holds the session (a continue copies its sources to the new link): nothing changes, try again
|
|
342
|
+
in a moment.
|
|
343
|
+
|
|
337
344
|
An archived session that nobody continued takes pushes as before; a schedule's anchor whose successor a prune deleted counts as continued by the schedule's head ([sessions.md](sessions.md), *Session chains* → Which link).
|
|
338
345
|
|
|
339
346
|
### Peers and a continue
|
|
@@ -207,7 +207,9 @@ second note; `words` is the few words `chi send --new --continues` prints; `to_h
|
|
|
207
207
|
[peers.md](peers.md), A continue.)
|
|
208
208
|
|
|
209
209
|
The refusal side: a push into a session that has been continued is refused with the next link's id
|
|
210
|
-
(`context_continued`, chi web 410, `chi context push` exit 1
|
|
210
|
+
(`context_continued`, chi web 410, `chi context push` exit 1; `in_flight` when a continue holding its transition lock
|
|
211
|
+
names it), or busy while another change holds that lock (423 `context_busy`); the check and the write run under a
|
|
212
|
+
shared hold of it (`SessionAccess::Local#context_push`). From `SessionAccess` (`session_access.rb`) and chi web's push route (`web/session_access_routes.rb`).
|
|
211
213
|
|
|
212
214
|
## Gates and config
|
|
213
215
|
|
data/docs/internals/peers.md
CHANGED
|
@@ -56,14 +56,26 @@ which posts `…/peers/NAME/say` with its `wait`: chi web waits, and its read ti
|
|
|
56
56
|
1. Refused before anything is written: no session, continued (with the next id), no `link.json`, a live worker
|
|
57
57
|
without the `peer_mail` Bridge feature (`WorkerLink.live_features`, read only), `UNTAKEN_MAX` (200) untaken
|
|
58
58
|
messages or noted receipts.
|
|
59
|
-
2.
|
|
59
|
+
2. Under a shared hold of the session's transition lock (`SessionTransition.shared`, `Local#moved_on`), the
|
|
60
|
+
continued check again, then the delivery (step 3): a continue holding the lock (from after its recap through
|
|
61
|
+
`PeerContinue`'s carry) refuses the say `:continued` naming its new link (`SessionChain::Successor.of` with
|
|
62
|
+
`in_flight: true`; the line `this session is being continued as <id>: say it there in a moment`, `in_flight`
|
|
63
|
+
on the wire), or `:busy` (`SessionTransition::Busy`'s words) when the holder names none. So a say never lands
|
|
64
|
+
in a mailbox the carry already read (N1). The feature probe before and the receipt wait after stay outside the
|
|
65
|
+
hold; the delivery's worker start (`resume_session`, a spawn) is inside it.
|
|
66
|
+
3. `SessionInbox.deliver(:peer)` (`WakePolicy::ROWS[:peer]`, the push row; `START_EVENTS[:peer] =
|
|
60
67
|
:peer_woke_session`): a session gone or being deleted refuses before its block writes. Inside the block:
|
|
61
68
|
the lock, the serial, the write, the trim. The block's "asks for a worker" is the message's own `wake`: no
|
|
62
69
|
`context.wake`, no 10-minute window.
|
|
63
|
-
|
|
70
|
+
4. The line (`PeerSay`): what the say saw at once (a running turn, a stopped or archived session, a one-turn run,
|
|
64
71
|
a failed start), else a receipt read every 250 ms within the wait, then the peer's other held receipts.
|
|
65
72
|
|
|
66
|
-
`chi peer pair` makes the old-worker and continued checks too, with the same sentences (`PeerPaired`)
|
|
73
|
+
`chi peer pair` makes the old-worker and continued checks too, with the same sentences (`PeerPaired`), and writes
|
|
74
|
+
`link.json` under the same shared hold (`:continued` in flight, `:busy`). A context push into the session's own
|
|
75
|
+
source does too (`Local#context_push`: 410 `context_continued` with `in_flight`, 423 `context_busy`). The continued
|
|
76
|
+
words are `SessionChain::Continued`'s, one wording for every refusal of a continued link ("this session" in a
|
|
77
|
+
peer's line: the installed skills look for `this session was continued as <id>`). Wire: an older chi `--remote`
|
|
78
|
+
reads a busy say or pair as a refusal with its detail, a busy push as `answered 423 context_busy: …`.
|
|
67
79
|
|
|
68
80
|
## The worker's mail path
|
|
69
81
|
|
|
@@ -193,7 +193,7 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
|
|
|
193
193
|
A per-method mapping covers the rest (`Remote#deliver_turn`, `#note`, `#context_push`, `#context_remove`,
|
|
194
194
|
`#bridge_reply` for answer/dismiss: chi web's 503 `not_live` or 404 `not_found` → nil, i.e. no worker; 504 → the
|
|
195
195
|
Bridge's 408; 501 → its 404). `#context_push` maps 409 to `:not_push` and 410 `context_continued` (a continued
|
|
196
|
-
session, its `next_id`) to `:continued`: a new refusal there gets a status and code of its own, as an older client
|
|
196
|
+
session, its `next_id`, `in_flight`) to `:continued`, and 423 `context_busy` to `:busy`: a new refusal there gets a status and code of its own, as an older client
|
|
197
197
|
reads every 409 as `not_push` and `continued` as a continue's refusal. `#context_add` sends `movable` and reports it
|
|
198
198
|
dropped when the 201 doesn't echo it (an older chi web; `chi context add` warns). Anything unmapped becomes `RemoteFailed` "remote NAME (URL) answered STATUS code:
|
|
199
199
|
message".
|
|
@@ -234,7 +234,7 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
|
|
|
234
234
|
(`force` from `req.GET`, no body read) and declared before the plain `/api/sessions/:id` rows. The plain delete
|
|
235
235
|
needs no feature: an older chi web deletes the link plainly (no revive, no undo) and its 200 has no
|
|
236
236
|
`unarchived`/`moved_back` (read as `[]`). The delete refusals reach the CLI with their own reason and message
|
|
237
|
-
(`continuing`, `delegate_unmovable`, `scheduled`, `chain_scheduled`, `worker_running`, `still_stopping`:
|
|
237
|
+
(`continuing`, `transition_held`, `delegate_unmovable`, `scheduled`, `chain_scheduled`, `worker_running`, `still_stopping`:
|
|
238
238
|
`Remote#raise_refusal` raises `DeleteRefused` with `ids` and `schedule_id`).
|
|
239
239
|
- **A route that answers more.** `GET /api/sessions/:id/delete_plan` answering for every session (`{chained: false,
|
|
240
240
|
session_id, link}` for one in no chain, and a file-less folder), together with a plain delete that takes the
|
|
@@ -19,9 +19,9 @@ SessionManager boundaries are in [Architecture](../architecture.md) and [Engine
|
|
|
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 mark and TERM (kind `stop`, `STOP_LOCK_WAIT` 10 s; 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,7 +136,10 @@ 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
|
|
@@ -149,9 +161,11 @@ of the state), not what WakePolicy does; the literal columns and `SHOWN` are gol
|
|
|
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,196 @@ 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:)` takes each id's lock in sorted order, creating a missing folder;
|
|
184
|
+
`deadline: nil` blocks (no caller since the continue took a deadline), seconds retry until then (`0`: one try)
|
|
185
|
+
and raise `SessionTransition::Busy`, which owns its refusal text and names the id. Ids taken before a busy one are
|
|
186
|
+
let go. While it holds a lock it writes its `kind` into the file (cleared on release, never from a lock another
|
|
187
|
+
holds; `try_exclusive` too).
|
|
188
|
+
- `holder(id, state_dir:)` is that kind (`:continue`, `:delete`), read only behind a failed shared try: a shared
|
|
189
|
+
holder (a send), an older chi's continue, a raw flock and a crash's leftover name none. `Busy.held(id, state_dir:)`
|
|
190
|
+
is the one place that says who holds a lock: a delete is "being deleted" whatever else is on disk; else a continue
|
|
191
|
+
in flight (`ContinueIntent.in_flight`) is "being continued as <new id>" (`SessionChain::Continued`'s words), a
|
|
192
|
+
continue before its intent "being continued", anything else "busy with another change" (each "; try again in a
|
|
193
|
+
moment"). A stop is "being stopped" and an archive "being archived", said as a delete is: a non-continue holder
|
|
194
|
+
(`other_than_continue?`) names no new link, and `in_flight` reads no continue under it, whatever intent a crashed
|
|
195
|
+
continue left. `exclusive`'s own Busy, the seats' busy refusal (`deliver_turn`), the continue's `transition_busy`
|
|
196
|
+
(its detail, which `--remote` reads back), `ContextSources.changing`, `Participants.invite`, the delete's refusal
|
|
197
|
+
(`DeleteRefused.held`) and the delete preview take their words from it; a delete holding the lock makes the seats
|
|
198
|
+
name no successor (`Hold.under`). The peer say/pair and the context push answer a status, `:busy`, whose words
|
|
199
|
+
are the plain ones.
|
|
200
|
+
- `try_exclusive(id, …)` is one try that creates no folder, crash repair's (`repair_intent`): a lock this thread
|
|
201
|
+
holds counts as taken, so a repair reached inside a continue never undoes it.
|
|
202
|
+
- `shared(id, state_dir:)` is a non-blocking shared hold (an invalid id is `false`; the lock file is created, the
|
|
203
|
+
folder only for a session whose file is there: a deleted session's folder is never made again, nothing is held and
|
|
204
|
+
the caller's own gone refusal follows; a lock file it made for a session gone by the block's end is taken back),
|
|
205
|
+
around every arrival's check and write (the seats, below), a peer say's, a peer pair's and a context push's
|
|
206
|
+
continued check and write (`SessionAccess::Local#moved_on`), a context add or remove (`ContextSources.changing`),
|
|
207
|
+
and an invite (`Participants.invite`). A caller that can't write the session folder
|
|
208
|
+
(a peer's chi behind the mailbox door) holds an existing lock file read-only, and holds nothing when there is none
|
|
209
|
+
(no transition holds a file that isn't there; one starting after it is not held off).
|
|
210
|
+
- `held?(id, state_dir:)` is a kernel probe (`in_flight`, `DeletePreview`, `holder`): it creates nothing and ignores the
|
|
211
|
+
registry, so it answers the same inside this thread's own hold.
|
|
212
|
+
- `forget(id, state_dir:)` takes back the lock file `exclusive` left for a session with no session file (one try
|
|
213
|
+
EX|NB; held, or this thread's, it stays) and its folder when that empties it.
|
|
214
|
+
|
|
215
|
+
**Order:** transition locks (several ids sorted) before any `owner.lock`. A taker that holds an `owner.lock` (a worker:
|
|
216
|
+
a delegate follow-up, an ask, a plugin's send, a ring, its own objectives note) only ever takes a transition lock
|
|
217
|
+
non-blocking: shared, or, for a stop of its delegates (`HoldStop#stop_delegates`, `Plugin::Sessions#stop`:
|
|
218
|
+
`stop_session(lock_wait: 0)`), exclusive in one try; so no owner-then-transition path waits. **Token per thread:** an exclusive hold is
|
|
219
|
+
the current thread's (`Thread#thread_variable_*`, not per process: chi web is multi-threaded, and not fiber-local);
|
|
220
|
+
that thread passes through `exclusive` and `shared` of a held id without touching the file (a second flock on the
|
|
221
|
+
held descriptor, or a dup, would convert it). Work handed to another thread doesn't carry the hold: it takes it again
|
|
222
|
+
or is refused. Before the registry, a shared hold inside a continue's own lock was refused; nothing a continue runs
|
|
223
|
+
under its lock takes one of its own id or reaches `follow_guard`, `Delete.link` or `Delete.chain`
|
|
224
|
+
(`spec/session_continue_spec.rb` records any), but the undo's ring wake (`wake_for_rings` → `wake_for_report`), whose
|
|
225
|
+
shared hold passes through on the token by design. **No fork while held:** a forked child keeps the flock; workers
|
|
226
|
+
start through `Process.spawn`, whose descriptors are close-on-exec.
|
|
227
|
+
|
|
228
|
+
**A continue's hold** (`SessionContinue.run` → `continue_once`, `spec/session_continue_spec.rb` "the transition
|
|
229
|
+
lock"). Unlocked: the refusals known before anything changes (`check!`, `archivable!`) and the recap wait (up to
|
|
230
|
+
`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
|
|
231
|
+
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
|
|
232
|
+
link is loaded and `check!`ed again (continued meanwhile → `Refused :continued`; deleted → not found; the delegate
|
|
233
|
+
plan made again), then the intent, the archive (`archive_session` → `stop_session`, nested), the new link's spawn and
|
|
234
|
+
carry (notes, peers, context, objectives, `ChildMove` notes and rings), or the undo (`return_rings`,
|
|
235
|
+
`NoteMove.give_back`, unarchive, `wake_for_rings` → `wake_for_report` → `resume_session`, `discard_failed_link`'s
|
|
236
|
+
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
|
|
237
|
+
exclusive of either id passes through, so no step refuses itself (`exclusive` skips held ids). Busy: a plain id is
|
|
238
|
+
refused `:transition_busy` (`SessionTransition::Busy.held`'s words naming the holder, a 409 of that name from chi
|
|
239
|
+
web; a schedule's chain firing counts it a skip, `Schedules::SKIP_REASONS`); a `last:<id>` continue with tries left
|
|
240
|
+
resolves again and waits again, so a second firing of the same chain follows the first one's new link. Any sender's turn
|
|
241
|
+
that meets the hold is refused naming the successor from the intent (`follow_guard`, "Arrivals declare their hold"
|
|
242
|
+
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
|
|
243
|
+
(`:continued` with `in_flight`), or `:busy` in `SessionTransition::Busy`'s words when the holder names none. Who
|
|
244
|
+
continues a link is one answer, `SessionChain::Successor.of(id, state_dir:, in_flight:)` (`via` `:next`, `:anchor`
|
|
245
|
+
or `:in_flight`), and the refusal one wording, `SessionChain::Continued` ("session X was continued as Y", "is being
|
|
246
|
+
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
|
|
247
|
+
own session (`ChildMove.adopt`, `NoteMove.adoption`, its objectives notes) take no transition hold, and must not (they
|
|
248
|
+
would be refused by the continue's exclusive). The reserved folder (`exclusive` makes it) goes whatever way a continue
|
|
249
|
+
ends before the new link is saved, with any note left there given back to the previous link; crash repair drops a
|
|
250
|
+
crashed continue's the same way. `Schedules::FIRING_TIMEOUT` (70 s) covers the recap, a lock wait per try and the
|
|
251
|
+
archive.
|
|
252
|
+
|
|
253
|
+
### Deletes, the prune and retention
|
|
254
|
+
|
|
255
|
+
- **A user's delete** (`SessionChain::Delete.link` / `.chain`, from `delete_session` with the chain keywords and
|
|
256
|
+
`delete_chain`: the CLI, chi web, `/exit --delete`) takes `exclusive(ids, kind: :delete, deadline:)` of every
|
|
257
|
+
session it takes or brings back (a link: it, the previous link it would revive, its delegates that go; a chain:
|
|
258
|
+
every link and their delegates), only ids still on disk (a gone one's folder is never made again), sorted, within
|
|
259
|
+
`LOCK_WAIT` (10 s) from the start. The plan is made (a chain's checks run) again under them; ids it adds then (late)
|
|
260
|
+
are a nested `exclusive` with the time left (held ids pass through). The stop (`release_for_delete!` →
|
|
261
|
+
`stop_session`), the task stop, the owner locks (`locked`, kind deleting), the removal, the undo
|
|
262
|
+
(`undo_deleted_link`) and the revival all run under the token. A lock not taken in time is
|
|
263
|
+
`DeleteRefused.held(busy)`: `:continuing` when a continue holds it, else `:transition_held` (chi web's 409 of that
|
|
264
|
+
name, which `--remote` reads back as `DeleteRefused`), Busy's words either way. A continue holding one of the ids
|
|
265
|
+
when the delete looks refuses it at once (`:continuing`, no wait: its end would change what the delete takes), and a
|
|
266
|
+
link continued while the delete waited for the locks is refused `:continuing` naming the new link rather than
|
|
267
|
+
deleted as a middle link. `refuse_continuing:` no longer
|
|
268
|
+
changes anything inside: either keyword takes `Delete.link`, which always refuses a held lock.
|
|
269
|
+
- **The schedule prune** (`Schedules::PrunePart`) takes `exclusive([link, next link], kind: :delete, deadline: 0)` per
|
|
270
|
+
link, oldest first, and checks the link's hold (`prune_hold`: archived, a protector, a worker, an open descendant)
|
|
271
|
+
before and again under it. Busy or a hold stops the prune below the link: never skipped past. The entry records it
|
|
272
|
+
(`extra["prune_waiting"]`, `PrunePart.waiting`; `chi schedule list`/`show`), the log says `prune_waiting` once per
|
|
273
|
+
link, and every tick tries a waiting entry again (`prunes_due`). The deletes inside are plain (`delete_ids`).
|
|
274
|
+
- **The retention sweep** (`SessionRetention.apply`, `prune_orphan_dirs`) and **a leaving worker's delete**
|
|
275
|
+
(`WorkerBoot#discard_left_session`, `#delete_left_scratch`, after the worker let go of its owner lock) take
|
|
276
|
+
`exclusive([id], kind: :delete, deadline: 0)` around the removal: held → kept (the sweep's `kept`; the worker's
|
|
277
|
+
`kept_session` / `scratch_kept`), and a later sweep takes it.
|
|
278
|
+
- The automatic deletes inside a transition (a continue's `discard_failed_link`) and `delete_resolved` /
|
|
279
|
+
`remove_files` themselves take no transition lock: the callers above hold it, so a continue's undo never refuses
|
|
280
|
+
itself.
|
|
281
|
+
|
|
282
|
+
### Stops, archives and the ring wake
|
|
283
|
+
|
|
284
|
+
- **A stop** (`SessionManager.stop_session`) takes `exclusive([id], kind: :stop, deadline: lock_wait)`
|
|
285
|
+
(`STOP_LOCK_WAIT` 10 s) for the owner read, the stop marker, the reminders hand-off and the TERM/CONT; the turn
|
|
286
|
+
cancel before it (a Bridge call and up to `STOP_CANCEL_WAIT`) and the owner wait after it (`wait:`) run unheld. Only
|
|
287
|
+
a saved session's lock is taken (a gone one's folder is never made again; `Session.mark_stopped`'s not found
|
|
288
|
+
follows). A hold this thread has passes through: a continue's archive (`archive_session` → `stop_session`), its
|
|
289
|
+
`discard_failed_link`, a delete's `release_for_delete!`; a plain delete with a stop (no chain keywords, a scratch's
|
|
290
|
+
end: `delete_resolved` takes no transition lock) turns a held one into its own refusal (`stop_held` →
|
|
291
|
+
`DeleteRefused.held`). Not taken in time → `SessionTransition::Busy`,
|
|
292
|
+
nothing marked: chi web's 409 `stop_held` (`kind`, `successor_id`: `--remote` builds the same Busy), `chi sessions
|
|
293
|
+
stop` prints it and exits 1. A worker stopping its delegates (the exit ask's stop-all, a plugin's
|
|
294
|
+
`ctx.sessions.stop`) tries once (`lock_wait: 0`): it holds its own `owner.lock`; a held child is left running
|
|
295
|
+
(logged / the plugin's `Error`, Busy's words).
|
|
296
|
+
- **An archive** (`archive_session`) stops the tree's live workers first (each stop its own hold, as above), then
|
|
297
|
+
takes `exclusive(tree on disk, kind: :archive, deadline: ARCHIVE_LOCK_WAIT)` (10 s) for the background-task stop
|
|
298
|
+
and the archived markers; a delegate its stopping worker discarded gets no folder again. Inside a continue the
|
|
299
|
+
previous link passes through and its delegates are taken. A lock not taken in time, its own or a stop's, is
|
|
300
|
+
`ArchiveRefused.held` (`:transition_held`, Busy's words; chi web's 409 `busy` with that reason, `--remote` keeps the
|
|
301
|
+
words). Its checks (`archivable!`) come before any lock, as before.
|
|
302
|
+
- **A ring's wake** (`wake_for_report`: `SessionInbox.wake(:ring, hold: :shared)`, on the resolved link) holds the
|
|
303
|
+
lock shared across the decide and the resume, so a stop lands before the check or after the start (its marker then
|
|
304
|
+
stays and the new worker exits on it, or the TERM reaches it): never between them. A transition holding it now →
|
|
305
|
+
`:busy` (`:continued` with a continue's new link), the ring left on disk. The ring's own write and its first wake
|
|
306
|
+
(`ChildReports.ring` → `SessionInbox.deliver(:ring)`, a `:none` row, its start on another thread) hold none:
|
|
307
|
+
still open (Open windows).
|
|
308
|
+
- **A restart** stays outside the lock (D3): it spans two processes (the old worker's leave, the new one's spawn).
|
|
309
|
+
Open windows has its row.
|
|
310
|
+
|
|
311
|
+
### Arrivals declare their hold
|
|
312
|
+
|
|
313
|
+
Every `SessionInbox::WakePolicy::ROWS` row names `hold:` (a required keyword: a row without it doesn't load), pinned
|
|
314
|
+
by `spec/session_lifecycle/allowed_spec.rb`. The hold is taken once, in the three seats, by `SessionInbox::Hold.under`:
|
|
315
|
+
`Dispatch.deliver` (around the refusal check, the write and the wake), `Dispatch.wake` (around the wake) and
|
|
316
|
+
`SessionManager.deliver_turn` (`follow_guard`, around all of the delivery: the resume, the Bridge's wait and post, the
|
|
317
|
+
file and the second liveness check). Not in `resume_session` / `start_for_inbox`: a continue's undo reaches them on its
|
|
318
|
+
own token. A seat met by a held lock refuses, nothing written: a continue naming its new link (`Successor.in_flight`,
|
|
319
|
+
else a saved one) → `:continued` / 409 `link_continued` with `successor_id`; else `:busy` / 409 `transition_busy`
|
|
320
|
+
(`DeliverResult::BUSY`, `SessionTransition::Busy`'s words). chi send, an ask and the Exchange under them retry busy as
|
|
321
|
+
they follow a continue (`Exchange#relocate busy:`: the same link again, within `CONTINUING_WAIT`); a same-mode schedule
|
|
322
|
+
firing counts it a skip; the web composer, a delegate follow-up, a plugin's send and a participant's turn report it.
|
|
323
|
+
|
|
324
|
+
| Row / arrival | Hold | Why |
|
|
325
|
+
|---|---|---|
|
|
326
|
+
| 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. |
|
|
327
|
+
| 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. |
|
|
328
|
+
| 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. |
|
|
329
|
+
| 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. |
|
|
330
|
+
| 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. |
|
|
331
|
+
| 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`). |
|
|
332
|
+
| context push, peer say, peer pair | shared | Phase 1 (`Local#moved_on`); the say's delivery seat holds again (shared beside shared). |
|
|
333
|
+
| invite (`Participants.invite`) | shared | A continue archives the link and ends its grants; refused `Grants::Invalid` with Busy's words. |
|
|
334
|
+
| 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. |
|
|
335
|
+
| `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. |
|
|
336
|
+
| 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. |
|
|
337
|
+
|
|
338
|
+
The raw `SessionInbox.write_*` sites are pinned with their hold in `spec/session_lifecycle_writers_spec.rb`. An older
|
|
339
|
+
chi's (0.190.x) worker or chi web takes no hold: its arrivals go in as before, and the tolerance paths stay
|
|
340
|
+
(`archivable!` refusing queued/busy, `NoteMove`, `ChildMove`'s movers).
|
|
341
|
+
|
|
163
342
|
## Open windows
|
|
164
343
|
|
|
165
344
|
These are documented race boundaries, not promises of an atomic lifecycle transition:
|
|
166
345
|
|
|
167
346
|
| Window | Code comment / current behavior | Pin |
|
|
168
347
|
|---|---|---|
|
|
169
|
-
| A ring wake decides to start, then a stop lands before resume. | `SpawnPart#wake_for_report` (`session_manager/spawn.rb`)
|
|
170
|
-
|
|
|
348
|
+
| 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). |
|
|
349
|
+
| 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. |
|
|
350
|
+
| 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). |
|
|
351
|
+
| A stop's turn cancel and owner wait are unheld. | `stop_session` cancels a running turn (Bridge, up to `STOP_CANCEL_WAIT`) before it takes the lock and waits for the owner after it lets go: a send in either may go in (and a new worker start after the wait, as before). A stop refused busy after the cancel has ended that turn. | `spec/session_manager/lifecycle_spec.rb` "under the transition lock" (held for the mark and TERM, not the owner wait). |
|
|
352
|
+
| 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
353
|
| 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
354
|
| 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
355
|
| 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
356
|
| 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`).
|
|
357
|
+
| 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`). |
|
|
358
|
+
| 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). |
|
|
359
|
+
| 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. |
|
|
360
|
+
| 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. |
|
|
361
|
+
| 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. |
|
|
362
|
+
| 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. |
|
|
363
|
+
| 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). |
|
|
364
|
+
| 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). |
|
|
365
|
+
| 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). |
|
|
366
|
+
| 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
367
|
| 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
368
|
|
|
178
369
|
## Adding a transition
|
|
@@ -183,7 +374,17 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
|
|
|
183
374
|
3. Identify every decider that reads the fact and how it observes the change (lock probe, direct read, poll, or SSE).
|
|
184
375
|
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
376
|
sleep or a process-wide integration test.
|
|
186
|
-
5.
|
|
377
|
+
5. A new arrival (a `WakePolicy` row, a delivery outside the seats) declares its hold: `hold: :shared` (the seat
|
|
378
|
+
takes it) or `hold: :none` with its reason; a raw `SessionInbox.write_*` site is listed with its hold in
|
|
379
|
+
`spec/session_lifecycle_writers_spec.rb`; one outside the inbox that changes what a transition carries takes
|
|
380
|
+
`SessionTransition.shared` around its check and write (see "Arrivals declare their hold").
|
|
381
|
+
6. If the fact changes a state, update `SessionLifecycle::STATES`/`Reading.derive` and `CANONICAL`, then the
|
|
187
382
|
`ALLOWED` cells (the literal ones by hand; the delivery ones follow `WakePolicy::ROWS`) and the matrix's rows; a
|
|
188
383
|
decider that answers otherwise is a `KNOWN_DIFFERENCES` entry with its reason, never a silent cell change.
|
|
189
|
-
|
|
384
|
+
7. A new multi-step transition takes `SessionTransition.exclusive` with its own `kind` (add its words to
|
|
385
|
+
`Busy::WORDS` so `Busy.held` names it; any kind but `continue` names no new link), with a deadline, before any
|
|
386
|
+
`owner.lock`; an automatic one tries once (`deadline: 0`) and leaves the session for later, and so does one a
|
|
387
|
+
worker runs (it holds an `owner.lock`). A literal operation that takes the lock gets its `TAKES_LOCK` cell.
|
|
388
|
+
8. Recheck lock order, crash cleanup, and the existing file-format/compatibility specs before changing runtime behavior.
|
|
389
|
+
A transition that must exclude a continue or an arrival takes the transition lock through `SessionTransition`,
|
|
390
|
+
never its own flock of `continue.lock`.
|
data/docs/peers.md
CHANGED
|
@@ -56,7 +56,9 @@ lost: it is a note, and the user's next message lets chi read it. The skills say
|
|
|
56
56
|
`chi send` past it.
|
|
57
57
|
|
|
58
58
|
A say is refused, with nothing written, for: no such session; a session being deleted; a continued one (`this
|
|
59
|
-
session was continued as <id>: say it there`);
|
|
59
|
+
session was continued as <id>: say it there`); one being continued right now (`this session is being continued as
|
|
60
|
+
<id>: say it there in a moment`: its new link is not saved yet); one busy with another change (`this session is busy
|
|
61
|
+
with another change; try again in a moment`); not paired (`not paired: run the pair script`); an older worker
|
|
60
62
|
(`restart the session`); 200 messages chi hasn't read yet.
|
|
61
63
|
|
|
62
64
|
Through `--remote NAME` (or `CHI_REMOTE`) the remote's chi web does the say and the wait, and returns the line.
|
data/docs/plugins.md
CHANGED
|
@@ -1529,7 +1529,8 @@ ctx.sessions.stop(id) # one of this session's own children
|
|
|
1529
1529
|
- `send(id, text)` sends a user message to a session (an id or a unique
|
|
1530
1530
|
prefix); it runs as a turn, and an idle session is woken. A session its
|
|
1531
1531
|
owner stopped or archived is not: `Error` (`session_stopped` /
|
|
1532
|
-
`session_archived`), nothing sent; nor one being deleted (`session_deleting`)
|
|
1532
|
+
`session_archived`), nothing sent; nor one being deleted (`session_deleting`) or held by a transition right now
|
|
1533
|
+
(`link_continued`, `transition_busy`: try again in a moment). It waits up to
|
|
1533
1534
|
5 s for the session's worker, so call it from an anytime command or a
|
|
1534
1535
|
thread of your own, never from a tool or hook of a running turn. A
|
|
1535
1536
|
session a `--non-interactive` one-shot has can't take it.
|