Skip to content

Keep rule criteria scores between 0 and 1 - #755

Open
yorzi wants to merge 3 commits into
activeagents:mainfrom
yorzi:fix/evaluation-sample-score-bounds
Open

yorzi wants to merge 3 commits into
activeagents:mainfrom
yorzi:fix/evaluation-sample-score-bounds

Conversation

@yorzi

@yorzi yorzi commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Rule criteria are documented to score 0.0–1.0. Two thresholds broke that:

  • min_length with chars: 0 in a dashboard evaluation over sampled traffic (EvaluationRunnerService#score_sample) divided an empty answer's length by zero, and [NaN, 1.0].min raised ArgumentError: comparison of Float with NaN failed, which marks the whole run failed. The scenario scorer already divides by [min, 1].max.
  • A negative ms or output_tokens gave max_latency_ms and token_budget a negative score (budget / duration), in the sample runner and in ActiveAgent::Evals::Scorer alike: ms: -100 with a 500 ms answer scored -0.2.

Both scorers now clamp: min_length divides by at least 1, and the two budgets are floored at 0, so an impossible budget scores 0.0.

The sample runner also had its own contains / not_contains matcher, which tried the pattern as a regex first, case-insensitively, and had no match timeout. It now calls ActiveAgent::Evals::Scorer.matches_pattern?, so sampled and scenario evaluations agree: literal text first, then a regex with PATTERN_TIMEOUT. On main, contains "V(2)" against "Version v(2)" scored 0.0 in a sampled evaluation and 1.0 in a scenario evaluation.

Tests

  • actionagent/test/evaluation_runner_service_test.rb: an empty answer with chars: 0 scores 0.0 instead of failing the run; negative chars, ms and output_tokens give 1.0, 0.0 and 0.0; contains / not_contains find literal text that is not a matching regex.
  • test/evals/scorer_test.rb: negative ms and output_tokens score 0.0 in a scenario evaluation.

All four fail on main and pass with the change.

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

Fixes #751

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 (run in full, Ruby 3.3.5, gemfiles/rails8.gemfile: 4730 runs, 0 failures, 11 errors, 66 skips. The 11 errors are all in actionagent/test/cli_contract_test.rb and are the same on unmodified main in my environment (NoMethodError: undefined method id' for an instance of Hashin rack-session under WebMock'sto_rack`), so they are unrelated to this change)
  • I updated documentation where needed (CHANGELOG entry)
  • 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

Not changed: neither scorer rejects a negative threshold when an evaluation is saved. Validating criteria config would be a separate change.

yorzi added 3 commits December 3, 2026 22:24
An empty answer divided by a zero length produced NaN. Negative
thresholds also produced negative scores. The sample runner duplicated
pattern matching already implemented by the scenario scorer.
A negative ms or output_tokens budget gave max_latency_ms and
token_budget a negative score in ActiveAgent::Evals::Scorer, the same
defect the previous commit fixed in the dashboard's sample runner.
Clamp both thresholds at zero, and describe the change in the
changelog as the file's other entries are written.

This branch has not been deployed

No deployments
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.

Rule criteria can fail a sampled run or score below zero

1 participant