Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,60 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- **An evaluation run is executed by one job** (`actionagent`). The run job
read a run's status, then the scenario runner wrote `running`, as two
steps, so a job delivered twice, or two workers that both loaded the run
as pending, each replayed the whole suite, or with
`scenario_evaluation_fan_out` on each enqueued a full set of replay jobs.
The runner now moves the run from pending to running in one conditional
update, as the execution job claims an agent run, and replays nothing
unless it was the one to do so; this covers `ProjectEvaluationJob` too.
The claim comes before the selection is read, so a selection that cannot
be resolved (an unsupported provider in a re-run's models) now fails the
run instead of leaving it pending forever.
- **A fanned-out replay is claimed before the agent runs** (`actionagent`).
`EvaluationReplayJob` checked for a stored result, replayed, and only
then took the run's lock to store, so two deliveries of one replay job
both called the provider (and the agent's tools) and the second answer
was dropped. A delivery that failed after another had stored the pair's
replay also marked that good result errored. The replay now takes a
claim, kept with the run's fan-out bookkeeping (no migration), before
the agent runs. A delivery that finds the pair claimed comes back when
the claim expires (30 minutes) and replays only if nothing was stored,
so a worker that stopped mid-replay is still covered. A failure is
stored only over the delivery's own pair. A worker that stops after the
provider answered and before the result is stored is still replayed
again: this is one active replay per pair, not exactly once.
- **A catalog document YAML refuses to load is an invalid document**
(`activeagent`, `actionagent`). `Catalog.parse` turned only a syntax
error into `Catalog::InvalidDocument`, while safe loading refuses a tag
naming a Ruby class (`!ruby/object:...`) or an alias to an undefined
anchor with other `Psych` errors. Those escaped the dashboard's catalog
import and preview as a 500, and the `catalogs_import` and
`catalogs_preview` tools as an internal error. They are now refused like
any other invalid catalog: 422 with "the catalog is not valid YAML: ...".
What safe loading permits is unchanged.
- **A run of only ungated groups no longer reads as "every gate met"**
(`activeagent`). An ungated group's row is met without being held to a
bar, so a report whose every result sat in ungated groups said "every
pass gate met" (`GateCheck`, `assert_meets_pass_gates`, the RSpec
matcher) and `evals run --wait` printed `Gates: every gate met`, even
when every answer had failed. The verdict is unchanged, since an ungated
group never fails the run, but the message now says that every group
covered is ungated and nothing was held to a bar.
- **The RubyLLM provider refuses media it would drop** (`activeagent`). It
sends RubyLLM the text of each message and silently left out every other
content block, so a message with an image (`image_url`, `image`,
`input_image`), audio or a file reached the model as its text alone, or
as an empty message, and the model answered as if it had seen it. Such
a message now raises `ActiveAgent::Providers::Errors::InvalidRequest`,
naming the block types, before any provider call. Blocks that are not
media (an earlier turn's reasoning) are still left out, as before.

## [1.9.8] - 2026-11-12

The dashboard holds a run to its catalog's pass bars: a product's and a
Expand Down
6 changes: 4 additions & 2 deletions actionagent/app/jobs/action_agent/evaluation_replay_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module ActionAgent
#
# A failure outside the replay is stored as the pair's errored result
# rather than raised, so the run still completes; a scenario removed from
# the suite during the run is left out of it.
# the suite during the run is left out of it. The same runner records the
# failure, since it knows whether this delivery claimed the pair and
# stored its result (see ScenarioEvaluationRunner#fail_result!).
class EvaluationReplayJob < ApplicationJob
queue_as :agents

Expand All @@ -21,7 +23,7 @@ def perform(run_id, scenario_id, spec, selection = {})
runner.replay_scenario!(run, scenario_id, spec)
rescue StandardError => e
Rails.logger.warn("[ActionAgent] evaluation run #{run_id}: replay of scenario #{scenario_id} failed: #{e.class}: #{e.message}")
ScenarioEvaluationRunner.new(run.evaluation, selection: selection, run: run).fail_result!(run.reload, scenario_id, spec, e)
runner.fail_result!(run.reload, scenario_id, spec, e)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion actionagent/app/jobs/action_agent/evaluation_run_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
module ActionAgent
# Executes an evaluation run created by Evaluation#run_later!. The run
# record already exists (pending), so the dashboard can show it while the
# job is queued; the runner marks it running, then complete or failed.
# job is queued; the runner claims it as running, then marks it complete
# or failed. A job delivered again finds the run claimed and replays
# nothing, even when two workers load it as pending at once.
class EvaluationRunJob < ApplicationJob
queue_as :agents

Expand Down
130 changes: 125 additions & 5 deletions actionagent/app/services/action_agent/scenario_evaluation_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module ActionAgent
class ScenarioEvaluationRunner < EvaluationRunnerService
Evals = ActiveAgent::Evals
JUDGE_LEASE_DURATION = 30.minutes
REPLAY_LEASE_DURATION = 30.minutes

# The providers a candidate model name resolves against. `mock` is the
# framework's test double, accepted so the test suite can compare cohorts
Expand Down Expand Up @@ -82,10 +83,15 @@ def initialize(evaluation, selection: {}, run: nil)
end

def call
pending = @run || @evaluation.evaluation_runs.create!(status: :pending)
# Another worker started this run (a job delivered twice, or handed to
# two workers): it is theirs to finish, so nothing here writes to it.
return pending.reload unless claim!(pending)

run = pending
scenarios = selected_scenarios
specs = model_specs
run = @run || @evaluation.evaluation_runs.create!(status: :pending)
run.update!(status: :running, selection: selection_summary(scenarios, specs))
run.update!(selection: selection_summary(scenarios, specs))
record_pass_thresholds!(run)
ensure_sandbox_live!

Expand Down Expand Up @@ -173,16 +179,35 @@ def call
# Replays one scenario under one model and stores the answer as a pending
# result, then enqueues its scoring. A result already stored for the
# pair (a retried job) is not replayed again.
#
# The replay is claimed before the agent runs, so a second delivery of
# the job (a queue redelivering it, or handing it to two workers) does
# not call the provider and the agent's tools a second time. A delivery
# that finds the pair claimed comes back when the claim expires (see
# #claim_replay!): by then the owner has stored the result, or stopped
# and left the pair to it.
def replay_scenario!(run, scenario_id, spec_value)
return unless run.running?

scenario = @evaluation.scenarios.find(scenario_id)
spec = model_spec_from(spec_value)
row = stored_result(run, scenario, spec)
unless row
key = replay_key(scenario, spec)
held_until = claim_replay!(run, key)
if held_until
EvaluationReplayJob.set(wait_until: held_until).perform_later(run.id, scenario.id, spec_value, @selection.to_h)
return
end
return unless @replay_token # the run stopped running

task = Evals::Scenario.from_hash(scenario.as_json_summary)
replay = fan_out_replay(task, spec)
row = run.with_lock { stored_result(run, scenario, spec) || store_replay(run, scenario, task, spec, replay) }
row = run.with_lock do
stored = stored_result(run, scenario, spec) || store_replay(run, scenario, task, spec, replay).tap { |created| @stored_result_id = created.id }
release_replay!(run, key)
stored
end
end
EvaluationJudgeJob.perform_later(row.id, @selection.to_h, run.id) if row.pending?
row
Expand Down Expand Up @@ -227,6 +252,12 @@ def judge_result!(row)
# replay (which records its own errors), so the run still completes. A
# scenario removed from the suite during the run has no result to
# store; the run completes without it (see #finish_fan_out!).
#
# Only this delivery's own pair is failed: one with no result yet and
# no other delivery replaying it, or the result this runner stored. A
# result another delivery stored is that delivery's to score, and a
# pair another delivery has claimed is its to store, so a duplicate
# delivery's failure cannot turn a good replay into an error.
def fail_result!(run, scenario_id, spec_value, error)
return unless run.running?

Expand All @@ -235,8 +266,15 @@ def fail_result!(run, scenario_id, spec_value, error)
spec = model_spec_from(spec_value)
run.with_lock do
row = stored_result(run, scenario, spec)
task = Evals::Scenario.from_hash(scenario.as_json_summary)
row ||= store_replay(run, scenario, task, spec, Evals::Replay.failed(error))
if row.nil?
next if replay_claimed_elsewhere?(run, replay_key(scenario, spec))

task = Evals::Scenario.from_hash(scenario.as_json_summary)
row = store_replay(run, scenario, task, spec, Evals::Replay.failed(error))
@stored_result_id = row.id
end
next unless row.id == @stored_result_id

attributes = { status: :errored, error_message: row.error_message.presence || error_text(error) }
if scoring_leases?
# Another replay delivery may fail while this result is being
Expand Down Expand Up @@ -291,6 +329,24 @@ def finish_fan_out!(run)

private

# Moves the run from pending to running in one conditional update, as
# AgentExecutionJob#claim_pending claims an agent run, and returns
# whether this runner is the one that did. Of two workers that loaded
# the run as pending, only the first to write replays the suite (or fans
# it out); the other replays nothing and leaves the run alone. The claim
# comes before the selection is read, so a selection that cannot be
# resolved fails the run rather than leaving it pending. Nothing is held
# over the replays.
def claim!(run)
now = Time.current
claimed = EvaluationRun.where(id: run.id, status: EvaluationRun.statuses[:pending])
.update_all(status: EvaluationRun.statuses[:running], updated_at: now)
return false if claimed.zero?

run.reload
true
end

def fan_out?(adapter)
ActionAgent.scenario_evaluation_fan_out == true && adapter.nil? && !browser_requested? &&
Evals::Runner.instance_method(:initialize).parameters.any? { |_type, name| name == :refine_gate }
Expand Down Expand Up @@ -404,6 +460,70 @@ def scoring_leases?
(%w[scoring_token scoring_expires_at] - EvaluationScenarioResult.column_names).empty?
end

# A pair's replay claim, kept with the run's fan-out bookkeeping
# (scores["_fan_out"]["replays"]) until the replay is stored, so no
# migration is needed. The result row cannot hold it: the row is
# created only once there is an answer to store, and nothing makes a
# pair's row unique to create it earlier.
def replay_key(scenario, spec)
"#{scenario.id}:#{spec.provider}/#{spec.model}"
end

# Claims the pair's replay for this runner (its token in @replay_token)
# and returns nil, or returns when another delivery's live claim
# expires. An expired claim is taken over: its worker stopped, or is
# still replaying after REPLAY_LEASE_DURATION, in which case the two
# replays overlap and the first to store its answer is kept. A run no
# longer running claims nothing (@replay_token stays nil).
#
# This holds one active replay per pair across ordinary duplicate
# deliveries. It is not exactly once: a worker that stops after the
# provider answered and before the result is stored is replayed again.
def claim_replay!(run, key)
@replay_token = nil
token = SecureRandom.uuid
held_until = nil
update_fan_out_state!(run) do |state|
now = Time.current
replays = state["replays"].is_a?(Hash) ? state["replays"] : {}
expires_at = replay_expiry(replays[key])
if expires_at && expires_at > now
held_until = expires_at
next state
end

@replay_token = token
state.merge("replays" => replays.merge(key => { "token" => token, "expires_at" => (now + REPLAY_LEASE_DURATION).iso8601(6) }))
end
held_until
end

# Drops this runner's claim once its replay is stored. A claim another
# delivery took over is left to that delivery. Called under the run's
# lock, after the store.
def release_replay!(run, key)
return unless run.running?

state = fan_out_state(run)
replays = state["replays"].is_a?(Hash) ? state["replays"] : {}
return unless @replay_token && replays.dig(key, "token") == @replay_token

scores = run.scores.is_a?(Hash) ? run.scores : {}
run.update!(scores: scores.merge("_fan_out" => state.merge("replays" => replays.except(key))))
end

def replay_claimed_elsewhere?(run, key)
claim = fan_out_state(run)["replays"].to_h[key]
expires_at = replay_expiry(claim)
expires_at.present? && expires_at > Time.current && claim["token"] != @replay_token
end

def replay_expiry(claim)
Time.iso8601(claim["expires_at"].to_s) if claim.is_a?(Hash)
rescue ArgumentError
nil
end

# What Evals::Runner does with a replay that raises: an errored replay,
# scored like any other.
def fan_out_replay(task, spec)
Expand Down
Loading
Loading