Class: SkillBench::Services::TrendRecorderService

Inherits:
Object
  • Object
show all
Defined in:
lib/skill_bench/services/trend_recorder_service.rb

Overview

Records evaluation results and computes trends.

Constant Summary collapse

WRITE_MUTEX =

Serializes the load -> append -> write of the shared trend history file. Batch runs (BatchRunnerService) execute evals concurrently and the trend file is process-global shared state; without this lock, concurrent records race on the temp-file rename and silently lose appended entries.

Mutex.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result, eval_name, skill_names) ⇒ TrendRecorderService

Returns a new instance of TrendRecorderService.

Parameters:

  • result (Hash)

    The evaluation result from Evaluation::Runner

  • eval_name (String)

    Name of the eval

  • skill_names (Array<String>)

    Names of the skills



29
30
31
32
33
# File 'lib/skill_bench/services/trend_recorder_service.rb', line 29

def initialize(result, eval_name, skill_names)
  @result = result
  @eval_name = eval_name
  @skill_names = skill_names
end

Class Method Details

.call(result, eval_name, skill_names) ⇒ Hash

Records evaluation results and computes trends.

Parameters:

  • result (Hash)

    The evaluation result from Evaluation::Runner

  • eval_name (String)

    Name of the eval

  • skill_names (Array<String>)

    Names of the skills

Returns:

  • (Hash)

    Result with success status and trend data



22
23
24
# File 'lib/skill_bench/services/trend_recorder_service.rb', line 22

def self.call(result, eval_name, skill_names)
  new(result, eval_name, skill_names).call
end

Instance Method Details

#callHash

Records evaluation results and computes trends.

Loads the trend history once and reuses it for both the trend computation and the append+write, avoiding a duplicate parse per run.

Returns:

  • (Hash)

    Result with success status and trend data



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/skill_bench/services/trend_recorder_service.rb', line 41

def call
  tracker = TrendTracker.new
  enriched = @result.merge(eval_name: @eval_name, skill_names: @skill_names)
  trend, record_result = record_atomically(tracker, enriched)

  record_success = record_result.is_a?(Hash) && record_result[:success]
  unless record_success
    message = if record_result.is_a?(Hash)
                record_result.dig(:response, :error, :message) ||
                  record_result.dig(:error, :message) ||
                  'Unknown error'
              else
                'Unexpected record response'
              end
    SkillBench::ErrorLogger.log_error(
      StandardError.new(message),
      "Trend tracking record failed for eval #{@eval_name}"
    )
    return {
      success: false,
      response: {
        error: {
          message: "Trend tracking record failed: #{message}",
          record_result: record_result
        }
      }
    }
  end
  { success: true, trend: trend }
rescue StandardError => e
  SkillBench::ErrorLogger.log_error(e, 'Trend tracking failed')
  { success: false, response: { error: { message: e.message } } }
end