Module: Legion::Extensions::Synapse::Runners::BlastRadius

Included in:
Actor::BlastRadius, Client, Challenge
Defined in:
lib/legion/extensions/synapse/runners/blast_radius.rb

Constant Summary collapse

TIER_CRITICAL =
'CRITICAL'
TIER_HIGH =
'HIGH'
TIER_MED =
'MED'
TIER_LOW =
'LOW'
BLAST_MULTIPLIERS =
{
  TIER_LOW      => 1.0,
  TIER_MED      => 1.5,
  TIER_HIGH     => 2.0,
  TIER_CRITICAL => 3.0
}.freeze

Instance Method Summary collapse

Instance Method Details

#blast_multiplier_for(blast_radius_tier) ⇒ Object



65
66
67
# File 'lib/legion/extensions/synapse/runners/blast_radius.rb', line 65

def blast_multiplier_for(blast_radius_tier)
  BLAST_MULTIPLIERS.fetch(blast_radius_tier.to_s.upcase, 1.0)
end

#blast_tier(synapse_id:) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/legion/extensions/synapse/runners/blast_radius.rb', line 57

def blast_tier(synapse_id:)
  Data::Model.define_synapse_model
  synapse = Data::Model::Synapse[synapse_id]
  return nil unless synapse

  synapse.blast_radius
end

#compute(**_opts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/legion/extensions/synapse/runners/blast_radius.rb', line 23

def compute(**_opts)
  Data::Model.define_synapse_model
  return { success: false, error: 'data unavailable' } unless data_available?

  synapses = Data::Model::Synapse.where(status: 'active').all
  return { success: true, updated: 0, skipped: 0 } if synapses.empty?

  graph = build_graph(synapses)
  updated = 0
  skipped = 0

  synapses.each do |synapse|
    depth, count = bfs_reachable(synapse.id, graph)
    tier = classify_tier(
      depth:      depth,
      downstream: count,
      throughput: synapse.baseline_throughput.to_f
    )

    synapse.update(
      propagation_depth:       depth,
      downstream_count:        count,
      blast_radius:            tier,
      blast_radius_updated_at: Time.now
    )
    updated += 1
  rescue StandardError => e
    log.warn("blast_radius update failed for synapse #{synapse.id}: #{e.message}")
    skipped += 1
  end

  { success: true, updated: updated, skipped: skipped }
end

#requires_llm_review?(blast_radius_tier) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
# File 'lib/legion/extensions/synapse/runners/blast_radius.rb', line 69

def requires_llm_review?(blast_radius_tier)
  tier = blast_radius_tier.to_s.upcase
  [TIER_HIGH, TIER_CRITICAL].include?(tier)
end