samagotchi 0.201.0 → 0.202.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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -1
  3. data/docs/architecture.md +47 -7
  4. data/docs/cli.md +20 -1
  5. data/docs/configuration.md +2 -1
  6. data/docs/internals/bridge.md +4 -4
  7. data/docs/internals/engine.md +9 -6
  8. data/docs/internals/knowledge.md +26 -6
  9. data/docs/internals/objectives.md +2 -2
  10. data/docs/internals/pages.md +4 -2
  11. data/docs/internals/participants.md +1 -1
  12. data/docs/internals/peers.md +9 -7
  13. data/docs/internals/remote-sessions.md +6 -6
  14. data/docs/internals/session-lifecycle.md +37 -15
  15. data/docs/internals/web-frontend.md +18 -7
  16. data/docs/pages.md +6 -3
  17. data/docs/plugins.md +2 -2
  18. data/docs/scheduling.md +40 -12
  19. data/docs/sessions.md +48 -6
  20. data/docs/sub-agent.md +1 -2
  21. data/docs/testing.md +92 -8
  22. data/lib/samagotchi/answer_display.rb +3 -2
  23. data/lib/samagotchi/answer_tail.rb +4 -4
  24. data/lib/samagotchi/bridge/card_places.rb +5 -5
  25. data/lib/samagotchi/bridge/turn_accumulator.rb +5 -5
  26. data/lib/samagotchi/bridge/turn_drawings/synth.rb +5 -5
  27. data/lib/samagotchi/bridge/turn_drawings.rb +2 -2
  28. data/lib/samagotchi/bridge/turn_ranges.rb +15 -8
  29. data/lib/samagotchi/bridge.rb +5 -5
  30. data/lib/samagotchi/broadcast_command.rb +3 -3
  31. data/lib/samagotchi/bundle_command/try/trace.rb +18 -6
  32. data/lib/samagotchi/bundles/knowledge/embedder.rb +2 -0
  33. data/lib/samagotchi/bundles/knowledge/github.rb +19 -0
  34. data/lib/samagotchi/bundles/knowledge/manifest.yml +6 -6
  35. data/lib/samagotchi/bundles/knowledge/plugin.rb +26 -54
  36. data/lib/samagotchi/bundles/knowledge/refresh.rb +89 -14
  37. data/lib/samagotchi/bundles/knowledge/store.rb +36 -2
  38. data/lib/samagotchi/bundles/schedules/manifest.yml +2 -2
  39. data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +24 -3
  40. data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
  41. data/lib/samagotchi/bundles/system/manifest.yml +3 -3
  42. data/lib/samagotchi/bundles/system/skill_pages.md +1 -1
  43. data/lib/samagotchi/chi_invocation.rb +1 -1
  44. data/lib/samagotchi/child_move.rb +6 -3
  45. data/lib/samagotchi/child_reports.rb +3 -3
  46. data/lib/samagotchi/children_status.rb +4 -2
  47. data/lib/samagotchi/client_id.rb +2 -2
  48. data/lib/samagotchi/compat.rb +4 -6
  49. data/lib/samagotchi/config.rb +3 -0
  50. data/lib/samagotchi/context_note.rb +1 -1
  51. data/lib/samagotchi/continue_intent.rb +1 -1
  52. data/lib/samagotchi/continue_offer.rb +2 -2
  53. data/lib/samagotchi/continue_repair_backoff.rb +71 -0
  54. data/lib/samagotchi/delivery.rb +1 -4
  55. data/lib/samagotchi/engine/participants.rb +1 -1
  56. data/lib/samagotchi/engine/recap.rb +1 -1
  57. data/lib/samagotchi/engine/turn_end.rb +1 -1
  58. data/lib/samagotchi/grants.rb +2 -2
  59. data/lib/samagotchi/guardrail_wiring.rb +1 -1
  60. data/lib/samagotchi/guardrails/approval.rb +3 -3
  61. data/lib/samagotchi/guardrails/pair_boundary.rb +3 -3
  62. data/lib/samagotchi/guardrails/participant_refusal.rb +2 -2
  63. data/lib/samagotchi/idle_recap.rb +6 -6
  64. data/lib/samagotchi/kernel_loop.rb +1 -1
  65. data/lib/samagotchi/last_turn.rb +9 -6
  66. data/lib/samagotchi/llm/chat_loop.rb +5 -2
  67. data/lib/samagotchi/mcp_command.rb +2 -2
  68. data/lib/samagotchi/memory_usage.rb +7 -6
  69. data/lib/samagotchi/note_command.rb +1 -1
  70. data/lib/samagotchi/note_delivery.rb +5 -5
  71. data/lib/samagotchi/objectives_backing.rb +3 -3
  72. data/lib/samagotchi/objectives_record.rb +2 -2
  73. data/lib/samagotchi/objectives_track.rb +2 -2
  74. data/lib/samagotchi/owner_lock.rb +28 -2
  75. data/lib/samagotchi/owner_prompt.rb +3 -3
  76. data/lib/samagotchi/pages/runtime.rb +9 -4
  77. data/lib/samagotchi/participant_revise.rb +6 -6
  78. data/lib/samagotchi/peer_receipts.rb +11 -4
  79. data/lib/samagotchi/plugin/side_question.rb +1 -1
  80. data/lib/samagotchi/recap_place.rb +5 -5
  81. data/lib/samagotchi/reply_for.rb +3 -3
  82. data/lib/samagotchi/reply_wait/liveness.rb +2 -2
  83. data/lib/samagotchi/reply_wait/poll.rb +3 -3
  84. data/lib/samagotchi/schedule_command.rb +1 -1
  85. data/lib/samagotchi/schedule_display.rb +4 -3
  86. data/lib/samagotchi/schedules/busy_part.rb +29 -5
  87. data/lib/samagotchi/schedules/history_part.rb +47 -7
  88. data/lib/samagotchi/schedules/marks_part.rb +52 -29
  89. data/lib/samagotchi/schedules/notices_part.rb +31 -4
  90. data/lib/samagotchi/schedules/protection_part.rb +69 -11
  91. data/lib/samagotchi/schedules/prune_part.rb +3 -2
  92. data/lib/samagotchi/schedules.rb +37 -47
  93. data/lib/samagotchi/send_command.rb +12 -12
  94. data/lib/samagotchi/session.rb +71 -59
  95. data/lib/samagotchi/session_access/contract.rb +7 -0
  96. data/lib/samagotchi/session_access/exchange.rb +1 -1
  97. data/lib/samagotchi/session_access/local.rb +9 -9
  98. data/lib/samagotchi/session_access/remote.rb +20 -24
  99. data/lib/samagotchi/session_access.rb +1 -1
  100. data/lib/samagotchi/session_chain/delete.rb +15 -8
  101. data/lib/samagotchi/session_chain/delete_preview.rb +3 -3
  102. data/lib/samagotchi/session_chain/links.rb +18 -4
  103. data/lib/samagotchi/session_chain/successor.rb +1 -1
  104. data/lib/samagotchi/session_chain.rb +3 -3
  105. data/lib/samagotchi/session_continue.rb +83 -32
  106. data/lib/samagotchi/session_inbox.rb +6 -17
  107. data/lib/samagotchi/session_inbox_delivery.rb +36 -13
  108. data/lib/samagotchi/session_lifecycle/allowed.rb +5 -5
  109. data/lib/samagotchi/session_manager/delegate_rule.rb +2 -2
  110. data/lib/samagotchi/session_manager/delivery.rb +13 -38
  111. data/lib/samagotchi/session_manager/emptiness.rb +35 -15
  112. data/lib/samagotchi/session_manager/lifecycle.rb +3 -2
  113. data/lib/samagotchi/session_manager/listing.rb +35 -10
  114. data/lib/samagotchi/session_manager/removal.rb +16 -0
  115. data/lib/samagotchi/session_manager/spawn.rb +9 -6
  116. data/lib/samagotchi/session_manager.rb +6 -4
  117. data/lib/samagotchi/session_messages.rb +602 -0
  118. data/lib/samagotchi/session_metrics.rb +7 -4
  119. data/lib/samagotchi/session_participants.rb +4 -4
  120. data/lib/samagotchi/session_protection.rb +16 -2
  121. data/lib/samagotchi/session_retention.rb +26 -12
  122. data/lib/samagotchi/session_row.rb +1 -1
  123. data/lib/samagotchi/session_stats.rb +17 -8
  124. data/lib/samagotchi/session_stores.rb +5 -0
  125. data/lib/samagotchi/session_transition.rb +3 -2
  126. data/lib/samagotchi/sessions_command.rb +55 -3
  127. data/lib/samagotchi/steer.rb +16 -50
  128. data/lib/samagotchi/storage_migration.rb +234 -0
  129. data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
  130. data/lib/samagotchi/terminal_ui/formatting.rb +5 -5
  131. data/lib/samagotchi/terminal_ui/join_replay.rb +3 -3
  132. data/lib/samagotchi/terminal_ui/question_prompt.rb +2 -2
  133. data/lib/samagotchi/toolkit_report_command.rb +1 -1
  134. data/lib/samagotchi/tools/ask_session.rb +2 -2
  135. data/lib/samagotchi/tools/send_note.rb +1 -1
  136. data/lib/samagotchi/turn_context.rb +3 -3
  137. data/lib/samagotchi/turn_endings.rb +17 -0
  138. data/lib/samagotchi/turn_excerpts.rb +7 -4
  139. data/lib/samagotchi/turn_flow.rb +1 -1
  140. data/lib/samagotchi/turn_note.rb +30 -2
  141. data/lib/samagotchi/turn_origin.rb +7 -7
  142. data/lib/samagotchi/turn_outcome.rb +11 -0
  143. data/lib/samagotchi/turn_stages/verify_anchors.rb +4 -4
  144. data/lib/samagotchi/verify_fresh.rb +6 -6
  145. data/lib/samagotchi/verify_fresh_origin.rb +4 -4
  146. data/lib/samagotchi/version.rb +1 -1
  147. data/lib/samagotchi/web/app.rb +4 -3
  148. data/lib/samagotchi/web/last_ask.rb +2 -2
  149. data/lib/samagotchi/web/message_display.rb +12 -12
  150. data/lib/samagotchi/web/page_routes.rb +9 -3
  151. data/lib/samagotchi/web/participant_view.rb +4 -4
  152. data/lib/samagotchi/web/participants_admin.rb +1 -1
  153. data/lib/samagotchi/web/public/bubbles.js +1 -1
  154. data/lib/samagotchi/web/public/composer_fold.js +0 -3
  155. data/lib/samagotchi/web/public/composer_grip.js +0 -2
  156. data/lib/samagotchi/web/public/page_view.js +29 -4
  157. data/lib/samagotchi/web/public/participant_model.js +1 -1
  158. data/lib/samagotchi/web/public/peer_wait.js +2 -4
  159. data/lib/samagotchi/web/public/schedule_marks.js +2 -5
  160. data/lib/samagotchi/web/public/schedule_name.js +14 -0
  161. data/lib/samagotchi/web/public/session_actions.js +5 -0
  162. data/lib/samagotchi/web/public/start_page.js +1 -1
  163. data/lib/samagotchi/web/public/stop_sheet.js +2 -4
  164. data/lib/samagotchi/web/public/working_set_rail.js +0 -3
  165. data/lib/samagotchi/web/push/attention.rb +1 -1
  166. data/lib/samagotchi/web/session_create.rb +1 -1
  167. data/lib/samagotchi/web/session_hub.rb +68 -20
  168. data/lib/samagotchi/web/session_summary.rb +18 -14
  169. data/lib/samagotchi/web/verify_fresh_routes.rb +4 -4
  170. data/lib/samagotchi/worker/turn_drain.rb +158 -0
  171. data/lib/samagotchi/worker.rb +8 -144
  172. data/lib/samagotchi/worker_boot.rb +21 -5
  173. data/lib/samagotchi/worker_participant_gate.rb +5 -5
  174. data/lib/samagotchi/worker_presence.rb +24 -1
  175. metadata +6 -1
