samagotchi 0.201.0 → 0.202.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -1
- data/docs/architecture.md +47 -7
- data/docs/cli.md +20 -1
- data/docs/configuration.md +2 -1
- data/docs/internals/bridge.md +4 -4
- data/docs/internals/engine.md +9 -6
- data/docs/internals/knowledge.md +26 -6
- data/docs/internals/objectives.md +2 -2
- data/docs/internals/pages.md +4 -2
- data/docs/internals/participants.md +1 -1
- data/docs/internals/peers.md +9 -7
- data/docs/internals/remote-sessions.md +6 -6
- data/docs/internals/session-lifecycle.md +37 -15
- data/docs/internals/web-frontend.md +18 -7
- data/docs/pages.md +6 -3
- data/docs/plugins.md +2 -2
- data/docs/scheduling.md +40 -12
- data/docs/sessions.md +48 -6
- data/docs/sub-agent.md +1 -2
- data/docs/testing.md +92 -8
- data/lib/samagotchi/answer_display.rb +3 -2
- data/lib/samagotchi/answer_tail.rb +4 -4
- data/lib/samagotchi/bridge/card_places.rb +5 -5
- data/lib/samagotchi/bridge/turn_accumulator.rb +5 -5
- data/lib/samagotchi/bridge/turn_drawings/synth.rb +5 -5
- data/lib/samagotchi/bridge/turn_drawings.rb +2 -2
- data/lib/samagotchi/bridge/turn_ranges.rb +15 -8
- data/lib/samagotchi/bridge.rb +5 -5
- data/lib/samagotchi/broadcast_command.rb +3 -3
- data/lib/samagotchi/bundle_command/try/trace.rb +18 -6
- data/lib/samagotchi/bundles/knowledge/embedder.rb +2 -0
- data/lib/samagotchi/bundles/knowledge/github.rb +19 -0
- data/lib/samagotchi/bundles/knowledge/manifest.yml +6 -6
- data/lib/samagotchi/bundles/knowledge/plugin.rb +26 -54
- data/lib/samagotchi/bundles/knowledge/refresh.rb +89 -14
- data/lib/samagotchi/bundles/knowledge/store.rb +36 -2
- data/lib/samagotchi/bundles/schedules/manifest.yml +2 -2
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +24 -3
- data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/skill_pages.md +1 -1
- data/lib/samagotchi/chi_invocation.rb +1 -1
- data/lib/samagotchi/child_move.rb +6 -3
- data/lib/samagotchi/child_reports.rb +3 -3
- data/lib/samagotchi/children_status.rb +4 -2
- data/lib/samagotchi/client_id.rb +2 -2
- data/lib/samagotchi/compat.rb +4 -6
- data/lib/samagotchi/config.rb +3 -0
- data/lib/samagotchi/context_note.rb +1 -1
- data/lib/samagotchi/continue_intent.rb +1 -1
- data/lib/samagotchi/continue_offer.rb +2 -2
- data/lib/samagotchi/continue_repair_backoff.rb +71 -0
- data/lib/samagotchi/delivery.rb +1 -4
- data/lib/samagotchi/engine/participants.rb +1 -1
- data/lib/samagotchi/engine/recap.rb +1 -1
- data/lib/samagotchi/engine/turn_end.rb +1 -1
- data/lib/samagotchi/grants.rb +2 -2
- data/lib/samagotchi/guardrail_wiring.rb +1 -1
- data/lib/samagotchi/guardrails/approval.rb +3 -3
- data/lib/samagotchi/guardrails/pair_boundary.rb +3 -3
- data/lib/samagotchi/guardrails/participant_refusal.rb +2 -2
- data/lib/samagotchi/idle_recap.rb +6 -6
- data/lib/samagotchi/kernel_loop.rb +1 -1
- data/lib/samagotchi/last_turn.rb +9 -6
- data/lib/samagotchi/llm/chat_loop.rb +5 -2
- data/lib/samagotchi/mcp_command.rb +2 -2
- data/lib/samagotchi/memory_usage.rb +7 -6
- data/lib/samagotchi/note_command.rb +1 -1
- data/lib/samagotchi/note_delivery.rb +5 -5
- data/lib/samagotchi/objectives_backing.rb +3 -3
- data/lib/samagotchi/objectives_record.rb +2 -2
- data/lib/samagotchi/objectives_track.rb +2 -2
- data/lib/samagotchi/owner_lock.rb +28 -2
- data/lib/samagotchi/owner_prompt.rb +3 -3
- data/lib/samagotchi/pages/runtime.rb +9 -4
- data/lib/samagotchi/participant_revise.rb +6 -6
- data/lib/samagotchi/peer_receipts.rb +11 -4
- data/lib/samagotchi/plugin/side_question.rb +1 -1
- data/lib/samagotchi/recap_place.rb +5 -5
- data/lib/samagotchi/reply_for.rb +3 -3
- data/lib/samagotchi/reply_wait/liveness.rb +2 -2
- data/lib/samagotchi/reply_wait/poll.rb +3 -3
- data/lib/samagotchi/schedule_command.rb +1 -1
- data/lib/samagotchi/schedule_display.rb +4 -3
- data/lib/samagotchi/schedules/busy_part.rb +29 -5
- data/lib/samagotchi/schedules/history_part.rb +47 -7
- data/lib/samagotchi/schedules/marks_part.rb +52 -29
- data/lib/samagotchi/schedules/notices_part.rb +31 -4
- data/lib/samagotchi/schedules/protection_part.rb +69 -11
- data/lib/samagotchi/schedules/prune_part.rb +3 -2
- data/lib/samagotchi/schedules.rb +37 -47
- data/lib/samagotchi/send_command.rb +12 -12
- data/lib/samagotchi/session.rb +71 -59
- data/lib/samagotchi/session_access/contract.rb +7 -0
- data/lib/samagotchi/session_access/exchange.rb +1 -1
- data/lib/samagotchi/session_access/local.rb +9 -9
- data/lib/samagotchi/session_access/remote.rb +20 -24
- data/lib/samagotchi/session_access.rb +1 -1
- data/lib/samagotchi/session_chain/delete.rb +15 -8
- data/lib/samagotchi/session_chain/delete_preview.rb +3 -3
- data/lib/samagotchi/session_chain/links.rb +18 -4
- data/lib/samagotchi/session_chain/successor.rb +1 -1
- data/lib/samagotchi/session_chain.rb +3 -3
- data/lib/samagotchi/session_continue.rb +83 -32
- data/lib/samagotchi/session_inbox.rb +6 -17
- data/lib/samagotchi/session_inbox_delivery.rb +36 -13
- data/lib/samagotchi/session_lifecycle/allowed.rb +5 -5
- data/lib/samagotchi/session_manager/delegate_rule.rb +2 -2
- data/lib/samagotchi/session_manager/delivery.rb +13 -38
- data/lib/samagotchi/session_manager/emptiness.rb +35 -15
- data/lib/samagotchi/session_manager/lifecycle.rb +3 -2
- data/lib/samagotchi/session_manager/listing.rb +35 -10
- data/lib/samagotchi/session_manager/removal.rb +16 -0
- data/lib/samagotchi/session_manager/spawn.rb +9 -6
- data/lib/samagotchi/session_manager.rb +6 -4
- data/lib/samagotchi/session_messages.rb +602 -0
- data/lib/samagotchi/session_metrics.rb +7 -4
- data/lib/samagotchi/session_participants.rb +4 -4
- data/lib/samagotchi/session_protection.rb +16 -2
- data/lib/samagotchi/session_retention.rb +26 -12
- data/lib/samagotchi/session_row.rb +1 -1
- data/lib/samagotchi/session_stats.rb +17 -8
- data/lib/samagotchi/session_stores.rb +5 -0
- data/lib/samagotchi/session_transition.rb +3 -2
- data/lib/samagotchi/sessions_command.rb +55 -3
- data/lib/samagotchi/steer.rb +16 -50
- data/lib/samagotchi/storage_migration.rb +234 -0
- data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
- data/lib/samagotchi/terminal_ui/formatting.rb +5 -5
- data/lib/samagotchi/terminal_ui/join_replay.rb +3 -3
- data/lib/samagotchi/terminal_ui/question_prompt.rb +2 -2
- data/lib/samagotchi/toolkit_report_command.rb +1 -1
- data/lib/samagotchi/tools/ask_session.rb +2 -2
- data/lib/samagotchi/tools/send_note.rb +1 -1
- data/lib/samagotchi/turn_context.rb +3 -3
- data/lib/samagotchi/turn_endings.rb +17 -0
- data/lib/samagotchi/turn_excerpts.rb +7 -4
- data/lib/samagotchi/turn_flow.rb +1 -1
- data/lib/samagotchi/turn_note.rb +30 -2
- data/lib/samagotchi/turn_origin.rb +7 -7
- data/lib/samagotchi/turn_outcome.rb +11 -0
- data/lib/samagotchi/turn_stages/verify_anchors.rb +4 -4
- data/lib/samagotchi/verify_fresh.rb +6 -6
- data/lib/samagotchi/verify_fresh_origin.rb +4 -4
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +4 -3
- data/lib/samagotchi/web/last_ask.rb +2 -2
- data/lib/samagotchi/web/message_display.rb +12 -12
- data/lib/samagotchi/web/page_routes.rb +9 -3
- data/lib/samagotchi/web/participant_view.rb +4 -4
- data/lib/samagotchi/web/participants_admin.rb +1 -1
- data/lib/samagotchi/web/public/bubbles.js +1 -1
- data/lib/samagotchi/web/public/composer_fold.js +0 -3
- data/lib/samagotchi/web/public/composer_grip.js +0 -2
- data/lib/samagotchi/web/public/page_view.js +29 -4
- data/lib/samagotchi/web/public/participant_model.js +1 -1
- data/lib/samagotchi/web/public/peer_wait.js +2 -4
- data/lib/samagotchi/web/public/schedule_marks.js +2 -5
- data/lib/samagotchi/web/public/schedule_name.js +14 -0
- data/lib/samagotchi/web/public/session_actions.js +5 -0
- data/lib/samagotchi/web/public/start_page.js +1 -1
- data/lib/samagotchi/web/public/stop_sheet.js +2 -4
- data/lib/samagotchi/web/public/working_set_rail.js +0 -3
- data/lib/samagotchi/web/push/attention.rb +1 -1
- data/lib/samagotchi/web/session_create.rb +1 -1
- data/lib/samagotchi/web/session_hub.rb +68 -20
- data/lib/samagotchi/web/session_summary.rb +18 -14
- data/lib/samagotchi/web/verify_fresh_routes.rb +4 -4
- data/lib/samagotchi/worker/turn_drain.rb +158 -0
- data/lib/samagotchi/worker.rb +8 -144
- data/lib/samagotchi/worker_boot.rb +21 -5
- data/lib/samagotchi/worker_participant_gate.rb +5 -5
- data/lib/samagotchi/worker_presence.rb +24 -1
- metadata +6 -1
|
@@ -17,7 +17,7 @@ module Samagotchi
|
|
|
17
17
|
# exists only after a turn that kept messages: never a skeleton file.
|
|
18
18
|
# The starting marker is one too: a start left one behind; a fresh one
|
|
19
19
|
# keeps the session from the deleters itself. So is the transition lock
|
|
20
|
-
# (a send's shared hold leaves it:
|
|
20
|
+
# (a send's shared hold leaves it: InboxDelivery::Hold).
|
|
21
21
|
# A bundle's chips (SessionChips) are its own, not the user's: a bundle
|
|
22
22
|
# that sets one at session start leaves an untouched session discardable.
|
|
23
23
|
EMPTY_SKELETON_FILES = ["pid", "owner.lock", WorkerLink::FILE, AnalyticsFile::NAME, StartingMarker::FILE,
|
|
@@ -93,20 +93,40 @@ module Samagotchi
|
|
|
93
93
|
def empty_session_dir?(dir)
|
|
94
94
|
return true unless Dir.exist?(dir)
|
|
95
95
|
|
|
96
|
-
Dir.children(dir).all?
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
96
|
+
Dir.children(dir).all? { |name| skeleton_entry?(dir, name) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Whether a session's directory holds the skeleton and an
|
|
100
|
+
# analytics.json with turns in it (a readable JSON object), nothing
|
|
101
|
+
# else: what a session whose file is gone left behind (the retention
|
|
102
|
+
# sweep takes such a folder once it is older than the window).
|
|
103
|
+
# #empty_session_dir? stays "never had a turn".
|
|
104
|
+
# @return [Boolean]
|
|
105
|
+
def analytics_only_dir?(dir)
|
|
106
|
+
return false unless Dir.exist?(dir) && AnalyticsFile.read(dir)
|
|
107
|
+
|
|
108
|
+
Dir.children(dir).all? { |name| name == AnalyticsFile::NAME || skeleton_entry?(dir, name) }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# One entry of a session's directory is part of the skeleton.
|
|
112
|
+
def skeleton_entry?(dir, name)
|
|
113
|
+
path = File.join(dir, name)
|
|
114
|
+
if EMPTY_SKELETON_DIRS.include?(name)
|
|
115
|
+
File.directory?(path) && (!EMPTY_DIRS.include?(name) || Dir.empty?(path))
|
|
116
|
+
elsif name == AnalyticsFile::NAME
|
|
117
|
+
analytics_empty?(path)
|
|
118
|
+
# Cards and notices from before any turn (Bridge::CardStore).
|
|
119
|
+
elsif name == "cards.json"
|
|
120
|
+
cards_empty?(path)
|
|
121
|
+
# The messages' file (SessionMessages, split): no_conversation?
|
|
122
|
+
# judges what it holds; one no session file names is a crashed first
|
|
123
|
+
# save's.
|
|
124
|
+
elsif SessionMessages::GENERATION_NAME.match?(name)
|
|
125
|
+
true
|
|
126
|
+
else
|
|
127
|
+
# A starting claim's temp files a kill left (StartingMarker.claim:
|
|
128
|
+
# starting.<pid>.<hex>, starting.old.<pid>.<hex>) are the marker's.
|
|
129
|
+
EMPTY_SKELETON_FILES.include?(name) || name.start_with?("#{StartingMarker::FILE}.")
|
|
110
130
|
end
|
|
111
131
|
end
|
|
112
132
|
|
|
@@ -307,8 +307,9 @@ module Samagotchi
|
|
|
307
307
|
# A stop drops the reminders: a restart's hand-off no successor took
|
|
308
308
|
# yet must not bring them back on the next resume.
|
|
309
309
|
ReminderCarry.remove(Session.session_dir(session_id, state_dir: sd))
|
|
310
|
-
# A deleter holding the lock (chi web, the
|
|
311
|
-
|
|
310
|
+
# A deleter or a storage migration holding the lock (chi web, the
|
|
311
|
+
# CLI) is no worker to stop.
|
|
312
|
+
pid = owner&.deleting? || owner&.migrating? ? 0 : owner&.pid.to_i
|
|
312
313
|
begin
|
|
313
314
|
Process.kill("TERM", pid) if pid && pid > 0
|
|
314
315
|
rescue Errno::ESRCH
|
|
@@ -53,36 +53,61 @@ module Samagotchi
|
|
|
53
53
|
.reject { |s| (!include_tests && s.test_run) || s.id == exclude }
|
|
54
54
|
.reject { |s| exclude_delegates && (s.delegate? || s.scratch) }
|
|
55
55
|
.select { |s| root.nil? || in_folder?(s.working_directory, root) }
|
|
56
|
-
.filter_map
|
|
57
|
-
dir = Session.session_dir(s.id, state_dir: sd)
|
|
58
|
-
owner = session_owner(s.id, state_dir: sd)
|
|
59
|
-
link = WorkerLink.resolve(dir, unlink: false, owner: owner)
|
|
60
|
-
next if live && !link.worker_owned?
|
|
61
|
-
|
|
62
|
-
SessionRow.build(s, session_dir: dir, owner: owner, link: link, roots: roots, budgets: budgets)
|
|
63
|
-
end
|
|
56
|
+
.filter_map { |s| session_row(s, sd, roots: roots, budgets: budgets, live: live) }
|
|
64
57
|
(limit ? rows.first(limit) : rows.to_a)
|
|
65
58
|
end
|
|
66
59
|
|
|
60
|
+
# One session's row as .session_rows builds it (owner lock, worker
|
|
61
|
+
# link, SessionRow.build); nil when +live+ and no worker owns it.
|
|
62
|
+
private def session_row(session, state_dir, roots:, budgets:, live: false)
|
|
63
|
+
dir = Session.session_dir(session.id, state_dir: state_dir)
|
|
64
|
+
owner = session_owner(session.id, state_dir: state_dir)
|
|
65
|
+
link = WorkerLink.resolve(dir, unlink: false, owner: owner)
|
|
66
|
+
return if live && !link.worker_owned?
|
|
67
|
+
|
|
68
|
+
SessionRow.build(session, session_dir: dir, owner: owner, link: link, roots: roots, budgets: budgets)
|
|
69
|
+
end
|
|
70
|
+
|
|
67
71
|
# .session_rows as the summaries route's hashes (SessionRow#to_summary_h,
|
|
68
72
|
# its 28 keys in order): chi web's GET /api/sessions/summaries.
|
|
69
73
|
# @return [Array<Hash>]
|
|
70
74
|
def session_summaries(**filters) = session_rows(**filters).map(&:to_summary_h)
|
|
71
75
|
|
|
76
|
+
# Every session's row, archived ones and test runs too, unfiltered: the
|
|
77
|
+
# one listing the tree walks (.children_of, .descendant_ids) share. A
|
|
78
|
+
# caller holds one only within a stretch with no write and no wait
|
|
79
|
+
# (rows carry owner, link and busy as read at listing time), and never
|
|
80
|
+
# passes a filtered listing in its place (an unarchive walks archived
|
|
81
|
+
# delegates).
|
|
82
|
+
# @return [Array<SessionRow>]
|
|
83
|
+
def fleet_rows(state_dir: nil) = session_rows(state_dir: state_dir, include_tests: true, include_archived: true)
|
|
84
|
+
|
|
72
85
|
# The sessions delegated by +parent_id+ (the `delegate` tool), newest
|
|
73
86
|
# first, as .session_rows. A running one (busy) counts against
|
|
74
87
|
# session.max_children. Archived ones too.
|
|
88
|
+
# @param rows [Array<SessionRow>, nil] a .fleet_rows to reuse (nil:
|
|
89
|
+
# lists the summaries and builds rows only for the children, the same
|
|
90
|
+
# rows .fleet_rows would hold; DelegateRelay polls this every 2 s)
|
|
75
91
|
# @return [Array<SessionRow>]
|
|
76
92
|
def children_of(parent_id, state_dir: nil, rows: nil)
|
|
77
93
|
return [] if parent_id.to_s.empty?
|
|
94
|
+
return rows.select { |s| s.parent_id == parent_id.to_s } if rows
|
|
78
95
|
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
sd = state_dir || Session.default_state_dir
|
|
97
|
+
SessionContinue.repair_interrupted(state_dir: sd)
|
|
98
|
+
roots = {}
|
|
99
|
+
budgets = SessionRow.budgets
|
|
100
|
+
Session.list(state_dir: sd, sort: "updated_at", order: "desc", include_archived: true)
|
|
101
|
+
.select { |s| s.parent_id == parent_id.to_s }
|
|
102
|
+
.map { |s| session_row(s, sd, roots: roots, budgets: budgets) }
|
|
81
103
|
end
|
|
82
104
|
|
|
83
105
|
# Children, their children, …: a delegated session doesn't delegate
|
|
84
106
|
# further today, a plugin's fork may. The walk doesn't enter +except+.
|
|
107
|
+
# One listing (.fleet_rows) for the whole walk unless +rows+ is given:
|
|
108
|
+
# a session made while it walks is not seen.
|
|
85
109
|
def descendant_ids(id, state_dir, except: [], rows: nil)
|
|
110
|
+
rows ||= fleet_rows(state_dir: state_dir)
|
|
86
111
|
seen = [id]
|
|
87
112
|
queue = [id]
|
|
88
113
|
until queue.empty?
|
|
@@ -455,6 +455,22 @@ module Samagotchi
|
|
|
455
455
|
raise DeleteRefused.new(id, :protection_unreadable, message: e.message)
|
|
456
456
|
end
|
|
457
457
|
|
|
458
|
+
# #refuse_protected! (a link's hold) of each of +ids+ over one
|
|
459
|
+
# SessionProtection.holds: the check to call per id in the caller's
|
|
460
|
+
# order, its own checks between, raising what #refuse_protected! raises
|
|
461
|
+
# for that id. A store that doesn't read refuses whichever id is checked
|
|
462
|
+
# first, as there; any other raise raises here, before any id.
|
|
463
|
+
# @return [Proc] id → nil, or raises DeleteRefused
|
|
464
|
+
def protection_check(ids, state_dir)
|
|
465
|
+
holds = SessionProtection.holds(ids, state_dir: state_dir)
|
|
466
|
+
lambda do |id|
|
|
467
|
+
hold = holds[id]
|
|
468
|
+
raise DeleteRefused.new(id, hold.reason, schedule_id: hold.ref) if hold
|
|
469
|
+
end
|
|
470
|
+
rescue SessionProtection::Unreadable => e
|
|
471
|
+
->(id) { raise DeleteRefused.new(id, :protection_unreadable, message: e.message) }
|
|
472
|
+
end
|
|
473
|
+
|
|
458
474
|
# Remove every store with state scoped to +id+. The file and sidecar
|
|
459
475
|
# directory keep the deleting owner lock; the other stores have their
|
|
460
476
|
# own locking where they need it. +still+, when given, is the caller's
|
|
@@ -169,7 +169,9 @@ module Samagotchi
|
|
|
169
169
|
|
|
170
170
|
presence = WorkerPresence.read(session.id, state_dir: sd, owner: session_owner(session.id, state_dir: sd))
|
|
171
171
|
raise OwnedByTUI, session.id if presence.tui_owned?
|
|
172
|
-
|
|
172
|
+
# A storage migration's hold is no worker: the one spawned waits for
|
|
173
|
+
# it (WorkerBoot#owner_lock_for).
|
|
174
|
+
return [session, :live] if presence.owned? && !presence.migrating?
|
|
173
175
|
|
|
174
176
|
# A worker being started for it, by this process or another (chi web,
|
|
175
177
|
# a `chi send`, a child's ring; a continue moving delegates to its new
|
|
@@ -197,13 +199,13 @@ module Samagotchi
|
|
|
197
199
|
|
|
198
200
|
# A ring waits in a parent's children/ (a failed continue's previous
|
|
199
201
|
# link got rings back): wake it as the ring's own delivery would
|
|
200
|
-
# (
|
|
202
|
+
# (InboxDelivery.wake :ring, its WakePolicy). Not for a parent that is
|
|
201
203
|
# gone, stopped (the stop marker; the file's status never decides),
|
|
202
204
|
# archived, a scratch session, a one-turn run's or owned, or a
|
|
203
205
|
# continue's new link still taking its delegates (its own spawn
|
|
204
206
|
# comes): the ring waits on disk for whoever runs it next. The check
|
|
205
207
|
# and the resume run under the session's transition lock, held shared
|
|
206
|
-
# (
|
|
208
|
+
# (InboxDelivery.wake's hold: the resolved link's), so a stop (which
|
|
207
209
|
# takes it exclusively for its mark and TERM) lands before the check
|
|
208
210
|
# or after the start, never between them; a transition holding it now
|
|
209
211
|
# leaves the ring on disk (:busy, or :continued naming no one here:
|
|
@@ -216,13 +218,13 @@ module Samagotchi
|
|
|
216
218
|
# :busy / :continued: a transition holds it)
|
|
217
219
|
def wake_for_report(session_id, state_dir: nil)
|
|
218
220
|
sd = state_dir || Session.default_state_dir
|
|
219
|
-
outcome =
|
|
221
|
+
outcome = InboxDelivery.wake(:ring, session_id, state_dir: sd, owner: ->(id) { session_owner(id, state_dir: sd) },
|
|
220
222
|
hold: :shared).wake
|
|
221
223
|
outcome == :live ? :owned : outcome
|
|
222
224
|
end
|
|
223
225
|
|
|
224
226
|
# Start a worker for a delivery whose WakePolicy decided :start
|
|
225
|
-
# (
|
|
227
|
+
# (InboxDelivery.deliver): resume_session, which keeps its own checks
|
|
226
228
|
# (a claim on the starting marker: of starts racing, one spawns),
|
|
227
229
|
# logged as +event+.
|
|
228
230
|
# @param event [Symbol] :delegate_woke_parent (a ring), :context_woke_session (a push) or
|
|
@@ -249,12 +251,13 @@ module Samagotchi
|
|
|
249
251
|
# earlier start's marker, and keeps the session. After a stop, a start
|
|
250
252
|
# marked before it is taken over (a stop cancels the hold-off), one a
|
|
251
253
|
# resume made after it holds (two sends after a stop start one worker).
|
|
254
|
+
# A storage migration holding the lock is no worker: the claim spawns.
|
|
252
255
|
# @return [Symbol] :claimed (this resume spawns), :starting (another
|
|
253
256
|
# start holds the claim) or :live (a worker took the lock since)
|
|
254
257
|
private def claim_start(session_id, state_dir:, stopped:)
|
|
255
258
|
over_before = stopped ? stopped_at(session_id, state_dir) : nil
|
|
256
259
|
return :starting unless StartingMarker.claim(session_id, state_dir: state_dir, over_before: over_before)
|
|
257
|
-
return :claimed unless session_owner(session_id, state_dir: state_dir)
|
|
260
|
+
return :claimed unless session_owner(session_id, state_dir: state_dir)&.then { |owner| !owner.migrating? }
|
|
258
261
|
|
|
259
262
|
StartingMarker.clear(session_id, state_dir: state_dir)
|
|
260
263
|
:live
|
|
@@ -133,12 +133,14 @@ module Samagotchi
|
|
|
133
133
|
def initialize(session_id) = super(session_id, Session::SCRATCH_REFUSED)
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
-
# The session's live owner:
|
|
137
|
-
#
|
|
138
|
-
#
|
|
136
|
+
# The session's live owner: OwnerLock.for_session, kept as the
|
|
137
|
+
# manager's seam: its own parts (listing, spawn, lifecycle, removal)
|
|
138
|
+
# call it, and chi web's stand-in managers (web/app.rb, SessionHub,
|
|
139
|
+
# deliver_turn's +manager+) answer it. Code outside the manager reads
|
|
140
|
+
# OwnerLock.for_session.
|
|
139
141
|
# @return [OwnerLock::Owner, nil]
|
|
140
142
|
def self.session_owner(session_id, state_dir: nil)
|
|
141
|
-
OwnerLock.
|
|
143
|
+
OwnerLock.for_session(session_id, state_dir: state_dir || Session.default_state_dir)
|
|
142
144
|
end
|
|
143
145
|
|
|
144
146
|
# The session's owner (#session_owner), unless it is the interactive
|