samagotchi 0.177.0 → 0.177.1
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 +18 -1
- data/docs/architecture.md +5 -4
- data/docs/cli.md +4 -1
- data/docs/internals/bundles.md +4 -3
- data/docs/internals/participants.md +8 -5
- data/docs/internals/session-lifecycle.md +167 -0
- data/docs/internals/web-frontend.md +7 -3
- data/docs/internals/working-set.md +2 -1
- data/docs/plugins.md +1 -1
- data/docs/releasing.md +3 -2
- data/docs/sessions.md +7 -5
- data/docs/testing.md +4 -2
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/compat.rb +1 -1
- data/lib/samagotchi/engine/session.rb +7 -0
- data/lib/samagotchi/memory_bundle/shipped_update.rb +1 -1
- data/lib/samagotchi/note_delivery.rb +9 -4
- data/lib/samagotchi/plugin/sessions.rb +2 -1
- data/lib/samagotchi/revise_anchor.rb +2 -0
- data/lib/samagotchi/schedules.rb +3 -1
- data/lib/samagotchi/session_chain/delete.rb +28 -5
- data/lib/samagotchi/session_chain/delete_preview.rb +2 -2
- data/lib/samagotchi/session_inbox.rb +29 -0
- data/lib/samagotchi/session_inbox_delivery.rb +13 -5
- data/lib/samagotchi/session_lifecycle/allowed.rb +66 -0
- data/lib/samagotchi/session_lifecycle/canonical.rb +49 -0
- data/lib/samagotchi/session_lifecycle/reading.rb +65 -0
- data/lib/samagotchi/session_lifecycle.rb +59 -0
- data/lib/samagotchi/session_manager/delivery.rb +29 -6
- data/lib/samagotchi/session_manager/lifecycle.rb +22 -14
- data/lib/samagotchi/session_manager/removal.rb +16 -8
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +22 -2
- data/lib/samagotchi/tool_names.rb +1 -1
- data/lib/samagotchi/tools/memory.rb +29 -0
- data/lib/samagotchi/turn_anchors.rb +5 -0
- data/lib/samagotchi/verify_anchor.rb +2 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/participant_show.rb +3 -4
- data/lib/samagotchi/web/participant_view.rb +4 -6
- data/lib/samagotchi/web/public/data.js +6 -2
- data/lib/samagotchi/web/public/delete_sheet.js +42 -5
- data/lib/samagotchi/web/public/ws_sections.js +1 -0
- data/lib/samagotchi/web/session_control.rb +4 -3
- data/lib/samagotchi/web/session_summary.rb +7 -0
- data/lib/samagotchi/worker_boot.rb +9 -6
- data/lib/samagotchi/worker_presence.rb +4 -0
- data/lib/samagotchi/working_set_command.rb +2 -2
- data/lib/samagotchi/working_set_steer.rb +3 -10
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a5b330c47fac34a4e9fd4c2d602e4cbc0241fe42a953bba227b6526ef619e7b
|
|
4
|
+
data.tar.gz: 4c9ae4e9df6279202aa9540984c70148ef1ea6d2e9898542cb219ab1980b6f14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc2236c6ee5a909b4cfef2b66ab813b1546b9c8fe432734aec2909f84703cbe3dba48491a0e1a02f115650c9252ce9d087ea9e1b8dba327b61e5b483a9541d47
|
|
7
|
+
data.tar.gz: a5b1653706fd962459dd639a4487d45bb28e96cdf3e022148d3fe4ce19967c84dd5a911d2f9014ad778c75945dfb0194b5c682549dd5fb39ec0c4886b3c0f65d
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,22 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.177.1] - 2026-11-19
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- chi web: deleting a chained session no longer deletes more than the sheet showed when something changed since it
|
|
16
|
+
opened (a delegate that finished, a schedule, a continue); the sheet shows the new plan to confirm.
|
|
17
|
+
- chi web: a participant's failed Verify turn comes back in their composer as a Verify turn, not plain text.
|
|
18
|
+
- `/working-set add system/x` is no longer refused as "already in the system prompt" when only a project memory x
|
|
19
|
+
is there (and the reverse); a bare name still matches either scope.
|
|
20
|
+
- A message sent to a session while it is being deleted is refused ("the session is being deleted") instead of being
|
|
21
|
+
reported delivered and then lost.
|
|
22
|
+
- `chi sessions restart` (and the web's restart) of a stopped session, or one being stopped, is refused at once with
|
|
23
|
+
what to do, instead of waiting for a restart that never comes.
|
|
24
|
+
|
|
25
|
+
Update with `chi update`.
|
|
26
|
+
|
|
11
27
|
## [0.177.0] - 2026-11-17
|
|
12
28
|
|
|
13
29
|
### Added
|
|
@@ -6480,7 +6496,8 @@ and long-lived sessions.
|
|
|
6480
6496
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6481
6497
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6482
6498
|
|
|
6483
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.177.
|
|
6499
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.177.1...HEAD
|
|
6500
|
+
[0.177.1]: https://github.com/dm1try/samagotchi/compare/v0.177.0...v0.177.1
|
|
6484
6501
|
[0.177.0]: https://github.com/dm1try/samagotchi/compare/v0.176.0...v0.177.0
|
|
6485
6502
|
[0.176.0]: https://github.com/dm1try/samagotchi/compare/v0.175.0...v0.176.0
|
|
6486
6503
|
[0.175.0]: https://github.com/dm1try/samagotchi/compare/v0.174.0...v0.175.0
|
data/docs/architecture.md
CHANGED
|
@@ -215,7 +215,7 @@ worker, and (its thin client load budgets) no turn loop, bundle updater, `tools/
|
|
|
215
215
|
|
|
216
216
|
The clients name tools and the session commands without loading them. A tool's name and the fixed texts it writes
|
|
217
217
|
into results (`Execute::HANDED_OVER`…) live in `ToolNames` (`tool_names.rb`, no requires), which the tool classes
|
|
218
|
-
read their constants from and the display code (`ToolActivity`, `ToolView`, `FileRef`, `
|
|
218
|
+
read their constants from and the display code (`ToolActivity`, `ToolView`, `FileRef`, `Objectives::Backing`) reads
|
|
219
219
|
directly. The session commands' names, the built-ins' registry and its class-level reads (`builtin_name`,
|
|
220
220
|
`builtin_registry`, `ui_only_entry`, `ui_only_refusal`, `delete_on_exit?`, `SHELL_BANG_PREFIX`…) live in
|
|
221
221
|
`SessionCommandCatalog` (`session_command_catalog.rb`), which the TUI, chi web, `chi send` and `PromptHistory`
|
|
@@ -652,6 +652,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
|
|
|
652
652
|
| Component | Main file(s) | What it is |
|
|
653
653
|
|---|---|---|
|
|
654
654
|
| Worker | `worker.rb` (`worker_boot.rb`, `worker_idle_exit.rb`, `worker_inbound.rb`, `worker_signals.rb`, `worker_wakes.rb`, `worker_task_wakes.rb`, `task_watch.rb`, `worker_participant_gate.rb`, `worker_exit_claim.rb`) | A session's background process: builds the `Engine` and `Bridge`, runs queued turns and the wake turns nobody typed (delegate reports, a background task that finished unseen: [Finish wake](internals/background-tasks.md#finish-wake), attached context), exits when idle. A spawned one traps TERM, HUP and INT (`WorkerSignals`, installed by `WorkerBoot.run_session_loop` when `SAMAGOTCHI_WORKER_PROCESS=1`): the running turn stops as a Stop with reason `signal`, is saved, and the worker leaves (`:signal`, exit 0; a new worker only for input already queued). A running turn is checkpointed at its iteration boundaries (`TurnCheckpoint`, the `interrupted_turn` mark), and the next worker settles a turn its predecessor died in (`TurnCheckpoint.settle`). The session is saved from the turn's thread, Bridge threads and a signal's thread; `Session#save` takes a per-session lock around its snapshot and write, so an older snapshot never lands over a newer one. `WorkerParticipantGate` is the one seat for "may this participant act" (a queued turn as it starts, the drain, the mid-turn stop, the Continue: [internals/participants.md](internals/participants.md)); `WorkerExitClaim` is the exit claim (`POST /exit`): one lock for the kind being taken and the exit taken. Threads: the gate is loop-thread only (a turn runs on the loop; no lock), the claim is safe from any thread (its own mutex, taken after the event lock). The concerns are `include`d parts in `lib/samagotchi/worker/` (`Worker::LeavePart`: exit and leave; `Worker::WakeTurnsPart`: the turns nobody typed; `Worker::StartupPart`: the start-up settle; `Worker::SignalGracePart`: a signal's grace; `Worker::ScratchPart`: a scratch worker whose terminal left; `Worker::ChildSidePart`: a delegate child's rings, Verify fresh verdicts; `Worker::CommandQueuePart`: session commands between turns). `worker.rb` keeps the loop, the wiring, the prompt turns and the drain. They share Worker's ivars, and each header says what it writes and reads. |
|
|
655
|
+
| Session lifecycle | `session_manager/`, `worker_boot.rb`, the session sidecar files | Marker writers, derived states, lock order, crash repair and the known open windows are mapped in [Session lifecycle](internals/session-lifecycle.md). |
|
|
655
656
|
| Config | `config.rb`, `config/restart_watch.rb` | Every setting as an `Entry`: env, config.yml and CLI layers ([configuration.md](configuration.md)); the notice a worker or chi web gets when config.yml changes a setting it reads only at its start. With `log.rb` it is the bottom layer: nothing it references reaches back to it, so `hosts:` and `models:` entries parse next to their types (`HostConfig.all`, `ModelSettings.all`). |
|
|
656
657
|
| Paths | `paths.rb` (`Paths`) | The XDG base dirs chi's files live under, read from the env on every call: `Paths.state_home` (`$XDG_STATE_HOME`, else `~/.local/state`) and `Paths.config_home` (`$XDG_CONFIG_HOME`, else `~/.config`), both defaults under `Dir.home`; a blank variable counts as unset, a relative one is made absolute from the current directory. `Paths.tilde` shows a path with `~` for the home folder. `SessionManager` hands a spawned worker the spawner's `XDG_STATE_HOME` / `XDG_CONFIG_HOME`, when set, made absolute, so a relative one isn't read from the session's folder. |
|
|
657
658
|
| MemoryBundle | `memory_bundle.rb`, `memory_bundle/{installer,builder,installed_bundle,plugin_ref,bundle_hook}.rb` (`Installer`, `Builder`, `InstalledBundle`, `PluginRef`, `BundleHook`) | Installing, building and reading bundles of memories, rules, plugins and scripts (`BundleHook`: an older record's retired class-file hook). |
|
|
@@ -671,12 +672,12 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
|
|
|
671
672
|
| Idle work | `idle_scheduler.rb` (`IdleScheduler`), `idle_recap.rb` (`IdleRecap`), `idle_reminders.rb` | One poller for an idle session's recap and reminders. |
|
|
672
673
|
| Attached context | `context_sources.rb` (`ContextSources`), `context_poller.rb`, `context_absorber.rb`, `context_candidates.rb` (`ContextCandidates`: proposed sources, attached on the owner's mention at a turn's start, before the worker's absorb, or in a one-shot's turn; `owner_prompt.rb` decides whose words count), `peer_sources.rb` (`PeerSources`: the sources peer bundles declare) | External sources a session keeps fresh, and the peer loop's wakes ([context.md](context.md)). |
|
|
673
674
|
| LLM context strategies | `llm_context_strategy.rb`, `llm_context_view.rb`, `llm_context_stale.rb`, `llm_context_forget.rb` | What a request sends of the history (none, stale, forget) ([internals/llm-context-forget.md](internals/llm-context-forget.md)). |
|
|
674
|
-
| Session chains | `session_continue.rb` (`SessionContinue`), `session_chain.rb` (`SessionChain`), `session_chain/links.rb` (`SessionChain::Links`) | A session that continues an earlier one. `SessionChain::Links` is the one chain walker (one listing; `latest`, `first_live`, `root`, `next_of`): `SessionChain.latest`/`.next_of`, `SessionInbox::Head` and the schedule tick all ask it. `SessionChain.opener_for` gives the text web `continue →` prefills in the new link: the previous link's own first typed message when that link continues one itself, else nil (the 201's `opener`; not saved) ([sessions.md](sessions.md)). |
|
|
675
|
-
| chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, the owner show's stamped with their turns' drawings and carrying no parts (a step's ✂ marks only), the participant show's with their parts, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/verify_fresh_routes.rb` (`Web::VerifyFreshRoutes`: Verify fresh children), `web/working_set_routes.rb` (`Web::WorkingSetRoutes`: the working set routes), `web/viewer.rb` (`Web::Viewer`: page capabilities), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions, prefs, test and presence), `web/block_renderer_routes.rb` (`Web::BlockRendererRoutes`: `GET /api/block_renderers` and one renderer's file, [internals/block-renderers.md](internals/block-renderers.md)), `web/reload_check_route.rb` (`Web::ReloadCheckRoute`: `POST /api/sessions/:id/reload_check`, the opt-in `web.reload_check`'s counts from the page's `reload_check.js`, 204 and one `reload_checked` log line, with `reload_mismatch`, its `kinds`, `excused` (ACCEPTED ids) and `explained` when the turn read otherwise after a reload; the worker's version is chi web's own view, its sidecar) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. |
|
|
675
|
+
| Session chains | `session_continue.rb` (`SessionContinue`), `session_chain.rb` (`SessionChain`), `session_chain/links.rb` (`SessionChain::Links`), `session_chain/delete.rb` (`SessionChain::Delete`), `session_chain/delete_preview.rb` (`SessionChain::Delete::Preview`), `continued_from.rb` (`ContinuedFrom`) | A session that continues an earlier one. `SessionChain::Links` is the one chain walker (one listing; `latest`, `first_live`, `root`, `next_of`): `SessionChain.latest`/`.next_of`, `SessionInbox::Head` and the schedule tick all ask it. `SessionChain.opener_for` gives the text web `continue →` prefills in the new link: the previous link's own first typed message when that link continues one itself, else nil (the 201's `opener`; not saved). `SessionChain::Delete` plans and deletes a link or its chain; `Delete::Preview` supplies the web delete sheet, and `ContinuedFrom` records what a continue must undo ([sessions.md](sessions.md)). |
|
|
676
|
+
| chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/request_body.rb` (`Web::RequestBody`: bounded body reads), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, the owner show's stamped with their turns' drawings and carrying no parts (a step's ✂ marks only), the participant show's with their parts, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/session_access_routes.rb` (`Web::SessionAccessRoutes`: the session-command routes), `web/verify_fresh_routes.rb` (`Web::VerifyFreshRoutes`: Verify fresh children), `web/working_set_routes.rb` (`Web::WorkingSetRoutes`: the working set routes), `web/viewer.rb` (`Web::Viewer`: page capabilities), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions, prefs, test and presence), `web/block_renderer_routes.rb` (`Web::BlockRendererRoutes`: `GET /api/block_renderers` and one renderer's file, [internals/block-renderers.md](internals/block-renderers.md)), `web/reload_check_route.rb` (`Web::ReloadCheckRoute`: `POST /api/sessions/:id/reload_check`, the opt-in `web.reload_check`'s counts from the page's `reload_check.js`, 204 and one `reload_checked` log line, with `reload_mismatch`, its `kinds`, `excused` (ACCEPTED ids) and `explained` when the turn read otherwise after a reload; the worker's version is chi web's own view, its sidecar) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. The shared body reader caps incoming requests. |
|
|
676
677
|
| Web Push | `web/push.rb` (`Web::Push`: `Runtime`, `preflight!`, the `web.push.*` settings), `web/push/crypto.rb` (`Push::Crypto`: RFC 8291 aes128gcm, RFC 8292 VAPID), `web/push/store.rb` (`Push::Store`, `Store::Sub`: `web-push/vapid.pem`, `subscriptions.json`), `web/push/client.rb` (`Push::Client`, `Client::Result`), `web/push/attention.rb` (`Push::Attention`: notify.js's rules in Ruby, shared cases in `spec/fixtures/attention_cases.json`), `web/push/presence.rb` (`Push::Presence`: the pages' "in front" reports), `web/push/notifier.rb` (`Push::Notifier`, a hub subscriber with a sender thread), `web/push_routes.rb` (`Web::PushRoutes`), `private_files.rb` (`PrivateFiles`, shared with the grants), `public/sw.js`, `public/push.js`, `public/manifest.webmanifest` | chi web pushes what the tab notifies for (approvals, questions, step-limit questions, cards, failed turns; done turns to a device that asks) to the owner's Home Screen app over an https public URL: the Notifier turns the hub's new attentions into show pushes after a hold, unless a chi web page is in front, at most 30 an hour, with one retry and a restart catch-up (`sent.json`) (each carries the keys still open, and the badge; no close push: every push shows a notification); the bell (`notifications.js`) subscribes the device, and the service worker and the page close the answered ones. See [internals/web-push.md](internals/web-push.md). |
|
|
677
678
|
| chi web's updates | `web/update_check.rb` (`Web::UpdateCheck`), `web/update_ops.rb` (`Web::UpdateOps`), `web/auto_update.rb` (`Web::AutoUpdate`) | The RubyGems checker and its `update_check.json`; the install, worker-restart and chi-web-restart operations (one at a time) the owner's routes and AutoUpdate share; `update.auto: install`'s thread (install when no turn runs, then idle workers and chi web). See [configuration](configuration.md#unattended-updates-updateauto). |
|
|
678
679
|
| Behind an auth proxy | `web/public_url.rb` (`Web::PublicUrl`: `web.public_url`, `web.proxy.identity_header`, `web.proxy.owner`), `web/proxy_gate.rb` (`Web::ProxyGate`, mixed into App; `RawHeaderNames`, prepended to WEBrick's request by `Web::Server`), `web/link_codes.rb` (`Web::LinkCodes`: the links' one-time codes), `proxy_trace.rb` (`ProxyTrace`), `web/public/token_fragment.js`, `web/public/auth_lost.js`, `web/tunnel.rb` + `web/tunnel/tailscale.rb` (`Web::Tunnel`, `Web::Tunnel::Tailscale`: `chi web --tunnel tailscale`, Tailscale Serve set for one run and the PublicUrl it makes) | Experimental: chi web behind an auth proxy. Every request needs the token; a proxied one's owner also needs the identity header (one clean value under one name); the `__Host-` cookie, an absolute `Location` from the public URL, https links with a one-time code in the fragment; the page's lost-sign-in banner. Bridges refuse proxy traces ([configuration.md](configuration.md#behind-an-auth-proxy)). |
|
|
679
|
-
| Participants | `participants.rb` (`Participants`, the `participants.json` sidecar), `share_command.rb` (`ShareCommand`, `chi share`), `session_participants.rb`, `participants_watch.rb`, `grants.rb` (`Grants`), `participant_exposure.rb` (`ParticipantExposure`), `web/principal.rb` (`Web::Principal`), `web/participant_access.rb` (`Web::ParticipantAccess`: the participant's gate and routes), `web/participants_admin.rb` (`Web::ParticipantsAdmin`: the owner's invite, list, revoke and cap routes), `web/participant_review.rb` + `web/participant_view.rb` (`Web::ParticipantReview`, `Web::ParticipantView`), `web/participant_show.rb` (`Web::ParticipantShow`), `web/participant_images.rb` (`Web::ParticipantImages`), `participant_uploads.rb` (`ParticipantUploads`), `participant_revise.rb` (`ParticipantRevise`), `participant_messages.rb` (`ParticipantMessages`), `revise_anchor.rb` (`ReviseAnchor`), `redact.rb` (`Redact`, `Redact::Viewer`: the redaction every string a participant gets passes, also the Engine's Verify quote check), `web/participant_stream_filter.rb`, `share_terms.rb` (`ShareTerms`), `guardrails/pair_boundary.rb` + `guardrails/participant_refusal.rb` + `guardrails/review_paths.rb` | The people an owner invites into one session through chi web: their grants and gate, what they read, their turns under the owner's guardrails ([internals/participants.md](internals/participants.md), [guardrails.md](guardrails.md)). |
|
|
680
|
+
| Participants | `participants.rb` (`Participants`, the `participants.json` sidecar), `share_command.rb` (`ShareCommand`, `chi share`), `session_participants.rb`, `participants_watch.rb`, `grants.rb` (`Grants`), `participant_exposure.rb` (`ParticipantExposure`), `participant_prompts.rb` (`ParticipantPrompts`), `participant_name.rb` (`ParticipantName`), `participant_turn_mode.rb` (`ParticipantTurnMode`), `web/principal.rb` (`Web::Principal`), `web/participant_access.rb` (`Web::ParticipantAccess`: the participant's gate and routes), `web/participants_admin.rb` (`Web::ParticipantsAdmin`: the owner's invite, list, revoke and cap routes), `web/participant_review.rb` + `web/participant_view.rb` (`Web::ParticipantReview`, `Web::ParticipantView`), `web/participant_show.rb` (`Web::ParticipantShow`), `web/participant_images.rb` (`Web::ParticipantImages`), `web/participant_history.rb` (`Web::ParticipantHistory`: prompt history), `participant_uploads.rb` (`ParticipantUploads`), `participant_revise.rb` (`ParticipantRevise`), `participant_messages.rb` (`ParticipantMessages`), `revise_anchor.rb` (`ReviseAnchor`), `redact.rb` (`Redact`, `Redact::Viewer`: the redaction every string a participant gets passes, also the Engine's Verify quote check), `web/participant_stream_filter.rb`, `share_terms.rb` (`ShareTerms`), `guardrails/pair_boundary.rb` + `guardrails/participant_refusal.rb` + `guardrails/review_paths.rb` | The people an owner invites into one session through chi web: their grants and gate, what they read, their turns under the owner's guardrails. Their own prompt history, display names and turn-mode decision are kept apart from the owner's paths ([internals/participants.md](internals/participants.md), [guardrails.md](guardrails.md)). |
|
|
680
681
|
| Analytics | `analytics_file.rb` (`AnalyticsFile`), `session_metrics/totals.rb` (`SessionMetrics::Totals`), `session_metrics/model_segment.rb` (`SessionMetrics::ModelSegment`) | A session's `analytics.json` (`SessionMetrics#persist`); the sums over its turn records (`Totals`: tokens, cost, speeds, kept as running counters) and their split per model after a `/model` switch (`ModelSegment`: a run of turns on one model, the `model_segments` rows); `session_metrics/cost.rb` (`SessionMetrics::Cost`): the spend `ctx.cost` reads; `session_metrics/usage.rb` (`SessionMetrics::Usage`): the work `ctx.usage` reads. `session_metrics/side_totals.rb` (`SessionMetrics::SideTotals`) and `side_usage.rb` (`SideUsage`): the side requests' sums, apart from the turns'. |
|
|
681
682
|
| Images / vision | `image_store.rb` (`ImageStore`), `vision_support.rb`, `vision_context.rb` | Stored prompt images and whether a model takes them. |
|
|
682
683
|
| Toolkits | `toolkit.rb` (`Toolkit`), `toolkit_binding.rb` (`ToolkitBinding`, the Engine's seam), `toolkit_command.rb` (`/toolkit`), `tools/registry.rb` (`Registry#toolkit`), `tools/tool_surface.rb` (`ToolSurface#left_out`, read by the prompt and `/toolkit`), `web/public/toolkit_chip.js` | Which registered tools a session's prompts declare: saved in the session, resolved at a turn's start (`Engine#apply_toolkit!`), named in the prompt's not-loaded line, a kit's prompt text after the appended files; `chi.toolkit` and `ctx.use_toolkit` for plugins ([configuration.md](configuration.md#toolkits)). |
|
data/docs/cli.md
CHANGED
|
@@ -740,7 +740,10 @@ approval, queued prompt, or running background task; otherwise it says to run
|
|
|
740
740
|
`chi sessions stop ID`, then send any prompt. That fallback drops reminders,
|
|
741
741
|
and may lose a running `/btw` and other in-memory state. A session with no running worker needs no restart (its next
|
|
742
742
|
prompt starts one on the newest chi), and an older worker without restart
|
|
743
|
-
support needs `chi sessions stop ID`.
|
|
743
|
+
support needs `chi sessions stop ID`. A stopped session, or one being stopped
|
|
744
|
+
(`chi sessions stop`), is refused at once without asking its worker: "can't
|
|
745
|
+
restart: the session is stopped; only its owner's message starts it again (on
|
|
746
|
+
the newest chi)". The Web UI's
|
|
744
747
|
`POST /api/sessions/:id/restart` does the same (409 with `reason` and `detail`
|
|
745
748
|
when it can't). An attached
|
|
746
749
|
terminal says at the join, in one `chi>` line, when the worker or the terminal
|
data/docs/internals/bundles.md
CHANGED
|
@@ -108,9 +108,10 @@ back to the source dir.
|
|
|
108
108
|
Class-file hooks (retired). A record an older chi installed may still have a `hooks` map and `hooks/*.rb`
|
|
109
109
|
(`InstalledBundle#hooks`). Nothing loads them, and nothing announces them any more (the first turn, `chi bundle
|
|
110
110
|
status` and `chi update` did from 0.158 to 0.166). A source with
|
|
111
|
-
hooks is refused before its manifest is read (`
|
|
112
|
-
run too; `ShippedUpdate`'s plan skips one the same way. Over such a record,
|
|
113
|
-
plugin and scripts
|
|
111
|
+
hooks is refused before its manifest is read (`Manifest::HooksRetired.refuse_source_files`, then `Manifest.read`),
|
|
112
|
+
strict or not, a dry run too; `ShippedUpdate`'s plan skips one the same way. Over such a record,
|
|
113
|
+
after the plugin and scripts (so a refused install leaves them), `AssetInstaller#retire_hooks` copies every edited or
|
|
114
|
+
unknown file under `hooks/` to the trash
|
|
114
115
|
(`Trash#copy_edits` with the recorded shas; a dev link never), removes the dir and records each as `:removed` (a dry
|
|
115
116
|
run's `:would_remove`) with the `AssetInstaller::RETIRED` note, which `#summary` lists on a line of
|
|
116
117
|
its own; `ShippedUpdate#trash_bound` names the same files (`Trash.edits` over `hooks/`). `Provenance#write` records
|
|
@@ -463,8 +463,8 @@ headers alike. A revoked or expired grant is refused by the gate (401) as on eve
|
|
|
463
463
|
|
|
464
464
|
**Their turn** takes only refs they uploaded ([Turns](#turns)); **what they see** is their own images as thumbnails
|
|
465
465
|
and anyone else's as "N images" ([What a participant sees](#what-a-participant-sees)). A corrupt or unreadable
|
|
466
|
-
record fails closed (every grant at quota, owning nothing, `Log.warn`
|
|
467
|
-
of theirs gives the text back with its chips (`prompt_restored`, below).
|
|
466
|
+
record fails closed (every grant at quota, owning nothing, `Log.warn` once per `(path, size, mtime)` state); the
|
|
467
|
+
owner can delete the file. A failed turn of theirs gives the text back with its chips (`prompt_restored`, below).
|
|
468
468
|
|
|
469
469
|
## What a participant sees
|
|
470
470
|
|
|
@@ -493,8 +493,9 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
493
493
|
`ParticipantAccess#own_turn?`; `input_merged`: the count and origins of their own lines only), anyone else's bare;
|
|
494
494
|
`prompt_restored` (a failed turn's prompt handed back, **their own turn only**: the origin's server-stamped author
|
|
495
495
|
is theirs; another person's, the owner's and an author-less one's give nothing; carries `prompt`, `images` as their
|
|
496
|
-
own refs (`.image_refs`), `revises: {turn_id}
|
|
497
|
-
|
|
496
|
+
own refs (`.image_refs`), `revises: {turn_id}`, `origin: {client_id, enqueued_id, author}` and a parsed Verify
|
|
497
|
+
claim as `verify: {turn_id, quote}`; malformed or boolean claims are omitted. Never `source`, the error or any
|
|
498
|
+
other field; the page refills its composer as the owner's, `restore.js`);
|
|
498
499
|
`question_requested` and `continue_offered` with one derived `kind` (`.waiting_kind`: `approval` for a guardrail's
|
|
499
500
|
approval or a relayed one, `continue` for the step-limit question and every offer, `question` else); the main
|
|
500
501
|
page's numbers (`context_status`: usage's `estimated_pct` and token counts, `bucket`, a switch's
|
|
@@ -620,7 +621,9 @@ owner's machine (`home`, the folders, `project-*`, `back-*`).
|
|
|
620
621
|
- **Verify verdict cards** (`verdict_card.js`). The built-in Verify preset carries the selected source turn id and quote
|
|
621
622
|
with the submitted turn, without changing its prompt text. A Verify turn that fails fast and is rolled back hands
|
|
622
623
|
the claim back with its prompt (`prompt_restored`'s `verify`), so the owner's resend from the composer is a Verify
|
|
623
|
-
turn again.
|
|
624
|
+
turn again. A participant's own failed turn also gets its parsed `verify` claim in `prompt_restored` (see
|
|
625
|
+
[What a participant sees](#what-a-participant-sees)). Before the Engine stamps the anchor or records a verdict,
|
|
626
|
+
it checks that the source turn exists and
|
|
624
627
|
its final assistant reply (`AnswerTail`: the turn's last assistant message with text) contains the quote. Matching is case-sensitive, collapses whitespace, and strips common
|
|
625
628
|
Markdown presentation (links, headings, list/blockquote prefixes, emphasis and code delimiters) from both sides;
|
|
626
629
|
this matches the rendered text the page selects without treating different casing as the same claim. The quote may
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Session lifecycle
|
|
2
|
+
|
|
3
|
+
There is no persisted lifecycle enum. A state is derived from the session file, sidecar files, locks, and the worker
|
|
4
|
+
link: `SessionLifecycle.read(id)` (`session_lifecycle.rb`) reads them once (`WorkerPresence` with its link looked at,
|
|
5
|
+
never unlinked, and `ContinueIntent.in_flight`) and names the first of its 15 states whose facts hold (Derived states).
|
|
6
|
+
The same session can satisfy more than one fact (archived while its worker is leaving); the precedence picks one. One
|
|
7
|
+
decider reads `SessionLifecycle`: `restart_session`'s precheck (Allowed operations). The others still read their own
|
|
8
|
+
subset of the facts in their own order, and what each answers per state is `ALLOWED` (Allowed operations), pinned by
|
|
9
|
+
the characterization matrix. The session file layout and user-facing session behavior are in [Sessions](../sessions.md); the Worker and
|
|
10
|
+
SessionManager boundaries are in [Architecture](../architecture.md) and [Engine internals](engine.md).
|
|
11
|
+
|
|
12
|
+
## Facts and markers
|
|
13
|
+
|
|
14
|
+
| Fact | Writer and removal | Cross-process readers and how they see change |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| `<id>.json` `status` | `Session#save` writes the session snapshot; the owner is the normal writer. `Session#load` overlays `stopped` as `stopped` without rewriting the file. | `SessionRow` and `SessionAccess::Local` read saved turn status; stop cancellation, restart fallback, and archive refusal also use it as a busy hint. Readers reload the file; the hub refreshes rows on its tick. It is turn state, not proof of liveness. |
|
|
17
|
+
| `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. |
|
|
18
|
+
| `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. |
|
|
19
|
+
| `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. |
|
|
20
|
+
| 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. |
|
|
21
|
+
| `stopped` | `SessionManager#stop_session` calls `Session.mark_stopped`; `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. |
|
|
22
|
+
| `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. |
|
|
23
|
+
| `continue.lock` and `continue.json` | `SessionContinue#with_lock` takes the exclusive lock for a continue; `ContinueIntent#hold` takes a nonblocking shared lock for readers that must exclude a continue. `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. | Followed sends, schedules, chain deletion, and `ContinueIntent.in_flight` 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. |
|
|
24
|
+
| `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. |
|
|
25
|
+
| `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. |
|
|
26
|
+
| 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. |
|
|
27
|
+
| Turn checkpoint and pending question | `TurnCheckpoint` writes the running turn overlay at iteration boundaries and clears it at settlement/end; `QuestionDesk` updates `Session#pending_question`, persisted by `Session#save` and cleared on answer/settlement. | The next worker settles a checkpoint on startup instead of replaying the dead turn. Session readers and Bridge snapshots read the pending question; answers go through the live Bridge when present. These are session data, not liveness locks. |
|
|
28
|
+
| `scratch` | `SpawnPart#spawn_session` saves the flag in the session file. There is no separate marker; terminal/worker cleanup deletes the scratch session. | Inbox wake policy and worker boot read the session field. Scratch sessions are not resumed by ordinary delivery; their worker is removed when its terminal leaves. |
|
|
29
|
+
|
|
30
|
+
`SessionStores` registers cross-version sidecar ownership and removal with the session directory. The lists above focus on
|
|
31
|
+
the lifecycle facts; deletion takes the session's `owner.lock` as `deleting`, rechecks `starting`, then removes the JSON
|
|
32
|
+
and entire sidecar directory.
|
|
33
|
+
|
|
34
|
+
## Derived states
|
|
35
|
+
|
|
36
|
+
`SessionLifecycle::STATES`, in precedence order (the first whose facts hold wins), as `Reading.derive` names them from a
|
|
37
|
+
`WorkerPresence` read with its link (`SessionLifecycle::Reading`: `state`, `presence` (also `facts`), `continuing`).
|
|
38
|
+
These are reader labels, not stored values:
|
|
39
|
+
|
|
40
|
+
| State | Facts that produce it |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `absent` | No session file; a leftover sidecar directory may still exist (its facts are ignored). |
|
|
43
|
+
| `tui_owned` | `owner.lock` held with kind `tui` (a one-shot `chi -p --non-interactive` owns it): an in-process one-turn host, not a worker. Wins over a stop, a start, an archive. |
|
|
44
|
+
| `deleting` | `owner.lock` held with kind `deleting` while the session's files go (`WorkerLink` reads it as `Starting`). Every delivery is refused (`WakePolicy`'s `:deleting`). |
|
|
45
|
+
| `stopping` | A worker holds the lock and the `stopped` marker exists, whatever its link. |
|
|
46
|
+
| `skew` | A worker holds the lock and its sidecar speaks a newer protocol (`WorkerLink::Skew`). |
|
|
47
|
+
| `leaving` | The worker closed its Bridge and still holds the lock (`leaving_at`, `WorkerLink::Leaving`). |
|
|
48
|
+
| `booting_stuck` | A worker has held the lock past `WorkerLink::START_LIMIT` without its sidecar (`Starting`, stuck). |
|
|
49
|
+
| `booting` | A worker holds the lock without its matching sidecar yet (`Starting`); also an owner of unknown kind (a lock record still blank after `OWNER_READ_ATTEMPTS`). |
|
|
50
|
+
| `live` | A worker holds the lock and its sidecar matches it (`WorkerLink::Live`). |
|
|
51
|
+
| `stopped_starting` | No owner; the `stopped` marker and a fresh `starting` marker (archived or not). |
|
|
52
|
+
| `stopped` | No owner; the `stopped` marker (archived or not). |
|
|
53
|
+
| `archived_starting` | No owner, no stop; `archived` and a fresh `starting` marker. |
|
|
54
|
+
| `starting` | No owner, no stop, not archived; a fresh `starting` marker names a live starter. |
|
|
55
|
+
| `archived` | No owner, no stop, no start; `archived` has `archived_at`. |
|
|
56
|
+
| `idle` | The session exists with none of the above. |
|
|
57
|
+
|
|
58
|
+
The compound states exist because the deciders disagree on precedence: owner first (WakePolicy, resume, archive,
|
|
59
|
+
delete) or stop first (a schedule's busy check, a terminal's attach); WakePolicy reads archived before starting. Facts
|
|
60
|
+
that are not states: `continuing` (`continue.json` names a successor and `continue.lock` is held: only a send's and a
|
|
61
|
+
schedule's link resolution reads it), a stale sidecar (`WorkerLink::Stale`: a crashed worker's leftover, reads as
|
|
62
|
+
the no-owner state), and the other crashed leftovers (a checkpoint, a `.processing` file, an unlocked continue intent).
|
|
63
|
+
`SessionLifecycle::CANONICAL` holds the fewest facts per state, each deriving back to it; `stopping` is a worker whose
|
|
64
|
+
Bridge answers, with a stop, and `stopped_starting` a start marked before the stop.
|
|
65
|
+
|
|
66
|
+
A read costs what `WorkerPresence.read(link: :look)` costs plus a `continue.json` stat: idle about 8 probes and one
|
|
67
|
+
flock, no JSON (~20–50 µs); a live worker adds the owner record and `bridge.json` (~0.1–0.2 ms); a continue in flight a
|
|
68
|
+
lock probe and its JSON. The worst case is `OwnerLock.owner`'s blank-record retry (0.1 s).
|
|
69
|
+
|
|
70
|
+
## Allowed operations
|
|
71
|
+
|
|
72
|
+
`SessionLifecycle::ALLOWED` (`session_lifecycle/allowed.rb`) is `{op => {state => cell}}`: every operation in every
|
|
73
|
+
state. A cell is `:go`, `:wait` or the decider's own refusal reason; `SessionLifecycle.verdict(op, cell)` reads it as
|
|
74
|
+
`:go`, `:wait` or `:refused` (resume's `live` and `starting` wait, restart's `fallback` goes).
|
|
75
|
+
|
|
76
|
+
- **Delivery columns** (send, note, push, ring, fresh_verdict, leave, schedule, plugin, delegate, participant,
|
|
77
|
+
automatic) are generated at load from `SessionInbox::WakePolicy::ROWS`, unchanged: each row's `decide` on
|
|
78
|
+
`CANONICAL[state]` (a worker asked for, no scratch file), `:start`/`:live` as go, `:starting`/`:stopped`/
|
|
79
|
+
`:archived`/`:none` as wait, `:gone`/`:owned`/`:deleting` as themselves. `:off` and `:scratch` are op-local.
|
|
80
|
+
`deleting` refuses every kind: `WakePolicy#refusal` before the write (nothing written), `#decide` after it (a
|
|
81
|
+
delete that took the lock between the two). What each kind does then: a turn delivery (`deliver_turn`, any sender)
|
|
82
|
+
answers 409 `DeliverResult::DELETING` ("the session is being deleted") and after its write takes its file back
|
|
83
|
+
(`SessionInbox.withdraw`; a file a worker claimed meanwhile stays delivered), also when the session went while it
|
|
84
|
+
wrote (and a folder the write made again goes); a note is a gone session's (`Session::NotFound`, its note taken
|
|
85
|
+
back); a ring, a push and a fresh verdict are refused before their write as for a gone parent (a push records to
|
|
86
|
+
its source's folder as for a gone session), and `wake_for_report` answers `:deleting`; a leave's respawn drops
|
|
87
|
+
(`why: deleting`).
|
|
88
|
+
- **Literal columns** (`LITERAL`): resume (`resume_session`), restart (`restart_session`: `stop_marked` in every
|
|
89
|
+
state with the stop marked: stopping, stopped, stopped_starting), stop (`stop_session`),
|
|
90
|
+
archive (`archivable!`), delete (`release_for_delete!`, without a stop), sched_chain and sched_same
|
|
91
|
+
(`Schedules#busy_reason`; `worker_busy` is "its worker is starting or leaving") and attach
|
|
92
|
+
(`TerminalUI::LocalLink#live_worker`: `gone_stopped`, `gone_worker_newer`). They assume neutral op-local facts: not
|
|
93
|
+
scratch, saved status idle, no `input/`, no question or offer, not SIGSTOPped, features restart and activity, an idle
|
|
94
|
+
worker with no streams. Absent's delete and schedule cells are unreachable (a gone session is refused first).
|
|
95
|
+
|
|
96
|
+
Link resolution (`SessionInbox::Head.resolve`, `Schedules#target_of`) stays outside: the cells are the link's own.
|
|
97
|
+
|
|
98
|
+
`restart_session` is the first decider migrated to the table: its lifecycle precheck is `SessionLifecycle.read` (the
|
|
99
|
+
owner read through `session_owner`) and `ALLOWED[:restart]`: `owned_by_tui` raises `OwnedByTUI`, a refusal cell
|
|
100
|
+
raises `RestartRefused` with it as the reason (`starting`, `not_running`, `stop_marked`), `fallback` goes to
|
|
101
|
+
`restart_fallback` (skew, a stuck start) and `go` asks the live worker. Its op-local checks stay where they were: the
|
|
102
|
+
SIGSTOP check (`:stopped`, the worker's pid: a different condition with its own words, before the table's refusal),
|
|
103
|
+
the worker's `restart` feature, the Bridge's reply and the fallback's holds. The matrix still drives it, so its
|
|
104
|
+
column is pinned against the precheck and the op-local paths together. The other deciders don't read `ALLOWED` yet.
|
|
105
|
+
|
|
106
|
+
## Characterization matrix
|
|
107
|
+
|
|
108
|
+
`spec/session_lifecycle/matrix_spec.rb` (rows, files and drivers in `spec/support/lifecycle_matrix.rb`) writes every
|
|
109
|
+
combination as real files: owner/link pairs (none, stale sidecar, tui, tui with a stale sidecar, deleting, a worker
|
|
110
|
+
Live, Starting, stuck, Leaving, Skew, an owner of unknown kind) × stop × starting × archived, one absent session, a
|
|
111
|
+
continue in flight on each archived no-owner row, and a start marked after the stop on each no-owner row with both
|
|
112
|
+
(the order is a row fact: `StartingMarker.claim` takes over only a start at or before `stopped_at`). The owner lock's
|
|
113
|
+
holder, `ContinueIntent.in_flight`, `Process.spawn`, TERM/CONT, the Bridge and the restart fallback are stubbed; no
|
|
114
|
+
process starts. Each row checks that `SessionLifecycle.read` names the state its facts derive, then drives every
|
|
115
|
+
operation (one driver each, every private reach in that one file) and projects its answer into a cell. A row the
|
|
116
|
+
code can't make (a one-turn run's lock with a stop) is marked `reachable: false` with its note and still asserted.
|
|
117
|
+
|
|
118
|
+
Every answer must equal `ALLOWED[op][state]` (for the session hub, `SHOWN[state]`: `Web::SessionSummary.build`'s
|
|
119
|
+
status and bridge_up, its `SessionRow`'s live), or be named by exactly one `KNOWN_DIFFERENCES` entry (op, a `when`
|
|
120
|
+
over the row, a plain reason); an entry that names no mismatch fails as stale. The entries are the findings for the
|
|
121
|
+
owner, not fixed: stop-first schedule and attach checks under a one-turn run's, a deleter's or an unknown owner's lock;
|
|
122
|
+
chain mode's starting check before any one-turn-run check; a start marked after the stop holding a resume off;
|
|
123
|
+
`wake_for_report` reporting a worker's `:live` as `:owned`; the hub's bridge_up, live and status overlay. (Restart
|
|
124
|
+
never reading the stop and `busy_reason`'s live branch falling through to the starting check were fixed: their
|
|
125
|
+
entries went stale and were removed.) The delivery columns are
|
|
126
|
+
generated from `WakePolicy::ROWS`, so for deliveries the matrix proves the states are drawn right (decide is a function
|
|
127
|
+
of the state), not what WakePolicy does; the literal columns and `SHOWN` are goldens.
|
|
128
|
+
|
|
129
|
+
## Locks and crash repair
|
|
130
|
+
|
|
131
|
+
`owner.lock` is the single-owner boundary for an Engine; its flock is released by process death. A starting claim uses
|
|
132
|
+
an atomic link rather than a long-held lock. A continue holds its exclusive `continue.lock` across the transition;
|
|
133
|
+
shared holds protect followed sends and chain operations. When chain deletion nests locks, it takes the continue hold
|
|
134
|
+
before the `owner.lock` deletion locks. Inside a worker, the lock order is Engine event lock, then
|
|
135
|
+
`WorkerExitClaim`'s mutex. Session saves serialize through their per-session save lock. These locks protect separate
|
|
136
|
+
facts; there is no global lifecycle lock or atomic snapshot across all markers.
|
|
137
|
+
|
|
138
|
+
A worker that crashes exits 1 and is not respawned just because input is queued. A later delivery may start a new
|
|
139
|
+
worker; under its owner lock, startup settles a turn checkpoint and stale running status rather than replaying the
|
|
140
|
+
dead turn. Interrupted continue intents are repaired separately by session listing/the web hub or before another
|
|
141
|
+
continue (`SessionContinue.repair_interrupted`), not by worker startup.
|
|
142
|
+
|
|
143
|
+
## Open windows
|
|
144
|
+
|
|
145
|
+
These are documented race boundaries, not promises of an atomic lifecycle transition:
|
|
146
|
+
|
|
147
|
+
| Window | Code comment / current behavior | Pin |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| A ring wake decides to start, then a stop lands before resume. | `SpawnPart#wake_for_report` (`session_manager/spawn.rb`): `resume_session` can clear that stop and start; the check and resume are not one transaction. | Unit spec: stop in the start callback and assert the worker is started and the marker cleared. |
|
|
150
|
+
| 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: the write-then-reread and the recheck under the existing deletion lock close it. 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. |
|
|
151
|
+
| 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. |
|
|
152
|
+
| 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. |
|
|
153
|
+
| 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. |
|
|
154
|
+
| 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. |
|
|
155
|
+
|
|
156
|
+
## Adding a transition
|
|
157
|
+
|
|
158
|
+
1. Name the fact being changed and its on-disk format; add cross-version handling to `SessionStores` when applicable.
|
|
159
|
+
2. Put the write/removal in its owning module and add the call site, with its reason, to
|
|
160
|
+
`spec/session_lifecycle_writers_spec.rb`.
|
|
161
|
+
3. Identify every decider that reads the fact and how it observes the change (lock probe, direct read, poll, or SSE).
|
|
162
|
+
4. If the change touches an open window above, extend its pin in the corresponding unit spec; don't hide a race with a
|
|
163
|
+
sleep or a process-wide integration test.
|
|
164
|
+
5. If the fact changes a state, update `SessionLifecycle::STATES`/`Reading.derive` and `CANONICAL`, then the
|
|
165
|
+
`ALLOWED` cells (the literal ones by hand; the delivery ones follow `WakePolicy::ROWS`) and the matrix's rows; a
|
|
166
|
+
decider that answers otherwise is a `KNOWN_DIFFERENCES` entry with its reason, never a silent cell change.
|
|
167
|
+
6. Recheck lock order, crash cleanup, and the existing file-format/compatibility specs before changing runtime behavior.
|
|
@@ -20,7 +20,9 @@ Verify, the composer's mode and the strip's hide went into modules of their own.
|
|
|
20
20
|
its own, wired from `app.js` in a few lines; a refactor that shrinks `app.js` ratchets its cap down with it. Never
|
|
21
21
|
raise either: extract instead. Ruby's twin is `Samagotchi/FileSize` (docs/testing.md, File size).
|
|
22
22
|
|
|
23
|
-
**New exports go in new modules.**
|
|
23
|
+
**New exports go in new modules.** An `npm test` ratchet parses every public module and compares existing modules'
|
|
24
|
+
exports with `spec/web/public/exports_baseline.json`; `release:bump` refreshes the baseline. Its `ALLOWED` entries
|
|
25
|
+
name the file and export and carry a one-line reason. The static JS is served at unversioned URLs. Today every load revalidates
|
|
24
26
|
(app.rb `serve_static` sends `Cache-Control: no-cache` with a content ETag, and `sw.js` has no fetch handler), but an
|
|
25
27
|
open tab still holds the modules it loaded, and a proxy that ignores `no-cache` can serve an old one: a new export
|
|
26
28
|
on an existing module, imported by a new version of another, then finds the old module without it and blanks the
|
|
@@ -390,8 +392,10 @@ is no longer the live one (a ✕ on another card while the first plan was read)
|
|
|
390
392
|
`GET /api/sessions/:id/delete_plan`, fetched as it opens and only for a chained session: the server's own plan and
|
|
391
393
|
refusals (`SessionChain::Delete::Preview`, the code the delete runs), so the sheet and the delete can't disagree; its
|
|
392
394
|
cost is one session listing walk per open. `deleteChoices` (pure) turns it into the two choices, a schedule's banner
|
|
393
|
-
and each refusal's "Not while …"; a plan that says no chain (a link alone past a gap) falls back to the confirm.
|
|
394
|
-
|
|
395
|
+
and each refusal's "Not while …"; a plan that says no chain (a link alone past a gap) falls back to the confirm. The
|
|
396
|
+
confirm sends the shown choice's `digest` (`expect=`, `data.js deleteSession`/`deleteChain` keep it out of `fetch`);
|
|
397
|
+
a `409 plan_changed` re-reads the plan and redraws the sheet with "What this deletes changed; check again" (a link no
|
|
398
|
+
longer chained gets the plain confirm). Any other refusal `runDeleteFlow` shows in the sheet
|
|
395
399
|
(`refusalModel`: a moved delegate that can't go back offers "Stop its worker, then delete" only when the 409 says
|
|
396
400
|
`stoppable`; it stops each, retries only once the stop answers `released`, and says so otherwise, never looping, one
|
|
397
401
|
stop at a time).
|
|
@@ -227,7 +227,8 @@ projection), on both loops. It costs one model step; a model may skip it (the no
|
|
|
227
227
|
those), what the caller's `found` look says can't be read (`WorkingSetCommand#missing`: a file not there or a
|
|
228
228
|
directory; a memory name `memory_read` rejects or that neither scope holds), an item holding the user's drop
|
|
229
229
|
(`undrop_first`: undrop brings it back without a step), one already in the system prompt and with no working-set
|
|
230
|
-
output (`in_prompt`: nothing to add
|
|
230
|
+
output (`in_prompt`: nothing to add; matched by name and scope, `Tools::MemoryRead.prompt_memory?` over
|
|
231
|
+
`Engine#prompt_memories`, a bare name or an unscoped prompt entry by name only), and one the model has whole (`already_sent`: live, a read of it sent). The
|
|
231
232
|
prompt-only refusal doesn't apply when the set holds a read of that memory: a stale or forgotten item may still be
|
|
232
233
|
added as the web row's `refresh`. **`unadd`** takes a pending add back (free); without one it is refused
|
|
233
234
|
(`not_added`).
|
data/docs/plugins.md
CHANGED
|
@@ -1248,7 +1248,7 @@ ctx.sessions.stop(id) # one of this session's own children
|
|
|
1248
1248
|
- `send(id, text)` sends a user message to a session (an id or a unique
|
|
1249
1249
|
prefix); it runs as a turn, and an idle session is woken. A session its
|
|
1250
1250
|
owner stopped or archived is not: `Error` (`session_stopped` /
|
|
1251
|
-
`session_archived`), nothing sent. It waits up to
|
|
1251
|
+
`session_archived`), nothing sent; nor one being deleted (`session_deleting`). It waits up to
|
|
1252
1252
|
5 s for the session's worker, so call it from an anytime command or a
|
|
1253
1253
|
thread of your own, never from a tool or hook of a running turn. A
|
|
1254
1254
|
session a `--non-interactive` one-shot has can't take it.
|
data/docs/releasing.md
CHANGED
|
@@ -76,7 +76,7 @@ as the GitHub release body.
|
|
|
76
76
|
| `rake lint` / `rake lint:fix` | RuboCop over the repo (must report no offenses; CI runs it) / its safe autocorrect (`rubocop -a`). |
|
|
77
77
|
| `rake gem:validate`, `gem:build`, `gem:install`, `gem:clean` | Check the gemspec; build the gem into `pkg/`; build and install it locally; remove the built gems. |
|
|
78
78
|
| `rake release:draft_changelog` | A draft Unreleased section from the commit subjects since the last tag, grouped. Stdout only. |
|
|
79
|
-
| `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG, a compatibility corpus at `spec/compat/X.Y.Z/` written through the current state writers (with `wire/`: a real Engine and Bridge's replies, recorded twice and refused if the two differ), refreshed `spec/shared/compat_wire/*.json` fixtures, and `requires_chi: ">= X.Y.Z"` for each bundle marked `requires_chi_next` (the marker dropped), then a profile left below a member's `requires_chi` raised to it, with a patch bump of its version (none when it moved since the last tag) and named in the CHANGELOG's "Update with `chi update`" line, and each entry an `# Unreleased` comment in `Plugin::Api::SINCE` or `Manifest::SINCE` names moved into the table at X.Y.Z (the comment dropped). No commit; commit the corpus and
|
|
79
|
+
| `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG, a compatibility corpus at `spec/compat/X.Y.Z/` written through the current state writers (with `wire/`: a real Engine and Bridge's replies, recorded twice and refused if the two differ), refreshed `spec/shared/compat_wire/*.json` fixtures, `spec/web/public/exports_baseline.json` rebuilt from the public modules, and `requires_chi: ">= X.Y.Z"` for each bundle marked `requires_chi_next` (the marker dropped), then a profile left below a member's `requires_chi` raised to it, with a patch bump of its version (none when it moved since the last tag) and named in the CHANGELOG's "Update with `chi update`" line, and each entry an `# Unreleased` comment in `Plugin::Api::SINCE` or `Manifest::SINCE` names moved into the table at X.Y.Z (the comment dropped). No commit; commit the corpus, fixtures and baseline with the release. |
|
|
80
80
|
| `rake release:check` | Clean tracked tree, VERSION == system bundle, a CHANGELOG section, no `requires_chi_next` left, no `# Unreleased` comment left in `Plugin::Api::SINCE` or `Manifest::SINCE`, `bundles:check`, `rake lint` (RuboCop) + `npm run lint` (the web frontend's ESLint), rspec (both roots: `spec` and the bundles' own `spec/`) + `rake bundles:specs` + npm test, `gem build`, then a clean install into a temp GEM_HOME that runs `chi --version`, `chi self` and `chi bundle list` with a temp HOME. Needs the network (gem dependencies). |
|
|
81
81
|
| `rake release:notes[X.Y.Z]` | Prints the CHANGELOG section (default: the current VERSION). |
|
|
82
82
|
|
|
@@ -119,7 +119,8 @@ The agent does each step and stops where the user has to say yes.
|
|
|
119
119
|
`spec/compat_spec.rb` names it, and the shim goes (or its date moves)
|
|
120
120
|
before the release. The bump also refreshes `spec/shared/compat_wire/*.json`
|
|
121
121
|
by running `UPDATE_COMPAT_WIRE=1 bundle exec rspec spec/compat/wire_readers_spec.rb`;
|
|
122
|
-
|
|
122
|
+
rebuilds `spec/web/public/exports_baseline.json` from every public module
|
|
123
|
+
except `vendor/`; commit both with the release. If either refresh fails, the
|
|
123
124
|
bump is already written; follow its rerun command before reviewing or committing.
|
|
124
125
|
5. **Check.** Add all release files, including the new compatibility corpus, then run it:
|
|
125
126
|
`git add -A && git commit -m "Release X.Y.Z"` and `bundle exec rake release:check`.
|
data/docs/sessions.md
CHANGED
|
@@ -25,13 +25,13 @@ A session is deleted if **expired by age OR overflow by count** (unless `keep_st
|
|
|
25
25
|
|
|
26
26
|
**Worker idle exit:** a background worker (plain `chi`, Web UI sessions) exits after `SAMAGOTCHI_SESSION_IDLE_EXIT_MINUTES` (`session.idle_exit_minutes`, default `30`, `0`=never) with no turn running or queued, no client on its stream (an open web tab or attached terminal keeps it), no reminder registered, no background task it watches for a [finish wake](internals/background-tasks.md#finish-wake) still running or waiting for its wake turn (with `session.task_wakes: wake`; not one whose turn you stopped) and no continue offer (the step-limit question) waiting for an answer. It removes `bridge.json` and frees `owner.lock`; the next prompt or `--attach` wakes a new worker (`WorkerIdleExit`, `WorkerBoot.run_session_loop`). As its Bridge stops, the worker marks the lock leaving (`OwnerLock#mark_leaving`: `leaving_at`, and `leave_wait`, its `recap.timeout`), since it keeps the lock while it writes the recap on leave: an `--attach` or `--resume` meanwhile (here, or a remote one through chi web's wake) prints `(waiting for the session to finish its recap…)` (`LaunchMode::RECAP_WAIT`) and waits for the release, up to that budget plus `OwnerLock::LEAVE_MARGIN` (5 s), before starting the new worker (`OwnerLock.await_release`). A lock held by a worker that isn't leaving (a live one, a stuck one) is left as before. A client can also ask the worker to exit right away (Bridge `POST /session/:id/exit`; `/exit` in an attached terminal does, `/detach` doesn't): the same rules apply without the timeout (even with `0`), and the asker's own stream doesn't count. The reply names what keeps it up (for background tasks, which ones and how to stop them). When every hold is one the user can stop — reminders, a watched task still running, a delegate with a live worker — the 409 also carries `holds: [{kind:, items: [{id:, label:, detail:}]}]` (a reminder's detail is its schedule, `every 20m`/`every 1h`, `, due now` when it is already due), and an attached terminal asks what to do with them; its "stop them and exit" posts `{"stop": "all"}`, which clears the reminders, stops those tasks (`TaskRuntime.stop_task`, as `task_stop`) and stops those children (`SessionManager.stop_session`) before leaving, re-checking first that nothing the user can't stop appeared meanwhile (`HoldStop`). A delegate counts only for that ask: it never holds the idle exit, and an exit that deletes or archives the session does not ask about it. The session's status stays as it was, not `stopped`. With `"restart": true` (a worker whose sidecar lists the `restart` feature) the worker hands the session to a new worker on the newest chi installed: it leaves, then starts its successor once its lock is free, keeping even an empty session and writing no recap. Clients' streams don't hold a restart (a web tab and an attached terminal reconnect to the new worker); what would be lost does: a turn running or queued, a continue offer, a question or approval waiting, a `/btw` (or another anytime command) still running, a delegate's approval relay open or settled in the last 10 minutes, and background tasks this conversation started that still run (`WorkerIdleExit#hold_for_restart`; 409 `held` with `reason`). Reminders go along: as it leaves, the worker writes them to `<id>/reminders.json` (0600: `session_id`, `written_at`, and each reminder's id, name, description, interval and next fire as wall-clock time; `ReminderCarry`), and its successor reads and deletes the file as it starts, before its idle scheduler runs. A restored reminder keeps its id and schedule; one that came due meanwhile fires once at once, and one further ahead than its interval (a clock that jumped) is due one interval from now. The file counts only for the same session within 2 minutes of `written_at`, and not once the session is stopped: otherwise it is deleted unread (log `reminders_carry_dropped`, at warn unless the session was stopped). A stop that lands while the worker leaves for a restart wins: the worker writes no file, and no successor starts (`WorkerBoot.run_session_loop`, log `restart_dropped`). So does one that lands as it leaves any other way (an idle exit, `/exit`, a signal) with input queued or delegate reports waiting: no new worker un-stops it (log `respawn_dropped`), and what waits stays for the next start. A person's send after the stop (chi send, a web tab, a terminal) still un-stops it, as a person's send always does (see *Who may wake a session* below): one that reaches a leaving worker clears the stop, so the leave's new worker runs it (log `send_unstopped_leaving`); an archive deletes the file of each session it archives. Once an exit or restart is taken (claimed before a stop-all stops anything), the first one decides how the worker leaves: a later request of the same kind is answered as that exit, one of another kind (a stop-all from another terminal after a restart, chi web's "Restart workers" after a `/exit`) gets 409 `held` with `reason` `leaving_exit`, `leaving_delete` or `leaving_restart`, and a restart says it was refused rather than "restarted". A write that fails keeps the worker up with its reminders (log `reminders_carry_failed`), and the caller reports no new worker. A reminder already due when the restart is asked runs its turn first, so the restart's wait (10 s) may report no new worker yet though the hand-off follows. A worker from before this still refuses a restart for its reminders (409 `reminders`). Only an asked restart carries them: the fallback's TERM (a worker that can't be asked, below), a stop, an idle exit (which reminders hold anyway) and a crash drop them as before. What lives only in the worker's memory goes: the event history a late client replays, the kept `/btw` answers, a plugin's in-memory state.
|
|
27
27
|
|
|
28
|
-
**Empty sessions:** a session nothing happened in is deleted when it is left, so `chi` → `/exit` leaves no trace. Empty means: no messages, no turn tried (a failed turn leaves a `last_prompt` and keeps it), no memory used, no pending question, nothing in `input/`, `notes/` or `images/`, nothing in its dir beyond the worker's skeleton, mode `assist`, and the default model. A session on another model (`/model`, `--model`) counts as prepared and stays (`SessionManager.discardable?`). The worker checks as it idle-exits or leaves on a client's request and deletes it once its lock is free, checking again first. The attached `/exit` then says `Detached; the session is empty: it will be discarded if nothing arrives before its worker stops.` (a note or prompt landing first keeps it). The retention sweep catches those killed first: empty sessions over an hour old with no live owner, whatever `DAYS`/`MAX`, and skeleton-only dirs with no `*.json` (removed as a delete removes, every session store, under the session's lock: a worker or a start that took the session since the check keeps it, and so does one whose file or content was written meanwhile, read again under that lock). `session.keep_empty: true` (env `SAMAGOTCHI_SESSION_KEEP_EMPTY`) turns all of it off.
|
|
28
|
+
**Empty sessions:** a session nothing happened in is deleted when it is left, so `chi` → `/exit` leaves no trace. Empty means: no messages, no turn tried (a failed turn leaves a `last_prompt` and keeps it), no memory used, no pending question, nothing in `input/`, `notes/` or `images/`, nothing in its dir beyond the worker's skeleton, mode `assist`, and the default model. A session on another model (`/model`, `--model`) counts as prepared and stays (`SessionManager.discardable?`). The worker checks as it idle-exits or leaves on a client's request and deletes it once its lock is free, checking again first and once more under the delete's lock (a prompt or note that went in before that keeps it). The attached `/exit` then says `Detached; the session is empty: it will be discarded if nothing arrives before its worker stops.` (a note or prompt landing first keeps it). The retention sweep catches those killed first: empty sessions over an hour old with no live owner, whatever `DAYS`/`MAX`, and skeleton-only dirs with no `*.json` (removed as a delete removes, every session store, under the session's lock: a worker or a start that took the session since the check keeps it, and so does one whose file or content was written meanwhile, read again under that lock). `session.keep_empty: true` (env `SAMAGOTCHI_SESSION_KEEP_EMPTY`) turns all of it off.
|
|
29
29
|
|
|
30
30
|
**Participants:** a session its owner invited participants into (`chi share`, see [CLI: Participants](cli.md#participants)) has two more files in its dir, neither in the session JSON: `participants.json` (0600), who is or was invited (`{participants: [{id, kind, name, role, added_at, expires_at, removed_at}]}`, never a token), which chi web and `chi share` write and the worker reads (`Participants.read`); and `participants.jsonl` (0600, append-only), the audit trail (grants issued, revoked and expired, each new peer, refused routes). A session nobody was invited to has neither. A continue, a fork or a delegate starts with no participants. Archiving or deleting the session revokes its links. See [internals/participants.md](internals/participants.md).
|
|
31
31
|
|
|
32
32
|
**Always attached:** every interactive `chi` (plain, `-p`, `--resume ID`, `--attach ID`, `chi scratch`) runs its session in a background worker and attaches to it; there is no setting for it. The worker runs in the session's `working_directory`, so `!commands` and tools see the directory the session was started in. Only `chi -p TEXT --non-interactive` runs its one turn in this process; while it does, the session can't be attached ("in use by a one-turn chi --non-interactive run or an older chi's terminal"). See [CLI: Sharing a session](cli.md#sharing-a-session).
|
|
33
33
|
|
|
34
|
-
**Who may wake a session:** every turn delivery names its sender (`SessionManager.deliver_turn` requires `client_id`), and the sender's kind picks what it may do to the worker (`ClientId.wake_kind`, `SessionInbox::WakePolicy.for_sender`). A person — `chi send`, a web tab, an attached terminal — starts an idle session, un-stops a stopped one and brings back an archived link. A schedule's firing, a plugin's `ctx.sessions.send`, a `delegate` follow-up, a participant's turn and any sender chi doesn't name start an idle session only: a session its owner stopped or archived refuses them (409 `session_stopped`, "the session is stopped; only its owner's message starts it again", or `session_archived`, "…brings it back"), nothing written. A schedule counts that as a skip (and skips a stopped session at its check, [scheduling.md](scheduling.md)); `delegate` says it as `Error: session <id8> refused: …`; a plugin gets `Error`. A turn already handed to a live worker is that worker's, as before. chi web's owner turn and command routes name a body that carries no `client_id` as `web:unnamed` (a web tab's rights).
|
|
34
|
+
**Who may wake a session:** every turn delivery names its sender (`SessionManager.deliver_turn` requires `client_id`), and the sender's kind picks what it may do to the worker (`ClientId.wake_kind`, `SessionInbox::WakePolicy.for_sender`). A person — `chi send`, a web tab, an attached terminal — starts an idle session, un-stops a stopped one and brings back an archived link. Nobody's message goes into a session being deleted (409 `session_deleting`, *Deleting a session* above). A schedule's firing, a plugin's `ctx.sessions.send`, a `delegate` follow-up, a participant's turn and any sender chi doesn't name start an idle session only: a session its owner stopped or archived refuses them (409 `session_stopped`, "the session is stopped; only its owner's message starts it again", or `session_archived`, "…brings it back"), nothing written. A schedule counts that as a skip (and skips a stopped session at its check, [scheduling.md](scheduling.md)); `delegate` says it as `Error: session <id8> refused: …`; a plugin gets `Error`. A turn already handed to a live worker is that worker's, as before. chi web's owner turn and command routes name a body that carries no `client_id` as `web:unnamed` (a web tab's rights).
|
|
35
35
|
|
|
36
36
|
**Which chi a worker runs:** a new or woken worker runs the newest chi installed for this Ruby (`gem 'samagotchi', '>= 0.a'`, prereleases count), whoever starts it: a `chi web` or terminal still on an older chi starts it on the newest one, so a stale process doesn't spread old code. A worker already running keeps its version until it is restarted. Should the newest install fail to load, the worker runs the starter's own version and logs `boot_fallback` (its stdio is `/dev/null`). Under `bundle exec` the worker drops Bundler's env first, so it activates the newest gem too. Two consequences: a wrapper pin (`chi _0.17.0_ web`) pins only that process, not the workers it starts; and a source checkout (`bin/chi` in a worktree, `bundle exec`) starts its workers on its own `lib/`, but a session it made that is later woken by an installed chi (`chi web`, `chi send`) runs the installed code. The names an older starter hands a newer worker (the boot line, its env keys, `input/` files, the session JSON fields and the Bridge routes sessions use on each other) are pinned in `spec/worker_contract_spec.rb`. A chi newer than 0.130.0 keeps the top-level keys it doesn't know (a newer chi's fields) when it saves a session, after its own, and doesn't act on them; `written_by` names the chi that saved the file last, and a worker woken on a file a newer chi saved logs `newer_writer`. chi 0.130.0 and older drop those keys: a session a newer chi made loses its newer fields when an older chi wakes or saves it (for example `chi --attach` from a project whose Ruby has an older chi). Keep the chi in every Ruby you run it from newer than 0.130.0.
|
|
37
37
|
|
|
@@ -43,7 +43,7 @@ A new session field is one `Session::FIELDS` row, plus a `SessionSetup` member w
|
|
|
43
43
|
|
|
44
44
|
**Stopping a worker:** `chi sessions stop ID` marks the session stopped (an `<id>/stopped` file holding when, `{"at"}`, not a session.json field, which a worker saving at that moment would write over; a resume removes it), sends its worker TERM, then CONT (a stopped worker, SIGSTOP or Ctrl-Z, runs its TERM handler only once continued, so it leaves at once instead of outliving the wait), and waits (up to 10 s) until the worker has let go of `owner.lock`. A running turn is canceled over the Bridge first, with reason `session_stopped` (the turn's line ends "(session stopped)", its note says `cancelled (session-stopped)`, and a command it was running says "stopped as the session was stopped"; a bare signal to the worker makes it "stopped by a signal to chi"; an older worker takes the reason as `manual`); the TERM stops whatever still runs as a Stop with reason `signal` and saves it (a spawned worker traps TERM, HUP and INT: `WorkerSignals`; a turn not ended within 3 s, 0.5 s after a stop or a second signal, is cut and the session saved as it was), and a stopped worker still saves its kept turn, since the marker, not the saved status, says stopped. Any TERM, HUP or INT does the same to a worker outside a stop: it leaves (log `worker stop reason=signal`) and the next send wakes a new one, so a `chi --resume ID` right after spawns a fresh worker. That is also how to restart a worker still running an older chi, which the attached terminal reports when a command or a question dismiss gets a 404, and the web when an answer, a dismiss, a command or a cancel does (`501 not_supported`; `BridgeClient.stale_worker_message`). A command this chi has that the older worker doesn't (`/llm-context`, the web's ⚙ panel, against a 0.39.0 worker) says the same, not `not a session command` (`SessionCommandCatalog.builtin_name`); a typo keeps its `400 unknown_command`. The web's `POST /api/sessions/:id/stop` waits the same way, for 2 s (the page's Stop shows the stop at once), or for the body's `wait` up to the same 10 s (`SessionManager::STOP_WAIT`): `chi --remote NAME sessions stop` sends it, so it waits as long as here. Before that stop, the page's `stop session` button asks what the worker still has that the user can stop: `GET /api/sessions/:id/holds` (owner-only) answers the worker's `holds` — the same list the exit ask's 409 carries — always an array, empty when there is no live worker, one from before the route, or one that did not answer. With something, a sheet (a bottom sheet on a phone, a popover at the button otherwise — `stop_sheet.js`) lists them, at most three of a kind named and `+N more`, and offers **Stop all** (`POST /api/sessions/:id/holds/stop` → `HoldStop#stop_all`, then the stop), **Stop session only** (the stop exactly as it was) or **Cancel**. Nothing to ask about is the plain confirm, one tap as before. Both buttons stay because a stop only TERMs the worker: its reminders die with it (a stop also deletes a restart's `reminders.json` no successor took yet, so a later resume doesn't bring them back), while a background task and a delegate are their own processes and keep running. A command sent during a turn that waits for its end (`/model X`, `!cmd`; see *Typing during a turn* in [cli.md](cli.md)) and hasn't run when the worker leaves (a stop, a crash) is answered `command_ran {status: "dropped"}`, so no UI keeps showing it waiting.
|
|
45
45
|
|
|
46
|
-
**Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped, unarchived, moved_back}`; `deleted` and `left_running` too; 409 with the refusal's reason as its code; 404). A schedule's target, anchor or head is refused (`scheduled`, naming the schedule): deleting a head would make the schedule fall back to an archived link. A user's delete (these three, `revive_previous:` and `refuse_continuing:` on `delete_session`) also knows about chains (`SessionChain::Delete`, *Session chains* → Deleting a link): it is refused while a continue of the session, or of the previous link it would bring back, is under way (`continuing`), and deleting a chain's newest link undoes its continue (D2/D5 below), the ids it brought back in `unarchived` and the delegates it gave back in `moved_back`. A previous link brought back is aged for retention from then on (`unarchived_at`) and has no participants (the archive ended them, and an unarchive doesn't bring them back). The scratch cleanup, the empty-session discard, the failed-continue rollback and a schedule's prune delete plainly; the retention sweep removes files directly (`remove_files`).
|
|
46
|
+
**Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. While the delete holds it (kind `deleting`), every delivery is refused: a message (`chi send`, the web, a schedule, a delegate, a plugin, a participant) gets 409 `session_deleting`, "the session is being deleted", and a send that read the session before the lock and wrote after it takes its file back and says the same (unless a worker took the file meanwhile: then it is delivered); a note is refused as for a gone session, and a delegate's ring, a push and a fresh verdict are not written. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped, unarchived, moved_back}`; `deleted` and `left_running` too; 409 with the refusal's reason as its code; 404). A schedule's target, anchor or head is refused (`scheduled`, naming the schedule): deleting a head would make the schedule fall back to an archived link. A user's delete (these three, `revive_previous:` and `refuse_continuing:` on `delete_session`) also knows about chains (`SessionChain::Delete`, *Session chains* → Deleting a link): it is refused while a continue of the session, or of the previous link it would bring back, is under way (`continuing`), and deleting a chain's newest link undoes its continue (D2/D5 below), the ids it brought back in `unarchived` and the delegates it gave back in `moved_back`. A previous link brought back is aged for retention from then on (`unarchived_at`) and has no participants (the archive ended them, and an unarchive doesn't bring them back). The scratch cleanup, the empty-session discard, the failed-continue rollback and a schedule's prune delete plainly; the retention sweep removes files directly (`remove_files`).
|
|
47
47
|
|
|
48
48
|
<a id="archiving-a-session"></a>**Archiving a session:** `chi sessions archive ID...`, `/archive` in a terminal and the Web UI's `archive` go through `SessionManager.archive_session`: it writes `<id>/archived` (`{"archived_at": …}`; not a session.json field, which every save rewrites) for the session and its delegated children. `Session.list` leaves archived sessions out unless `include_archived:`, and everything built on it follows: `chi sessions list` (`--archived` shows them, `[archived]`), the summaries (`--live`, json/tsv, the desktop panel, the agent's `list_sessions`) and the retention prune, which neither deletes nor counts them against `max_count`. `children_of` (max_children, `delegate_result`) still sees them, and `--resume`/`--attach ID`, `chi send`/`chi note ID` reach them as before, except that `chi send` and `chi note` to a link that was continued go to its chain's newest link (*Session chains*). Refused: a turn running in the session or in one of its children (naming the child; 409 `busy` on the web), a prompt queued in `input/` (it would run on the next resume) or a live worker's step-limit question still open, in it or a child (409 `busy` too), a one-turn `chi --non-interactive` run owning it (`owned_by_tui`), a `chi scratch` session (`scratch`). A live idle worker is stopped first, and the marker is written even if it is still shutting down. Input a human typed brings a session back (`{"unarchived_at": …}`): a prompt from the web, an attached terminal or `chi send` (origin `web:*`, `tui:*`, `cli:send`, its own first prompt: `spawn:first`; input naming no sender doesn't), steering merged into a running turn, a `/continue` answer or a question answered (the step-limit question too); a delegate's follow-up, a plugin's turn, a reminder, the idle recap, a note and just opening it don't. A child's input brings only the child back. The retention sweep ages an unarchived session from when it was unarchived, so unarchiving an old session doesn't let the next sweep take it. `/archive` leaves the session first, as `/exit` does, then archives it: in an attached terminal the worker is asked to exit (one that stays up for another UI is stopped by the archive; a running turn, a queued prompt or an open step-limit question refuses it), and an empty session is discarded instead; `chi scratch` refuses it. Typed while a turn runs, `/archive` waits for the turn's end (an attached terminal for the commands queued behind it too) and then archives. `chi sessions unarchive ID...` and the web's `unarchive` bring back the whole family. Web routes: `POST /api/sessions/:id/archive` (200 `{status, session_id, archived, stopped, discarded}`, ids) and `POST /api/sessions/:id/unarchive` (200 `{status, session_id, unarchived}`). The session hub and `GET /api/sessions` keep archived sessions, `archived: true` in their summaries: the page leaves them out of the strip, its count and the list at render, and the `archived` toggle beside the all-sessions search shows them, dimmed with an `archived` badge. The info bar marks a session whose live worker runs an older chi than the newest installed (`worker_version` in its summary): `chi 0.18.1 · Restart`, which asks to confirm and calls `POST /api/sessions/:id/restart` (a refusal's reason shows in a toast); a worker from before restarts shows `chi sessions stop ID` instead. The info bar reads `continue → · archive · stop · delete` (`unarchive` on an archived one; no `continue →` on a link continued already, see *Session chains*; `continue →` is a plain button like `archive`, in the accent on an archived session, where it is the thing to do); archiving the open session stays on it, with an Undo toast.
|
|
49
49
|
|
|
@@ -386,7 +386,7 @@ A session can **continue** an earlier one: "the next run of the same routine" (a
|
|
|
386
386
|
- **The page:** the info bar's `continue →` continues the open session (`continues: <id>, idle: true`; it reads `continuing…` through the recap wait) and opens the new link with an opener in the composer, not sent (a draft written in this session stays instead; one carried over from another session or the start page gives way to the opener, and the toast's **Restore draft** brings it back): the previous link's own first typed message when that link continues one (the 201's `opener`; a `!shell` line isn't taken), else `Continue where we left off.`. So whatever you sent on the last link comes back on the next one, and editing it once changes it for every later link; the previous link is archived, a toast says so (`Continued 3fa2c1d0 in 4b7e9a01; 3fa2c1d0 is archived; 1 open delegate moved`), and a moved delegate's card folds under the new link. When the previous link's model's host is gone the link starts on the default model and the toast carries the server's `model_warning` too, and then stays until closed. A fresh link (one with no turn yet, however it was made: `continue →`, `chi send --new --continues`, a reload) shows the model picker in its composer with the link's model, until its first turn starts (a failed or canceled first turn ends it too); a pick runs `/model <name>` in the link (a command bubble; the info bar follows) and changes neither the start page's remembered model nor its Recent list, and a Send right after it waits for the `/model` to be taken. A link a one-turn `chi --non-interactive` run has, or one continued already, shows none. A link continued already has no `continue →`: its `→` link goes to the next link (a stale page's continue answered 409 `continued` opens `next_id`). A continue refused for open delegates that can't move shows a toast that names each one (its preview and what the server says to do: `older chi worker 0.46.1; restart it`, `in use by a one-turn chi --non-interactive run or an older chi's terminal; let it finish`), each a link to its page; any other refusal shows the server's words. The info bar of a link carries `← 2026-10-08` (the previous link's day) and, on an earlier link, `2026-10-10 →`, each a link with its id, its full start (`2026-10-10 14:32`) and its preview in the tooltip; a neighbour that started on the open link's own day shows its time instead (`← 09:12`, `14:32 →`). A link made by `continue →` inherits the previous link's preview (and its title, if it has one) when it is created, so its card keeps its chain's title whatever opener it is sent, and its top bar and browser tab show its card's title. A link with a recap of its own reads its auto title, else its recap's first sentence, instead (a link without one reads its chain's name, and a first link's recap names its chain). A link whose title is the opener and nothing else (a `chi send --new --continues` link whose first message is `Continue where we left off.`) shows its chain's first link's title instead, on its card, in the popover and in its info bar's title line, display only (its messages and data keep the opener; its own title when the first link is gone). The lists fold a chain into the card of its latest listed link, whatever the earlier links' archived state (typing in an archived link brings it back, folded there still), their delegates with them: the card's `↩ #N` chip (`#N of M` when later links aren't listed; its tooltip `Session chain: link N of M`) opens a popover of the other links, newest first (`#N`, its date, with its time (`2026-10-17 14:32`) when another link of the chain started the same day, its own title when it differs from the card's (a link inherits its chain's, so mostly it doesn't), else its recap's first sentence, else its preview, `archived`), a click opens one; the chip shows a live dot or `waiting` for a link that has a worker or waits on the user, and a waiting link puts its chain's card first. All sessions folds nothing while a search is typed or the `archived` toggle is on: every link is a card of its own then, its chip `#N of M`, with its own delegates folded in, so a search finds an earlier link and its delegates.
|
|
387
387
|
- **CLI:** `chi send --new --continues (ID|PREFIX|last:ID) [--model M] [-m TEXT]` (see *Starting a session*).
|
|
388
388
|
- **Which link:** an id, a unique prefix, or `last:<id or prefix>`, the latest link of the chain that session is in. It walks the links that still exist: a deleted link in the middle (`chi sessions delete`, the retention sweep of an unarchived one) ends the walk before it, so `last:` of an earlier link then names that earlier link, and continuing it starts a second line beside the links after the gap; name a link after the gap instead. A trigger names the chain this way: a person's message to an archived link that nobody continued brings it back (a human's input), it doesn't continue the chain; an unattended sender's is refused (*Who may wake a session*). That is the rule: `chi send` and a note go to the chain's newest link (*Sending a message*, *Context notes*); the web composer, a participant's turn and `delegate(session:)` go to the link they name. One walker answers every one of these (`SessionChain::Links`: one session listing, archive flags read once; the earliest created successor wins a fork a hand edit made, a loop ends where it would repeat), with two rules on it, not unified on purpose: `last:` and a schedule take the chain's **end** (`Links#latest`: a continue refuses a link continued already, and a schedule never un-archives a chain you retired), `chi send` and a note the **first link not archived** (`Links#first_live`: a person's input goes where the chain is live, and brings back an archived end). A chain pruned by a schedule keeps its `anchor`: the kept window's oldest link still names a link that is gone, so the walk simply stops there; the page's chip counts from the surviving root (pruning renumbers the links) and its popover says `earlier links pruned` where the walk stops, rather than linking to a deleted session.
|
|
389
|
-
- **Deleting a link** (`SessionChain::Delete`; the CLI, the web and `/exit --delete`): a link of a chain is deleted alone by default, and what follows depends on where it is. **The newest link** (nobody continues it, it isn't archived itself, the link before it is archived) undoes its continue: the delegates the continue moved go back to the previous link, finished ones too (`continued_from.json`'s `moved_ids`, still under the link; without the record, its children whose `parent.json` says they came from the previous link), each with a note saying the link was deleted; every note waiting in the link but the continue's own goes back too (`NoteMove.give_back`); then the previous link and what the continue archived with it come back to the lists (without the record, the previous link alone). The previous link is **not started**: reports a moved-back delegate left wait for its next start. What dies with the link: its turns, context sources, objectives edits, session approvals and participant grants (the previous link kept its own copies). Every refusal comes before anything goes: the link's delegates that would go are checked too (a schedule on one, a one-turn run), and they and the link are removed (and the undo runs) only under their `owner.lock`s (kind deleting, taken without waiting, so a worker that took one refuses it); a moved delegate that can't go back (`ChildMove.unmovable`: an older chi's worker, a one-turn run) refuses it (`delegate_unmovable`, naming it), as does a worker that took the link after the stop. Deleting the links one after another undoes each continue by its own record. **A middle link** splits the chain (the earlier links stay archived, the later ones go on as their own chain); nothing is undone or re-linked. A link whose chain is all archived stays archived around the gap. **The link's own delegates** (any position) follow one rule, `SessionChain::Delete::DELEGATES`: a running one (a worker owns it or is starting for it, a one-turn run; a saved `running` with no worker is a crashed run, and goes) is left running with its whole subtree, its file untouched (its parent's id names a deleted session; its reports are refused as for any gone parent); every other node under the link goes, deepest first, before the link. A session in no chain (a link alone past a gap too) is deleted as before. **The web asks first**: for a chained session, chi web's delete sheet reads `GET /api/sessions/:id/delete_plan` (`:owner`; no query or body; no-store), `SessionChain::Delete::Preview` over the same `LinkPlan`/`ChainPlan` and checks the delete runs (`check_link!`, `check_chain!`): the link's place in the chain, what comes back and goes for each choice, and each choice's refusal now (a schedule on the chain, the link or a delegate that would go, a continue under way, a one-turn run, a moved delegate that can't go back and whether the page can stop it). One session listing walk per call; the page asks only for a chained session as the sheet opens. It takes and releases each link's continue lock (shared, as the delete does), creating its empty file where there was none, and writes nothing else; an unknown id is the usual 404. The moved count is each moved delegate with its subtree (they come back with it), and a `delegate_unmovable` 409 says `stoppable` itself.
|
|
389
|
+
- **Deleting a link** (`SessionChain::Delete`; the CLI, the web and `/exit --delete`): a link of a chain is deleted alone by default, and what follows depends on where it is. **The newest link** (nobody continues it, it isn't archived itself, the link before it is archived) undoes its continue: the delegates the continue moved go back to the previous link, finished ones too (`continued_from.json`'s `moved_ids`, still under the link; without the record, its children whose `parent.json` says they came from the previous link), each with a note saying the link was deleted; every note waiting in the link but the continue's own goes back too (`NoteMove.give_back`); then the previous link and what the continue archived with it come back to the lists (without the record, the previous link alone). The previous link is **not started**: reports a moved-back delegate left wait for its next start. What dies with the link: its turns, context sources, objectives edits, session approvals and participant grants (the previous link kept its own copies). Every refusal comes before anything goes: the link's delegates that would go are checked too (a schedule on one, a one-turn run), and they and the link are removed (and the undo runs) only under their `owner.lock`s (kind deleting, taken without waiting, so a worker that took one refuses it); a moved delegate that can't go back (`ChildMove.unmovable`: an older chi's worker, a one-turn run) refuses it (`delegate_unmovable`, naming it), as does a worker that took the link after the stop. Deleting the links one after another undoes each continue by its own record. **A middle link** splits the chain (the earlier links stay archived, the later ones go on as their own chain); nothing is undone or re-linked. A link whose chain is all archived stays archived around the gap. **The link's own delegates** (any position) follow one rule, `SessionChain::Delete::DELEGATES`: a running one (a worker owns it or is starting for it, a one-turn run; a saved `running` with no worker is a crashed run, and goes) is left running with its whole subtree, its file untouched (its parent's id names a deleted session; its reports are refused as for any gone parent); every other node under the link goes, deepest first, before the link. A session in no chain (a link alone past a gap too) is deleted as before. **The web asks first**: for a chained session, chi web's delete sheet reads `GET /api/sessions/:id/delete_plan` (`:owner`; no query or body; no-store), `SessionChain::Delete::Preview` over the same `LinkPlan`/`ChainPlan` and checks the delete runs (`check_link!`, `check_chain!`): the link's place in the chain, what comes back and goes for each choice, and each choice's refusal now (a schedule on the chain, the link or a delegate that would go, a continue under way, a one-turn run, a moved delegate that can't go back and whether the page can stop it). One session listing walk per call; the page asks only for a chained session as the sheet opens. It takes and releases each link's continue lock (shared, as the delete does), creating its empty file where there was none, and writes nothing else; an unknown id is the usual 404. The moved count is each moved delegate with its subtree (they come back with it), and a `delegate_unmovable` 409 says `stoppable` itself. Each choice carries a `digest` (`SessionChain::Delete.digest`: the sorted ids it deletes, leaves, revives and moves back); the sheet's DELETE sends it as `expect=`, and the delete compares it with the plan it runs (a link's under its holds, as `delete_link` starts; the chain's before its checks) and refuses `plan_changed` (409) before anything changes, a session no longer chained too. Without `expect` (the CLI, an older page) it deletes as it plans then. **The whole chain** (`chi sessions delete --chain`, `DELETE /api/sessions/:id/chain`, `SessionManager.delete_chain`): every link reachable from this one on its branch, newest first, each with its delegates by the same rule. Refused before anything goes when a schedule is on the chain (`chain_scheduled`) or on a delegate that would go (`scheduled`), a link or such a delegate is in a one-turn run, a continue of a link is under way (`continuing`), without `force` a link has a worker, or a link's worker outlives the stop's wait: every link is checked and stopped before the first is deleted, and each then goes under the owner locks of it and its delegates. A chain with a gap before this link reaches only the part after the gap: the earlier links stay archived (`cut_off: true`). A link refused part-way (a worker that took it after its stop) leaves it, its delegates and the earlier part of the chain whole, its new end back in the lists, and the result lists what was left.
|
|
390
390
|
|
|
391
391
|
## Schedules
|
|
392
392
|
|
|
@@ -556,5 +556,7 @@ the session; the message directs the user to `chi sessions stop ID`, then any pr
|
|
|
556
556
|
Reminders, a running `/btw`, and other in-memory worker state cannot be
|
|
557
557
|
checked and may be lost in this fallback. A stopped worker (SIGSTOP or
|
|
558
558
|
Ctrl-Z: `ps` state `T`) answers neither the ask nor a TERM, so a restart
|
|
559
|
-
refuses it at once, before asking, with its pid and `kill -CONT PID`.
|
|
559
|
+
refuses it at once, before asking, with its pid and `kill -CONT PID`. A
|
|
560
|
+
session whose stop is marked (stopped, or its worker being stopped) is refused
|
|
561
|
+
before any of this (`stop_marked`: no successor would come).
|
|
560
562
|
The web restart route behaves the same way.
|
data/docs/testing.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
bundle exec parallel_rspec -n 8 spec lib/samagotchi/bundles/*/spec # Ruby specs, both roots, in parallel
|
|
5
5
|
bundle exec rspec spec lib/samagotchi/bundles/*/spec # the same, plain
|
|
6
6
|
bundle exec rake bundles:specs # the shipped bundles' own specs, on the bundle test kit alone
|
|
7
|
-
npm test # web frontend specs
|
|
7
|
+
npm test # web frontend specs, including the new-module exports ratchet
|
|
8
8
|
npm run lint # web frontend: undefined names and unused imports (ESLint; CI runs it)
|
|
9
9
|
npm run e2e # web UI happy paths in Chromium, fake model (once: npx playwright install chromium)
|
|
10
10
|
npx playwright test spec/e2e/stage.spec.js # one e2e file (the root playwright.config.js is the suite's)
|
|
@@ -478,7 +478,9 @@ file's layer (any `foo/*.rb` → `spec/foo_golden_spec.rb` when there is one; `t
|
|
|
478
478
|
words the attached TUI prints, pick its `event_renderer` and `attached_loop` specs by a rule; `memory_bundle/*.rb`,
|
|
479
479
|
`bundle_command.rb`, `memory_paths.rb`, `model_overlay.rb` and the corpus's fixtures pick the bundle-state corpus). Changes to `tool_declarations.rb` and `system_prompt.rb` also pick the
|
|
480
480
|
effective-model, request, prompt-snapshot and full system-prompt goldens because they hash the request's prompt and
|
|
481
|
-
tools.
|
|
481
|
+
tools. Changes under `lib/samagotchi/worker/*.rb` also pick `spec/worker_spec.rb`, `spec/worker_*_spec.rb`,
|
|
482
|
+
`spec/web/app_session_settings_characterization_spec.rb` and `spec/require_cycle_spec.rb`. Then come the other name
|
|
483
|
+
matches (a spec named after several changed files first, e.g. `engine_toolkit_spec.rb` for `engine.rb` and
|
|
482
484
|
`toolkit.rb`; then one beside the file, so `plugin/context.rb` picks `spec/samagotchi/plugin/*context*` before
|
|
483
485
|
`spec/guardrails/context_spec.rb`), then the specs that name a method the change touches (the innermost `def` around a
|
|
484
486
|
changed line, read with Prism; one `git grep` for up to 12 names; names under 4 characters, `initialize`, `to_s`,
|