samagotchi 0.191.0 → 0.193.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +91 -1
  3. data/docs/architecture.md +8 -7
  4. data/docs/bundles.md +46 -29
  5. data/docs/cli.md +37 -15
  6. data/docs/configuration.md +10 -4
  7. data/docs/context.md +8 -5
  8. data/docs/guardrails.md +9 -4
  9. data/docs/internals/bridge.md +3 -1
  10. data/docs/internals/bundles.md +2 -2
  11. data/docs/internals/inline-widgets.md +2 -1
  12. data/docs/internals/pages.md +4 -4
  13. data/docs/internals/participants.md +6 -8
  14. data/docs/internals/peers.md +75 -22
  15. data/docs/internals/prompt-caching.md +2 -1
  16. data/docs/internals/remote-sessions.md +9 -0
  17. data/docs/internals/session-lifecycle.md +36 -21
  18. data/docs/internals/web-frontend.md +195 -25
  19. data/docs/internals/working-set.md +5 -1
  20. data/docs/peers.md +71 -22
  21. data/docs/plugins.md +7 -4
  22. data/docs/releasing.md +30 -2
  23. data/docs/scheduling.md +10 -3
  24. data/docs/sessions.md +3 -3
  25. data/docs/testing.md +36 -5
  26. data/docs/thin-clients.md +114 -12
  27. data/lib/samagotchi/bridge.rb +2 -3
  28. data/lib/samagotchi/bundles/claude-peer/manifest.yml +2 -2
  29. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +33 -17
  30. data/lib/samagotchi/bundles/codex-peer/manifest.yml +2 -2
  31. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +34 -17
  32. data/lib/samagotchi/bundles/coordinator/manifest.yml +2 -2
  33. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +31 -0
  34. data/lib/samagotchi/bundles/mcp/manifest.yml +4 -2
  35. data/lib/samagotchi/bundles/mcp/plugin.rb +7 -405
  36. data/lib/samagotchi/bundles/mcp/server_config.rb +158 -0
  37. data/lib/samagotchi/bundles/mcp/sign_in.rb +261 -0
  38. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  39. data/lib/samagotchi/client_id.rb +2 -19
  40. data/lib/samagotchi/compat.rb +6 -5
  41. data/lib/samagotchi/config.rb +7 -0
  42. data/lib/samagotchi/continue_offer.rb +13 -1
  43. data/lib/samagotchi/delivery.rb +3 -7
  44. data/lib/samagotchi/engine/models.rb +17 -0
  45. data/lib/samagotchi/engine/plugins.rb +2 -0
  46. data/lib/samagotchi/guardrails/pair_boundary.rb +49 -18
  47. data/lib/samagotchi/jsonl_store.rb +13 -2
  48. data/lib/samagotchi/llm/anthropic_messages.rb +11 -0
  49. data/lib/samagotchi/llm/openai_chat.rb +5 -0
  50. data/lib/samagotchi/llm/prompt_cache.rb +5 -0
  51. data/lib/samagotchi/pages/launch.rb +1 -1
  52. data/lib/samagotchi/peer_cold.rb +92 -0
  53. data/lib/samagotchi/peer_command.rb +24 -9
  54. data/lib/samagotchi/peer_continue.rb +32 -16
  55. data/lib/samagotchi/peer_exchanges.rb +7 -0
  56. data/lib/samagotchi/peer_mailbox.rb +21 -4
  57. data/lib/samagotchi/peer_receipts.rb +33 -6
  58. data/lib/samagotchi/peer_say.rb +34 -16
  59. data/lib/samagotchi/plugin/api.rb +2 -1
  60. data/lib/samagotchi/plugin/context.rb +13 -1
  61. data/lib/samagotchi/plugin/peer.rb +118 -53
  62. data/lib/samagotchi/plugin/peers.rb +13 -6
  63. data/lib/samagotchi/schedule_command.rb +1 -0
  64. data/lib/samagotchi/schedules/prune_part.rb +32 -0
  65. data/lib/samagotchi/schedules.rb +14 -9
  66. data/lib/samagotchi/session.rb +7 -0
  67. data/lib/samagotchi/session_access/local.rb +98 -37
  68. data/lib/samagotchi/session_access/remote.rb +1 -1
  69. data/lib/samagotchi/session_access/remote_peers.rb +3 -3
  70. data/lib/samagotchi/session_chain/links.rb +8 -3
  71. data/lib/samagotchi/session_continue.rb +15 -7
  72. data/lib/samagotchi/session_lifecycle.rb +4 -0
  73. data/lib/samagotchi/session_manager/delivery.rb +0 -6
  74. data/lib/samagotchi/session_manager/lifecycle.rb +30 -17
  75. data/lib/samagotchi/session_manager/listing.rb +2 -1
  76. data/lib/samagotchi/session_manager/removal.rb +7 -5
  77. data/lib/samagotchi/session_manager/spawn.rb +8 -4
  78. data/lib/samagotchi/session_manager.rb +4 -0
  79. data/lib/samagotchi/session_row.rb +2 -0
  80. data/lib/samagotchi/session_stores.rb +16 -11
  81. data/lib/samagotchi/session_transition.rb +61 -15
  82. data/lib/samagotchi/system_one/runs.rb +5 -2
  83. data/lib/samagotchi/testing/boundary.rb +0 -1
  84. data/lib/samagotchi/testing/host.rb +1 -0
  85. data/lib/samagotchi/testing/recorder.rb +3 -0
  86. data/lib/samagotchi/tools/cancel_schedule.rb +10 -6
  87. data/lib/samagotchi/version.rb +1 -1
  88. data/lib/samagotchi/web/app.rb +3 -1
  89. data/lib/samagotchi/web/ask_create.rb +138 -0
  90. data/lib/samagotchi/web/ask_routes.rb +56 -9
  91. data/lib/samagotchi/web/last_ask.rb +78 -0
  92. data/lib/samagotchi/web/peer_routes.rb +10 -5
  93. data/lib/samagotchi/web/public/agent_rows.js +206 -0
  94. data/lib/samagotchi/web/public/agent_runs.js +595 -0
  95. data/lib/samagotchi/web/public/answer_fold.js +41 -44
  96. data/lib/samagotchi/web/public/answer_refs.js +3 -9
  97. data/lib/samagotchi/web/public/answer_write.js +28 -0
  98. data/lib/samagotchi/web/public/app.js +75 -99
  99. data/lib/samagotchi/web/public/block_fix.js +30 -12
  100. data/lib/samagotchi/web/public/cards_place.js +6 -4
  101. data/lib/samagotchi/web/public/chains.js +3 -1
  102. data/lib/samagotchi/web/public/command_list.js +5 -3
  103. data/lib/samagotchi/web/public/composer.js +9 -6
  104. data/lib/samagotchi/web/public/composer_mount.js +18 -11
  105. data/lib/samagotchi/web/public/draft_keys.js +10 -0
  106. data/lib/samagotchi/web/public/drafts.js +278 -0
  107. data/lib/samagotchi/web/public/history_reveal.js +5 -2
  108. data/lib/samagotchi/web/public/index.html +38 -2
  109. data/lib/samagotchi/web/public/owner_claim.js +7 -12
  110. data/lib/samagotchi/web/public/page_view.js +1 -1
  111. data/lib/samagotchi/web/public/pages.css +1 -7
  112. data/lib/samagotchi/web/public/peer_mailbox_api.js +2 -1
  113. data/lib/samagotchi/web/public/peer_note.js +4 -2
  114. data/lib/samagotchi/web/public/peer_row.js +37 -0
  115. data/lib/samagotchi/web/public/prompt_history.js +6 -0
  116. data/lib/samagotchi/web/public/quiet_notes.js +12 -1
  117. data/lib/samagotchi/web/public/revise_stack.js +5 -2
  118. data/lib/samagotchi/web/public/send_turn.js +62 -23
  119. data/lib/samagotchi/web/public/session_actions.js +80 -16
  120. data/lib/samagotchi/web/public/session_prefs.js +9 -3
  121. data/lib/samagotchi/web/public/session_view.js +7 -2
  122. data/lib/samagotchi/web/public/turn_block.js +4 -0
  123. data/lib/samagotchi/web/public/turn_events.js +0 -2
  124. data/lib/samagotchi/web/public/unqueue.js +22 -9
  125. data/lib/samagotchi/web/public/viewer_self.js +1 -6
  126. data/lib/samagotchi/web/public/views.js +12 -1
  127. data/lib/samagotchi/web/session_access_routes.rb +6 -3
  128. data/lib/samagotchi/web/session_control.rb +4 -2
  129. data/lib/samagotchi/web/session_create.rb +50 -33
  130. data/lib/samagotchi/web/session_hub.rb +52 -36
  131. data/lib/samagotchi/web/session_summary.rb +45 -7
  132. data/lib/samagotchi/web/start_dir.rb +6 -4
  133. data/lib/samagotchi/worker/mail.rb +11 -1
  134. data/lib/samagotchi/worker.rb +7 -5
  135. data/lib/samagotchi/worker_inbound/mail.rb +34 -6
  136. data/lib/samagotchi/worker_inbound.rb +11 -3
  137. data/lib/samagotchi/worker_link.rb +13 -1
  138. data/lib/samagotchi/worker_presence.rb +22 -6
  139. data/lib/samagotchi/worker_wakes.rb +33 -5
  140. metadata +12 -2
  141. data/lib/samagotchi/web/public/pages_group.js +0 -67
data/docs/guardrails.md CHANGED
@@ -561,14 +561,19 @@ message:
561
561
  `batch`;
562
562
  - owner-voiced tools, which act in the owner's name beyond the turn:
563
563
  `delegate` and any `delegate_*` tool, `register_reminder`,
564
- `cancel_reminder`, `schedule_task`, `list_schedules`, `cancel_schedule`
564
+ `cancel_reminder`, `schedule_task`, `cancel_schedule`
565
565
  (a durable schedule outlives the session and fires on this machine),
566
- `send_note`, `forget_outputs`, `task_create`,
566
+ `send_note`, `ask_session`, `forget_outputs`, `task_create`,
567
567
  `task_stop`, `find_tools` (it loads tools into the session), `objectives`
