Module: Legion::Extensions::Agentic::Memory::Trace::Helpers::ErrorTracer

Defined in:
lib/legion/extensions/agentic/memory/trace/helpers/error_tracer.rb

Constant Summary collapse

DEBOUNCE_WINDOW =

seconds

60
ERROR_VALENCE =
-0.6
ERROR_INTENSITY =
0.7
FATAL_VALENCE =
-0.8
FATAL_INTENSITY =
0.9

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/legion/extensions/agentic/memory/trace/helpers/error_tracer.rb', line 32

def active?
  @active == true
end

.setupObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/memory/trace/helpers/error_tracer.rb', line 17

def setup
  return if @active

  @recent       = {}
  @recent_mutex = ::Mutex.new
  @runner       = Object.new.extend(Legion::Extensions::Agentic::Memory::Trace::Runners::Traces)
  @write_queue  = ::Queue.new
  @worker       = ::Thread.new { drain_queue }
  @worker.name  = 'legion-error-tracer'
  wrap_logging_methods
  @active = true
  register_shutdown_hook
  Legion::Logging.info '[memory] ErrorTracer active — errors/fatals will become episodic traces'
end

.shutdownObject

Gracefully shut down the background worker and unregister the at_exit hook.



37
38
39
40
41
42
43
44
45
46
# File 'lib/legion/extensions/agentic/memory/trace/helpers/error_tracer.rb', line 37

def shutdown
  return unless @active

  @write_queue&.push(:stop)
  @worker&.join(5) # wait up to 5 seconds for clean exit
  @active = false
  Legion::Logging.info '[memory] ErrorTracer shut down'
rescue StandardError
  @active = false
end