Module: Legion::Extensions::Llm::Inventory::ScopedRefresher

Defined in:
lib/legion/extensions/llm/inventory/scoped_refresher.rb

Overview

DEPRECATED (Phase 4 removal): the only Phase 1 file permitted to hold a direct Legion::LLM::Inventory reverse reference. Old released provider actors keep using ScopedRefresher#tick until their Phase 2 migration; a migrated actor instead injects ScopedRefresher::LegacyCoordinatorAdapter into Inventory::Publisher and never calls #tick. Neither old lane hashes nor old health feed the new registry. Phase 4 deletes this file once every provider and coordinator floor has migrated.

Mix into a Legion::Extensions::Llm::::Actors::DiscoveryRefresh class. The host class must include Legion::Extensions::Helpers::Lex (auto-injects log / settings / handle_exception / cache_) and define:

- #scope_key          — Hash like { provider: :vllm, instance: instance_id }
- #compute_lanes_for_scope — Array<Hash> lane fact-sheets (no health, no
                          lane_weight — added by Inventory.write_lane).
                          Each lane MUST set :id via compose_id.
- #credential_hash    — String identifying the auth credential for this scope
                      (used by the auth-failure cooldown circuit).

Defined Under Namespace

Classes: LegacyCoordinatorAdapter

Constant Summary collapse

AUTH_COOLDOWN_TTL =

Auth-failure cooldown TTL (5 minutes). Operator can fix the credential and lanes auto-recover on the next tick after expiry.

300

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.compose_id(lane_fields) ⇒ Object

G22: 5-part lane id composed here and ONLY here. All gem writers MUST call this helper; Inventory.write_lane rejects any lane with a missing or malformed :id. Accepts a Hash (or keyword splat) with keys: tier, provider_family, instance_id, type, model.



38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/llm/inventory/scoped_refresher.rb', line 38

def self.compose_id(lane_fields)
  t  = lane_fields[:tier]
  pf = lane_fields[:provider_family]
  ii = lane_fields[:instance_id]
  ty = lane_fields[:type]
  mo = lane_fields[:model]
  "#{t}:#{pf}:#{ii}:#{ty}:#{mo}"
end

Instance Method Details

#tickObject

G7 write-then-delete-orphans: write new lanes FIRST (eliminates zero-results race window), then delete orphans from the previous scope snapshot.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/legion/extensions/llm/inventory/scoped_refresher.rb', line 49

def tick(**)
  return if auth_cooldown_active?

  new_lanes = safe_compute
  log.info("[llm][scoped_refresher] action=tick provider=#{scope_key[:provider]} lanes_computed=#{new_lanes ? new_lanes.size : 0}")
  return unless new_lanes&.any?

  written = 0
  new_lanes.each do |lane_fact|
    written += 1 if Legion::LLM::Inventory.write_lane(lane: lane_fact)
  end
  log.info("[llm][scoped_refresher] action=tick_complete provider=#{scope_key[:provider]} lanes_computed=#{new_lanes.size} lanes_written=#{written}")

  orphans = (@prev_scope_keys || []) - new_lanes.map { it[:id] }
  orphans.each { |id| Legion::LLM::Inventory.delete_lane(id: id) }

  @prev_scope_keys = new_lanes.map { it[:id] }
end