@@ -134,7 +134,7 @@ The routes: [thin-clients.md](../thin-clients.md); the MCP protocol: [mcp-server
134
134
  3. **Remote → HTTPTransport.** The first request on a `Remote` is preceded by `check_server!`, which sends
135
135
  `GET /api/info` and needs `app: "chi-web"` plus the `session_commands` feature. Next come
136
136
  `GET /api/sessions/resolve?id=ab12`, `GET /api/sessions/resolve?id=<full id>&head=1` (`{id, asked, via}`:
137
- `SessionInbox::Head.resolve(:send, …)` on the server, `via` `same`, `head` or `continuing`; an older chi web
137
+ `InboxDelivery::Head.resolve(:send, …)` on the server, `via` `same`, `head` or `continuing`; an older chi web
138
138
  ignores `head=1` and answers `{id}`, read as `same`, so the message goes to the id named as before; a participant's
139
139
  token never asks, and the participant branch of the route answers `{id}` alone) and
140
140
  `POST …/wait/prepare {busy: true, queue:}` (`Remote#busy`) on the id it answered, then
@@ -224,9 +224,10 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
224
224
  (`SessionAccessRoutes::FEATURE`, mirrored as `Remote::FEATURE` so chi web needn't be loaded). If it's missing,
225
225
  `RemoteTooOld` says "remote NAME runs chi X, too old for this command through --remote: update chi there (chi
226
226
  update)": no release number, which would be a guess before the release. A 404 counts as a missing route
227
- only when its detail starts with `not found: /` (the 404 from `serve_static`, for a path no route takes). A route's
228
- own 404 (no such session or source) stays a refusal. **Keep that rule:** a new route's 404 must never use the
229
- `not found: /…` wording.
227
+ by its `reason: "no_route"` (`SessionAccess::Contract::NO_ROUTE`, beside `error: "not_found"` and the words: the
228
+ 404 from `serve_static`, for a path no route takes); a chi web that sends no reason (0.201.0 and older) by its
229
+ detail starting with `not found: /`. A route's own 404 (no such session or source) stays a refusal. **Keep that
230
+ rule:** a new route's 404 must never carry the `no_route` reason nor use the `not found: /…` wording.
230
231
  - **Answers across versions.** The corpus's `wire/remote/` (`CompatRemote`, recorded at each release) pins the shape
231
232
  of chi web's answers to `Remote`: `spec/compat/remote_readers_spec.rb` reads the previous release's answers with
232
233
  today's `Remote` (exact values, so `head`'s `:same` fallback or a nil `SessionView` field fails) and sends its
