Skip to content

fix(eval): verify which agent answered each eval scenario - #4092

Merged
itomek merged 5 commits into
mainfrom
issue-4069
Sep 22, 2026
Merged

itomek merged 5 commits into
mainfrom
issue-4069

Conversation

@itomek

@itomek itomek commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

An eval run could score the wrong agent and nobody would know. The runner asks for an agent in prompt prose ("you MUST pass agent_type=..."), and a driver that drops that kwarg gets the backend default instead — while the result still carries the requested id. So a run labelled as the flagship could be measuring ChatAgent, and every "no regression" claim resting on it would be measuring the wrong thing.

Now the driver hands back its session id, the runner reads that session back from the backend, and a scenario result records what was requested and what was observed. A disagreement is an INFRA_ERROR: a score measured against the wrong agent is not a score. Statuses that never produced a measurement keep their own status, since they never created a session to check.

One case this cannot see: over HTTP a dropped kwarg reads back as the string chat, never null, so a scenario that legitimately asks for chat is indistinguishable from a drop. Harmless for every non-chat scenario, which is the case the guard exists for — pinned by a test so it's read rather than rediscovered.

The eval itself was not run, and this PR does not claim it was. The judge credential is dead repo-wide (#4080, Anthropic org spend limit) and the flagship has no committed baseline yet (#2983). The change is proven by unit tests over the provenance path instead.

Closes #4069

Test plan

  • python -m pytest tests/unit/eval/ → 679 passed, 1 skipped (18 of them new, in test_scenario_agent_provenance.py)
  • python util/lint.py --all → [SUCCESS] ALL QUALITY CHECKS PASSED!
  • Reviewer: the mismatch path is exercised by test_dropped_kwarg_is_caught_and_fails_the_scenario, which is the exact bug — requested gaia, session ran chat, result becomes INFRA_ERROR naming both.
🔍 Technical details

Run output:

$ python -m pytest tests/unit/eval -q
679 passed, 1 skipped, 1 warning in 85.24s (0:01:25)

$ python -m pytest tests/unit/eval/test_scenario_agent_provenance.py -q
18 passed

Three sites coerce a missing/unknown agent type to chat on the create→read-back path, and all three are left alone deliberately — the UI depends on them, and the fix belongs in the eval harness, not in session storage:

  • database.py create_session — stores agent_type or "chat"
  • utils.py session_to_response + models.py SessionResponse.agent_type: str = "chat" — serialises a missing value as "chat"
  • _chat_helpers.py — the runtime picks the agent from the same stored value, so the HTTP read-back reflects what actually answered

The last two are why a naive observed is None test would never exercise the branch real code takes. Two tests pin them.

Alias resolution goes through AgentRegistry.canonical_id on an undiscovered registry — alias-only, no hub wheels needed — so doc-lite vs doc is not reported as a mismatch.

A scenario result recorded the agent the runner asked for, never the one
that ran. The ask is prompt prose ("you MUST pass agent_type=..."), and a
driver that drops the kwarg gets the backend default — so a run could
score ChatAgent while every result claimed the flagship.

The driver now returns its session_id, the runner reads that session back
over HTTP, and the result carries agent_type_requested alongside
agent_type_observed. A disagreement forces INFRA_ERROR: a score measured
against the wrong agent is not a score. Statuses that never produced a
measurement keep their own status, since they never created a session.

Over HTTP a dropped kwarg reads back as the string "chat", never null —
so a scenario legitimately requesting chat is the one case this cannot
tell apart. Tests pin both layers that launder it.

Closes #4069
urllib.request.urlopen trips bandit B310, and a nosec needs a
justification entry to pass lint. The rest of the eval harness already
uses requests for its Agent UI calls.
@itomek itomek added the ready_for_ci Run CI workflows on draft PR without requesting review label Sep 22, 2026
@github-actions github-actions Bot added eval Evaluation framework changes tests Test changes performance Performance-critical changes labels Sep 22, 2026
@itomek
itomek marked this pull request as ready for review September 22, 2026 00:28
The provenance check fired on every scenario and failed any result with
no session_id, which broke 8 payload-parsing tests in tests/test_eval.py
and would have mislabelled real runs the same way.

Resolving the contradiction the check shipped with: the schema declared
session_id optional while the runner treated its absence as fatal. It is
conditionally fatal, and the condition is the scenario, which a static
schema cannot see — so the schema stays optional (a driver that aborts
before create_session has no id to give) and the runner owns the rule:

  - No agent requested: check nothing. The backend default is correct by
    definition, and this is what the 8 tests were exercising.
  - Mismatch: always fatal. The score belongs to an agent nobody asked
    for, whatever status it carried.
  - Cannot verify (no session_id, or the read-back failed): this only
    discards a score, so it downgrades PASS/FAIL to INFRA_ERROR and
    leaves any other status alone with a provenance_warning.

That last rule is why BLOCKED_BY_ARCHITECTURE survives an unverifiable
result: it says something INFRA_ERROR does not, and an unreadable session
is no reason to throw that away. A mismatch still overrides it, because
"the architecture blocks gaia" is false if chat answered.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

The fix is correct and the problem is real: a driver that silently drops agent_type from create_session would produce results attributed to the wrong agent, and every "no regression" claim resting on those results would be meaningless. The provenance guard closes that gap cleanly.

The code is well-structured — three small, testable helpers, one injection point in run_scenario_subprocess, and a direct result path in AgentEvalRunner for scenarios that never get that far. The test suite covers the exact bug, the happy path, every failure mode (no session id, unreachable backend, mismatch on a non-PASS status), the known chat blind spot, and the two backend layers that launder a dropped kwarg into the string "chat" — that last group is especially good. The PR is honest that the eval itself wasn't run and explains why; that's the right call given the dead judge credential.

Two nits:

🟢 _stamp_agent_provenance references _NO_MEASUREMENT_STATUSES, which is defined ~370 lines later in the file. Python resolves it at call time, so it's not broken — but a reader scanning the function in isolation has to scroll far to see what statuses trigger the early return.

🟢 test_a_scenario_that_never_measured_keeps_its_own_status parametrizes ["TIMEOUT", "SETUP_ERROR", "ERRORED"] but omits "BUDGET_EXCEEDED" and "INFRA_ERROR", the other two members of _NO_MEASUREMENT_STATUSES. Adding them makes the coverage exhaustive at zero cost.

🔍 Technical details

Forward reference (runner.py:297): _NO_MEASUREMENT_STATUSES is at line 706; _stamp_agent_provenance uses it at line 297. A one-line comment at the _stamp_agent_provenance definition naming the set (e.g. # see _NO_MEASUREMENT_STATUSES) would help. Alternatively, move the frozenset earlier in the file.

Parametrize gap (test_scenario_agent_provenance.py:349):

@pytest.mark.parametrize("status", ["TIMEOUT", "SETUP_ERROR", "ERRORED", "BUDGET_EXCEEDED", "INFRA_ERROR"])

Both are 🟢 nits; neither is a merge blocker.

The provenance guard read _NO_MEASUREMENT_STATUSES ~370 lines before the
frozenset was defined, so nothing near the early return said which statuses
trigger it. Moving the definition above the guard also lets the unmeasured-status
test parametrize every member instead of three of five.
@itomek

itomek commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Both review nits are fixed, and the branch is now synced with main.

The status set the guard checks is defined right above it instead of ~370 lines below, and the unmeasured-status test now covers all five members of that set rather than three.

Test plan

  • pytest tests/unit/eval on the merged head — 683 passed, 1 skipped (53s)
  • black --check / isort --check-only clean on both changed files
  • Full CI green on the previous head (all 27 checks); re-running now on the merged head
🔍 Technical details

Evidence captured on 75c50352, which merges origin/main at b869e9a3 into the branch (merge was conflict-free; main's only change to runner.py in that range was a prompt docstring line, no contract change to the provenance path).

Nit dispositions:

  • Forward reference — took the "move the frozenset earlier" option rather than the comment, so the guard's early return and the set it tests are adjacent. black then wanted one blank line at the vacated site.
  • Parametrize gap — BUDGET_EXCEEDED and INFRA_ERROR added. Both hit the same early return, so the existing assertions (status preserved, agent_type_requested stamped, no error key) hold unchanged for all five.

No gaia eval run: the judge credential is out of org budget repo-wide (#4080), so an eval here would measure nothing. The change is internal harness logic with no LLM-behaviour surface — unit tests and CI are the applicable tiers.

@itomek

itomek commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Merging. All 29 checks green on 75c50352, no open review threads.

Three other open PRs also touch the eval runner — #4096, #4056 (draft), #3982 — so noting the order deliberately: this one lands first as the smallest and only ready+green of the four, and the others pick it up on their next sync.

🔍 Technical details

main gained three commits (741c16fd, 5aa58901, 4fd28f2c) after evidence was captured; all three are in agents/base/memory.py, llm/providers/, and connectors/store.py — disjoint from src/gaia/eval/, and mergeStateStatus is CLEAN. Not re-syncing for them, since a fresh CI cycle would only measure against a base that moves again.

Overlap detail: #4056's branch already carries this PR's test_scenario_agent_provenance.py, so it is downstream of this change rather than in conflict with it. #4096 and #3982 touch different regions of runner.py (scenario consolidation and MCP interpreter resolution respectively); neither overlaps the provenance helpers added here.

@itomek
itomek added this pull request to the merge queue Sep 22, 2026
Merged via the queue into main with commit 0816b01 Sep 22, 2026
40 checks passed
@itomek
itomek deleted the issue-4069 branch September 22, 2026 02:25
kovtcharov-amd pushed a commit that referenced this pull request Sep 22, 2026
Resolves src/gaia/eval/runner.py against #4092 (0816b01), which added
the agent-provenance check while this branch was making the flagship the
agent every scenario runs as. The two are complementary: #4092 verifies
which agent answered, this branch decides which one is asked for.

Resolution keeps #4092's mechanism whole. Its
_resolve_scenario_agent_type is restored at both call sites, and each
site passes the value that helper computed rather than self.agent_type
directly - otherwise _stamp_agent_provenance would compare a requested
agent against a session created with a different one and report a
mismatch that never happened.

That reinstates the per-scenario YAML override this branch had removed in
code, which is the better of the two: an override that exists and is
honoured beats one silently ignored, and
tests/unit/eval/test_scenario_agent_types.py already fails CI loudly if
any scenario carries an agent_type key. Enforcement moves from silent to
loud, which is the direction the no-silent-fallbacks rule points.

The constructor default stays at DEFAULT_AGENT_TYPE rather than None,
and that is now load-bearing for #4092 rather than just tidiness:
_stamp_agent_provenance returns early when no agent was requested, so a
null default would disarm the provenance check for every programmatic
runner. Noted in a comment at the default so it does not get "simplified"
back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eval Evaluation framework changes performance Performance-critical changes ready_for_ci Run CI workflows on draft PR without requesting review tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eval: scenario provenance records what was requested, not what ran

1 participant