rubik 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ATTRIBUTION.md +1 -1
- data/CHANGELOG.md +65 -1
- data/lib/rubik/kernel/dispatcher.rb +19 -23
- data/lib/rubik/kernel/init.rb +22 -18
- data/lib/rubik/orchestrator/goal_ledger/ledger.rb +3 -9
- data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +3 -9
- data/lib/rubik/orchestrator/subagent/deferred_spec.rb +51 -2
- data/lib/rubik/orchestrator/subagent/dependency.rb +20 -20
- data/lib/rubik/orchestrator/subagent/execution_reads.rb +1 -1
- data/lib/rubik/orchestrator/subagent/journal.rb +3 -9
- data/lib/rubik/orchestrator/subagent/lifecycle.rb +10 -1
- data/lib/rubik/orchestrator/subagent/paging.rb +49 -0
- data/lib/rubik/orchestrator/subagent/reaper.rb +1 -3
- data/lib/rubik/orchestrator/subagent/redeploy_transaction.rb +99 -0
- data/lib/rubik/orchestrator/subagent/result_archive.rb +12 -22
- data/lib/rubik/orchestrator/subagent/reuse.rb +37 -31
- data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +1 -1
- data/lib/rubik/orchestrator/subagent/supervisor.rb +6 -2
- data/lib/rubik/orchestrator/subagent/task_ownership.rb +2 -2
- data/lib/rubik/orchestrator/subagent/transcript_reader.rb +14 -13
- data/lib/rubik/repl/commands/subagents.rb +3 -2
- data/lib/rubik/repl/pruner/service.rb +4 -9
- data/lib/rubik/runtime/context.rb +6 -1
- data/lib/rubik/runtime/fiber.rb +17 -5
- data/lib/rubik/runtime/manager.rb +19 -12
- data/lib/rubik/storage/layout.rb +14 -3
- data/lib/rubik/tools/base.rb +31 -0
- data/lib/rubik/tools/builtins/dmesg.rb +1 -1
- data/lib/rubik/tools/builtins/exec.rb +1 -2
- data/lib/rubik/tools/builtins/files.rb +1 -1
- data/lib/rubik/tools/builtins/goal_ledger.rb +1 -1
- data/lib/rubik/tools/builtins/grep.rb +2 -2
- data/lib/rubik/tools/builtins/interactive.rb +1 -3
- data/lib/rubik/tools/builtins/lsp.rb +2 -2
- data/lib/rubik/tools/builtins/pruner.rb +1 -1
- data/lib/rubik/tools/builtins/runtime.rb +1 -1
- data/lib/rubik/tools/builtins/send_message.rb +14 -3
- data/lib/rubik/tools/builtins/skill.rb +1 -1
- data/lib/rubik/tools/builtins/storage.rb +1 -1
- data/lib/rubik/tools/builtins/subagent.rb +2 -1
- data/lib/rubik/tools/builtins/subagent_lifecycle.rb +5 -3
- data/lib/rubik/tools/builtins/symbols.rb +4 -4
- data/lib/rubik/tools/builtins/task.rb +1 -1
- data/lib/rubik/tools/builtins/vakanuvis.rb +1 -1
- data/lib/rubik/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4570babb9dc3d48184b0285c431ef1d7fd37e5f900d1b745033d2f2fd7d35c0
|
|
4
|
+
data.tar.gz: 198350a1de0ef4233150c52445becc263b1456f013190d3400264ffde790ecfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c4761f4faf92b3d0c6fc8997196c92c975ec973a84ace43739a7cc433349ae8b266894cf024f4c66023d14592fd2e1aad416d53f41c5fe85d5d5adb7b8ff2af
|
|
7
|
+
data.tar.gz: 48c5177c5a1fe0e3209df5defd222845f9194d7f86cfd281cc9190cce3e332e9c7ad062a88243cd403a5ca94ef744bb5bf8f48f87afd85064ef913031e5f8eb2
|
data/ATTRIBUTION.md
CHANGED
|
@@ -121,7 +121,7 @@ SOFTWARE.
|
|
|
121
121
|
| **`strings-ansi`** | Piotr Murach | MIT | ANSI-aware string truncation and alignment for REPL formatters. |
|
|
122
122
|
| **`reline`** | Hiroshi SHIBATA & Ruby Team | Ruby License / BSD-2-Clause | Line-editing, history navigation, autocompletion hooks, and headless terminal adaptation. |
|
|
123
123
|
| **`prism`** | Kevin Newton & Ruby Core Team | MIT | High-performance Ruby parsing and AST extraction ([`Rubik::AST::RubyExtractor`](lib/rubik/ast/ruby_extractor.rb)). |
|
|
124
|
-
| **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,
|
|
124
|
+
| **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,200+ unit, integration, and contract tests. |
|
|
125
125
|
| **`rubocop`** | Bozhidar Batsov & contributors | MIT | Static code analysis, style enforcement, and architectural hygiene gates. |
|
|
126
126
|
| **`benchmark`, `logger`, `pstore`, `reline`, `fiddle`** | Ruby core / rubygems teams | Ruby License / BSD-2-Clause | Ruby stdlib gems pinned explicitly in `rubik.gemspec` as they are unbundled from the default set in Ruby 3.4/3.5. |
|
|
127
127
|
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,69 @@ commits, 2026-08-23 → 2026-10-09, see `git log`).
|
|
|
6
6
|
|
|
7
7
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
8
8
|
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
## [0.8.1] - 2026-11-06
|
|
12
|
+
|
|
13
|
+
A reliability-and-single-homing patch: the kernel hardens the spatiotemporal
|
|
14
|
+
invariants (failure rollback, lock ordering, queue observability), the subagent
|
|
15
|
+
family converges on guarded state machines and truthful reporting for unborn
|
|
16
|
+
work, and five duplicated helpers (config_get, pagination window, coeffect
|
|
17
|
+
resolution, attention vocabulary, tombstone table) each collapse to one owner.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **Per-tool coeffect resolution unified behind `BaseTool#service` (#383):**
|
|
22
|
+
each builtin's private "fetch a service (or its subagent-plane fallback)"
|
|
23
|
+
dance now delegates to one Services-delegating helper, closing issue #368;
|
|
24
|
+
nil-guard on the fallback mock tightened in both `BaseTool#service` and
|
|
25
|
+
`SubagentToolHelpers`.
|
|
26
|
+
- **Shared pagination window extracted (ResultArchive ≅ TranscriptReader)
|
|
27
|
+
(#381):** the duplicated page-window slicing (offset/limit, ellipsis
|
|
28
|
+
framing) moved into one module closing issue #374; the predicate exposed
|
|
29
|
+
via `alias_method` to satisfy rubocop without renaming call sites.
|
|
30
|
+
- **Five `config_get` copies converged on `Layout.config_get` (#382):** the
|
|
31
|
+
string/symbol dotted-key access duplicated across five call sites now
|
|
32
|
+
delegates to one superset helper closing issue #373.
|
|
33
|
+
- **DeferredSpec transitions guarded like the family contract (#372):** the
|
|
34
|
+
raw `attr_accessor` written from six supervisor sites became a
|
|
35
|
+
`TRANSITIONS`-guarded machine (`mark_spawning!`/`requeue!`/`cancel!`,
|
|
36
|
+
fail-loud `StateError` on undeclared edges, same-state idempotency,
|
|
37
|
+
first-reason-wins cancellation), so an illegal edge can no longer fail
|
|
38
|
+
silently and `cancel_spec!`'s inline twin is gone.
|
|
39
|
+
- **Attention vocabulary derived from Lifecycle (#376):** the tool plane's
|
|
40
|
+
hand-copied "needs attention" state set moved beside `TRANSITIONS` in
|
|
41
|
+
`lifecycle.rb` (`PARKED_STATES`/`ATTENTION_STATES`, `parked?` recomposed
|
|
42
|
+
under one monitor acquisition); `TranscriptReader::ACTIVE_STATES` drops
|
|
43
|
+
its dead `:queued` entry — an Instance can never hold that state.
|
|
44
|
+
- **Tombstone table single-owned (#370):** the finished table is born in the
|
|
45
|
+
constructor alongside `@instances`/`@deferred` instead of relying on nine
|
|
46
|
+
defensive `@finished ||= {}`-style sites across seven files; semantics
|
|
47
|
+
unchanged.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- **Kernel & Runtime Composability & Resilience Hardening (F1-F5) (#380):**
|
|
52
|
+
- **Fiber Failure Reversibility (F1):** `ComponentFiber#activate!` now rolls back partial inverses on `Interrupt`, `SystemExit`, and non-`StandardError` signals before re-raising, eliminating leaked sub-contexts and unexecuted inverses.
|
|
53
|
+
- **Fail-Fast Provide on Disposed Context (F2):** `Context#provide` and `Manager#provide` now raise `ContextDisposedError` when invoked on a disposed context/manager instead of silently dropping services.
|
|
54
|
+
- **Context Dispose Lock-Order (F3):** `Context#dispose` now resolves `dmesg` outside `@monitor.synchronize`, preserving strict parent→child locking across context hierarchies and preventing latent deadlocks.
|
|
55
|
+
- **Monitor Scope Decoupling (F4):** `Init#kill_all`, `Init#reap_dead_units!`, and `Manager#dispose!` now take snapshots under the monitor and invoke external teardown/kills outside the lock, preventing blocking of supervisor inspection methods (`Init#get`, `Manager#active_fibers`).
|
|
56
|
+
- **Dispatcher Queue Watermark Observability (F5):** `Dispatcher#post` now emits a warning to the logger and `dmesg` when queue depth reaches high watermarks (`DEFAULT_WARN_QUEUE_DEPTH = 1000`), enhancing event queue visibility under high throughput.
|
|
57
|
+
- **Redeploy rolls back its transaction like spawn (#371):** a settle race
|
|
58
|
+
(reaper archive/kill between the redeployable? check and the guarded reset)
|
|
59
|
+
or any raise after the irreversible `redeploy_for!` mutation previously
|
|
60
|
+
leaked the freshly extended child context, a mutated instance, a registered
|
|
61
|
+
unit — and when `start_async` flipped then aborted, a `:running` zombie
|
|
62
|
+
holding a concurrency slot forever; the spawn-style rollback now covers it.
|
|
63
|
+
- **Queued and launching specs reported truthfully (#375):** `invoke_subagent`
|
|
64
|
+
no longer answers `:queued` for a requeue the cancelled-guard refused,
|
|
65
|
+
`send_message` to a queued spec names the deps and the real next actions
|
|
66
|
+
instead of "redeploy it" (false twice over), and the REPL list prints
|
|
67
|
+
"queued/launching (waiting on: ...)" instead of "ended (0.0s)" for a
|
|
68
|
+
mid-launch spec.
|
|
69
|
+
- **Deps:** `tree_sitter_language_pack` 1.22.1 → 1.23.1 (#379), rubocop dev
|
|
70
|
+
dep 1.92.1 → 1.92.2 (#378), CI `actions/cache` v4 → v6 (#377).
|
|
71
|
+
|
|
9
72
|
## [0.8.0] - 2026-11-05
|
|
10
73
|
|
|
11
74
|
A configuration-architecture minor: the write plane goes strict — typed
|
|
@@ -1304,7 +1367,8 @@ installation section.
|
|
|
1304
1367
|
- Context: serialized index mutations, snapshot-outside-lock reconcile,
|
|
1305
1368
|
streaming-first truncation.
|
|
1306
1369
|
|
|
1307
|
-
[Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.8.
|
|
1370
|
+
[Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.8.1...HEAD
|
|
1371
|
+
[0.8.1]: https://github.com/ozgurulukir/rubik/compare/v0.8.0...v0.8.1
|
|
1308
1372
|
[0.8.0]: https://github.com/ozgurulukir/rubik/compare/v0.7.1...v0.8.0
|
|
1309
1373
|
[0.7.1]: https://github.com/ozgurulukir/rubik/compare/v0.7.0...v0.7.1
|
|
1310
1374
|
[0.7.0]: https://github.com/ozgurulukir/rubik/compare/v0.6.0...v0.7.0
|
|
@@ -10,6 +10,7 @@ module Rubik
|
|
|
10
10
|
# subscriber error isolation.
|
|
11
11
|
class Dispatcher
|
|
12
12
|
STOP_MARKER = :__dispatcher_stop__
|
|
13
|
+
DEFAULT_WARN_QUEUE_DEPTH = 1000
|
|
13
14
|
|
|
14
15
|
Event = Struct.new(:name, :payload, :subsystem, :level, :facility_id, keyword_init: true)
|
|
15
16
|
Barrier = Struct.new(:queue)
|
|
@@ -44,6 +45,18 @@ module Rubik
|
|
|
44
45
|
subsystem: subsystem.to_sym, level: level, facility_id: facility_id
|
|
45
46
|
)
|
|
46
47
|
)
|
|
48
|
+
|
|
49
|
+
q_size = @queue.size
|
|
50
|
+
if q_size >= DEFAULT_WARN_QUEUE_DEPTH && (q_size % 500).zero?
|
|
51
|
+
msg = "Dispatcher event queue high watermark reached: #{q_size} pending events"
|
|
52
|
+
@logger&.warn(msg)
|
|
53
|
+
begin
|
|
54
|
+
@dmesg&.log(:kernel, :warn, msg, facility_id: "dispatcher", queue_size: q_size)
|
|
55
|
+
rescue StandardError
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
47
60
|
true
|
|
48
61
|
end
|
|
49
62
|
|
|
@@ -92,29 +105,12 @@ module Rubik
|
|
|
92
105
|
end
|
|
93
106
|
alias dispose stop
|
|
94
107
|
|
|
95
|
-
def stopped?
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def worker_alive?
|
|
104
|
-
!@worker_thread.nil? && @worker_thread.alive?
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def subscribers(event_name)
|
|
108
|
-
@lock.synchronize { @listeners[event_name.to_sym].dup }
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def all_subscribers
|
|
112
|
-
@lock.synchronize { @listeners.transform_values(&:dup) }
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def queue_size
|
|
116
|
-
@queue.size
|
|
117
|
-
end
|
|
108
|
+
def stopped? = @lock.synchronize { @stopped }
|
|
109
|
+
def alive? = !stopped? && worker_alive?
|
|
110
|
+
def worker_alive? = !@worker_thread.nil? && @worker_thread.alive?
|
|
111
|
+
def subscribers(event_name) = @lock.synchronize { @listeners[event_name.to_sym].dup }
|
|
112
|
+
def all_subscribers = @lock.synchronize { @listeners.transform_values(&:dup) }
|
|
113
|
+
def queue_size = @queue.size
|
|
118
114
|
|
|
119
115
|
private
|
|
120
116
|
|
data/lib/rubik/kernel/init.rb
CHANGED
|
@@ -88,42 +88,46 @@ module Rubik
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def reap_dead_units!
|
|
91
|
-
@monitor.synchronize do
|
|
91
|
+
units_to_reap = @monitor.synchronize do
|
|
92
92
|
reaped = []
|
|
93
93
|
@units.each_value do |unit|
|
|
94
94
|
unit.sync_state! if unit.respond_to?(:sync_state!)
|
|
95
95
|
next unless unit.dead? && unit.state != :reaped
|
|
96
96
|
|
|
97
|
-
safely_dispose_context(unit)
|
|
98
|
-
unit.transition_to!(:reaped, reason: "reaped")
|
|
99
97
|
reaped << unit
|
|
100
98
|
end
|
|
101
|
-
@dmesg&.log(:kernel, :info, "reaped #{reaped.size} dead units", facility_id: "init") unless reaped.empty?
|
|
102
99
|
reaped
|
|
103
100
|
end
|
|
101
|
+
|
|
102
|
+
units_to_reap.each do |unit|
|
|
103
|
+
safely_dispose_context(unit)
|
|
104
|
+
unit.transition_to!(:reaped, reason: "reaped")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
@dmesg&.log(:kernel, :info, "reaped #{units_to_reap.size} dead units", facility_id: "init") unless units_to_reap.empty?
|
|
108
|
+
units_to_reap
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
def kill(id, reason = "killed")
|
|
107
|
-
@monitor.synchronize
|
|
108
|
-
|
|
109
|
-
return false unless unit
|
|
112
|
+
unit = @monitor.synchronize { @units[id.to_s] }
|
|
113
|
+
return false unless unit
|
|
110
114
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
end
|
|
115
|
+
safely_kill_unit(unit, reason)
|
|
116
|
+
true
|
|
114
117
|
end
|
|
115
118
|
|
|
116
119
|
def kill_all(reason = "killed")
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
# Snapshot in reverse chronological (LIFO) order under the monitor lock,
|
|
121
|
+
# then invoke safely_kill_unit OUTSIDE the lock to prevent blocking
|
|
122
|
+
# supervisor operations during slow/external unit kills (Finding F4).
|
|
123
|
+
units_to_kill = @monitor.synchronize do
|
|
124
|
+
@order.reverse_each.filter_map { |id| @units[id] }
|
|
125
|
+
end
|
|
122
126
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
true
|
|
127
|
+
units_to_kill.each do |unit|
|
|
128
|
+
safely_kill_unit(unit, reason)
|
|
126
129
|
end
|
|
130
|
+
true
|
|
127
131
|
end
|
|
128
132
|
|
|
129
133
|
def resume_all
|
|
@@ -4,6 +4,7 @@ require "time"
|
|
|
4
4
|
require "json"
|
|
5
5
|
require_relative "../../prompt/context_compactor"
|
|
6
6
|
require_relative "../../prompt/conversation_rows"
|
|
7
|
+
require_relative "../../storage/layout"
|
|
7
8
|
require_relative "../../uris"
|
|
8
9
|
require_relative "suspend_lifecycle"
|
|
9
10
|
require_relative "xml_render"
|
|
@@ -98,15 +99,8 @@ module Rubik
|
|
|
98
99
|
SuspendLifecycle.load(store: store, storage_id: storage_id, config: config, dmesg: dmesg, event_bus: event_bus)
|
|
99
100
|
end
|
|
100
101
|
|
|
101
|
-
def config_get(config, key, default)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
val = if config.is_a?(Hash)
|
|
105
|
-
config.dig(*key.to_s.split("."))
|
|
106
|
-
elsif config.respond_to?(:fetch)
|
|
107
|
-
config.fetch(key, nil)
|
|
108
|
-
end
|
|
109
|
-
val.nil? ? default : val
|
|
102
|
+
def config_get(config, key, default = nil)
|
|
103
|
+
Rubik::Storage::Layout.config_get(config, key, default)
|
|
110
104
|
end
|
|
111
105
|
end
|
|
112
106
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "../../prompt/conversation_rows"
|
|
4
|
+
require_relative "../../storage/layout"
|
|
4
5
|
|
|
5
6
|
module Rubik
|
|
6
7
|
module Orchestrator
|
|
@@ -52,15 +53,8 @@ module Rubik
|
|
|
52
53
|
Directive.new(ledger: ledger, window: [window, 1].max, deps: deps)
|
|
53
54
|
end
|
|
54
55
|
|
|
55
|
-
def config_get(config, key, default)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
val = if config.is_a?(Hash)
|
|
59
|
-
config.dig(*key.to_s.split("."))
|
|
60
|
-
elsif config.respond_to?(:fetch)
|
|
61
|
-
config.fetch(key, nil)
|
|
62
|
-
end
|
|
63
|
-
val.nil? ? default : val
|
|
56
|
+
def config_get(config, key, default = nil)
|
|
57
|
+
Rubik::Storage::Layout.config_get(config, key, default)
|
|
64
58
|
end
|
|
65
59
|
end
|
|
66
60
|
|
|
@@ -19,9 +19,22 @@ module Rubik
|
|
|
19
19
|
# this spec — nil for explicitly detached work. A cancelled owner makes
|
|
20
20
|
# the claim loops drop the spec before it ever starts.
|
|
21
21
|
class DeferredSpec
|
|
22
|
+
class StateError < StandardError; end
|
|
23
|
+
|
|
24
|
+
# The spec machine's every legal from->to edge (Lifecycle family
|
|
25
|
+
# doctrine: one guarded transition per state machine, fail-loud on
|
|
26
|
+
# undeclared edges, same-state idempotent). :cancelled is absorbing —
|
|
27
|
+
# a cancelled spec never re-queues (requeue! refuses) and never
|
|
28
|
+
# re-launches (the claim loops skip it).
|
|
29
|
+
TRANSITIONS = {
|
|
30
|
+
queued: [:spawning, :cancelled],
|
|
31
|
+
spawning: [:queued, :cancelled],
|
|
32
|
+
cancelled: []
|
|
33
|
+
}.transform_values(&:freeze).freeze
|
|
34
|
+
|
|
22
35
|
attr_reader :id, :parent_id, :role, :type_name, :prompt, :system_prompt,
|
|
23
|
-
:workspace, :model, :max_steps, :deps, :provider, :owner
|
|
24
|
-
|
|
36
|
+
:workspace, :model, :max_steps, :deps, :provider, :owner,
|
|
37
|
+
:state, :cancel_reason
|
|
25
38
|
|
|
26
39
|
def initialize(id:, role:, prompt:, type_name:, deps:, parent_id: ConversationId::ROOT_ID, system_prompt: nil,
|
|
27
40
|
workspace: "inherit", model: "inherit", max_steps: nil, provider: nil, owner: nil)
|
|
@@ -45,6 +58,27 @@ module Rubik
|
|
|
45
58
|
def spawning? = @state == :spawning
|
|
46
59
|
def cancelled? = @state == :cancelled
|
|
47
60
|
|
|
61
|
+
# The only mutators (Lifecycle family): the dependency engine claims
|
|
62
|
+
# with mark_spawning!, re-queues a concurrency-refused launch with
|
|
63
|
+
# requeue!, and cancels with cancel! — first reason wins, exactly
|
|
64
|
+
# like TaskCancellation#cancel!. Same-state writes are idempotent
|
|
65
|
+
# no-ops; anything else undeclared raises StateError.
|
|
66
|
+
def mark_spawning!
|
|
67
|
+
transition!(:spawning)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def requeue!
|
|
71
|
+
transition!(:queued) unless cancelled?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def cancel!(reason)
|
|
75
|
+
return false if cancelled?
|
|
76
|
+
|
|
77
|
+
@cancel_reason = reason.to_s
|
|
78
|
+
transition!(:cancelled)
|
|
79
|
+
true
|
|
80
|
+
end
|
|
81
|
+
|
|
48
82
|
# Duck-type yüzeyi: render'lar (list/status/wait) Instance ile
|
|
49
83
|
# DeferredSpec'i AYIRT ETMEDEN kullanır — dallanma yok.
|
|
50
84
|
def running? = false
|
|
@@ -70,6 +104,21 @@ module Rubik
|
|
|
70
104
|
started_at: nil, ended_at: nil, transcript: nil, last_error: @cancel_reason,
|
|
71
105
|
result_summary: nil, result: nil, detached: @owner.nil? }
|
|
72
106
|
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
# Guarded low-level seam (mirrors Lifecycle#transition!): business
|
|
111
|
+
# callers use the named drivers; illegal edges fail loud with both
|
|
112
|
+
# endpoints in the message. No own lock — every writer already holds
|
|
113
|
+
# the supervisor monitor.
|
|
114
|
+
def transition!(to)
|
|
115
|
+
target = to.to_sym
|
|
116
|
+
return @state if @state == target
|
|
117
|
+
|
|
118
|
+
raise StateError, "illegal DeferredSpec transition #{@id}: #{@state} -> #{target}" unless TRANSITIONS.fetch(@state, []).include?(target)
|
|
119
|
+
|
|
120
|
+
@state = target
|
|
121
|
+
end
|
|
73
122
|
end
|
|
74
123
|
end
|
|
75
124
|
end
|
|
@@ -94,13 +94,13 @@ module Rubik
|
|
|
94
94
|
# Claim fence: cancellation may land between the entry guard and
|
|
95
95
|
# this loop — a cancelled owner never launches.
|
|
96
96
|
if owned_claim_blocked?(spec)
|
|
97
|
-
|
|
97
|
+
spec.cancel!("owner task cancelled (^C)")
|
|
98
98
|
cancelled << spec
|
|
99
99
|
next
|
|
100
100
|
end
|
|
101
101
|
next unless dependencies_evaluate(spec) == :ready
|
|
102
102
|
|
|
103
|
-
spec.
|
|
103
|
+
spec.mark_spawning!
|
|
104
104
|
claimed << spec
|
|
105
105
|
end
|
|
106
106
|
end
|
|
@@ -130,17 +130,17 @@ module Rubik
|
|
|
130
130
|
# to death through the same fixed-point wave as a dead
|
|
131
131
|
# predecessor.
|
|
132
132
|
if owned_claim_blocked?(spec)
|
|
133
|
-
|
|
133
|
+
spec.cancel!("owner task cancelled (^C)")
|
|
134
134
|
wave << spec
|
|
135
135
|
next
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
case dependencies_evaluate(spec)
|
|
139
139
|
when :ready
|
|
140
|
-
spec.
|
|
140
|
+
spec.mark_spawning!
|
|
141
141
|
claimed << spec
|
|
142
142
|
when :dead
|
|
143
|
-
|
|
143
|
+
spec.cancel!("predecessor failed or is no longer tracked")
|
|
144
144
|
wave << spec
|
|
145
145
|
end
|
|
146
146
|
end
|
|
@@ -188,9 +188,9 @@ module Rubik
|
|
|
188
188
|
verdicts = spec.deps.map do |d|
|
|
189
189
|
deferred_pred = @deferred[d[:id]]
|
|
190
190
|
return :dead if deferred_pred&.cancelled?
|
|
191
|
-
return :dead if deferred_pred.nil? && @instances[d[:id]].nil? &&
|
|
191
|
+
return :dead if deferred_pred.nil? && @instances[d[:id]].nil? && @finished[d[:id]].nil?
|
|
192
192
|
|
|
193
|
-
inst = @instances[d[:id]] ||
|
|
193
|
+
inst = @instances[d[:id]] || @finished[d[:id]]
|
|
194
194
|
|
|
195
195
|
if d[:type] == "FS"
|
|
196
196
|
return :dead if inst&.failed?
|
|
@@ -229,12 +229,18 @@ module Rubik
|
|
|
229
229
|
inst&.kill if killed_midflight
|
|
230
230
|
killed_midflight ? [:cancelled, spec] : [:launched, inst]
|
|
231
231
|
rescue ConcurrencyExceededError
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
requeued = false
|
|
233
|
+
@monitor.synchronize do
|
|
234
|
+
requeued = !!spec.requeue!
|
|
235
|
+
end
|
|
236
|
+
# Truthful outcome: a cancelled spec was NOT re-queued — reporting
|
|
237
|
+
# [:queued, ...] made invoke_subagent render "QUEUED" for a spec
|
|
238
|
+
# that will never launch.
|
|
239
|
+
requeued ? [:queued, spec] : [:cancelled, spec]
|
|
234
240
|
rescue StandardError => e
|
|
235
241
|
cancelled = nil
|
|
236
242
|
@monitor.synchronize do
|
|
237
|
-
|
|
243
|
+
spec.cancel!("launch failed: #{e.class}: #{e.message}")
|
|
238
244
|
cancelled = spec
|
|
239
245
|
end
|
|
240
246
|
announce_cancellations([cancelled])
|
|
@@ -253,7 +259,7 @@ module Rubik
|
|
|
253
259
|
break if wave.empty?
|
|
254
260
|
|
|
255
261
|
wave.each do |spec|
|
|
256
|
-
|
|
262
|
+
spec.cancel!("predecessor failed or is no longer tracked")
|
|
257
263
|
cancelled << spec
|
|
258
264
|
end
|
|
259
265
|
dead_ids = wave.map(&:id)
|
|
@@ -262,11 +268,6 @@ module Rubik
|
|
|
262
268
|
cancelled
|
|
263
269
|
end
|
|
264
270
|
|
|
265
|
-
def cancel_spec!(spec, reason)
|
|
266
|
-
spec.cancel_reason = reason
|
|
267
|
-
spec.state = :cancelled
|
|
268
|
-
end
|
|
269
|
-
|
|
270
271
|
def announce_cancellations(specs)
|
|
271
272
|
specs.each do |spec|
|
|
272
273
|
Notices.emit(@event_bus, Notices::COMPLETED_EVENT,
|
|
@@ -293,7 +294,7 @@ module Rubik
|
|
|
293
294
|
def refute_dead_dependencies!(specs)
|
|
294
295
|
specs.each do |spec|
|
|
295
296
|
spec.deps.each do |d|
|
|
296
|
-
inst = @instances[d[:id]] ||
|
|
297
|
+
inst = @instances[d[:id]] || @finished[d[:id]]
|
|
297
298
|
if inst
|
|
298
299
|
# Tek tüketici: atomlar yeterli — yeni bir Instance
|
|
299
300
|
# predicate'ine gerek yok (settled? disposed'u dışlar,
|
|
@@ -309,7 +310,7 @@ module Rubik
|
|
|
309
310
|
end
|
|
310
311
|
|
|
311
312
|
def refute_unknown_dependencies!(specs)
|
|
312
|
-
known = @instances.keys +
|
|
313
|
+
known = @instances.keys + @finished.keys + @deferred.keys + specs.map(&:id)
|
|
313
314
|
specs.each do |spec|
|
|
314
315
|
spec.deps.each do |d|
|
|
315
316
|
next if known.include?(d[:id])
|
|
@@ -334,8 +335,7 @@ module Rubik
|
|
|
334
335
|
def kill_locked(id, cascade, cancelled)
|
|
335
336
|
if (spec = @deferred[id])
|
|
336
337
|
if spec.spawning?
|
|
337
|
-
spec.
|
|
338
|
-
spec.state = :cancelled
|
|
338
|
+
spec.cancel!("killed while launching")
|
|
339
339
|
else
|
|
340
340
|
@deferred.delete(id)
|
|
341
341
|
end
|
|
@@ -18,7 +18,7 @@ module Rubik
|
|
|
18
18
|
return nil if sid.empty?
|
|
19
19
|
|
|
20
20
|
@monitor.synchronize do
|
|
21
|
-
(@instances.values +
|
|
21
|
+
(@instances.values + @finished.values).find do |inst|
|
|
22
22
|
inst.respond_to?(:storage_id) && inst.storage_id.to_s == sid
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -6,6 +6,7 @@ require "time"
|
|
|
6
6
|
require "fileutils"
|
|
7
7
|
require_relative "../../platform"
|
|
8
8
|
require_relative "../../security/redactor"
|
|
9
|
+
require_relative "../../storage/layout"
|
|
9
10
|
|
|
10
11
|
module Rubik
|
|
11
12
|
module Orchestrator
|
|
@@ -306,15 +307,8 @@ module Rubik
|
|
|
306
307
|
value.length > limit ? "#{value[0, limit]}... [truncated #{value.length - limit} chars]" : value
|
|
307
308
|
end
|
|
308
309
|
|
|
309
|
-
def config_get(config, key, default)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
val = if config.is_a?(Hash)
|
|
313
|
-
config[key] || config.dig(*key.split("."))
|
|
314
|
-
elsif config.respond_to?(:fetch)
|
|
315
|
-
config.fetch(key, nil)
|
|
316
|
-
end
|
|
317
|
-
val.nil? ? default : val
|
|
310
|
+
def config_get(config, key, default = nil)
|
|
311
|
+
Rubik::Storage::Layout.config_get(config, key, default)
|
|
318
312
|
end
|
|
319
313
|
end
|
|
320
314
|
end
|
|
@@ -38,6 +38,15 @@ module Rubik
|
|
|
38
38
|
disposed: []
|
|
39
39
|
}.transform_values(&:freeze).freeze
|
|
40
40
|
|
|
41
|
+
# Attention vocabulary (the tool plane's "needs attention" classification,
|
|
42
|
+
# derived here so a state rename can never silently desync it — the tool
|
|
43
|
+
# layer hand-copied these until now). PARKED_STATES is the vocabulary's
|
|
44
|
+
# own words for the condvar-parked set; ATTENTION_STATES rides
|
|
45
|
+
# :waiting_input on top. A named owned constant, not a computation from
|
|
46
|
+
# TRANSITIONS — no clean derivation from the edges exists.
|
|
47
|
+
PARKED_STATES = [:paused_error, :waiting_budget, :budget_exhausted].freeze
|
|
48
|
+
ATTENTION_STATES = (PARKED_STATES + [:waiting_input]).freeze
|
|
49
|
+
|
|
41
50
|
# --- Predicates: control-flow questions answer here, not at
|
|
42
51
|
# consumers. All take the re-entrant monitor; callers composing
|
|
43
52
|
# them under a held lock pay nothing extra, and external readers
|
|
@@ -74,7 +83,7 @@ module Rubik
|
|
|
74
83
|
|
|
75
84
|
# Condvar-parked, reap-immune; the resume_all targets.
|
|
76
85
|
def parked?
|
|
77
|
-
@monitor.synchronize {
|
|
86
|
+
@monitor.synchronize { PARKED_STATES.include?(@state) }
|
|
78
87
|
end
|
|
79
88
|
|
|
80
89
|
# The no-resurrection set (kill's race window included).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubik
|
|
4
|
+
module Orchestrator
|
|
5
|
+
module Subagent
|
|
6
|
+
# Pure pagination window arithmetic for subagent output streams
|
|
7
|
+
# (ResultArchive ≅ TranscriptReader — architecture scan 2026-11-06).
|
|
8
|
+
# Leaf helper: zero IO, zero locks, isolated and deterministic.
|
|
9
|
+
module Paging
|
|
10
|
+
Window = Struct.new(:cursor, :body, :next_cursor, :has_more, :total_chars, :returned_chars, keyword_init: true) do
|
|
11
|
+
def more? = has_more
|
|
12
|
+
alias_method :has_more?, :more?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module_function
|
|
16
|
+
|
|
17
|
+
# Clamps negative cursor values to 0.
|
|
18
|
+
def clamp_cursor(cursor)
|
|
19
|
+
[cursor.to_i, 0].max
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Computes the window slice for a given text and cursor/limit bounds.
|
|
23
|
+
# Returns nil if cursor exceeds total_chars.
|
|
24
|
+
def window(text, cursor:, limit:, default:, max:)
|
|
25
|
+
body = text.to_s
|
|
26
|
+
total = body.length
|
|
27
|
+
cur = clamp_cursor(cursor)
|
|
28
|
+
return nil if cur > total
|
|
29
|
+
|
|
30
|
+
size = limit.to_i
|
|
31
|
+
size = default if size <= 0
|
|
32
|
+
size = [size, max].min
|
|
33
|
+
slice = body[cur, size].to_s
|
|
34
|
+
nxt = cur + slice.length
|
|
35
|
+
has_more = nxt < total
|
|
36
|
+
|
|
37
|
+
Window.new(
|
|
38
|
+
cursor: cur,
|
|
39
|
+
body: slice,
|
|
40
|
+
next_cursor: has_more ? nxt : nil,
|
|
41
|
+
has_more: has_more,
|
|
42
|
+
total_chars: total,
|
|
43
|
+
returned_chars: slice.length
|
|
44
|
+
).freeze
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -43,7 +43,7 @@ module Rubik
|
|
|
43
43
|
next unless inst.archive!
|
|
44
44
|
|
|
45
45
|
dropped_steering << id if inst.respond_to?(:pending_redeploy_messages?) && inst.pending_redeploy_messages?
|
|
46
|
-
|
|
46
|
+
@finished[id] = inst
|
|
47
47
|
reaped << id
|
|
48
48
|
end
|
|
49
49
|
reaped.each { |id| @instances.delete(id) }
|
|
@@ -85,8 +85,6 @@ module Rubik
|
|
|
85
85
|
# FIFO taşma: en eski mezar taşı evict edilir ve cleanup ile
|
|
86
86
|
# :disposed'a çekilir (ctx zaten dispose'lu; cleanup no-op güvenli).
|
|
87
87
|
def evict_overflow!
|
|
88
|
-
return unless @finished
|
|
89
|
-
|
|
90
88
|
while @finished.size > tombstone_limit
|
|
91
89
|
_id, inst = @finished.shift
|
|
92
90
|
inst&.cleanup
|