@@ -314,8 +315,7 @@ with a "Machine-local" comment; the rest branch on `@access.remote?` (`SendComma
314
315
  - **`client_id` only tightens.** `handle_question_answer` (`Web::SessionControl`) forwards `client_id` only when it is `ClientId::CLI_ANSWER`
315
316
  and drops any other value, so a remote answer is held to the parent rules and can't pass for the user's own. On
316
317
  create and turn, a `cli:send` / `cli:answer` / `agent:` id adds checks (`ClientId.parent_line?`) and never removes
317
- any. An agent's id goes to a chi web without `agent_sender` in its `/api/info` features as `cli:send`
318
- (`Remote#sent_id`, compat shim agent_client_id), for a turn and a create.
318
+ any. An agent's id is sent unchanged to chi web for a turn and a create.
319
319
  - **A remote attach's `client_id`** (`tui:<pid>@<host>`, P4-D6) is forwarded as given on `/turn` and `/command`, as
320
320
  the page's is: the token is the owner. Only the cli ids (`cli:send`, `cli:answer`) add checks there; a parent
321
321
  agent driving the TUI from a pipe answers as `cli:answer`, held to that machine's `guardrails.parent_answers`.
@@ -15,13 +15,14 @@ SessionManager boundaries are in [Architecture](../architecture.md) and [Engine
15
15
  | Fact | Writer and removal | Cross-process readers and how they see change |
16
16
  |---|---|---|
17
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
+ | `messages-<gen>.jsonl` (a split session's conversation) | `Session#save` through `SessionMessages::Store`, the owner as for `<id>.json`: an append to the generation `<id>.json`'s `messages_log` names (cut to its committed `bytes` first), else a new generation (`File::EXCL`) then the metadata; `chi sessions migrate` converts an inline file under the session's transition lock (kind `migrate`) and its `owner.lock` (kind `migrating`), the generation synced (`SessionMessages.sync!`: `F_FULLFSYNC` on macOS, else `fsync`) before the metadata names it. A replaced or uncommitted generation is a stray a later save removes after `STRAY_GRACE` (60 s). Deletion removes it with the session directory. | Readers parse `<id>.json` and read exactly the committed bytes of the generation it names (`SessionMessages.parse`/`.load`); one gone since is read again from a fresh `<id>.json`, once, then fails closed. Every save renames `<id>.json`, so the hub's `[mtime, size]` key sees an append. |
18
19
  | `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
- | `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
+ | `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. Kind `migrating` is `chi sessions migrate` converting the file (`StorageMigration`, milliseconds): a delivery's decision after its write and a leaving worker's respawn read the presence once it is gone (`WorkerPresence.settled`, up to `OwnerLock::MIGRATING_WAIT` 5 s; still held then, `WakePolicy#decide` reads it as `:starting`), a worker taking the lock waits for it as long (`WorkerBoot#owner_lock_for`), so a resume reads it as no owner and spawns (`resume`, `claim_start`), a stop never signals it, and `WorkerLink` reads it as `Starting` (`booting`). Never refused as `deleting`. |
20
21
  | `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
22
  | 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
23
  | `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
24
  | `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` | `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
+ | `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`), `chi sessions migrate`'s conversion of a session tries it once (kind `migrate`, before its `owner.lock` held as `migrating`; `StorageMigration`), 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
26
  | `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
27
  | `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
28
  | 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. |
@@ -76,7 +77,7 @@ state. A cell is `:go`, `:wait` or the decider's own refusal reason; `SessionLif
76
77
  `:go`, `:wait` or `:refused` (resume's `live` and `starting` wait, restart's `fallback` goes).
77
78
 
78
79
  - **Delivery columns** (send, note, push, ring, fresh_verdict, leave, schedule, plugin, delegate, participant,
79
- agent, automatic) are generated at load from `SessionInbox::WakePolicy::ROWS`, unchanged: each row's `decide` on
80
+ agent, automatic) are generated at load from `InboxDelivery::WakePolicy::ROWS`, unchanged: each row's `decide` on
80
81
  `CANONICAL[state]` (a worker asked for, no scratch file), `:start`/`:live` as go, `:starting`/`:stopped`/
81
82
  `:archived`/`:none` as wait, `:gone`/`:owned`/`:deleting` as themselves. `:off` and `:scratch` are op-local.
82
83
  `deleting` refuses every kind: `WakePolicy#refusal` before the write (nothing written), `#decide` after it (a
@@ -105,7 +106,7 @@ state. A cell is `:go`, `:wait` or the decider's own refusal reason; `SessionLif
105
106
  scratch, saved status idle, no `input/`, no question or offer, not SIGSTOPped, features restart and activity, an idle
106
107
  worker with no streams. Absent's delete and schedule cells are unreachable (a gone session is refused first).
107
108
 
108
- Link resolution (`SessionInbox::Head.resolve`, `Schedules#target_of`) stays outside: the cells are the link's own.
109
+ Link resolution (`InboxDelivery::Head.resolve`, `Schedules#target_of`) stays outside: the cells are the link's own.
109
110
 
110
111
  The running-tasks check of a user's delete and archive (`SessionManager::RunningTasks`, `tasks_running`) is op-local,
111
112
  not an `ALLOWED` cell: it reads the transcript and each `task.json`, not the lifecycle's facts, and runs after the
@@ -145,7 +146,7 @@ Live, Starting, stuck, Leaving, Skew, an owner of unknown kind) × stop × start
145
146
  continue in flight on each archived no-owner row, and a start marked after the stop on each no-owner row with both
146
147
  (the order is a row fact: `StartingMarker.claim` takes over only a start at or before `stopped_at`), and four rows
147
148
  (idle, archived, stopped, a live worker's) with the transition lock held for real by another thread
148
- (`transitioning`): their deliveries go through the seats (`SessionInbox.deliver`, `deliver_turn`) and must answer
149
+ (`transitioning`): their deliveries go through the seats (`InboxDelivery.deliver`, `deliver_turn`) and must answer
149
150
  `TRANSITIONING`'s busy for a `:shared` row, the state's cell for a `:none` one. The owner lock's
150
151
  holder, `ContinueIntent.in_flight`, `Process.spawn`, TERM/CONT, the Bridge and the restart fallback are stubbed; no
151
152
  process starts. Each row checks that `SessionLifecycle.read` names the state its facts derive, then drives every
@@ -173,13 +174,33 @@ a user's delete holds them exclusively for its whole run, and the prune, the ret
173
174
  delete for each removal ("Deletes, the prune and retention"); a stop holds it exclusively for its mark and TERM, an
174
175
  archive for its task stop and markers, and a ring's wake shared across its check and resume ("Stops, archives and
175
176
  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
176
- `WorkerExitClaim`'s mutex. Session saves serialize through their per-session save lock. These locks protect separate
177
+ `WorkerExitClaim`'s mutex. Session saves serialize through their per-session save lock, and across Session objects
178
+ of one session in a process through `SessionMessages.locked` (per path). These locks protect separate
177
179
  facts; there is no global lifecycle lock or atomic snapshot across all markers.
178
180
 
181
+ A split session's messages file (docs/sessions.md, Messages file) repairs itself on its owner's next save: a torn or
182
+ uncommitted tail past the committed bytes is cut by the next append, a generation no `<id>.json` names (a crashed
183
+ rewrite's, a replaced one) is removed once older than `STRAY_GRACE`, and a first save's generation with no `<id>.json`
184
+ is an orphan folder the retention sweep prunes. A generation shorter than its committed bytes (power loss: nothing is
185
+ fsynced, as for `<id>.json`) fails closed as a corrupt file; the owner, if running, writes its messages into a new one.
186
+
179
187
  A worker that crashes exits 1 and is not respawned just because input is queued. A later delivery may start a new
180
188
  worker; under its owner lock, startup settles a turn checkpoint and stale running status rather than replaying the
181
189
  dead turn. Interrupted continue intents are repaired separately by session listing/the web hub or before another
182
- continue (`SessionContinue.repair_interrupted`), not by worker startup.
190
+ continue (`SessionContinue.repair_interrupted`), not by worker startup. A pass tries each intent's lock before it
191
+ reads anything: held (a continue runs), the intent is left unread; taken, it loads that one session and lists the
192
+ fleet only for an older intent's descendants (no `archived_ids`), once per pass. A non-system error in the undo (bad
193
+ data) sets the intent aside as `continue.json.bad` with `continue_repair_failed`, as a corrupt intent.
194
+
195
+ A `SystemCallError` in one intent's repair (the undo's marker write on a full disk or an unwritable folder, a read
196
+ refused, the lock file's open, the set-aside's rename) is never raised from `repair_interrupted`: the intent stays,
197
+ the pass goes on with the next one, and `ContinueRepairBackoff` (`continue_repair_backoff.rb`) leaves that intent alone, unread, for 60 s
198
+ after the first failure, doubling to 600 s. It lives in the process's memory, keyed by the intent's path (a CLI run
199
+ starts fresh; chi web's hub stops retrying each second); `continue_repair_deferred` (sid, error, msg, retry_in) is a
200
+ WARN once per intent and error class, DEBUG while it repeats, and a success or the intent gone forgets it. A continue
201
+ of a session whose own intent is still there under the lock is refused (`SessionContinue::Refused`, `:undo_pending`:
202
+ "an earlier continue of X hasn't been undone yet (Errno::ENOSPC); try again in a minute"), so the crashed continue's
203
+ `archived_ids` are never overwritten.
183
204
 
184
205
  ### The transition lock (`SessionTransition`)
185
206
 
@@ -202,7 +223,8 @@ continue, followed send and delete honour it.
202
223
  is the one place that says who holds a lock: a delete is "being deleted" whatever else is on disk; else a continue
203
224
  in flight (`ContinueIntent.in_flight`) is "being continued as <new id>" (`SessionChain::Continued`'s words), a
204
225
  continue before its intent "being continued", anything else "busy with another change" (each "; try again in a
205
- moment"). A stop is "being stopped" and an archive "being archived", said as a delete is: a non-continue holder
226
+ moment"). A stop is "being stopped", an archive "being archived" and a storage migration "being migrated" (not in
227
+ `Busy::TRANSITIONS`: a stop waits it out, it is one session's conversion), said as a delete is: a non-continue holder
206
228
  (`other_than_continue?`) names no new link, and `in_flight` reads no continue under it, whatever intent a crashed
207
229
  continue left. `exclusive`'s own Busy, the seats' busy refusal (`deliver_turn`), the continue's `transition_busy`
208
230
  (its detail, which `--remote` reads back), `ContextChange.under`, `Participants.invite`, the delete's refusal
@@ -233,7 +255,7 @@ continue, followed send and delete honour it.
233
255
  again in a moment" for a new link in flight, ": change it there" for a saved one) name nobody under a delete, a
234
256
  stop or an archive, on purpose, the peer say/pair, the context push and an invite (`Participants.invite`: ": invite
235
257
  there", "in a moment" in flight) name the saved successor. Every site that takes the lock shared across a check and a write uses it.
236
- - `held?(id, state_dir:)` is a kernel probe (`in_flight`, `DeletePreview`, `holder`): it creates nothing and ignores the
258
+ - `held?(id, state_dir:)` is a kernel probe (`in_flight`, `SessionChain::Delete::Preview`, `holder`): it creates nothing and ignores the
237
259
  registry, so it answers the same inside this thread's own hold.
238
260
  - `forget(id, state_dir:)` takes back the lock file `exclusive` left for a session with no session file (one try
239
261
  EX|NB; held, or this thread's, it stays) and its folder when that empties it.
@@ -334,19 +356,19 @@ archive.
334
356
  previous link passes through and its delegates are taken. A lock not taken in time, its own or a stop's, is
335
357
  `ArchiveRefused.held` (`:transition_held`, Busy's words; chi web's 409 `busy` with that reason, `--remote` keeps the
336
358
  words). Its checks (`archivable!`) come before any lock, as before.
337
- - **A ring's wake** (`wake_for_report`: `SessionInbox.wake(:ring, hold: :shared)`, on the resolved link) holds the
359
+ - **A ring's wake** (`wake_for_report`: `InboxDelivery.wake(:ring, hold: :shared)`, on the resolved link) holds the
338
360
  lock shared across the decide and the resume, so a stop lands before the check or after the start (its marker then
339
361
  stays and the new worker exits on it, or the TERM reaches it): never between them. A transition holding it now →
340
362
  `:busy` (`:continued` with a continue's new link), the ring left on disk. The ring's own write and its first wake
341
- (`ChildReports.ring` → `SessionInbox.deliver(:ring)`, a `:none` row, its start on another thread) hold none:
363
+ (`ChildReports.ring` → `InboxDelivery.deliver(:ring)`, a `:none` row, its start on another thread) hold none:
342
364
  still open (Open windows).
343
365
  - **A restart** stays outside the lock (D3): it spans two processes (the old worker's leave, the new one's spawn).
344
366
  Open windows has its row.
345
367
 
346
368
  ### Arrivals declare their hold
347
369
 
348
- Every `SessionInbox::WakePolicy::ROWS` row names `hold:` (a required keyword: a row without it doesn't load), pinned
349
- by `spec/session_lifecycle/allowed_spec.rb`. The hold is taken once, in the three seats, by `SessionInbox::Hold.under`:
370
+ Every `InboxDelivery::WakePolicy::ROWS` row names `hold:` (a required keyword: a row without it doesn't load), pinned
371
+ by `spec/session_lifecycle/allowed_spec.rb`. The hold is taken once, in the three seats, by `InboxDelivery::Hold.under`:
350
372
  `Dispatch.deliver` (around the refusal check, the write and the wake), `Dispatch.wake` (around the wake) and
351
373
  `SessionManager.deliver_turn` (`follow_guard`, around all of the delivery: the resume, the Bridge's wait and post, the
352
374
  file and the second liveness check). Not in `resume_session` / `start_for_inbox`: a continue's undo reaches them on its
@@ -382,7 +404,7 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
382
404
  | Window | Code comment / current behavior | Pin |
383
405
  |---|---|---|
384
406
  | 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). |
385
- | 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. |
407
+ | A ring's own delivery wakes the parent while a stop lands. | `ChildReports.ring` → `InboxDelivery.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. |
386
408
  | 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). |
387
409
  | 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). |
388
410
  | 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. |
@@ -391,7 +413,7 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
391
413
  | 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. |
392
414
  | 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). |
393
415
  | 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`). |
394
- | 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). |
416
+ | 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 `InboxDelivery.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). |
395
417
  | 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. |
396
418
  | 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. |
397
419
  | 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. |
@@ -36,7 +36,7 @@ the shim and refresh the baseline. `answer_fold.js` and `agent_rows.js` draw a d
36
36
  row (its element and words); `quiet_notes.js` supplies the notes row's words, and `agent_runs.js` owns the notes rows,
37
37
  reports and peer answers (The notes rows and the run line, below). `details_motion.js`,
38
38
  `turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
39
- `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `views.js` (the views by hash, in one place: All sessions at `#/sessions` opened, closed and left; a page at `#/p/NAME`, read before the session intent, `hashIntent` calling it `keep`: `body.page-view`, Back to where it was opened from (kept in the history entry's `history.state.from`, so Back and Forward keep it), the session's hash not written while a view owns the URL (`keepSessionHash`), a session picked leaving it; the Pages list at `#/pages` the same way, `body.pages-list`, and the pages pill pressed on either; the session's `#/s/<id>` written; a hash change applied and selected; app.js makes it after the lists and hands its functions lazily to what it made before), the page's modules `page_route.js`, `page_view.js`, `page_model.js`, `page_blocks.js`, `page_table.js`, `page_table_model.js`, `pages_model.js` (the page's one list of pages), `pages_list.js` (the Pages list at `#/pages`, read by `views.js` beside a page's hash), `pages_wiring.js` (`wirePages`: the pill, the list, the view and the links, one call in app.js), `page_links.js` and `page_params.js` (a page in chi web: [pages.md](pages.md#chi-web)), `worker_features.js`, `version_notices.js`, `owner_claim.js` (its `showPending` calls the injected `keepSessionHash`, following `views.js`'s rule not to write the session hash while a view owns the URL), `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js`, `peer_text.js`, `peer_row.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `peer_wait.js` (the chip of a peer
39
+ `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `stop_sheet.js` (The Stop sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `schedule_name.js` (a schedule's name — its title in quotes, else its short id — shared by the Stop sheet's schedules' line and `schedule_marks.js`), `hash_intent.js` (what the hash asks for: session, all, start or keep), `views.js` (the views by hash, in one place: All sessions at `#/sessions` opened, closed and left; a page at `#/p/NAME`, read before the session intent, `hashIntent` calling it `keep`: `body.page-view`, Back to where it was opened from (kept in the history entry's `history.state.from`, so Back and Forward keep it), the session's hash not written while a view owns the URL (`keepSessionHash`), a session picked leaving it; the Pages list at `#/pages` the same way, `body.pages-list`, and the pages pill pressed on either; the session's `#/s/<id>` written; a hash change applied and selected; app.js makes it after the lists and hands its functions lazily to what it made before), the page's modules `page_route.js`, `page_view.js`, `page_model.js`, `page_blocks.js`, `page_table.js`, `page_table_model.js`, `pages_model.js` (the page's one list of pages), `pages_list.js` (the Pages list at `#/pages`, read by `views.js` beside a page's hash), `pages_wiring.js` (`wirePages`: the pill, the list, the view and the links, one call in app.js), `page_links.js` and `page_params.js` (a page in chi web: [pages.md](pages.md#chi-web)), `worker_features.js`, `version_notices.js`, `owner_claim.js` (its `showPending` calls the injected `keepSessionHash`, following `views.js`'s rule not to write the session hash while a view owns the URL), `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js`, `peer_text.js`, `peer_row.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `peer_wait.js` (the chip of a peer
40
40
  the session waits for, its popover and Cancel: The peer exchange), `peer_chip_kind.js` (the peer chips as a kind of the context chips: The peer exchange), `plugin_chip.js` and `plugin_chip_kind.js` (a bundle's own chip, its card and buttons, and its kind: The peer exchange, the plugin chips), `context_groups.js` (a bundle's sources folded into one chip: its rows, chip and list, pure: The peer exchange, the source kind), `peer_mailbox_api.js` (the chip's message and Unpair calls), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them), `drafts.js` (the composer's drafts: The drafts, below), `draft_follow.js` (a continue made elsewhere: the drafts to hand over, pure), `draft_keys.js` (their storage keys, so `session_prefs.js` sweeps them without a new export), `served_ref.js`
41
41
  (`isServedRef`, which the stream's `generation_completed` reads, beside a `modelServed` already set, for a served
42
42
  model's `modelServed`), `answer_write.js` (the answer's live write onto its bubble, kept in its own module so a new `markdown_place.js` or `block_fix.js` importing it never waits on an old `answer_refs.js`) and the `objectives_*.js` modules are new modules for that reason, and so are `model_switch.js` (the "may /model run here"
@@ -64,10 +64,11 @@ their viewer (The viewer, below), their show and stream are filtered (`Web::Part
64
64
  | **`store.current`** (`session_state.js`: `emptySessionState` / `sessionStateFrom`; per field: `session_fields.js FIELDS`) | the open session's fields, about 40 (info bar, chips, verdicts, timing, worker, stream cursor) | `store.update` / `setStatus` from app.js, `stream_handlers.js`, `session_sync.js`, `session_view.js`, `send_turn.js` (`firstPreview`, `owner`), `session_actions.js` (`status`), `owner_verify.js` (`verdicts`, `verifyFresh`); `forgetSession`'s `replaceCurrent` (`session_view.js`). Two writers in place, on purpose (D8 in `FIELDS`): live_timing.js's `activeTurn`, verdict_fresh.js's running list | the store runs the field's redraws (`FIELDS[key].redraws`) |
65
65
  | **`store.sessions`** (the hub's projection) | every card | `store.update({sessions})` from app.js: `openSessionEvents` (`applySessionEvent`), `refresh` (the list fallback), `addCreatedSession`, `views.js applyView` (re-sorted), `replaceSelectedCard` (`setLiveStatus` through `setStatus`, `readTurnEnd`, `setUsedMemories`), the stream's close (`withoutWorker`); `session_actions.js` (`setSessions`) | the store: `lists` and `infoBar`. **Always a new array**; an entry is replaced, never changed in place. `followSelectedSession` copies the open one's owner and worker (`fieldsFromCard`) and, when not streaming, its status (`setStatus(…, "hub")`) into `store.current` |
66
66
  | **Factory closures**: the `create*` factories (popovers, panels, views) | each component's own state: open-for, busy, error, its own fetched list | the factory | an `onChange` hook back into app.js, or a getter the factory reads at draw time |
67
- | **The history DOM** | the conversation as drawn (a running turn's reason bubble, `.bubble.said`, is live only: see A turn opened in the history): which turn a bubble belongs to (`data-turn-id`, `data-answer-turn`), what opens a turn (`TURN_PROMPT`, `bubbles.js`: a prompt or a wake's note, the same turns `Steer.turn_opening?` counts for a card's `turns_since`), an opening's id for a card's and the saved recap's stamp (`data-turn-id` on a prompt, `data-opening-id` on a wake's note or `/continue no`'s reason line; `card_stamps.js` places a snapshot's card after the stamped opening, `recap_stamp.js` the saved recap after the last turn it covers, each by its count (`turns_since`) only without one), kept command bubbles, which texts were shown, unnamed badges, folded answers, long prompts, delegate reports and peer answers (`.folded`, each behind its `.answer-fold` row; a report's and a peer answer's `.answer-fold.agent-row`), the notes rows over a stretch of background items (`.quiet-notes`, open by its `open` class, the items `.quiet-hidden`; never stored) and the run lines over a run with a report, a peer answer or a finished steps block in it (`.quiet-notes.agent-line`, its open segment its `data-open`, the closed segments' rows and items `.quiet-hidden`, a block under its line `.in-line`; never stored), Revise stamps (`data-revises` on a prompt; a Verify turn's `data-verify`) and the stacks' folded versions (`.stack-hidden`, `.stack-stub.open`); the switcher's version on view is `revise_stack.js`'s own (a copy `.stack-view` before the top answer, the top `.stack-swapped`; never stored) | `bubbles.js`, `cards_place.js`, `question_cards.js`, `turn_block.js`/`stage_view.js`, `answer_fold.js`, `agent_runs.js`, `revise_stack.js`, `stream_handlers.js` (a live `turn_completed`'s `revises` and `verify` onto its prompt) | read back as state: `turn_range.js turnElements` (one walker for a turn's elements), `keptCommandBubbles`, `seedSeenFromDom`, `nameUnnamedBadges`/`nameVerdictCards`, `answer_fold.js`, `agent_runs.js` and `revise_stack.js` (their observers decorate every path that fills `#history`; the stacks are `stacks()` of the stamps, read again on each change, never a store field), `history_reveal.js revealInHistory` (the one way a jump unfolds what hides its target) |
67
+ | **The history DOM** | the conversation as drawn (a running turn's reason bubble, `.bubble.said`, is live only: see A turn opened in the history): which turn a bubble belongs to (`data-turn-id`, `data-answer-turn`), what opens a turn (`TURN_PROMPT`, `bubbles.js`: a prompt or a wake's note, the same turns `Speaker.turn_opening?` counts for a card's `turns_since`), an opening's id for a card's and the saved recap's stamp (`data-turn-id` on a prompt, `data-opening-id` on a wake's note or `/continue no`'s reason line; `card_stamps.js` places a snapshot's card after the stamped opening, `recap_stamp.js` the saved recap after the last turn it covers, each by its count (`turns_since`) only without one), kept command bubbles, which texts were shown, unnamed badges, folded answers, long prompts, delegate reports and peer answers (`.folded`, each behind its `.answer-fold` row; a report's and a peer answer's `.answer-fold.agent-row`), the notes rows over a stretch of background items (`.quiet-notes`, open by its `open` class, the items `.quiet-hidden`; never stored) and the run lines over a run with a report, a peer answer or a finished steps block in it (`.quiet-notes.agent-line`, its open segment its `data-open`, the closed segments' rows and items `.quiet-hidden`, a block under its line `.in-line`; never stored), Revise stamps (`data-revises` on a prompt; a Verify turn's `data-verify`) and the stacks' folded versions (`.stack-hidden`, `.stack-stub.open`); the switcher's version on view is `revise_stack.js`'s own (a copy `.stack-view` before the top answer, the top `.stack-swapped`; never stored) | `bubbles.js`, `cards_place.js`, `question_cards.js`, `turn_block.js`/`stage_view.js`, `answer_fold.js`, `agent_runs.js`, `revise_stack.js`, `stream_handlers.js` (a live `turn_completed`'s `revises` and `verify` onto its prompt) | read back as state: `turn_range.js turnElements` (one walker for a turn's elements), `keptCommandBubbles`, `seedSeenFromDom`, `nameUnnamedBadges`/`nameVerdictCards`, `answer_fold.js`, `agent_runs.js` and `revise_stack.js` (their observers decorate every path that fills `#history`; the stacks are `stacks()` of the stamps, read again on each change, never a store field), `history_reveal.js revealInHistory` (the one way a jump unfolds what hides its target) |
68
68
  | **A drawn turn** (`turn_drawings` of the full read) | every finished turn, as live drew it: `turnGroups` groups by the stamps only, a turn's stamped items (`drawn: <turn_id>`) one group, and `turnHistoryNodes` draws it by feeding its drawing's events to a live turn block offscreen (`turn_block.js drawnTurnNodes`: the block's own handlers, as the stage's), the stage's extras (a reminder, merged lines, a card that waited when it arrived, an answered question) in the order live left them for the history (`turn_settle.js settleOrder`, pure: from the drawing's `part_settled` and question events, whether the turn was opened, and whether a question had a lead-in) and the end as live, then the answer, the merged lines and the steps' texts from their saved items (markdown, refs). Each of its top-level elements carries `data-drawn`: `cards_place.js` leaves that turn's in-turn CardStore entries (`of_turn`) to it, and a kept reminder bubble of that turn (`data-turn-id`) stays out after a resync. chi web sends a drawing for every finished turn (one made from its messages where live wrote none): `drawnGroup` pairs the record the end names (`end.record_id`, by place for a turn saved before turn ids), else by the turn's id, and the answer's `data-answer-turn` is the end's own `turn_id` only (a made-up id, `m…` or `…~N`, keys none: no Revise). Nothing is rebuilt from messages: an item that comes unstamped is a `plain` group drawn as a plain row of its text (its prompt or answer bubble, no steps), the running turn's as expected (`runningTurnId`, the show's `current_turn`: it has no line yet), any other a miss, marked `data-undrawn`, logged once per render (`console.warn`) and counted by the reload check (`undrawn`), never a throw; a drawing with no parts (a minimal line) draws its prompt, answer and end | chi web (the show) | `renderHistory`, the reload check's render |
69
69
  | **The cards as data** (`card_registry.js`; app.js `cardRegistry`) | every question, continue offer and plugin card of the open session, keyed as `stage_waiting.js` keys them (`q:<id>`, `c:<id>`, `continue`): its kind and folded text (`card_kinds.js`), status (pending, answered, cancelled; resolved or dropped for the continue offer; asks or shown for a plugin card), `of_turn`, `opening_id`, step, `relayed_to` | `observeCards` around the stream handlers (outside the participant wrap: the page's handler first, then `apply`), so a read's replay feeds it too; `session_view.js renderSessionView` seeds it from the read right before the replay (`seed`: CardStore's listing, the pending question, the continue offer; it replaces), `forgetSession` resets it. Idempotent: a merge per key, a final status never back to pending, the first `of_turn`/`opening_id`/step kept, so seed then replay is what live holds. A question still pending at its turn's end is cancelled (the page cancels the card, no event comes) | an observer: nothing on the page draws from it; its one reader is the opt-in reload check (`reload_check.js`: this turn's entries against a registry seeded from a fresh read). `stage_cuts_parity.test.js` checks it against the stage's waiting cards at each cut, `card_registry.test.js` the events against each cut's seed and replay |
70
70
  | **What was opened of a running turn** (`stage_view_memory.js`, in `session_view.js`) | per session, for this tab: the cloud open, the steps opened in it, the working set's reader on an item; a Map of at most 20 sessions, nothing stored or sent (the peek isn't kept: it closes with its popover) | `session_view.js leaveSession`, from `session_sync.js select` and from `forgetSession` itself for the session it drew last (so the start page, `clearSelection`, keeps it too) before its reset (`captureView`); dropped by `endTurnView` | `renderSessionView`, once the read is drawn: put back (`applyView`) only when the read's running turn (`current_turn.turn_id`) is the one saved; taken either way |
71
+ | **A model pick's lines** (`model_switch.js`, the module's own `picked`) | the `/model` lines a picked switch registered, per session id — page-wide: registering one session's pick drops the other sessions' lines (the page shows one session's pick at a time) | `registerPick` (start_page.js `pickForSession`, before the `/model` goes; `pickReply` adds a question's `--yes` line when the confirm comes back) | the open session's `command_ran` / `command_queued` (stream_handlers.js) ask `pickReply`: a registered line's bubble is skipped once its switch lands (the mark is the trace); an error or busy draws it as typed |
71
72
  | **The drafts** (`drafts.js`; app.js `drafts`) | the composer's `{text, chips}` per session window (`""` the start page): `#prompt` and the mount's chips are the one on view, a view `forgetSession` swaps | through it only, by the draft's key (the lint block `samagotchi/prompt-writes`): see The drafts | `show(key)` paints the box; a write to the key on view writes the box |
72
73
  | **localStorage** (`storage.js` `readStored`/`writeStored`, guarded) | per-browser choices only; a session's view settings per session (`session_prefs.js`) | the module that owns the choice | read at start, a session's view settings again when its view is drawn (see Storage keys) |
73
74
  | **SSE** | see Streams | the server | events go into the DOM directly (a participant's through `participant_main.js wrapHandlers` first) |
@@ -315,7 +316,8 @@ redraws follow. Never copy payload keys into `store.current` by hand.
315
316
  The redraws, by their store names:
316
317
  - `infoBar` (`updateInfoBar()`): the session bar's buttons and info line (`info_bar_model.js sessionBar` →
317
318
  `info_bar.js`), the schedule notice under it (`#scheduleNotice`, from the open card's `schedule_marks` in
318
- `store.sessions`, words in `schedule_marks.js`; its Start is `version_notices.js`'s), the annotate bar, the fold controls, `updateSessionTitle()` and the fresh link's picker. Cheap: it
319
+ `store.sessions`, words in `schedule_marks.js`; a schedule's name — its title in quotes, else its short id — from
320
+ `schedule_name.js`, shared with the Stop sheet's schedules' line; its Start is `version_notices.js`'s), the annotate bar, the fold controls, `updateSessionTitle()` and the fresh link's picker. Cheap: it
319
321
  runs on most writes and every clock tick.
320
322
  - `composer` (`composer_mode.js` `update()`): the composer's placeholder, buttons and delivery line (selected, running,
321
323
  owner).
@@ -554,6 +556,16 @@ After a delete, `listAfterDelete` drops the `deleted` ids and un-archives the `u
554
556
  selection clears when it went, and the toast (`deleteToast`) says what went, what was stopped and what stays, with
555
557
  "Open" for the link that came back or a delegate left running.
556
558
 
559
+ **The Stop sheet** (`stop_sheet.js`; docs/sessions.md, Stopping a worker): what the Stop button asks when the open
560
+ session's worker still has things the user can stop. `session_actions.js stopOne` reads the worker's holds first
561
+ (`GET …/holds`, the schedules the stop leaves waiting beside them); with something, `createStopSheet` opens — a
562
+ bottom sheet on a phone, a popover at the button otherwise (`chip_popover.js`) — listing each kind (three named, then
563
+ `+N more`; reminders noted "they end with the session") and the waiting schedules' one sentence (`scheduleWords`,
564
+ each name from `schedule_name.js`), and offering **Stop all** (`POST …/holds/stop`, then the stop), **Stop session
565
+ only** (today's Stop exactly) or **Cancel**. Nothing to stop — or no worker to ask — is today's one tap, the confirm
566
+ saying the waiting schedules under it. A sheet never opens over a session the page has left: `stopOne` re-checks the
567
+ open one after the holds read.
568
+
557
569
  ## Safe areas
558
570
 
559
571
  The owner page runs under a phone's notch, status bar and home indicator (`viewport-fit=cover`; the body is `100dvh`,
@@ -976,8 +988,7 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
976
988
  the chips' own load (a session opened) calls `peers.refresh({ reuse: true })`. A pairing made from the peer's side
977
989
  sends the page nothing: the chip appears at the next read (a focus, a peer note, a send).
978
990
  - `peer_wait.js` (pure): `waitingChipModel` ("Claude · waiting 8 min", state `awaiting`, apart from a send's
979
- `waiting`; the app it names is the row's `app`, the wait mark's, else `APPS`, the fallback for an older worker's
980
- wait, gone in the release after next, else the label), `waitingPopoverTemplate` (the wait, the minutes left, Cancel: `context_chips.js cancelWait`, the
991
+ `waiting`; the app it names is the row's `app`, the wait mark's, else the label), `waitingPopoverTemplate` (the wait, the minutes left, Cancel: `context_chips.js cancelWait`, the
981
992
  Unpair route with no confirm), `waitMinutesLeft`. `peer_chip.js peerGroups` admits a row with `paired_at` or
982
993
  `waiting`; a waited-for one is drawn by these.
983
994
  - `peer_mailbox_api.js` (state): `getPeerMessage(id, name, serial)` (a message's text: View latest answer, a
@@ -1096,8 +1107,8 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
1096
1107
  line)`, app.js's `sendCommand(id, line, {clientId, card: true})` then `followWokenWorker`, as `cards_place.js
1097
1108
  onCardAction` sends a card's (so the reply shows as a bubble, the line isn't echoed as typed, and no cache-confirm
1098
1109
  asks); a failure is a toast. The stream's `chips_updated` calls `contextChips.refresh()` (one with `peers`, a peer's receipts, calls
1099
- `peers.refresh()` instead: The peer exchange): one `GET …/context` per change per open tab, and an open card follows its chip in place. A lost event (a stream `reset`) leaves the strip
1100
- as it was until the next event or the window's focus.
1110
+ `peers.refresh()` instead: The peer exchange): one `GET …/context` per change per open tab, and an open card follows its chip in place. A lost event (a stream `reset`) reads the
1111
+ chips again: the reset refreshes them and resyncs the session (`stream_handlers.js`), and a dropped stream's reconnect (`session_sync.js`) does the same.
1101
1112
 
1102
1113
  ## The drafts
1103
1114
 
data/docs/pages.md CHANGED
@@ -111,7 +111,8 @@ differ in what happens to one that isn't there:
111
111
  name the script never declared with `the script has no param "dayz" (it has: days)` (or `the script takes no
112
112
  params`). The last good result is kept.
113
113
  - **The page falls back.** chi web can only ask for what an earlier run stored, and the script (or the data its
114
- choices come from) may have changed since: a choice that is gone takes the default, and the run goes on.
114
+ choices come from) may have changed since: a choice that is gone takes the default, and the run goes on. A toast
115
+ says what ran instead: `Ran Period: 7 days: 90 days is no longer a choice`.
115
116
 
116
117
  There is **one stored result per page**, as without params: it records the values that made it, and the page presses
117
118
  those. A run with no value takes the default, not the last choice: `chi page run usage` puts the page back on 7 days.
@@ -129,7 +130,8 @@ it. On an older chi `runtime` is a `NameError`, and the run fails with it (the l
129
130
  of its prompt in quotes), `title`, `mode`, `prompt`, `recurrence_words`, `next_due`, `last_fired`, `last_result`,
130
131
  `enabled`, `state` (`on`, `firing` or `off`), `off_reason` (`owner`, `skips`, `failures`, `done`, `missed` or
131
132
  `off`; nil unless off), `skips`, `max_skips`, `failures`, `max_failures`, `skip_window`, `anchor`, `head`,
132
- `created_at`, `history`: its runs, oldest first, each with `at`, `status`, `detail` and `session_id`, and
133
+ `created_at`, `history`: its runs, oldest first, each with `at`, `status`, `detail`, `session_id` and `code` (the
134
+ reason as a code, nil where none is known: classify by it, never by `detail`'s words), and
133
135
  `condition`: its `--if CMD` as `{"cmd", "by", "set_at"}`, nil for none ([Conditions](scheduling.md#conditions---if)).
134
136
  Times are ISO 8601 UTC strings, nil when there is none.
135
137
  - `runtime.schedules.rows`: every schedule as a table row (all but `history`): `ui.table runtime.schedules.rows,
@@ -173,7 +175,8 @@ uses them (the reflect bundle's) settles.
173
175
  person: a schedule, a delegate report, a reminder), `model` (for a failed turn, its model ref without the host),
174
176
  `cost` (reported plus estimated), `tool_calls`, `tool_errors`, `tool_calls_by_tool`, `tool_errors_by_tool`,
175
177
  `failure_kind` (one of `host_model_not_found`, `host_rejected`, `host_error`, `timeout`, `host_unreachable`,
176
- `context_overflow`, `empty_answer`, `other`, `none`; nil unless failed) and `context_used_tokens`.
178
+ `context_overflow`, `empty_answer`, `other`, `none`; nil unless failed: by the turn's error kind where that names
179
+ one, else by its failure line) and `context_used_tokens`.
177
180
  - **The window.** Turns count by when they started; tool records, approvals and notices by their turn; your lines
178
181
  and steers by their own time; a question with no turn id by when it was asked. Anything with neither is left out.
179
182
  - **No text.** Counts, ids, times, model names, the project's name and path, and the names the Hashes are keyed by
data/docs/plugins.md CHANGED
@@ -1179,8 +1179,8 @@ ctx.chips.list # => this bundle's chips by name: {label:, state:, dot
1179
1179
  left out of the strip.
1180
1180
  - chi web only: the terminal draws no chips. A `--non-interactive` one-shot sets them too, shown when the session is
1181
1181
  opened in chi web later. A participant never sees them.
1182
- - It needs a chi newer than 0.195.0: guard with `ctx.respond_to?(:chips)` and mark the bundle `requires_chi_next`
1183
- ([releasing](releasing.md)). In the test kit chips are in memory: `bundle.chips` (this bundle's, by name, as
1182
+ - It needs chi 0.196.0: set `requires_chi: ">= 0.196.0"` ([releasing](releasing.md)); an older chi refuses the
1183
+ bundle rather than call a `ctx.chips` it doesn't have. In the test kit chips are in memory: `bundle.chips` (this bundle's, by name, as
1184
1184
  stored) and `bundle.chip_writes` (how many changes were written).
1185
1185
 
1186
1186
  ## Side answers: `ctx.ask_model`
data/docs/scheduling.md CHANGED
@@ -122,7 +122,9 @@ The skip is "the session is being deleted", and the next tick finds the session
122
122
  gone.
123
123
 
124
124
  **Stopped by its owner** (`chi sessions stop`, the web's Stop: the stop marker,
125
- `WorkerPresence#stop_marked?`) comes next, in both modes: a skip ("the session is
125
+ `WorkerPresence#stop_marked?`, read as `Schedules::BusyPart.stop_holds?`: the marker
126
+ unless a deleter holds the lock, a one-turn run's too while F1 stands) comes next, in
127
+ both modes: a skip ("the session is
126
128
  stopped; only its owner's message starts it again"), never a restart. A stop that
127
129
  lands between the check and a same-mode firing is the same skip: `deliver_turn`
128
130
  refuses a schedule's wake of a stopped session (a schedule is no person,
@@ -174,17 +176,28 @@ of the session a schedule acts on (its resolved target), and a `⏸ schedule` ba
174
176
  card, while the session is stopped (`Schedule "nightly reflect" waits: it skips while this
175
177
  session is stopped.`, with **Start**, which starts it through the restart route) or once
176
178
  the schedule's newest outcome is a skip (`skipped 3 of 12: …`, the newest skip's words;
177
- for a chain's open terminal or tab, "It runs once you leave."). The notice describes the
178
- newest outcome: the line goes once a firing starts (a firing in flight is running, not
179
- waiting), when the schedule is disabled or removed, when a stopped session starts (a skip
180
- for the stop is over: the next tick runs it), and when an outcome newer than the skip
179
+ for a chain's open terminal or tab, "It runs once you leave."). "Stopped" is the
180
+ tick's own reading (`stop_holds?`, read fresh with the session's summary), so a one-turn
181
+ run (`chi -p X --non-interactive`) on a stopped session, whose card shows the run's
182
+ status, still names the schedules its stop holds. The notice describes the newest
183
+ outcome: the line goes once a firing starts unless the session is stopped (a firing in
184
+ flight is running: it is named while its session is stopped, as the Stop sheet names
185
+ it, `Schedules#waiting`), when the schedule is disabled or removed, when a stopped
186
+ session starts (a skip for the stop is over: the next tick runs it), and when an
187
+ outcome newer than the skip
181
188
  arrives — a failed firing, a fire or a missed occurrence (the `skips` counter goes on
182
189
  counting for `max_skips`; the line returns at the next skip).
183
190
  No push: the turn-off at `max_skips` is the one push. The session hub reads the marks
184
- (`Schedules.session_marks`: one read of the store and one session listing) outside its
185
- lock, when `schedules.json` changed or the disabled-notice claim came due, and when the
186
- sessions folder changed at most once every 5 seconds; it puts them in each session's
187
- summary (`schedule_marks`, `Schedules.shown_marks`).
191
+ (`Schedules.session_marks(sessions:)`: one read of the store, the chains walked over the
192
+ hub's own rows, `SessionHub.chain_row`, taken under its lock with the decision to read:
193
+ no session listing) outside its lock, when `schedules.json` changed or the
194
+ disabled-notice claim came due, and when the sessions folder changed or a session's
195
+ archived or `continues` flag did (an archive writes only in the session's own folder) at
196
+ most once every 5 seconds; it puts them in each session's
197
+ summary (`schedule_marks`, `Schedules.shown_marks`). Each read is numbered when it is
198
+ decided (under the lock) and swaps in only when newer than the last one swapped: two
199
+ scans at once (the tick thread's, an auto-update's) never put an older read over a
200
+ newer one.
188
201
 
189
202
  ## Skip, not failure
190
203
 
@@ -200,7 +213,8 @@ or `offer`, or `busy_child`/`queued_child`/`offer_child` (a chain's own running
200
213
  delegate refuses the archive, since `archivable!` walks the whole descendant tree),
201
214
  `SessionContinue::Refused(:continued)` (a human continued it while we were
202
215
  resolving), `:open_children` and `:transition_busy` (another continue of the
203
- chain's end held its transition lock past the continue's 10 s on each of its tries), and a
216
+ chain's end held its transition lock past the continue's 10 s on each of its tries), `:undo_pending` (a crashed
217
+ continue of the chain's end is still to be undone, its repair backed off), and a
204
218
  same-mode turn its target's transition lock refused (`transition_busy`, or `link_continued` naming a
205
219
  continue's new link: the turn's own hold, nothing written).
206
220
  So is an archived target that a continue is still
@@ -237,7 +251,13 @@ line each in local time: `fired`, `skipped`, `failed`, `missed`, your `enabled`
237
251
  `disabled`, a `chi schedule edit`'s `edited` (naming the fields), with the reason and
238
252
  the session it acted on (a skip or
239
253
  failure that used up the budget says `disabled: <reason>`). `list --format json` has
240
- them as each entry's `history` (and an unpushed turn-off as `disabled_notice`).
254
+ them as each entry's `history` (and an unpushed turn-off as `disabled_notice`). A row
255
+ is `{at, status, detail, session_id, code}`: `detail` the words shown, `code` the
256
+ reason as a code where one is known (a busy cell's: `stopped`, `deleting`,
257
+ `worker_busy`, `worker_newer`; `open_tab`; a wake refusal's `session_stopped` /
258
+ `session_archived`; a refusal's reason, e.g. `transition_busy`; a failed turn's error
259
+ kind). chi web classifies a skip by its code, by its words only for a row an older chi
260
+ wrote without one (docs/architecture.md, "Codes beside words").
241
261
 
242
262
  `list --format json` gives each entry every stored field (with any key a newer chi
243
263
  added), then `recurrence_words`, `skip_window`, and what a reader would otherwise work
@@ -283,7 +303,15 @@ An accepted delivery is **pending**, not fired: `schedules.json` records its
283
303
  session and turn id, and the next tick follows that turn's own outcome, even if a
284
304
  later turn has replaced `last_turn`. A completed turn is a success; a failed or
285
305
  canceled turn counts toward `max_failures`, with its reason in `chi schedule list`
286
- and `show`. A question does not time out with the 40-second firing step: the turn
306
+ and `show`. A turn that failed for its configuration turns a recurring schedule off at
307
+ its first failure, since every firing would fail the same way: the host doesn't serve
308
+ the session's model (`LastTurn#error_reason` `model_not_served`: a pinned model the host
309
+ no longer has) or refused the key (`error_kind` `auth`; `Schedules::HistoryPart::CONFIG_FAILURES`, the
310
+ history row's `code`). Its reason names the host, the model and the fix (`host main
311
+ doesn't serve main:m: /model main:served or edit the session's model`), in the phone
312
+ notification, `chi schedule show` and the Schedules page ("off: needs a fix"); fix it,
313
+ then `chi schedule enable`. A flaky failure (a connection, a 5xx, a timeout) keeps the
314
+ `max_failures` budget. A question does not time out with the 40-second firing step: the turn
287
315
  stays pending until its hard limit, derived from the schedule interval (at least
288
316
  10 minutes and at most 6 hours). If no outcome is known by then, it counts as a
289
317
  failure with reason `no outcome`. Failed, canceled and expired turns are not