568
568
  (a move on the owner's list), and
569
- `memory_write` (a memory reaches the owner's later sessions); and the tools
569
+ `memory_write` (a memory reaches the owner's later sessions); the tools
570
570
  that read the owner's background tasks and their output, `task_wait`,
571
- `task_get`, `task_list` (a pair turn starts none);
571
+ `task_get`, `task_list` (a pair turn starts none); and the ones that read
572
+ the owner's other sessions, reminders and schedules and the session's
573
+ attached context: `list_sessions`, `list_reminders`, `list_schedules`,
574
+ `context_read`. Every built-in tool has its place in
575
+ `PairBoundary::TOOL_CLASSES` (a spec fails on one that hasn't); a plugin's
576
+ or an MCP server's tool goes on to the path and command checks;
572
577
  - `ask_user_question`, with the advice to ask in the reply: nobody on the
573
578
  participant's side answers a card.
574
579
 
@@ -661,7 +661,9 @@ newer worker; never driven, `wake` answers 409 `worker_newer`); else `Live` (its
661
661
  holder as the caller already read it (nil: free), so one read serves a summary and its status. `WorkerLink.client` is
662
662
  the Live's client or nil; `WorkerLink.await` polls for a new worker's Live (an `until:` check tells a restart's
663
663
  successor from the old worker); chi web's `App#worker_link` / `#await_worker_link` wrap them. The Bridge writes
664
- `pid` and `protocol` with its port and removes its sidecar on stop only when the file still carries its epoch.
664
+ `pid` and `protocol` with its port and removes its sidecar on stop only when the file still carries its epoch. When to
665
+ bump `protocol` (the owner's OK each time; additive changes never) is in docs/releasing.md, "Bumping
666
+ WorkerLink::PROTOCOL"; `spec/worker_link_contract_spec.rb` pins each protocol's sidecar keys, routes and features.
665
667
 
666
668
  The sidecar's `features` array is the worker's capability handshake: clients check a name rather than infer
667
669
  compatibility from its version. `Bridge::FEATURES` advertises:
@@ -23,7 +23,7 @@ read side, never the reverse.
23
23
  <system memories>/.bundles/ MemoryPaths.bundles_dir
24
24
  <name>/manifest.json the install record (Provenance#write, read as InstalledBundles::Record)
25
25
  <name>/manifest.yml the bundle's own manifest as installed (Provenance#write's manifest_from:), its sha
26
- the record's manifest_sha; a dev install links it to the source (DEV_SHA)
26
+ the record's manifest_sha; a dev install links it to the source (`InstalledBundles::Sha::DEV`)
27
27
  <name>/bases/ each file's base for the next upgrade's 3-way merge: as installed, or the
28
28
  bundle's own text after a merge
29
29
  <name>/incoming/ the bundle's text for each file marked conflict, until the file settles (Provenance:
@@ -67,7 +67,7 @@ read side, never the reverse.
67
67
  | `TextMerge` | the text merge: `.merge(base:, ours:, theirs:)` → a `Result` (`status` `:clean` with `text`, `:conflict` with `hunks`, `:failed` with `why`). `git merge-file -p --diff3 --marker-size=20` on temp copies in a temp cwd, with every `GIT_*` that points at a repository or a config unset or at `/dev/null` (it can run inside another tool's hook). git isn't a runtime dependency: none on PATH, or macOS's `/usr/bin/git` with no developer tools behind it (`.apple_stub?`, by `xcode-select -p`; running it pops a dialog), is `:failed`. So is a git past `TIMEOUT` (10 s; its process group is killed: this runs under `SystemBundle`'s lock), and any doubt about the answer: `min(hunks, 127)` against the exit status, a status over 127, a NUL in a side, marker lines that don't pair up (a user's line equal to one), a line no input holds, or an empty answer to non-empty inputs. `Scan` reads the output: a hunk unions (ours, then the entries of theirs that ours lacks) only when the last heading before it, at level 1 or 2 and outside code fences, HTML comments and any hunk, is titled exactly `Changelog` or `Change log`, with nothing but list entries (an item and its indented lines) since that heading and no fence or comment open, and base, ours and theirs each hold only list entries, with every base entry still on both sides: both only added. Any other hunk is a real conflict, and markers never leave the module. An entry is an item and the lines indented deeper under it, nested items too, and the union compares whole entries. `.changed_sections(base, theirs, ours)`: the headings of the sections the bundle changed and the file hasn't got, and whether text under no heading did, which is what names a miss: a conflict's hunks can't, since the whole file stays and the one hunk may be a Changelog line beside a whole new section. `Hunk#heading` counts the places under no heading |
68
68
  | `InstalledBundles::FileStanding` (installed_bundles/file_standing.rb) | the one owner of what chi says of an edited bundle file, used by every surface: `Behind` (`#state`, `#line`: `x.md stays behind 0.8.0: no merge possible (why); missed ## A, ## B, ## C and 2 more`, `would stay` in a dry run), `MergeNote`, `.merged_line`, `.no_merge` (for `LEGACY_BASE` it says chi can't tell whether the file holds edits), `.clauses` (a report's clauses for one bundle), `.behind_count`, `.stay_behind`, `.counts_sentence` (the push), `.still_behind`, `.text` (UTF-8, whatever a name or heading was tagged), `FORCE_TAKES`, `FORCE_MOVES`, `IN_THE_TRASH`. Behind means marked and bytes other than the mark's `incoming_sha` (`.behind?`, read by `InstalledBundles::Record#behind_files` and `Remerge` alike): a file brought level by hand isn't, a missing one is a missing file, and one that can't be read is. An older mark no retry has looked at reads `may be behind` (`Behind#unsure`, and the counts say so), and isn't behind at all when level with its recorded source on disk (`InstalledBundles::Record#behind_file?`). A new surface reads these and adds no wording |
69
69
  | `Remerge` | the retry at the same version, memory files only, for a file marked `conflict` (its `FileState` and `REMERGE` row; a `:decide` cell through `Merger::Upgrade#decision`): `#run(dry_run:)` → a `Result` (`merged`, `settled`, `stamped`, `behind`, `warnings`, `trash_copy`). It merges what merges and settles those entries (`Provenance#resolve_conflicts`, the index line refreshed), checking a merged incoming file against the manifest's sha256, in a dry run too. It leaves `version`, `installed_at` and the assets alone: the Installer would `rm_rf` guardrails, plugin and scripts under live sessions. Every file it leaves is in `behind`, with why: one not shipped now (`MemoryFiles.select`) keeps its mark, base and text; one whose `incoming_sha` isn't the shipped text (a checkout at one VERSION) is left alone, no git runs, and it reads as its mark says; a mark with no digest (older chi) is tried as well, and a real conflict then records it (`Provenance#refresh_marks`, which writes only when the mark would read differently, so a conflict at each start writes nothing). A mark whose digest matches is tried on every run, since the file or git may have changed. `noop` and `keep` settle quietly; `fast_forward` waits for the next upgrade, reading as behind until then; `install` is a missing file, which isn't behind, and a warning says so. A file it can't read or replace stays as it is, saying why. Called from `ShippedUpdate.plan_row`/`apply` (`chi update`) and `SystemBundle.sync`'s equal-version branch, under its lock (each chi start and `chi update`); a bundle chi doesn't ship retries through `chi bundle upgrade`. No marks: nothing is read beyond the record. One marked file costs one git run per Engine start, about 12 ms on the Studio (0.1 ms with none) |
70
- | `Provenance` | the `.bundles/<name>/` dir's write side (an `InstalledBundles::Dir`): `#write` the record + bases (its `files:` is the full list: a key left out is dropped, a nil value keeps the entry with no base; `marks:` are the files left behind, each a `FileStanding::Behind`, and `incoming_dir:` the bundle text each speaks of, recorded as `incoming_sha` and saved at `#incoming_path`; an older mark that stays keeps `legacy_base`), `#resolve_conflicts` (base to the incoming file, mark and its fields (`MARK_FIELDS`) and saved text gone; a file whose incoming copy is gone keeps both), `#refresh_marks` (what a retry found: why, missed, the digest and `legacy_base`, the saved text), `#note_merged` and `#clear_merge_notes(notes)` (`MERGE_NOTE_FIELDS`, kept through `#write`; the saved text is best effort, after the manifest, so it can't leave a plugin under the old record's sha; any other failure writing the record still can, until a retry), `#record` → `InstalledBundles::Record` (the Dir's). `#write(manifest_from: DIR)` keeps `DIR/manifest.yml` at `#kept_manifest_path` (written aside and renamed; for `dev:` a link to its realpath) and records `manifest_sha` (`FileDigest.sha256`, `DEV_SHA` for dev) and `installed_by` (this chi's VERSION); the Installer and `Profile.install` pass their source dir, and a write without it carries the existing record's two fields, the kept file left alone. The in-place edits (`#resolve_conflicts`, `#record_restored`, `#refresh_marks`, `#note_merged`, `#clear_merge_notes`) keep them. The record's mirror of the manifest keys (`requires_chi` … `setting_types`) is still written from the kwargs, exactly as before: an older chi sharing the memories dir (an old worker, chi web, gem or worktree) reads only the record, and without the mirror's `requires_chi` it would load a too-new bundle's plugin. A key a later manifest gains is never mirrored. Any chi without the kept manifest that rewrites a record drops `manifest_sha` and `installed_by` (it rebuilds the record from its own kwargs). `#adopt_manifest(dir, dry_run:)` heals such a record (`InstalledBundles::Record#manifest_unkept?`: no `manifest_sha`, or its file gone): when `dir` is the source of what's installed (its manifest names the bundle at the recorded version; each mirrored key, normalised as `#mirror_fields` records it (the one shape `#write` uses too), equals the record's, a key the record lacks being fine only when `BundleManifest::SINCE` has it, since an older chi couldn't have recorded it (a recorded hook doesn't count: retired); and every recorded plugin, hook, script, rule and unmarked memory sha is that of `dir`'s file; else the why names the key or file) it keeps `dir/manifest.yml` and records `manifest_sha`, nothing else (not `installed_at`, the mirror or `installed_by`); otherwise it returns why and writes nothing. Never for a dev record (its next `install --dev` links the file) |
70
+ | `Provenance` | the `.bundles/<name>/` dir's write side (an `InstalledBundles::Dir`): `#write` the record + bases (its `files:` is the full list: a key left out is dropped, a nil value keeps the entry with no base; `marks:` are the files left behind, each a `FileStanding::Behind`, and `incoming_dir:` the bundle text each speaks of, recorded as `incoming_sha` and saved at `#incoming_path`; an older mark that stays keeps `legacy_base`), `#resolve_conflicts` (base to the incoming file, mark and its fields (`MARK_FIELDS`) and saved text gone; a file whose incoming copy is gone keeps both), `#refresh_marks` (what a retry found: why, missed, the digest and `legacy_base`, the saved text), `#note_merged` and `#clear_merge_notes(notes)` (`MERGE_NOTE_FIELDS`, kept through `#write`; the saved text is best effort, after the manifest, so it can't leave a plugin under the old record's sha; any other failure writing the record still can, until a retry), `#record` → `InstalledBundles::Record` (the Dir's). `#write(manifest_from: DIR)` keeps `DIR/manifest.yml` at `#kept_manifest_path` (written aside and renamed; for `dev:` a link to its realpath) and records `manifest_sha` (`FileDigest.sha256`, `InstalledBundles::Sha::DEV` for dev) and `installed_by` (this chi's VERSION); the Installer and `Profile.install` pass their source dir, and a write without it carries the existing record's two fields, the kept file left alone. The in-place edits (`#resolve_conflicts`, `#record_restored`, `#refresh_marks`, `#note_merged`, `#clear_merge_notes`) keep them. The record's mirror of the manifest keys (`requires_chi` … `setting_types`) is still written from the kwargs, exactly as before: an older chi sharing the memories dir (an old worker, chi web, gem or worktree) reads only the record, and without the mirror's `requires_chi` it would load a too-new bundle's plugin. A key a later manifest gains is never mirrored. Any chi without the kept manifest that rewrites a record drops `manifest_sha` and `installed_by` (it rebuilds the record from its own kwargs). `#adopt_manifest(dir, dry_run:)` heals such a record (`InstalledBundles::Record#manifest_unkept?`: no `manifest_sha`, or its file gone): when `dir` is the source of what's installed (its manifest names the bundle at the recorded version; each mirrored key, normalised as `#mirror_fields` records it (the one shape `#write` uses too), equals the record's, a key the record lacks being fine only when `BundleManifest::SINCE` has it, since an older chi couldn't have recorded it (a recorded hook doesn't count: retired); and every recorded plugin, hook, script, rule and unmarked memory sha is that of `dir`'s file; else the why names the key or file) it keeps `dir/manifest.yml` and records `manifest_sha`, nothing else (not `installed_at`, the mirror or `installed_by`); otherwise it returns why and writes nothing. Never for a dev record (its next `install --dev` links the file) |
71
71
  | `InstalledBundles::Manifest` (installed_bundles/manifest.rb) | the one answer to "this installed bundle's manifest" (`InstalledBundles::Record#manifest`): requires_chi, trust_level, needs, the scripts' names, context providers, block renderers, pages (`pages:`, kept file only: never mirrored, so `[]` from the record), session settings and settings with their types, file descriptions, a profile's includes. Read from the kept `manifest.yml` (`origin: :kept`) when the record's `manifest_sha` is set and the file still has it (`InstalledBundles::Sha.matches?`, so a dev link is never checked), else from the record's `mirror` (`origin: :record`), in these cases: no kept file and no `manifest_sha` (a record from before chi kept it; no problem); no kept file, or something other than a file in its place, while `manifest_sha` is set (`:missing`); a kept file and no `manifest_sha` (a chi without the kept manifest rewrote the record: `problems["manifest.yml"] = :stale`); a kept file with another sha, or one that isn't a YAML mapping (`:edited`); the sha matches (`:kept`). `#standing` is that symbol, `#key_problems` the rest. The kept file is read by `BundleManifest.tolerant` key by key in a fixed order (its comment): a key that doesn't parse under this chi takes the mirror's value if that parses, else empty, with its message in `problems` (a reader that logged it logs that); `block_renderers` is checked against the record's scripts when the kept `scripts:` fails, and an older install's `hooks:` is ignored (no problem row). `description` and `unknown_keys` come only from a kept file; a profile's `includes` is always the record's (its members, identity). The value is deep-frozen, since callers share it. One process-wide cache (a Hash under a Mutex, cleared at `CACHE_LIMIT`) keyed by the record value and the kept file's stat (mtime, size, inode, device; a dev link's target): chi web asks per request, a worker at start and per `ContextProviders.resolve`. `#requires_chi_failure(version = VERSION)` is the one requires_chi gate; `#experimental?`, `#needs?`, `#context_providers?`, `#block_renderers?`, `#pages?` |
72
72
  | `ManifestStanding` (manifest_standing.rb) | the one owner of the words for an installed bundle's `manifest.yml` as `InstalledBundles::Manifest` read it: `.state` (`:kept`, `:legacy`, `:stale`, `:missing`, `:edited`), `.label` (`[kept]` / `[from the install record]`), `.line(bundle, refused:)` (the case and the command: `chi bundle upgrade NAME` (reads it again from a git URL, or a source that didn't match, with why), `chi update keeps it` while untried, the source is gone (`Installer.source_gone_line`), `chi bundle install --dev SOURCE` for a dev record; for a kept one, only the keys whose `BundleManifest::SINCE` floor is above the record's `installed_by`: newer than its installer), `.keep(bundle, source_dir:, dry_run:)` → `Outcome` (the record after, the line, `kept`): `Provenance#adopt_manifest` from `source_dir`, else from the recorded source (a dir; a zip/tar through `PreparedSource`, cleaned up; never a git clone). Read by `ShippedUpdate` (`Row#manifest`, the plan's dry `keep` and apply's), `UpdateCommand#external_rows` (a `kept its manifest` row, else a warn row, before the bundle's re-check, which then sees the kept file) and `chi bundle status NAME` (`BundleCommand#manifest_line`: `Manifest:`, the label, `.status_line`: for a record with a folder source (a bundle chi ships: this chi's shipped copy at the recorded version, which `chi update` reads), a dry `adopt_manifest` first, so the line says whether `chi update` keeps it or why not; an archive isn't extracted there, its line says `chi update tries to keep it`; a profile chi doesn't ship is never kept by `chi update`, so its line names `chi bundle upgrade NAME`) |
73
73
  | `InstalledBundles::Record`, `BundleHook`, `PluginRef` (installed_bundles/record.rb, bundle_hook.rb, plugin_ref.rb) | value objects for the record; tolerant of older records (missing keys read as empty). `InstalledBundles::Record`'s members are identity and state (name, version, scope, source, `installed_at`, `source_commit`, files and their marks, hooks, guardrails, scripts and the plugin with their shas, a profile's `includes`, `dev`, `dir`, the kept manifest's `manifest_sha` and `installed_by`, nil on a record from before it was kept); the manifest keys it records sit in one `mirror` Hash (`MIRROR_KEYS`, frozen: a key a later manifest gains is never mirrored) that only `InstalledBundles::Manifest` reads, so manifest data is read through `#manifest`. `BundleHook` is an older record's hook entry: `.parse` and `#sha256` (what the retire, uninstall and the trash selection read) |
@@ -149,7 +149,8 @@ session switch, a turn's end, Revise's clones, the stage's hand-off to `#history
149
149
 
150
150
  **The only way out is composer text.** Fill reply builds `id: option (note) · …` from the picked rows (a row with no
151
151
  pick is left out) and hands it to app.js's `fillComposer`, after a typed draft on a new line (`withDraft`; the draft
152
- is kept). It never sends: the owner reads the text and sends it or not. `replyText` drops a leading `!` or `/` from
152
+ is kept). Both act on the open session's draft (`drafts.js`, [web-frontend.md](web-frontend.md#the-drafts)): a pick in
153
+ one session never lands in another's text. It never sends: the owner reads the text and sends it or not. `replyText` drops a leading `!` or `/` from
153
154
  an id too (an id of only those is its row's number), so the filled text never starts a shell line or a session command
154
155
  even from data the normaliser didn't mend; the draft before it is the owner's own. The row's `wp-id` chip shows that
155
156
  same cleaned id (`rowId`, one rule for both), so what is drawn is what fills. A walk has no way out at all. The model's
@@ -48,7 +48,7 @@ runner too (its `Pages.script_path`), accepted: the shipped one loads the schedu
48
48
  ## The one launch path
49
49
 
50
50
  `chi page run` does not run the script in its own process. `Launch.run` starts the runner, exactly as chi web's
51
- Refresh will (Build 2), so a page that passes from the terminal passes on Refresh (the spike saw two paths give a
51
+ Refresh does, so a page that passes from the terminal passes on Refresh (the spike saw two paths give a
52
52
  script 152 against 73 preloaded libraries and a stale `PWD`). It costs about 70 ms more per terminal run.
53
53
 
54
54
  1. `Pages.check_name!`, then the script must exist (`Missing`), then `Store.locked(name)`: a non-blocking `flock` on
@@ -58,7 +58,8 @@ script 152 against 73 preloaded libraries and a stale `PWD`). It costs about 70
58
58
  2. `ProcessGroup.spawn(env, RbConfig.ruby, "-I", <this chi's lib>, "-e", 'require "samagotchi/pages/runner"; exit
59
59
  Samagotchi::Pages::Runner.run(ARGV)', NAME, TIMEOUT, DEADLINE, 3 => lock)`, in a group of its own, `chdir:` the
60
60
  pages folder, stdin closed, the lock on fd 3. The env is a worker's changes
61
- (`SessionManager::WorkerCommand#spawn_options`): `ChildEnv.unbundled` (an installed gem's Bundler changes undone),
61
+ (`SessionManager::WorkerCommandPart#spawn_options`, private in `session_manager/worker_command.rb`):
62
+ `ChildEnv.unbundled` (an installed gem's Bundler changes undone),
62
63
  `ChildEnv.unset` (the spawner's guardrails settings and session markers), `Launch.cleared_keys` unset
63
64
  (`CHI_REMOTE`, every `SAMAGOTCHI_WORKER_*` key and the vendor agent markers `AgentCaller::VENDOR_MARKERS`:
64
65
  `CLAUDECODE`, `CODEX_THREAD_ID`, `AI_AGENT`, read from those constants), `Paths.absolute_xdg`, and `PWD` set to the
@@ -187,8 +188,7 @@ pages: `load` shares a read that is out, `reload` asks again, a failed read keep
187
188
  `pages_list.js` (the Pages list, `#/pages`: its hash, its cards in `/api/pages`'s order), `page_view.js` (the header, the states, the calls; an answer for a page no longer open is
188
189
  dropped, `latest.js`), `page_model.js` (the words: meta, the failed and changed lines, Copy the error), `page_blocks.js`
189
190
  (text, walk in a widget host with `drawWalk`, an unknown type as one muted line), `page_table.js` and
190
- `page_table_model.js` (cells, sort, the phone's rows), `pages_group.js` (All sessions' former group, kept for an
191
- older cached app.js until after 0.189.0; nothing new imports it), `page_links.js` (the
191
+ `page_table_model.js` (cells, sort, the phone's rows), `page_links.js` (the
192
192
  delegated click on the turn roots and the page view for `#/p/` anchors), `pages.css`. What a script wrote reaches the
193
193
  page as text or attributes, never as markup, except the server's sanitised `html`.
194
194
 
@@ -220,7 +220,8 @@ Everything else is `:owner`: `/answer`, `/command`,
220
220
  A participant's turn acts with the session's tools under the owner's guardrails, its asks go to the owner and offer
221
221
  once only, and `Guardrails::PairBoundary` denies secrets, chi itself and chi web on loopback, background and
222
222
  scheduled jobs, the environment and credential printers, git config writes (reads only) and git's hooks,
223
- owner-voiced tools and the owner's task outputs, and the model's own question, and asks before a command that makes
223
+ owner-voiced tools, the owner's task outputs, the owner's other sessions, reminders and schedules and the
224
+ attached context (`PairBoundary::TOOL_CLASSES`), and the model's own question, and asks before a command that makes
224
225
  a link and before a write that may land outside the project, failing closed (a global install or a user config write
225
226
  that names no path, `Guardrails::ImplicitWriters`, and a script read from stdin count; a session at or above home has
226
227
  none: every write asks) ([guardrails](../guardrails.md#a-participants-pair-boundary)).
@@ -264,11 +265,7 @@ of its own after it.
264
265
 
265
266
  **chi web.** The author is the grant's (`p:<id>`) and the client id `participant:<id>` (`ClientId.participant`, its
266
267
  `ClientId::Sender` row: a human's input, never the owner's, origin `participant`, source `participant`, labelled
267
- `invited`; not the author, which says who wrote it). A `review:<id>` from chi 0.171 and before (in
268
- `turn_drawings.jsonl`, input files, an older chi web still running) reads the same (`ClientId::LEGACY_REVIEW_PREFIX`,
269
- compat shim `review_client_id`, until 0.173), and a live worker that doesn't name `participant_client_id`
270
- (`Delivery::PARTICIPANT_ID_FEATURE`) is sent `review:<id>` (`SessionManager` delivery; a dequeue's id, only echoed
271
- back, is left as it is); the body's `client_id`, `author` and
268
+ `invited`; not the author, which says who wrote it). The body's `client_id`, `author` and
272
269
  `no_interrupt` never count, its `images` only as refs to their own uploads, and its `delivery` only as `queue` or
273
270
  next step (none: next step).
274
271
  Refused before delivery, each audited:
@@ -925,8 +922,9 @@ participant TUI in v1.
925
922
  an event type it doesn't name is dropped.
926
923
  - A participant's message is a turn of its own, or goes into their own running turn at its next step (chi web, the
927
924
  Bridge, the inbox), never into anyone else's turn and never a cut, a command or a
928
- shell line (chi web, the Bridge, the worker), and runs only on a worker with `pair_turns`: the pair boundary denies secrets and
929
- owner-voiced tools, the owner's guardrails decide the rest, and every ask is the owner's, once only.
925
+ shell line (chi web, the Bridge, the worker), and runs only on a worker with `pair_turns`: the pair boundary denies secrets,
926
+ owner-voiced tools and the owner's readers (tasks, other sessions, reminders, schedules, attached context), the
927
+ owner's guardrails decide the rest, and every ask is the owner's, once only.
930
928
  - No turn an older chi ran read-only runs with tool rights: an invite without `mode: "pair"`, or a Verify fresh child
931
929
  saved otherwise, is refused at the worker (`outdated`), and `Guardrails::ParticipantRefusal` denies every call of
932
930
  any other participant turn that isn't a current invite's.
@@ -27,13 +27,16 @@ A bad file is a `BadFile` with its reason. A directory link is never followed: a
27
27
  listed, `serials` reads a linked folder as empty and `post` refuses one.
28
28
 
29
29
  **chi's side, `sessions/<id>/peer_receipts.json`** (`PeerReceipts`), written only by the session's worker, on
30
- its loop thread: `{peers: {<peer>: {box, taken, receipts}}}`, `Receipt(serial, state, reason, turn, outcome,
31
- at)`. `box` is 6 random hex the worker mints (and writes at once) with a peer's first message; `taken` is the
30
+ its loop thread: `{peers: {<peer>: {box, taken, receipts}}, peer_wakes}`, `Receipt(serial, state, reason, turn,
31
+ outcome, at)`. `peer_wakes` is `WorkerWakes#peer_in_a_row` (the `peer.turns` count), saved at each change
32
+ (`Worker::MailPart#save_peer_wakes`, given to `WorkerWakes` as `on_peer_count`: each `count!(peer: true)` and the
33
+ reset in `human_input!(interactive: true)`, all on the loop thread) and read at the worker's start; absent is 0 (a
34
+ 0.192.0 file; an older worker's write drops it: a reset). `box` is 6 random hex the worker mints (and writes at once) with a peer's first message; `taken` is the
32
35
  newest serial it took. The CLI and chi web only read it.
33
36
 
34
37
  `SessionStores` rows: `link.json`, `in/`, `lock` (removal `:peer_mailbox`: a delete removes the session's
35
- mailbox folder) and `peer_receipts.json` (`:session_files`); a continue leaves all of them with the previous
36
- link (below).
38
+ mailbox folder) and `peer_receipts.json` (`:session_files`); a continue copies `link.json` to the new link and
39
+ leaves the rest with the previous one (below).
37
40
 
38
41
  ## Who is a peer
39
42
 
@@ -53,16 +56,30 @@ starts without it.
53
56
  `chi peer say` (`PeerCommand`) → `SessionAccess::Local#peer_say` (`RemotePeers#peer_say` through `--remote`,
54
57
  which posts `…/peers/NAME/say` with its `wait`: chi web waits, and its read timeout is the wait plus 30 s).
55
58
 
56
- 1. Refused before anything is written: no session, continued (with the next id), no `link.json`, a live worker
57
- without the `peer_mail` Bridge feature (`WorkerLink.live_features`, read only), `UNTAKEN_MAX` (200) untaken
58
- messages or noted receipts.
59
+ 0. **The link it runs on** (`Local#peer_head`): the id said to, or, when it is archived, its chain's first live
60
+ link (`SessionChain::Links#first_live`, `SessionInbox::Head`'s walk; only an archived id lists the sessions).
61
+ Every step below is keyed on that link, never on the id asked (its `taken`, its receipts, its worker, its hold),
62
+ and a received say's `PeerSay#forwarded_to` names it (on the wire; the line ends `· session continued as <id8>:
63
+ answer there`; an older client drops it and prints the old line). One hop: a link continued again meanwhile is
64
+ refused as continued. `peer_pair` (`PeerPaired#forwarded_to`), `peer_unpair` (the asked link's pairing and the
65
+ live link's, `PeerUnpaired`) and `peer_list` walk the same way; `chi peer ls` resolves with the access's `head`
66
+ (chi send's, also through `--remote`) and names the link. chi web's `GET …/peers`, the chip's feed, stays on
67
+ its page's session.
68
+
69
+ 1. Refused before anything is written: no session, continued (with the next id), no `link.json` (on a link
70
+ reached from a continued id: `:continued` naming that link, the words the 0.192.0 skills pair again on), a live
71
+ worker without the `peer_mail` Bridge feature (`WorkerLink.live_features`, read only), `UNTAKEN_MAX` (200)
72
+ untaken messages or noted receipts.
59
73
  2. Under a shared hold of the session's transition lock (`SessionTransition.shared`, `Local#moved_on`), the
60
74
  continued check again, then the delivery (step 3): a continue holding the lock (from after its recap through
61
75
  `PeerContinue`'s carry) refuses the say `:continued` naming its new link (`SessionChain::Successor.of` with
62
- `in_flight: true`; the line `this session is being continued as <id>: say it there in a moment`, `in_flight`
76
+ `in_flight: true`; the line `this session is being continued as <id>: say it again in a moment`, `in_flight`
63
77
  on the wire), or `:busy` (`SessionTransition::Busy`'s words) when the holder names none. So a say never lands
64
- in a mailbox the carry already read (N1). The feature probe before and the receipt wait after stay outside the
65
- hold; the delivery's worker start (`resume_session`, a spawn) is inside it.
78
+ in a mailbox the carry already read (N1). The pairing is read again inside the hold: a continue saves its new
79
+ link, then copies the pairing in its `before_spawn` holding the link's lock, so a say meanwhile is busy, never a
80
+ refusal that sends the peer to pair again. The feature probe before and the receipt wait after stay outside the
81
+ hold; the delivery's worker start (`resume_session`, a spawn) is inside it. A delivery the row's own hold
82
+ refused (`Hold.under`) reads as `:continued` (its successor named) or `:busy`, not as no such session.
66
83
  3. `SessionInbox.deliver(:peer)` (`WakePolicy::ROWS[:peer]`, the push row; `START_EVENTS[:peer] =
67
84
  :peer_woke_session`): a session gone or being deleted refuses before its block writes. Inside the block:
68
85
  the lock, the serial, the write, the trim. The block's "asks for a worker" is the message's own `wake`: no
@@ -70,8 +87,8 @@ which posts `…/peers/NAME/say` with its `wait`: chi web waits, and its read ti
70
87
  4. The line (`PeerSay`): what the say saw at once (a running turn, a stopped or archived session, a one-turn run,
71
88
  a failed start), else a receipt read every 250 ms within the wait, then the peer's other held receipts.
72
89
 
73
- `chi peer pair` makes the old-worker and continued checks too, with the same sentences (`PeerPaired`), and writes
74
- `link.json` under the same shared hold (`:continued` in flight, `:busy`). A context push into the session's own
90
+ `chi peer pair` makes the old-worker and continued checks too, on the link step 0 reached, with the same sentences
91
+ (`PeerPaired`), and writes `link.json` under the same shared hold (`:continued` in flight, `:busy`). A context push into the session's own
75
92
  source does too (`Local#context_push`: 410 `context_continued` with `in_flight`, 423 `context_busy`). The continued
76
93
  words are `SessionChain::Continued`'s, one wording for every refusal of a continued link ("this session" in a
77
94
  peer's line: the installed skills look for `this session was continued as <id>`). Wire: an older chi `--remote`
@@ -90,7 +107,7 @@ why a wake can't run: `:queued`, `:exit`, `:leaving`, `:before_turn` (nil: it ma
90
107
  plus `box`), its text by `PeerNote.body` (a wake note up to the tool output cap, a plain one up to
91
108
  `PeerNote::HELD_CHARS`; over it, `PeerNote.message_text` points at `<peer>_read(serial: N)`).
92
109
  - **Wake:** the batch wakes when a message in it asked, `peer.turns` is above 0 (else `held: off`), the caller
93
- gave no `hold:` and `WorkerWakes#wake_hold(peer: !agreed)` is nil. The turn starts at the batch's last note;
110
+ gave no `hold:`, the cache isn't cold (else `held: cold`, below) and `WorkerWakes#wake_hold(peer: !agreed)` is nil. The turn starts at the batch's last note;
94
111
  its wake line, its origin (`peer:<name>`, `ClientId::PEER_PREFIX`) and the count come from the newest message
95
112
  that asked; an agreeing one (`VERDICT OK`) counts toward `session.max_wakes` only. In the start grace nothing
96
113
  is taken and `mail_wake_waiting?` joins `idle_wait`'s check.
@@ -100,6 +117,20 @@ why a wake can't run: `:queued`, `:exit`, `:leaving`, `:before_turn` (nil: it ma
100
117
  note already in the conversation doesn't wake.
101
118
  - **An unreadable file** (a transient read error) raises and the batch retries on the next pass; a bad file's
102
119
  contents are refused as `invalid` and move `taken`.
120
+ - **The cold hold** (`MailPart#cold_hold?`, `PeerCold`): none of the batch's asking messages is an answer chi asked
121
+ for that doesn't agree (`PeerCold.asked_for?`: its `re` is a `sent` row of `peer_exchanges.jsonl` for that peer,
122
+ in this session or `Session#continues`, that no earlier message of the peer's claimed, as `PeerExchanges.joined`
123
+ pairs them: one answer claims a send, so an old or repeated `re` is held; a log that is there and can't be read,
124
+ `PeerExchanges.read!`, counts as asked), and `PeerCold.cold?`: the host keeps a
125
+ TTL'd cache (`Engine#remote_cache_ttl`: the chat adapter's `cache_breakpoints?`, a remote Claude model's chat
126
+ requests, through `OpenAIChat`, or `AnthropicMessages` with a dialect whose breakpoints weren't refused; `PromptCache.ttl_seconds`;
127
+ nil on a local model), `Session#last_turn`'s `ended_at` is older than it (a `ContinueOffer` stamp or a failed
128
+ turn's taken as it is: never earlier than the last request), and `analytics.json`'s `context.used_tokens` is above
129
+ `PeerCold::FLOOR_TOKENS` (20,000). No `ended_at`, no count or an unparsable time: warm. Side requests (recap,
130
+ `ctx.ask_model`) go through `IdleClient` with no breakpoints, so they neither read nor refresh the cache: the
131
+ turn's end is the cache's last refresh. Its one-time notice is its own (`WorkerWakes#notice_peer_cold!`, reset by
132
+ interactive input), apart from the budget's. The notices' once-flags are the worker's, not saved: a new worker
133
+ (an idle exit, a restart) can say a held message once more, though the count it reads (`peer_wakes`) is saved.
103
134
  - **The wake turn:** `MailWake(peer, turn_id, plain_note, agreed)`, run by `WakeTurnsPart#run_mail_wake_turn`
104
135
  through `run_wake`. The one-time hook notice for a held message (`WorkerInbound#peer_held`) is the TUI's and
105
136
  the web's.
@@ -134,18 +165,40 @@ wake line. The wording is model-visible and eval-tuned (0017).
134
165
  The peer bundles' base: `ctx.peers.link(PEER)` (`Plugin::Peers`, read only) is the pairing whose address the
135
166
  transport sends to; `<peer>_read` reads a message (`ctx.peers.message`) paged by lines, in the peer block; the
136
167
  status card reads the link and the newest message, and says "paired the old way: pair again" when an older
137
- bundle's context source (`LEGACY_INBOX`, `LEGACY_OUTBOX`) is attached. Its quiet init task `tell_moved` posts the
138
- `moved` message to the address of the pairing the previous link kept (`ctx.peers.left_behind`), once (a marker
139
- in the session's data dir).
168
+ bundle's context source (`LEGACY_INBOX`, `LEGACY_OUTBOX`) is attached. A continue tells the peer nothing: the
169
+ pairing is copied (below), and the next send's header names the new id. (An older chi's init task posted a
170
+ `moved` message; the skills still name it as chi's, and don't reply to it.) `ctx.peers.left_behind` reads the
171
+ previous link's pairing, the one the copy came from.
172
+
173
+ A model's send to a dormant pairing (`Peer#quiet_check!`, `by: "model"` only): the newest of the link's `paired_at`,
174
+ `last-send.json`, the `sent` rows of `peer_exchanges.jsonl` and the peer's newest message, over this session and
175
+ `ctx.continues` (one hop: the copied pairing keeps its `paired_at` and the new link's logs start empty), is older than
176
+ `peer.quiet_minutes`. In a turn with `ctx.turn_interactive?` (the turn's origin `ClientId.interactive?`; a person's first prompt
177
+ from a web tab or a TUI keeps that screen's id, `Session#first_turn_client_id`, and a Continue tap on a step-limit
178
+ offer continues an interactive offer turn as its screen's, `ContinueOffer#continue_client`) it asks
179
+ through `ctx.ask_user` (Send tagged `:spend`); in any other turn `ask_user` would block with nobody to answer
180
+ (`QuestionDesk` waits with no timeout), so it raises `SendError` at once. A Don't send (or no answer) is remembered
181
+ until the next `before_turn`. The tools' descriptions don't change (no prompt rebuild).
182
+
183
+ The skills (`scripts/chi-peer-SKILL.md`) say an answer from a file (`$TMPDIR/chi-peer/answer-<ref>.md`, `chi peer
184
+ say … < file`): a say refused with "try again" is run again as it is; after a `#N received` line or a failure with
185
+ no line it is not (a say has no idempotency key, so a second run writes a second message).
140
186
 
141
187
  ## A continue: `PeerContinue`
142
188
 
143
- `SessionContinue::CARRY` step `:peers`, in the new link's `before_spawn` (both workers down): the previous link's
144
- messages never taken and those whose receipts are still `held` or `noted`, in the worker's order, become one note
145
- in the new link (`NOTE_SOURCE` "peer messages"), each text in its peer block and cut past 4 KiB, within the
146
- inbox's note limit, with no `<peer>_read` pointer. The previous link's mailbox, `taken` and receipts are only read,
147
- so there is no undo. The pairing stays; the peer pairs again (`tell_moved`). Moving the pairing with the chain
148
- (and the peer's prompt-cache cost of re-pairing) is a later discussion.
189
+ `SessionContinue::CARRY` step `:peers` (its store `:peer_mailbox`, its file `link.json`), in the new link's
190
+ `before_spawn` (both workers down): first each pairing of the previous link is copied to the new one as it is
191
+ (`PeerMailbox.carry_links`: `address`, `from` and `paired_at` kept), whether or not anything is unread; then the
192
+ previous link's messages never taken and those whose receipts are still `held` or `noted`, in the worker's order,
193
+ become one note in the new link (`NOTE_SOURCE` "peer messages"), each text in its peer block and cut past 4 KiB,
194
+ within the inbox's note limit; a cut text ends pointing at `<peer>_read(serial: N, box: "<previous id8>")`, which
195
+ `Plugin::Peers#message` reads from the link this session continues (that id's first 8 as the box; one hop, this
196
+ session's own chain only). Each part is best effort (logged, the link starts
197
+ without it). The previous link's mailbox, `taken` and receipts are only read, so there is no undo: the copies are
198
+ in the new link's mailbox folder, which a failed continue's delete removes (`discard_failed_link` →
199
+ `delete_session` → `:peer_mailbox`). The previous link keeps its own `link.json`. Forwarded answers that name a
200
+ send of the previous link (`re`) show in the new link's chip as an answer with no send (its `peer_exchanges.jsonl`
201
+ starts empty).
149
202
 
150
203
  ## chi web
151
204
 
@@ -238,7 +238,8 @@ is prefilled once. The native and the chat loop use the same plan.
238
238
  - **TTL.** Anthropic keeps a breakpoint 5 minutes after its last read; a session the user comes back to later
239
239
  writes its prompt again. `cache.ttl: 1h` sends `cache_control: {type: "ephemeral", ttl: "1h"}` on both
240
240
  breakpoints (the log line shows `cache=1h`). Off by default: a 1h write costs 2× the input price, a 5m write
241
- 1.25×, a read 0.1× either way, so 1h pays off only when pauses of 5–60 minutes are common.
241
+ 1.25×, a read 0.1× either way, so 1h pays off only when pauses of 5–60 minutes are common. The peer mail's cold hold
242
+ reads the same TTL (`PromptCache.ttl_seconds`, `Engine#remote_cache_ttl`: [peers.md](peers.md), The worker's mail path).
242
243
  - **Routing.** Every chat request carries a `Session-Id` header, which OpenRouter uses to keep a conversation on
243
244
  one provider. `cache.key: session` also sends the session id as `prompt_cache_key` in the body, the field
244
245
  OpenAI's API routes and caches by (OpenRouter honours it too); the log line shows `cache_by=session`. Only
@@ -102,6 +102,9 @@ command, on an idle session with its offer standing and a live worker, is bound
102
102
  instead, the offer's turn id from `ReplyWait.own_turn`, as chi answer follows it; the worker's ack is not read): chi web's `POST …/ask`
103
103
  builds one per request over a `Local` that delivers through chi web's own manager and Bridge (`Web::AskRoutes::
104
104
  AskAccess`), and `McpServer::Tools` reuses `SessionAccess::Ask` / `Exchange` through the MCP server without chi web.
105
+ chi web's create that answers its first turn (`Web::AskCreate`) spawns the session idle, its prompt as the preview,
106
+ then runs the same `SessionAccess::Ask` through `AskRoutes#run_ask`; a `request_id` names the session itself
107
+ (`SessionInbox.enqueued_id_for("create:" + key)`), so a retry finds it and the Ask rebinds to the first turn.
105
108
  The ask chain carries a turn's anchors (`Ask#call` → `Exchange#attempt` → `Local#deliver_turn` → the manager's
106
109
  `deliver_turn`, `anchors:` passed only when given): chi web's `/ask` puts a message's `reply_for` there
107
110
  (`TurnAnchors`). `SessionAccess::Remote#deliver_turn` refuses a non-empty one (local only, exit 2), and neither
@@ -224,6 +227,12 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
224
227
  only when its detail starts with `not found: /` (the 404 from `serve_static`, for a path no route takes). A route's
225
228
  own 404 (no such session or source) stays a refusal. **Keep that rule:** a new route's 404 must never use the
226
229
  `not found: /…` wording.
230
+ - **Answers across versions.** The corpus's `wire/remote/` (`CompatRemote`, recorded at each release) pins the shape
231
+ of chi web's answers to `Remote`: `spec/compat/remote_readers_spec.rb` reads the previous release's answers with
232
+ today's `Remote` (exact values, so `head`'s `:same` fallback or a nil `SessionView` field fails) and sends its
233
+ requests to today's chi web (same status, every old key path kept with its JSON type). Canned replies check
234
+ parsing only: a new request field an older chi web ignores still needs a feature of its own (below). Ask, last-ask
235
+ and MCP (`ask_routes.rb`, `last_ask.rb`, `mcp_route.rb`) have no in-repo reader and aren't recorded.
227
236
  - **A field an older chi web would ignore.** A body field whose meaning is a restriction (`share --identity`'s
228
237
  `identity`: an older chi web drops it and issues a link anyone could open) gets a feature of its own
229
238
  (`bound_grants`, `App::BOUND_FEATURE`), and `Remote` requires it before sending the field (`require_feature!`):
@@ -14,14 +14,14 @@ SessionManager boundaries are in [Architecture](../architecture.md) and [Engine
14
14
 
15
15
  | Fact | Writer and removal | Cross-process readers and how they see change |
16
16
  |---|---|---|
17
- | `<id>.json` `status` | `Session#save` writes the session snapshot; the owner is the normal writer. `Session#load` overlays `stopped` as `stopped` without rewriting the file. | `SessionRow` and `SessionAccess::Local` read saved turn status; stop cancellation, restart fallback, and archive refusal also use it as a busy hint. Readers reload the file; the hub refreshes rows on its tick. It is turn state, not proof of liveness. |
17
+ | `<id>.json` `status` | `Session#save` writes the session snapshot; the owner is the normal writer. `Session#load` (and `summary_from_file`) overlays `stopped` as `stopped` without rewriting the file; the file's status is kept in `Session#loaded_status` (not saved, nil for a session built in memory). | `SessionRow` and `SessionAccess::Local` read saved turn status; stop cancellation, restart fallback, and archive refusal also use it as a busy hint. Readers reload the file; the hub refreshes rows on its tick. It is turn state, not proof of liveness. The session hub shows `stopped` only in a stopped state (`STOPPED_STATES`): `Web::SessionSummary.shown` derives the state from the facts, and a restored file whose own status says `stopped` stays stopped everywhere. |
18
18
  | `starting` (`{pid, at}`) | `SpawnPart#spawn_session` marks before the first session file; `#spawn_worker_for_session` marks around `Process.spawn`; `#claim_start` claims with `StartingMarker.claim`. Failures clear it; `Worker#start` clears it after acquiring `owner.lock`. A stale/dead marker is taken over after 60 seconds or when its pid is gone. | `WorkerPresence`, resume, archive, delete, and retention read it directly; `WorkerPresence` checks age and pid. The session hub also refreshes presence. The atomic hard-link claim arbitrates competing starters; there is no event notification. |
19
19
  | `owner.lock` and `leaving_at` | `OwnerLock.acquire` creates the file, takes its exclusive flock, and writes `{pid, kind, started_at}`; `OwnerLock#mark_leaving` adds `leaving_at` and `leave_wait`; `#release` unlocks and closes but leaves the file. Deletion removes it with the session directory. | `OwnerLock.owner` probes the kernel flock, then reads the record. The kernel releases the lock on process death; the record alone does not establish ownership. Presence and `WorkerLink` decisions probe it; hub presence refreshes poll it. `leaving_at` marks a worker that closed its Bridge but still holds the lock for leave work. |
20
20
  | `bridge.json` | `Bridge#write_sidecar` publishes the worker endpoint; `Bridge#remove_sidecar` removes its own sidecar when stopping. A crash can leave it behind. | `WorkerLink.resolve` combines the sidecar with `owner.lock` and pid; a sidecar alone is stale. Readers waiting for a worker poll `WorkerLink.resolve`; a stale unlink rechecks the owner and removes only the unchanged file. Live clients see worker events over Bridge SSE. |
21
21
  | In-memory exit claim | `Worker#exit_request` uses `WorkerExitClaim#claim`, `#accept`, `#release` and `#forget`; `#stopped!` records the last stop-all. It dies with that Worker. | Only that worker's threads read it; the Bridge's `/exit` and the loop coordinate through the Engine event lock, not a cross-process file. |
22
22
  | `stopped` | `SessionManager#stop_session` calls `Session.mark_stopped` under the session's transition lock (kind `stop`, "Stops, archives and the ring wake"); `SpawnPart#resume` and delivery's `#start_for_send` clear it with `Session.clear_stopped` when starting for a person. Session-directory deletion removes it. | `WorkerPresence`, the worker startup/signal paths, and `Session#load` check the marker. It is read from disk on a decision (and on the hub refresh); no worker event is required. Its timestamp is compared with `starting.at` so a stop cancels an older start, not a later resume. |
23
23
  | `archived` | `ArchiveStore.archive` is called by `SessionManager#archive_session`; `ArchiveStore.unarchive` is called by `#unarchive_session`, `SessionContinue#undo_failed_continue`, and the chain-delete undo/revival paths. Session-directory deletion removes it. | Lists, chain resolution, delivery, schedules, retention, and `WorkerPresence` call `ArchiveStore.archived?` against the file; changes are seen by the next read or list refresh. |
24
- | `continue.lock` and `continue.json` | `SessionTransition` is the only code that flocks `continue.lock`: a continue takes it exclusively after its recap, for the previous link and the new link's reserved id at once (`SessionContinue#with_lock`: `exclusive`, `LOCK_WAIT` 10 s a try, then `Refused :transition_busy`), a user's link or chain delete takes it exclusively for its whole run (`SessionChain::Delete`, kind `delete`, `LOCK_WAIT` 10 s), the schedule prune, the retention sweep and a leaving worker's empty or scratch delete try it once (kind `delete`), a stop takes it for its mark and TERM (kind `stop`, `STOP_LOCK_WAIT` 10 s; a worker stopping its delegates tries once), an archive for its task stop and markers (kind `archive`, `ARCHIVE_LOCK_WAIT` 10 s), a ring's wake holds it shared across its check and resume, crash repair tries it once (`try_exclusive`), an exclusive holder records its kind in the file while it holds it (`holder`, which `Busy.held` reads), arrivals and readers that must exclude a continue take a nonblocking shared hold (`shared`: each `WakePolicy` row's `hold`, taken in the seats), and previews probe it (`held?`). `ContinueIntent#write` records the successor before archive and updates the archived ids after; failed-continue cleanup removes the intent. The lock file remains until session-directory deletion; a continue that ends before its new link is saved removes that link's reserved folder, and the previous link's lock when the link was deleted meanwhile (`SessionTransition.forget`). | Every `:shared` delivery (sends, every turn sender, pushes, peer says), peer pairs, context adds/removes/pushes, invites, schedules, the delete preview, `SessionLifecycle.read` (`transitioning`) and `ContinueIntent.in_flight` (through `SessionChain::Successor`) inspect the lock and intent. flock coordinates the live transition; readers reload the JSON. An intent without a held lock is a crashed continue, not an active one; so is one whose successor is neither saved nor held (a continue holds both), and one under another kind's hold (a delete, a stop, an archive: `SessionTransition.other_than_continue?`). |
24
+ | `continue.lock` and `continue.json` | `SessionTransition` is the only code that flocks `continue.lock`: a continue takes it exclusively after its recap, for the previous link and the new link's reserved id at once (`SessionContinue#with_lock`: `exclusive`, `LOCK_WAIT` 10 s a try, then `Refused :transition_busy`), a user's link or chain delete takes it exclusively for its whole run (`SessionChain::Delete`, kind `delete`, `LOCK_WAIT` 10 s), the schedule prune, the retention sweep and a leaving worker's empty or scratch delete try it once (kind `delete`), a stop takes it for its turn cancel, mark and TERM (kind `stop`, `STOP_LOCK_WAIT` 10 s for a short hold, a continue naming its new link, a delete or an archive refused at once; a worker stopping its delegates tries once), an archive for its task stop and markers (kind `archive`, `ARCHIVE_LOCK_WAIT` 10 s), a ring's wake holds it shared across its check and resume, crash repair tries it once (`try_exclusive`), an exclusive holder records its kind in the file while it holds it (`holder`, which `Busy.held` reads), arrivals and readers that must exclude a continue take a nonblocking shared hold (`shared`: each `WakePolicy` row's `hold`, taken in the seats), and previews probe it (`held?`). `ContinueIntent#write` records the successor before archive and updates the archived ids after; failed-continue cleanup removes the intent. The lock file remains until session-directory deletion; a continue that ends before its new link is saved removes that link's reserved folder, and the previous link's lock when the link was deleted meanwhile (`SessionTransition.forget`). | Every `:shared` delivery (sends, every turn sender, pushes, peer says), peer pairs, context adds/removes/pushes, invites, schedules, the delete preview, `SessionLifecycle.read` (`transitioning`) and `ContinueIntent.in_flight` (through `SessionChain::Successor`) inspect the lock and intent. flock coordinates the live transition; readers reload the JSON. An intent without a held lock is a crashed continue, not an active one; so is one whose successor is neither saved nor held (a continue holds both), and one under another kind's hold (a delete, a stop, an archive: `SessionTransition.other_than_continue?`). |
25
25
  | `parent.json` | `Session#reparent` writes the override when `ChildMove` moves a child. Session-directory deletion removes it. | `ChildReports` resolves the current parent when routing a ring; the worker reads the override when loading its parent. Readers reload the file; it is not an event stream. |
26
26
  | `reminders.json` | `Worker::LeavePart#carry_reminders` writes it for an asked restart, or removes it when stopped/no successor; stop, archive, and a stopped restart also remove it. `ReminderCarry#take` reads and removes it at worker start. | Only the next worker restores it into its Engine. It is a one-shot hand-off, not polled state; the session id, 120-second window, and stop marker are checked before restore. |
27
27
  | Pending `input/`, `children/`, and `notes/` | `SessionInbox.write_input`, `#write_ring`, and `#write_note` write the files. A worker claims input and notes by atomic rename to `.processing`, then removes or settles them; rings are consumed by `ChildReports`. Session-directory deletion removes all three. | The worker checks input around turns and on its idle loop; rings and notes are checked by worker wake/absorption paths. The file is the durable queue; Bridge SSE can announce a live turn, but the worker's file scan is the fallback and recovery path. |
@@ -146,15 +146,15 @@ operation (one driver each, every private reach in that one file) and projects i
146
146
  code can't make (a one-turn run's lock with a stop) is marked `reachable: false` with its note and still asserted.
147
147
 
148
148
  Every answer must equal `ALLOWED[op][state]` (for the session hub, `SHOWN[state]`: `Web::SessionSummary.build`'s
149
- status and bridge_up, its `SessionRow`'s live), or be named by exactly one `KNOWN_DIFFERENCES` entry (op, a `when`
149
+ status and bridge_up, the live its summary gates the open question on (`SessionSummary.shown`)), or be named by exactly one `KNOWN_DIFFERENCES` entry (op, a `when`
150
150
  over the row, a plain reason); an entry that names no mismatch fails as stale. The entries are the findings for the
151
151
  owner, not fixed: stop-first schedule checks under a one-turn run's or an unknown owner's lock (`#busy_cell`'s stop override), and attach's under a
152
152
  one-turn run's, a deleter's or an unknown owner's; chain mode's starting check before any one-turn-run check (`#busy_cell`'s F1b override); a start
153
153
  marked after the stop holding a resume off;
154
- `wake_for_report` reporting a worker's `:live` as `:owned`; the hub's bridge_up, live and status overlay. (Restart
155
- never reading the stop, the restart and schedule reading a deleter as starting, the schedule's Skew words, and
156
- `busy_reason`'s live branch falling through to the starting check were fixed: their entries went stale and were
157
- removed.) The delivery columns are
154
+ `wake_for_report` reporting a worker's `:live` as `:owned`. (Restart
155
+ never reading the stop, the restart and schedule reading a deleter as starting, the schedule's Skew words,
156
+ `busy_reason`'s live branch falling through to the starting check, and the hub's bridge_up, live and status overlay (F3/(c))
157
+ were fixed: their entries went stale and were removed.) The delivery columns are
158
158
  generated from `WakePolicy::ROWS`, so for deliveries the matrix proves the states are drawn right (decide is a function
159
159
  of the state), not what WakePolicy does; the literal columns and `SHOWN` are goldens.
160
160
 
@@ -180,10 +180,15 @@ continue (`SessionContinue.repair_interrupted`), not by worker startup.
180
180
  in lib that flocks or probes it (`spec/session_transition_lock_spec.rb`). The file keeps its name: an older chi's
181
181
  continue, followed send and delete honour it.
182
182
 
183
- - `exclusive(ids, kind:, state_dir:, deadline:)` takes each id's lock in sorted order, creating a missing folder;
184
- `deadline: nil` blocks (no caller since the continue took a deadline), seconds retry until then (`0`: one try)
185
- and raise `SessionTransition::Busy`, which owns its refusal text and names the id. Ids taken before a busy one are
186
- let go. While it holds a lock it writes its `kind` into the file (cleared on release, never from a lock another
183
+ - `exclusive(ids, kind:, state_dir:, deadline:, refuse_transitions: false)` takes each id's lock in sorted order,
184
+ creating a missing folder; `deadline: nil` blocks (no caller since the continue took a deadline), seconds retry
185
+ until then (`0`: one try) and raise `SessionTransition::Busy`, which owns its refusal text and names the id. With
186
+ `refuse_transitions` (a stop's; a deadline required, else `ArgumentError`) each failed try reads the holder again
187
+ (`Busy.held(id, taker: kind)`) and raises at once when it is a transition (`Busy#transition?`: a delete, an
188
+ archive, a continue whose intent names its new link); a stop, a repair, a holder that names nothing (an older
189
+ chi's, a continue before its intent, the new link's own hold) and every shared hold are waited out to the
190
+ deadline. Re-reading each try catches a delete that takes the lock while the stop waits behind a send. Ids taken
191
+ before a busy one are let go. While it holds a lock it writes its `kind` into the file (cleared on release, never from a lock another
187
192
  holds; `try_exclusive` too).
188
193
  - `holder(id, state_dir:)` is that kind (`:continue`, `:delete`), read only behind a failed shared try: a shared
189
194
  holder (a send), an older chi's continue, a raw flock and a crash's leftover name none. `Busy.held(id, state_dir:)`
@@ -196,7 +201,10 @@ continue, followed send and delete honour it.
196
201
  (its detail, which `--remote` reads back), `ContextSources.changing`, `Participants.invite`, the delete's refusal
197
202
  (`DeleteRefused.held`) and the delete preview take their words from it; a delete holding the lock makes the seats
198
203
  name no successor (`Hold.under`). The peer say/pair and the context push answer a status, `:busy`, whose words
199
- are the plain ones.
204
+ are the plain ones. Those are `Busy#retry_message`, `#message` for every taker but a stop: a stop's Busy
205
+ (`taker: :stop`) that met a transition says what to do instead ("session ab12cd34 is being deleted", "… being
206
+ archived", "… being continued as <new id>: stop that one"). `DeleteRefused.held` and `ArchiveRefused.held` keep
207
+ the retry words (`retry_message`) for a stop they wrap.
200
208
  - `try_exclusive(id, …)` is one try that creates no folder, crash repair's (`repair_intent`): a lock this thread
201
209
  holds counts as taken, so a repair reached inside a continue never undoes it.
202
210
  - `shared(id, state_dir:)` is a non-blocking shared hold (an invalid id is `false`; the lock file is created, the
@@ -281,15 +289,20 @@ archive.
281
289
 
282
290
  ### Stops, archives and the ring wake
283
291
 
284
- - **A stop** (`SessionManager.stop_session`) takes `exclusive([id], kind: :stop, deadline: lock_wait)`
285
- (`STOP_LOCK_WAIT` 10 s) for the owner read, the stop marker, the reminders hand-off and the TERM/CONT; the turn
286
- cancel before it (a Bridge call and up to `STOP_CANCEL_WAIT`) and the owner wait after it (`wait:`) run unheld. Only
292
+ - **A stop** (`SessionManager.stop_session`) takes `exclusive([id], kind: :stop, deadline: lock_wait,
293
+ refuse_transitions: true)` (`STOP_LOCK_WAIT` 10 s for a short hold; a continue naming its new link, a delete or an
294
+ archive refused at once) for the turn cancel, the owner read, the stop marker, the reminders hand-off and the
295
+ TERM/CONT; the owner wait after it (`wait:`) runs unheld. The turn cancel (a Bridge call whose read timeout is
296
+ `STOP_CANCEL_WAIT`, then up to `STOP_CANCEL_WAIT` for the worker's save) is the one deliberate, bounded exception
297
+ to "never a Bridge wait under a hold": a refused stop leaves the turn running, and no deadlock follows, because
298
+ every shared taker refuses at once on a held lock, a worker's own exclusive takes are one try, and the canceled
299
+ worker saves its turn without the transition lock. Only
287
300
  a saved session's lock is taken (a gone one's folder is never made again; `Session.mark_stopped`'s not found
288
301
  follows). A hold this thread has passes through: a continue's archive (`archive_session` → `stop_session`), its
289
302
  `discard_failed_link`, a delete's `release_for_delete!`; a plain delete with a stop (no chain keywords, a scratch's
290
303
  end: `delete_resolved` takes no transition lock) turns a held one into its own refusal (`stop_held` →
291
- `DeleteRefused.held`). Not taken in time → `SessionTransition::Busy`,
292
- nothing marked: chi web's 409 `stop_held` (`kind`, `successor_id`: `--remote` builds the same Busy), `chi sessions
304
+ `DeleteRefused.held`). Not taken in time, or held by a transition → `SessionTransition::Busy` (`taker: :stop`),
305
+ nothing canceled or marked: chi web's 409 `stop_held` (`kind`, `successor_id`: `--remote` builds the same Busy), `chi sessions
293
306
  stop` prints it and exits 1. A worker stopping its delegates (the exit ask's stop-all, a plugin's
294
307
  `ctx.sessions.stop`) tries once (`lock_wait: 0`): it holds its own `owner.lock`; a held child is left running
295
308
  (logged / the plugin's `Error`, Busy's words).
@@ -331,7 +344,7 @@ firing counts it a skip; the web composer, a delegate follow-up, a plugin's send
331
344
  | context add / remove (`Local#context_add`/`#context_remove`, chi web's URL add and detach) | shared | `ContextSources.changing`: a continue copies the session's own sources. Refused `ContextSources::Held` (423 `context_busy`). |
332
345
  | context push, peer say, peer pair | shared | Phase 1 (`Local#moved_on`); the say's delivery seat holds again (shared beside shared). |
333
346
  | invite (`Participants.invite`) | shared | A continue archives the link and ends its grants; refused `Grants::Invalid` with Busy's words. |
334
- | revoke, peer unpair | none | Removals: a continue ends every grant at the archive, and the new link's pairing is the peer's to make (`Plugin::Peer#tell_moved`); refusing them would only make the owner retry. |
347
+ | revoke, peer unpair | none | Removals: a continue ends every grant at the archive, and an unpair of a continued id ends the live link's pairing too (`Local#peer_unpair`); refusing them would only make the owner retry. |
335
348
  | `Local#answer` / `#dismiss`, cancel (cut), the attached TUI's `post_turn`, `Bridge#enqueue_turn` (the input fallback) | worker-side | Bridge-only: the live worker's own session (a continue's archive stops that worker and `archivable!` refuses it busy or queued). Over `--remote` the TUI's turn is chi web's turn route, `deliver_turn`'s seat. |
336
349
  | The new link's boot (`ChildMove.adopt`, `NoteMove.adoption`, its objectives notes) | worker-side, none | Runs inside its creator's exclusive hold of the new link: a hold there would be refused until the continue ends. |
337
350
 
@@ -348,7 +361,7 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
348
361
  | A ring wake decides to start, then a stop lands before resume (closed). | Before: `SpawnPart#wake_for_report` (`session_manager/spawn.rb`) checked, then `resume_session` cleared a stop that landed meanwhile and started the worker. Now the wake holds the session's transition lock shared across the check and the resume and the stop takes it exclusively for its mark and TERM: the stop comes after the start, whole (its marker stays), or the wake meets the stop's hold and leaves the ring on disk (`:busy`). | `spec/session_manager/spawn_spec.rb` ".wake_for_report" (a stop from another thread in the start callback is held off and its marker stays; a held lock answers `:busy`, nothing started). |
349
362
  | A ring's own delivery wakes the parent while a stop lands. | `ChildReports.ring` → `SessionInbox.deliver(:ring)` (a `:none` row: its write must never be refused) decides, then starts the parent on another thread (`ChildReports#starter`, `start_for_inbox`): the hold of `wake_for_report` does not cover it, so a stop between the decide and the start can be cleared by it as before. | No pin (declared); a shared hold around the start alone, on the starter's thread, would close it. |
350
363
  | A restart outside the transition lock. | `restart_session` asks the worker to leave and its successor to start (or the fallback TERMs and resumes); it spans two processes, so it takes no transition lock (D3): a continue, a delete, a stop or an archive may interleave with it, each with its own checks (the restart precheck reads `SessionLifecycle`). | No pin (declared). |
351
- | A stop's turn cancel and owner wait are unheld. | `stop_session` cancels a running turn (Bridge, up to `STOP_CANCEL_WAIT`) before it takes the lock and waits for the owner after it lets go: a send in either may go in (and a new worker start after the wait, as before). A stop refused busy after the cancel has ended that turn. | `spec/session_manager/lifecycle_spec.rb` "under the transition lock" (held for the mark and TERM, not the owner wait). |
364
+ | A stop's owner wait is unheld (its turn cancel: closed). | `stop_session` waits for the owner after it lets go of the lock: a send in that wait may go in (and a new worker start after the wait, as before). The turn cancel now runs under the stop's hold (its Bridge read bounded by `STOP_CANCEL_WAIT`), so a stop refused busy no longer ends the turn. | `spec/session_manager/lifecycle_spec.rb` "under the transition lock" (held for the mark and TERM, not the owner wait) and "mid-turn" (the cancel under the stop's hold, its read timeout; a refused stop cancels nothing). |
352
365
  | Empty-session discard races a delivery (closed for turns and notes). | `WorkerBoot#discard_left_session` (`worker_boot.rb`) checks emptiness after releasing the worker lock and again under the deletion lock (`delete_session`'s `still:`): a send or note that went in before the lock keeps the session. One that reads the session during the lock is refused (`DeliverResult::DELETING`, a note as gone); one that read it before the lock and wrote after it reads it again after its write and takes its file back (`SessionInbox.withdraw`), so no turn or note is reported delivered and then removed. No new lock for that: the write-then-reread and the recheck under the existing deletion lock close it (the discard also tries the session's transition lock once, kind `delete`: a send or a transition holding it keeps the session). What remains: a ring or fresh verdict that read the session before the lock and wrote after it is not taken back: it goes with the directory, or stays for the next worker if the delete gives up; neither is reported to a person. | `run_session_loop_spec.rb`: a send at deletion-lock acquisition is refused; one just before the lock keeps the session. `delivery_spec.rb` / `note_delivery_spec.rb`: the lock (or the removal) between the check and the write, deterministic through the bridge / writer seam. |
353
366
  | Stop reads an owner pid, then sends TERM. | `LifecyclePart#stop_session` (`session_manager/lifecycle.rb`): the pid can be reused between the owner read and `Process.kill`; protecting that requires a real pid-reuse scenario. | No unit pin: pid reuse/process signaling is not reliably representable without real processes. |
354
367
  | Saved `status` is used as a lifecycle hint. | `LifecyclePart#restart_fallback_holds` and `RemovalPart#archive_refusal` (`session_manager/lifecycle.rb`, `session_manager/removal.rb`) use saved `running` status as a busy hint; status is not a lock or proof that a worker is alive. | Unit spec: pin fallback refusal from saved status without a live Bridge. |
@@ -359,8 +372,9 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
359
372
  | A send between a continue's exclusive hold and its archive marker (closed). | Before: `follow_guard` held only for a followed send to an archived link, so a send (any sender) to a link a continue held but had not archived yet went in, and the archive then refused the continue as busy or queued. Now every `:shared` row's delivery takes the hold in its seat: refused naming the new link (`link_continued`), else `transition_busy`. | `spec/session_inbox/hold_spec.rb` (each sender busy under a really held lock; a send to a link not archived yet refused naming the new link); the matrix's transitioning rows. |
360
373
  | A frozen worker's Bridge post under a send's hold. | `deliver_turn` holds the session's lock shared across the Bridge's post (up to `BridgeClient::READ_TIMEOUT` 30 s for a worker that doesn't answer); a continue of that session waits `LOCK_WAIT` per try and is refused `transition_busy`, and a stop or an archive waits its 10 s and is refused (`stop_held` / `transition_held`, "busy with another change"): stopping that frozen worker can take a second try. | No unit pin: a frozen worker's post is a timing case. |
361
374
  | A delete or a send during a continue's recap. | `SessionContinue.continue_once` waits for the recap before it takes the transition lock: in that window a link delete and the delete preview no longer see a continue (`:continuing`): the delete may take the link's lock exclusively, and the continue's lock wait then ends busy ("being deleted"); a followed send to the link goes in. Under the lock the continue checks the link again: deleted → not found (its folder not brought back), continued by another → `Refused :continued`, a turn queued → the archive's refusal. | `session_continue_spec.rb` "the transition lock": the lock not held during the recap, a send then accepted, a link deleted or continued during the recap refused under the lock. |
375
+ | A stop is refused during a live continue. | `ContinueIntent#write` records the new link before archive; if the live continue names it, a stop refusal can name that successor up to a few seconds before it is saved while the archive waits up to 5 s and then spawns it. Opening the named link at once can show gone until it appears, and a failed spawn means it never appears. | `continue_intent.rb` (`in_flight`) and `session_continue.rb`. |
362
376
  | The new link's worker boots inside the continue's hold. | `SessionContinue.spawn_continuation` spawns it while the continue holds the new link's transition lock exclusively; its boot writes (`Worker#start` → `ChildMove.adopt`, `WorkerInbound` → `NoteMove.adoption`, its objectives notes through the note row, `:none`) take no transition hold. A hold added on that path would be refused until the continue ends (drop the new link's hold before the spawn instead). A send or a peer pair to the new link from outside is `transition_busy` until the continue lets go (milliseconds after the spawn): the senders retry. | `session_continue_spec.rb`: the boot's adoption on another thread makes no `SessionTransition` call, adopts the note, and a note through `NoteDelivery` goes in. |
363
- | An unpair or a revoke during a continue. | `:none` (above): an unpair of the old link while the new worker's `tell_moved` re-pairs the peer may leave the peer paired with the new link. | No pin (declared). |
377
+ | An unpair or a revoke during a continue. | `:none` (above): the continue archives the old link, saves the new one, then copies the pairing in the new link's `before_spawn` (`PeerMailbox.carry_links`, reading `link.json` at that moment, so an unpair before it wins). An unpair that lands between the copy's read of the old `link.json` and its write of the new one removes the old link's only; the copy keeps the peer paired with the new link (unpair again). | No pin (declared). |
364
378
  | Sends to a session a delete holds (open, by design). | `SessionChain::Delete` holds the transition locks from before its stop to the end: a send, a push, a peer say or a context change to the link, its previous link or a delegate that goes is refused `transition_busy` "being deleted" for the stop (up to the delete's wait, 10 s from the CLI), the task stop (about 4 s a link) and the removal; a chain delete holds every link's for the whole chain (N links × stop + tasks: minutes for a long chain with `--stop-tasks`). chi send and an ask retry within their wait; the web composer, a delegate, a plugin and a participant report it. Before, those sends went in and the delete stopped or removed them. | `session_chain/delete_spec.rb` "under the transition locks" (a send during the stop refused as being deleted, both locks the delete's). |
365
379
  | A delete meets a send's or another change's hold (closed). | Before: `Delete.link`, `hold_all` took `SH\|NB`, so a continue was refused but another delete, a prune or the retention sweep could run beside it, and a send held nothing off. Now a user's delete waits up to `LOCK_WAIT` for the locks exclusively, then refuses (`continuing` / `transition_held`, the holder named); the prune, the sweep and a leaving worker's delete try once and keep the session. | `session_chain/delete_spec.rb` (a short shared hold waited out, a long one refused, a held delegate refuses), `session_retention_spec.rb`, `session_discardable_spec.rb` (held → kept). |
366
380
  | A prune at a link it can't delete (closed: visible, never skipped). | Before: a link another enabled schedule protects (its anchor inside the chain, a stale head) was refused `prune_stopped` at every firing, after the link's delegates were already deleted, and the chain grew silently. Now the hold is checked before anything in the subtree goes and the prune stops there with a record (`prune_waiting`, list/show) and one log line; a held transition lock on the link or the next does the same, and every tick retries. Still open: the chain grows behind such a link until the other schedule is cancelled (re-linking the chain around it is held, D6). | `schedules_spec.rb` "a prune held at a link" (held link: kept with every later link, resumed next tick; next link held; the mid-chain schedule: one log, list/show lines, nothing deleted around it, gone after cancel). |
@@ -382,7 +396,8 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
382
396
  `ALLOWED` cells (the literal ones by hand; the delivery ones follow `WakePolicy::ROWS`) and the matrix's rows; a
383
397
  decider that answers otherwise is a `KNOWN_DIFFERENCES` entry with its reason, never a silent cell change.
384
398
  7. A new multi-step transition takes `SessionTransition.exclusive` with its own `kind` (add its words to
385
- `Busy::WORDS` so `Busy.held` names it; any kind but `continue` names no new link), with a deadline, before any
399
+ `Busy::WORDS` so `Busy.held` names it; any kind but `continue` names no new link; a long one a stop should not
400
+ wait for goes in `Busy::TRANSITIONS`, and a stop meeting it is refused at once), with a deadline, before any
386
401
  `owner.lock`; an automatic one tries once (`deadline: 0`) and leaves the session for later, and so does one a
387
402
  worker runs (it holds an `owner.lock`). A literal operation that takes the lock gets its `TAKES_LOCK` cell.
388
403
  8. Recheck lock order, crash cleanup, and the existing file-format/compatibility specs before changing runtime behavior.