Class: Legion::Extensions::Llm::Inventory::ProbeCoordinator
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Inventory::ProbeCoordinator
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/extensions/llm/inventory/probe_coordinator.rb
Overview
Enqueue-only probe handle with per-instance/revision coalescing and
single-flight state. It owns no timer, thread, thread pool, provider
API call, or registry transition. It is the probe_request_handle
passed to Registry.claim_instance. See phase-1-lex-llm-additive.md
section 13.2.
Instance Method Summary collapse
- #begin_probe(request: nil) ⇒ Object
-
#enqueue_probe_request(instance_key:, publisher_token_id:, unavailable_revision:, reason:) ⇒ Object
Registry calls this after a root swap on dispatch_instance_unavailable.
- #finish_probe(request: nil) ⇒ Object
- #in_flight? ⇒ Boolean
-
#initialize(instance_key:, enqueue:) ⇒ ProbeCoordinator
constructor
A new instance of ProbeCoordinator.
- #pending?(unavailable_revision:) ⇒ Boolean
Constructor Details
#initialize(instance_key:, enqueue:) ⇒ ProbeCoordinator
Returns a new instance of ProbeCoordinator.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/llm/inventory/probe_coordinator.rb', line 20 def initialize(instance_key:, enqueue:) raise Errors::ValidationError, 'instance_key must be an InstanceKey' unless instance_key.is_a?(Identity::InstanceKey) raise Errors::ValidationError, 'enqueue must be provided' if enqueue.nil? @instance_key = instance_key @enqueue = enqueue @pending = nil @in_flight_form = nil @in_flight_request = nil @mutex = Mutex.new end |
Instance Method Details
#begin_probe(request: nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/legion/extensions/llm/inventory/probe_coordinator.rb', line 51 def begin_probe(request: nil) @mutex.synchronize do return false unless @in_flight_form.nil? if request.nil? @in_flight_form = :cadence @in_flight_request = nil else raise Errors::ValidationError, 'request must be a ProbeRequest' unless request.is_a?(ProbeRequest) return false unless @pending && request.equal?(@pending) @in_flight_form = :request @in_flight_request = request @pending = nil end true end end |
#enqueue_probe_request(instance_key:, publisher_token_id:, unavailable_revision:, reason:) ⇒ Object
Registry calls this after a root swap on dispatch_instance_unavailable.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/extensions/llm/inventory/probe_coordinator.rb', line 33 def enqueue_probe_request(instance_key:, publisher_token_id:, unavailable_revision:, reason:) request = ProbeRequest.new( instance_key: instance_key, publisher_token_id: publisher_token_id, unavailable_revision: unavailable_revision, reason: reason ) raise Errors::ValidationError, 'instance_key mismatch' unless request.instance_key == @instance_key to_enqueue = nil @mutex.synchronize do had_pending = !@pending.nil? retain_greater(request) to_enqueue = @pending if @in_flight_form.nil? && !had_pending end return true if to_enqueue.nil? run_enqueue(to_enqueue) end |
#finish_probe(request: nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/legion/extensions/llm/inventory/probe_coordinator.rb', line 70 def finish_probe(request: nil) still_pending = nil @mutex.synchronize do validate_finish_form!(request) @in_flight_form = nil @in_flight_request = nil still_pending = @pending end run_enqueue(still_pending) unless still_pending.nil? still_pending end |
#in_flight? ⇒ Boolean
86 87 88 |
# File 'lib/legion/extensions/llm/inventory/probe_coordinator.rb', line 86 def in_flight? @mutex.synchronize { !@in_flight_form.nil? } end |
#pending?(unavailable_revision:) ⇒ Boolean
82 83 84 |
# File 'lib/legion/extensions/llm/inventory/probe_coordinator.rb', line 82 def pending?(unavailable_revision:) @mutex.synchronize { !@pending.nil? && @pending.unavailable_revision == unavailable_revision } end |