Skip to content

Claim a pending evaluation run before replaying it - #713

Merged
TonsOfFun merged 1 commit into
activeagents:mainfrom
yorzi:fix/evaluation-run-claim
Nov 17, 2026
Merged

TonsOfFun merged 1 commit into
activeagents:mainfrom
yorzi:fix/evaluation-run-claim

Conversation

@yorzi

@yorzi yorzi commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What this does

EvaluationRunJob checked run.pending?, and the scenario runner wrote running later, as two steps. A job delivered twice, or two workers that both loaded the run as pending, each replayed the whole suite: every replay a billed provider call that may call the agent's tools. With scenario_evaluation_fan_out on, each enqueued a full set of EvaluationReplayJobs. ProjectEvaluationJob has the same check-then-run shape.

ScenarioEvaluationRunner#call now claims the run first with one conditional update (pending → running where the status is still pending), as AgentExecutionJob#claim_pending does since #664. A runner that loses the claim returns the run without writing to it. The claim sits in the runner rather than in each job, so EvaluationRunJob, ProjectEvaluationJob and any run!(run:) caller are covered. Nothing is held over the replays, and there is no migration.

Claiming first also fixes a second bug in the same lines. run used to be assigned only after selected_scenarios and model_specs, so an error raised there reached the rescue with run == nil, and a run created by run_later! stayed pending forever. One example is a re-run whose stored model names a provider the dashboard does not support. Such a run now fails with the error.

Unchanged: a worker that dies after the claim leaves the run running. That is the gap #664 describes for agent runs, and recovering from it belongs with #674.

Tests, in actionagent/test/evaluation_run_claim_test.rb:

  • Fail before the change: two workers that load the same pending run (two threads on their own connections, held right after the run lookup until both have it, no sleeps) replay the suite once. Before, it ran 6 replays instead of 3. The same race with fan-out on enqueues one set of replay jobs (6 → 3). A runner handed a stale pending copy of a claimed run replays nothing (3 → 0). A pending run whose models cannot be resolved ends failed instead of staying pending.
  • Guard existing behavior: a pending run is executed once and completed. A redelivered job leaves a running, complete or failed run as it is.
  • Removing the status condition from the claim fails 3 tests. The new file passes 20/20 on Rails 8.1 and 20/20 on Rails 7.2 (database migrated as the CI job builds it).

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the contributing guide
  • This fits activeagent's stated focus
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my use case

Related issue

None filed. This is the evaluation-run counterpart of #662/#664.

Quality check

  • The project's hooks and linters pass (bin/rubocop on the changed files)
  • The new tests fail before this change and pass after it
  • The full test suite passes. Engine suite on Rails 7.2: 2033 runs, 0 failures, 0 errors. On Rails 8.1: 0 failures, and 11 errors, all in CliContractTest (rack-session undefined method 'id' for Hash), which fail identically on an untouched main in this environment
  • I updated documentation where needed (CHANGELOG only)
  • I didn't edit generated files by hand

Ownership

  • I understand every line of this change and can answer questions about it

API changes

  • Breaking change
  • New public methods or classes
  • Changed method signatures
  • No API changes

EvaluationRunJob checked `run.pending?` and the scenario runner then wrote
`running`, as two steps. A job delivered twice, or two workers that both
loaded the run as pending, each replayed the whole suite (every replay a
billed provider call that may call the agent's tools), or with
scenario_evaluation_fan_out on each enqueued a full set of replay jobs.

ScenarioEvaluationRunner#call now moves the run from pending to running in
one conditional update, as AgentExecutionJob#claim_pending does, and a
runner that loses the claim returns without writing to the run. The claim
sits in the runner, so ProjectEvaluationJob, which has the same
check-then-run shape, is covered as well. It happens before the selection
is read, so a selection that raises (an unsupported provider in a re-run's
models) now fails the run instead of leaving it pending forever: `run` was
still unassigned when the rescue ran.
@yorzi yorzi mentioned this pull request Nov 15, 2026
11 of 19 tasks
TonsOfFun added a commit that referenced this pull request Nov 17, 2026
@TonsOfFun
TonsOfFun merged commit 0aab257 into activeagents:main Nov 17, 2026
18 checks passed
@TonsOfFun TonsOfFun added this to the 1.9.9 milestone Nov 17, 2026
@TonsOfFun TonsOfFun mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants