Skip to content

feat(evalbench): evalbench-score CLI wrapping Client.evaluate (#435, #97) - #453

Merged
haiyuan-eng-google merged 3 commits into
GoogleCloudPlatform:mainfrom
caohy1988:feat/435-evalbench-score
Aug 30, 2026
Merged

haiyuan-eng-google merged 3 commits into
GoogleCloudPlatform:mainfrom
caohy1988:feat/435-evalbench-score

Conversation

@caohy1988

Copy link
Copy Markdown
Collaborator

Summary

Slice 3 of #435 (W0.2 leftover / remaining #97). Thin bq-agent-sdk evalbench-score CLI wrapping existing Client.evaluate + LLMAsJudge prebuilts over the EvalBench mirror table, filtered by TraceFilter(experiment_id=job_id) and pinned to one import version (latest successful, or --import-version). --exit-code reuses the evaluate CI gate.

Depends on

#451 (slice 1 writer) and #452 (slice 2 failed_sessions view / version pin). Stacked on #452. Merge after those, or together.

Closes the W0.2 leftover of #97 for the score CLI; does not close #97 or #435 (taxonomy / localization / live harness remain).

Out of scope

Taxonomy, localization, live W0.3 harness, dashboards, D4, partner-job import, modifying Client.evaluate.

Test plan

  • Unit tests stub Client / manifest (no live BigQuery): wiring, version pin, --strict, --exit-code pass/fail, invalid evaluator, BQ error
  • Codex + Kimi review this PR on GitHub

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Kimi

Review: PR 453 — feat(evalbench): evalbench-score CLI wrapping Client.evaluate (#435 slice 3, #97)

Verdict: Approve (comment). No P0/P1 findings.

Counts: P0 = 0, P1 = 0, P2 = 4 (notes only, non-blocking).

Reviewed git diff a354f1b..2e4614d in the slice-3 worktree; ran the prescribed suite: 172 passed (test_cli_evalbench_import.py, test_cli_evalbench_failed_sessions.py, test_cli_evalbench_score.py, test_evalbench_importer.py, test_evalbench_import_sessions.py, 5.0s, no live BigQuery).

Contract checklist — all verified

  • Client points at the mirror table. evalbench_score builds the client via the existing _build_client(project_id, dataset_id, table_id, ...) with --table-id defaulting to evalbench_agent_events (src/bigquery_agent_analytics/cli.py:2615). The reserved ADK agent_events table is rejected by _validate_destination_table before any client or BigQuery call (cli.py:2613), and after resolution the CLI refuses a --table-id that does not match the version's manifest-bound events_table (cli.py:2630-2637) — so the client can never be pointed at a table the version was not published to. No dataset override anywhere; pointing the Client at the mirror is the whole trick, as specified.
  • TraceFilter(experiment_id=job_id). EvalBenchImportSessions.trace_filter() returns TraceFilter(experiment_id=job_id, session_ids=[...], limit=len(session_ids)) (evalbench.py:2425-2428). Mapped events stamp attributes.experiment_id = job_id (_base_attributes, evalbench.py:3300), and TraceFilter.to_sql_conditions() queries JSON_VALUE(attributes, '$.experiment_id') (trace.py:762), so the job pin lands.
  • --import-version pins one published version; no mixing. _resolve_manifest (evalbench.py:2337-2373) requires an explicit version to have a committed manifest row and resolves None to the job's latest successful import via the same _LATEST_IMPORT_QUERY semantics as evalbench_failed_sessions / failed_sessions(). The version pin reaches Client.evaluate exclusively through existing TraceFilter fields (experiment_id + the version's exact session_ids read from the manifest-bound table by _IMPORT_SESSIONS_QUERY), not through custom_labels/$.custom_tags and not through any invented evalbench_import_version filter — the code comments say exactly this. Cross-version mixing is structurally impossible: published session identities are evalbench-import:{job}:{version}:{scenario} with escaped components (_session_identity), so two retained versions of one job never share a session id. trace_filter() additionally refuses an empty session set (evalbench.py:2420-2424), closing the "no session_ids = unfiltered" widening hole — good catch, this was the one place the design could have silently scored every retained version.
  • --exit-code matches evaluate. Identical logic to the existing command: if exit_code and report.pass_rate < 1.0: _emit_evaluate_failures(report); raise typer.Exit(code=1) (cli.py:2649-2651 vs cli.py:588-590). Passing scorecard with --exit-code exits 0; failures without the flag exit 0. Covered by test_exit_code_flag_returns_1_and_emits_fail_lines_on_failure, test_exit_code_flag_returns_0_when_all_pass, test_without_exit_code_flag_failures_still_exit_0.
  • Exit codes. 0 on produced scorecard; 2 on invalid input (unknown --evaluator, reserved table, unpublished job/version, table not bound to version, version with no sessions) or BQ error via the generic except Exception → Exit(2). Unknown evaluator exits 2 before _build_client, import_sessions, or evaluate (cli.py:2602-2609; asserted by test_unknown_evaluator_exits_2_before_any_client with assert_not_called on all three).
  • --strict. Passed straight through: client.evaluate(evaluator=judge, filters=pinned.trace_filter(), strict=strict) (cli.py:2638-2640); Client.evaluate itself is untouched by this diff.
  • --evaluator. Exactly correctness|hallucination|sentiment via the existing _LLM_JUDGES table (cli.py:276-289), same with/without-threshold factory pattern as evaluate.
  • Tests. Fully mocked (_build_client and import_sessions monkeypatched in CLI tests; _FakeClient for import_sessions); no live BigQuery; no modification of Client.evaluate; no new scoring engine. Reuses _LLM_JUDGES, _build_client, _emit_evaluate_failures.

P2 notes (non-blocking)

  1. cli.py:2600 imports the private _validate_destination_table from .evalbench. Same-package private reuse is consistent with the codebase's _-helper style, but if a third caller appears, consider promoting it.
  2. tests/test_cli_evalbench_score.py:214 asserts "Evaluation Report: correctness_judge" in the text output while the judge under test is hallucination — the string comes from the mocked report's evaluator_name, so the test is correct, but the mismatch is mildly confusing to a reader.
  3. import_sessions materializes all of a version's distinct session ids and pins limit=len(session_ids); a very large version yields a large IN UNNEST(@session_ids) parameter. Inherent to the "pin via session_ids" design and documented; worth a note if 100k-scenario jobs ever show up.
  4. EvalBenchImportSessions.manifest is carried as a plain dict copy and serialized via to_dict(); only events_table/scores_table are read from it today. Fine as-is.

Docs (docs/evalbench.md), CHANGELOG.md, and examples/evalbench_score_gate.sh are accurate against the implementation — including the removal of the stale slice-2 line "There is no evalbench-score command." The example script's exit-code table matches the CLI.

LGTM.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Codex

Verdict

REQUEST_CHANGES

  • P0: 0
  • P1: 1
  • P2: 0 (informational only)

Findings

  • [P1] (confidence: 10/10) src/bigquery_agent_analytics/cli.py:2612 — --threshold is documented as a 0–1 value, but the command passes it directly to LLMAsJudge without checking the range or finiteness. Local CLI reproduction confirmed that -0.1, 1.1, nan, and inf all reach Client.evaluate instead of exiting 2. In particular, --threshold -0.1 --exit-code treats a score of 0.0 as passing and exits 0, which can make the CI gate falsely green even when judging fails. Validate math.isfinite(threshold) and 0.0 <= threshold <= 1.0 before constructing the client/judge, and add unit coverage asserting invalid values exit 2 before any client or BigQuery call.

Verified

  • Client is constructed with the EvalBench mirror table (evalbench_agent_events by default, or the supplied --table-id), and the manifest binding is checked before evaluation.
  • Evaluation uses TraceFilter(experiment_id=job_id, session_ids=<pinned version sessions>, limit=<session count>), preventing retained import versions from mixing.
  • Explicit --import-version requires a published manifest row; omission resolves the latest successful import.
  • --exit-code reuses the existing report.pass_rate < 1.0 gate and _emit_evaluate_failures; success remains exit 0 and handled input/BigQuery failures exit 2.
  • Unit tests use mocked/fake BigQuery clients. Client.evaluate is unchanged, and no scoring engine was added.

Pytest

python3 -m pytest -q tests/test_cli_evalbench_import.py tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py

Result: 172 passed in 3.91s.

What can wait

No P2 findings. Slice 1, slice 2, taxonomy, localization, harnesses, and dashboards remain out of scope and are not blockers for this review.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Kimi

Re-review: PR #453 at c11551e (slice 3, evalbench-score)

Verdict: APPROVE — P0: 0, P1: 0

Previous Codex P1 on 2e4614d — FIXED

--threshold on evalbench-score was not range/finite-checked; nan/inf/out-of-range values could reach the judge and green-gate CI via --exit-code.

Verified at c11551e, not rubber-stamped:

  • src/bigquery_agent_analytics/cli.py:2614-2624 — after the reserved-table check and before with_t(threshold) judge construction, _build_client, and import_sessions:

    if threshold is not None and not (
        math.isfinite(threshold) and 0.0 <= threshold <= 1.0
    ):
        typer.echo("Error: --threshold must be a finite value in [0.0, 1.0] ...", err=True)
        raise typer.Exit(code=2)

    The typer.Exit propagates through the except typer.Exit: raise guard, so it exits 2 rather than being swallowed by the generic except Exception handler. Ordering is exactly as required: no client, no judge, no BigQuery call on the reject path.

  • math import added (cli.py:36). Docstring exit-code list updated to match the new behavior (cli.py:2594-2599).

  • Tests in tests/test_cli_evalbench_score.py:

    • parametrized -0.1, 1.1, nan, inf, -inf → exit 2 with the error message, and spies assert the judge factory, _build_client, and import_sessions were never called;
    • --threshold -0.1 --exit-code still exits 2 (no FAIL lines, no client build) — the green-gate scenario is directly covered;
    • boundaries 0.0 and 1.0 accepted, with the judge's criteria threshold asserted to equal the parsed value.

Note: typer parses "nan"/"inf" into actual float NaN/inf, so the math.isfinite guard is what rejects them — the tests confirm this end-to-end.

New P0/P1 scan at c11551e

import_sessions interpolating manifest["events_table"] into _IMPORT_SESSIONS_QUERY (evalbench.py:2477), with client.query() running before the CLI --table-id compare (cli.py:2644-2652): NOT P1.

  • The interpolated value is not CLI input; it is a column of the dataset's import manifest, written only by EvalBenchRun.materialize, which validates events_table with _validate_destination_table → _validate_source_segment (^[A-Za-z0-9_-]+$) before publishing. Legitimately written manifest rows can never contain backticks or ;.
  • Reaching the interpolation with a hostile value requires write access to the BQAA-owned target dataset (to tamper with the manifest table). An actor with that access can already run arbitrary BigQuery jobs in that project — there is no privilege escalation. This matches the slice-1/2 trust model, which treats committed manifest state as authoritative over self-claims (that is the entire view-authentication design).
  • The subsequent --table-id mismatch raises before client.evaluate runs, so a bound-to-elsewhere version is still refused for scoring; the read-only SELECT DISTINCT session_id executes first, which is the documented "version stays bound to the table it was published to" behavior.
  • Same interpolate-from-manifest pattern already exists in failed_sessions (slice 2); per instructions that is not re-litigated, and this instance is no worse.

A defense-in-depth _validate_source_segment on the manifest read path would be cheap hardening, but it is P3 at most, not a blocker.

Tests

pytest tests/test_cli_evalbench_score.py — 20 passed (3.13s), including the 8 new threshold tests.

Diff scope check

git diff 2e4614d..c11551e touches only src/bigquery_agent_analytics/cli.py (+15/-1) and tests/test_cli_evalbench_score.py (+55). No unrelated churn; slice-1/slice-2 files untouched.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Codex

Verdict

REQUEST_CHANGES

  • P0: 0
  • P1: 1
  • P2: 0 (informational only)

Scope and verification

  • Reviewed the exact fix diff 2e4614d8f751059c79fcfcc88b59fc8fed4e8272..c11551edd910287b6130f61a3c8103343a08fd6a.
  • Read the evalbench-score handler, evalbench.import_sessions and its manifest/query path, tests/test_cli_evalbench_score.py, and tests/test_evalbench_import_sessions.py at HEAD c11551edd910287b6130f61a3c8103343a08fd6a.
  • The prior threshold P1 is fixed. cli.py:2616-2624 requires a finite value in [0.0, 1.0] before judge construction (cli.py:2625), client construction (cli.py:2628), or import_sessions (cli.py:2636). The tests reject -0.1, 1.1, nan, inf, and -inf with exit 2 and no judge/client/import call; the --threshold -0.1 --exit-code regression stays exit 2 with no FAIL output; 0.0 and 1.0 are accepted.

Findings

P1

  1. Stored manifest table ref can execute SQL before validation - src/bigquery_agent_analytics/evalbench.py:2477

    import_sessions() reads manifest["events_table"] as an arbitrary string at line 2469, formats it into the backtick-quoted FROM at line 2477, and submits it with client.query() at line 2481. The CLI does not compare pinned.events_table with the requested --table-id until cli.py:2644-2645, after that query has completed.

    A stored value that closes the identifier and adds semicolon-delimited statements renders as a valid BigQuery script. BigQuery executes semicolon-separated statements as a multi-statement query, and those scripts can contain DML/DDL with side effects (Google Cloud documentation). The normal materialize path validates table segments before writing the manifest, but the read path does not revalidate mutable persisted data.

    This is still P1, not a trusted-manifest non-issue. An attacker needs write access to the manifest, but BigQuery write roles can be scoped to a table or dataset (BigQuery IAM roles); the scoring identity can have broader permissions. The current code therefore allows a manifest writer to make the scorer act as a confused deputy. The deployment may use one equally privileged identity for both roles, which limits impact there, but the repository neither enforces nor documents that invariant.

    Required fix: Before formatting or submitting _IMPORT_SESSIONS_QUERY, require the stored events_table to be a canonical target_project.target_dataset.<validated_table> reference with every segment validated. For the CLI path, compare the stored binding with the requested table before any events-table query, for example by passing the expected reference into import_sessions or by separating manifest resolution from session lookup. Add a regression test with a backtick/semicolon manifest payload and assert that only the manifest lookup occurs and the call exits 2 before any events-table query.

    Confidence: 100. The exact script rendering was reproduced locally without a live BigQuery call, two independent reviewers agreed, and a fresh validation pass confirmed the execution order and missing read-side validation.

Actionable Findings

  • #1 - P1 - src/bigquery_agent_analytics/evalbench.py:2477 - validate the persisted table reference and binding before query submission; add the malicious-manifest fail-before-query test. Route: gated_auto -> downstream-resolver.

Pytest

python3 -m pytest -q tests/test_cli_evalbench_import.py tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py

Result: 180 passed in 3.61s.

Coverage

  • Local correctness and security reviewers independently found #1; the independent validator confirmed it.
  • The cross-model adversarial pass ran on Claude Opus 5 (served model verified; requested high effort, actual effort unverified). It found no threshold-delta defect and independently identified the same manifest-to-SQL path as a residual risk, classifying it outside its narrower parent-to-head diff; the user's explicit slice-3 scope makes it a current P1 here.
  • Previous-feedback verification found the posted threshold P1 fully addressed.
  • No plan was used, so settlement suppression was not evaluated.

What can wait

No P2 findings. Slice 1 / #451, slice 2 / #452, the analogous slice-2 interpolation family, taxonomy, localization, harnesses, and dashboards remain out of scope and are not blockers in this review.


Final verdict

REQUEST_CHANGES. The threshold P1 is fixed, but #1 remains a slice-3 P1. Validate the manifest-bound table reference and reject it before query submission.

Actionable findings: #1 - P1 - src/bigquery_agent_analytics/evalbench.py:2477 - stored manifest identifier reaches executable SQL before validation - gated_auto -> downstream-resolver - suggested fix present - confidence 100.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Codex

Verdict

REQUEST_CHANGES

  • P0: 0
  • P1: 1
  • P2: 0 (informational only)

Scope and verification

  • Reviewed the exact fix diff 2e4614d8f751059c79fcfcc88b59fc8fed4e8272..c11551edd910287b6130f61a3c8103343a08fd6a.
  • Read the evalbench-score handler, evalbench.import_sessions and its manifest/query path, tests/test_cli_evalbench_score.py, and tests/test_evalbench_import_sessions.py at HEAD c11551edd910287b6130f61a3c8103343a08fd6a.
  • The prior threshold P1 is fixed. cli.py:2616-2624 requires a finite value in [0.0, 1.0] before judge construction (cli.py:2625), client construction (cli.py:2628), or import_sessions (cli.py:2636). The tests reject -0.1, 1.1, nan, inf, and -inf with exit 2 and no judge/client/import call; the --threshold -0.1 --exit-code regression stays exit 2 with no FAIL output; 0.0 and 1.0 are accepted.

Findings

P1

  1. Stored manifest table ref can execute SQL before validation - src/bigquery_agent_analytics/evalbench.py:2477

    import_sessions() reads manifest["events_table"] as an arbitrary string at line 2469, formats it into the backtick-quoted FROM at line 2477, and submits it with client.query() at line 2481. The CLI does not compare pinned.events_table with the requested --table-id until cli.py:2644-2645, after that query has completed.

    A stored value that closes the identifier and adds semicolon-delimited statements renders as a valid BigQuery script. BigQuery executes semicolon-separated statements as a multi-statement query, and those scripts can contain DML/DDL with side effects (Google Cloud documentation). The normal materialize path validates table segments before writing the manifest, but the read path does not revalidate mutable persisted data.

    This is still P1, not a trusted-manifest non-issue. An attacker needs write access to the manifest, but BigQuery write roles can be scoped to a table or dataset (BigQuery IAM roles); the scoring identity can have broader permissions. The current code therefore allows a manifest writer to make the scorer act as a confused deputy. The deployment may use one equally privileged identity for both roles, which limits impact there, but the repository neither enforces nor documents that invariant.

    Required fix: Before formatting or submitting _IMPORT_SESSIONS_QUERY, require the stored events_table to be a canonical target_project.target_dataset.<validated_table> reference with every segment validated. For the CLI path, compare the stored binding with the requested table before any events-table query, for example by passing the expected reference into import_sessions or by separating manifest resolution from session lookup. Add a regression test with a backtick/semicolon manifest payload and assert that only the manifest lookup occurs and the call exits 2 before any events-table query.

    Confidence: 100. The exact script rendering was reproduced locally without a live BigQuery call, two independent reviewers agreed, and a fresh validation pass confirmed the execution order and missing read-side validation.

Actionable Findings

  • #1 - P1 - src/bigquery_agent_analytics/evalbench.py:2477 - validate the persisted table reference and binding before query submission; add the malicious-manifest fail-before-query test. Route: gated_auto -> downstream-resolver.

Pytest

python3 -m pytest -q tests/test_cli_evalbench_import.py tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py

Result: 180 passed in 3.61s.

Coverage

  • Local correctness and security reviewers independently found #1; the independent validator confirmed it.
  • The cross-model adversarial pass ran on Claude Opus 5 (served model verified; requested high effort, actual effort unverified). It found no threshold-delta defect and independently identified the same manifest-to-SQL path as a residual risk, classifying it outside its narrower parent-to-head diff; the user's explicit slice-3 scope makes it a current P1 here.
  • Previous-feedback verification found the posted threshold P1 fully addressed.
  • No plan was used, so settlement suppression was not evaluated.

What can wait

No P2 findings. Slice 1 / #451, slice 2 / #452, the analogous slice-2 interpolation family, taxonomy, localization, harnesses, and dashboards remain out of scope and are not blockers in this review.


Final verdict

REQUEST_CHANGES. The threshold P1 is fixed, but #1 remains a slice-3 P1. Validate the manifest-bound table reference and reject it before query submission.

Actionable findings: #1 - P1 - src/bigquery_agent_analytics/evalbench.py:2477 - stored manifest identifier reaches executable SQL before validation - gated_auto -> downstream-resolver - suggested fix present - confidence 100.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Kimi

PR #453 re-review (slice 3) — head cf3fa84

Verdict: APPROVE

The Codex P1 on c11551e (confused-deputy: persisted manifest events_table interpolated into _IMPORT_SESSIONS_QUERY and submitted before the --table-id compare) is genuinely fixed, and I found no new P0/P1 in the diff c11551e..cf3fa84 or the surrounding slice-3 code.

Scope honored: slice 3 only; slice-2 failed_sessions interpolation (evalbench.py:2306) was not re-litigated.

Codex P1 — requirement-by-requirement

1. Validate persisted events_table as canonical target_project.target_dataset.<validated_table> BEFORE formatting/submitting — FIXED.

New _validate_manifest_events_table (evalbench.py:3101-3144) treats the stored value as untrusted: non-empty string, exactly three .-separated segments, table segment through _validate_destination_table (charset [A-Za-z0-9_-]+, case-insensitive rejection of reserved agent_events), and exact equality of the project/dataset segments against the already-_validate_source_segment-validated targets. It runs at evalbench.py:2489 — after _resolve_manifest (whose only BigQuery call is the parameterized manifest lookup) and before _IMPORT_SESSIONS_QUERY.format(...) (evalbench.py:2509) and client.query. A closed backtick, ;, or cross-project/dataset reference cannot survive: any such character fails either the segment count or the charset/equality checks, and the raise happens before the query string is even built.

2. Compare stored binding with requested --table-id BEFORE any events-table query — FIXED.

import_sessions gains an optional events_table parameter (evalbench.py:2441). When given, the expected name is validated (_validate_destination_table) and expanded to the canonical ref before any BigQuery call — including the manifest lookup (evalbench.py:2476-2480); the binding-vs-requested compare (evalbench.py:2496-2500) runs after the manifest lookup but before the session query. evalbench-score passes --table-id through (cli.py:2642), so the mismatch now exits 2 before the events table is touched instead of after. The pre-existing post-pin compare in the CLI (cli.py:2647-2653) remains as a documented second line of defense, which is fine.

Verified that nothing queries BigQuery before this gate on the CLI path: _build_client (cli.py:97-117) constructs Client(verify_schema=False) — no network call.

3. Regression tests with hostile payloads asserting only the manifest lookup occurs — PRESENT and MEANINGFUL.

  • tests/test_evalbench_import_sessions.py: parametrized over 11 hostile values plus None and 7 — backtick-close + DROP TABLE, ; SELECT 1, cross-project, cross-dataset, 1/2/4-segment refs, reserved agent_events/AGENT_EVENTS, empty string — asserting ValueError, exactly one client call, that call targeting the manifest, and no SELECT DISTINCT session_id statement. Separate tests cover the pinned-version path, the expected-table mismatch (asserting only the manifest lookup ran), the expected-table happy path, and caller-side events_table validation with zero client calls.
  • tests/test_cli_evalbench_score.py: a recording fake BQ client drives the real import_sessions through the CLI with four hostile stored values (including the multi-statement payload and cross-project ref), asserting exit 2, events_table in the error output, exactly one query (the manifest lookup), no events-table statement, and client.evaluate never called. A second test pins that --table-id actually reaches import_sessions.

These are real regression tests, not shape-checks: they would fail on c11551e.

New-issue sweep (P0/P1 only)

  • Importer compatibility: materialize writes the manifest's events_table as the canonical FQDN ("events_table": events_ref, evalbench.py:1038), so the new three-segment validation does not break legitimate scoring of existing imports.
  • scores_table is still read from the manifest unvalidated (evalbench.py:2517) but is never interpolated into a query in import_sessions and is unused by the CLI — informational field only. Not a P1.
  • TOCTOU between manifest read and session query: the validated ref is constrained to target_project.target_dataset.<safe-name>, so the worst case is a read-only query against another mirror table in the scored dataset. Not a P1.
  • Error-message content: mismatch messages echo the stored and expected refs to stderr; both are charset-validated by that point or the message is a validation failure. No injection surface.
  • The diff is minimal (4 files, +291/-1, mostly tests) and touches nothing outside slice 3.

Tests

Independently re-ran (worktree src shadowing the main-repo editable install via PYTHONPATH, verified the imported package resolves to the worktree):

python3 -m pytest -q tests/test_cli_evalbench_import.py tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py
205 passed, 2 warnings in 1.78s

Matches the implementer's report of 205 passed.

P0 = 0, P1 = 0. Approve.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Kimi

PR #453 re-review (slice 3) — head cf3fa84

Verdict: APPROVE

The Codex P1 on c11551e (confused-deputy: persisted manifest events_table interpolated into _IMPORT_SESSIONS_QUERY and submitted before the --table-id compare) is genuinely fixed, and I found no new P0/P1 in the diff c11551e..cf3fa84 or the surrounding slice-3 code.

Scope honored: slice 3 only; slice-2 failed_sessions interpolation (evalbench.py:2306) was not re-litigated.

Codex P1 — requirement-by-requirement

1. Validate persisted events_table as canonical target_project.target_dataset.<validated_table> BEFORE formatting/submitting — FIXED.

New _validate_manifest_events_table (evalbench.py:3101-3144) treats the stored value as untrusted: non-empty string, exactly three .-separated segments, table segment through _validate_destination_table (charset [A-Za-z0-9_-]+, case-insensitive rejection of reserved agent_events), and exact equality of the project/dataset segments against the already-_validate_source_segment-validated targets. It runs at evalbench.py:2489 — after _resolve_manifest (whose only BigQuery call is the parameterized manifest lookup) and before _IMPORT_SESSIONS_QUERY.format(...) (evalbench.py:2509) and client.query. A closed backtick, ;, or cross-project/dataset reference cannot survive: any such character fails either the segment count or the charset/equality checks, and the raise happens before the query string is even built.

2. Compare stored binding with requested --table-id BEFORE any events-table query — FIXED.

import_sessions gains an optional events_table parameter (evalbench.py:2441). When given, the expected name is validated (_validate_destination_table) and expanded to the canonical ref before any BigQuery call — including the manifest lookup (evalbench.py:2476-2480); the binding-vs-requested compare (evalbench.py:2496-2500) runs after the manifest lookup but before the session query. evalbench-score passes --table-id through (cli.py:2642), so the mismatch now exits 2 before the events table is touched instead of after. The pre-existing post-pin compare in the CLI (cli.py:2647-2653) remains as a documented second line of defense, which is fine.

Verified that nothing queries BigQuery before this gate on the CLI path: _build_client (cli.py:97-117) constructs Client(verify_schema=False) — no network call.

3. Regression tests with hostile payloads asserting only the manifest lookup occurs — PRESENT and MEANINGFUL.

  • tests/test_evalbench_import_sessions.py: parametrized over 11 hostile values plus None and 7 — backtick-close + DROP TABLE, ; SELECT 1, cross-project, cross-dataset, 1/2/4-segment refs, reserved agent_events/AGENT_EVENTS, empty string — asserting ValueError, exactly one client call, that call targeting the manifest, and no SELECT DISTINCT session_id statement. Separate tests cover the pinned-version path, the expected-table mismatch (asserting only the manifest lookup ran), the expected-table happy path, and caller-side events_table validation with zero client calls.
  • tests/test_cli_evalbench_score.py: a recording fake BQ client drives the real import_sessions through the CLI with four hostile stored values (including the multi-statement payload and cross-project ref), asserting exit 2, events_table in the error output, exactly one query (the manifest lookup), no events-table statement, and client.evaluate never called. A second test pins that --table-id actually reaches import_sessions.

These are real regression tests, not shape-checks: they would fail on c11551e.

New-issue sweep (P0/P1 only)

  • Importer compatibility: materialize writes the manifest's events_table as the canonical FQDN ("events_table": events_ref, evalbench.py:1038), so the new three-segment validation does not break legitimate scoring of existing imports.
  • scores_table is still read from the manifest unvalidated (evalbench.py:2517) but is never interpolated into a query in import_sessions and is unused by the CLI — informational field only. Not a P1.
  • TOCTOU between manifest read and session query: the validated ref is constrained to target_project.target_dataset.<safe-name>, so the worst case is a read-only query against another mirror table in the scored dataset. Not a P1.
  • Error-message content: mismatch messages echo the stored and expected refs to stderr; both are charset-validated by that point or the message is a validation failure. No injection surface.
  • The diff is minimal (4 files, +291/-1, mostly tests) and touches nothing outside slice 3.

Tests

Independently re-ran (worktree src shadowing the main-repo editable install via PYTHONPATH, verified the imported package resolves to the worktree):

python3 -m pytest -q tests/test_cli_evalbench_import.py tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py
205 passed, 2 warnings in 1.78s

Matches the implementer's report of 205 passed.

P0 = 0, P1 = 0. Approve.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Codex

PR 453 re-review

Verdict: LGTM
Scope: Slice 3 only, commit range c11551edd910287b6130f61a3c8103343a08fd6a..cf3fa8482e674b387d37ca780bb26f903d14d007
Mode: Markdown report-only; nothing posted to GitHub and no repository changes made.

Counts

Severity Count
P0 0
P1 0
P2 0 (informational only)

Findings

None.

Prior P1 re-check

The manifest-table confused-deputy P1 is fixed.

  • src/bigquery_agent_analytics/evalbench.py:2476 validates the optional expected mirror table before client creation or any BigQuery call.
  • src/bigquery_agent_analytics/evalbench.py:2489 revalidates the stored manifest value immediately after the manifest lookup. The validator at src/bigquery_agent_analytics/evalbench.py:3102 requires exactly three segments, validates the table segment with _validate_destination_table, rejects the reserved agent_events table, and requires the stored project and dataset to equal the scored target.
  • src/bigquery_agent_analytics/evalbench.py:2496 compares the validated stored binding with the caller's expected mirror table before the session query is formatted at src/bigquery_agent_analytics/evalbench.py:2509 or submitted at src/bigquery_agent_analytics/evalbench.py:2513.
  • src/bigquery_agent_analytics/cli.py:2640 passes --table-id into import_sessions, so the production CLI path performs the binding check before any events-table query. The later comparison remains a second defense.
  • tests/test_evalbench_import_sessions.py:253 covers hostile, cross-project/dataset, noncanonical, reserved, empty, and non-string stored values. It asserts one manifest lookup and no session query. tests/test_evalbench_import_sessions.py:299 covers an expected-table mismatch before the events-table read, and tests/test_evalbench_import_sessions.py:336 covers invalid expected tables before any query.
  • tests/test_cli_evalbench_score.py:270 verifies --table-id propagation. tests/test_cli_evalbench_score.py:307 drives hostile manifest values through the real import_sessions path and verifies exit 2, exactly one manifest query, no SELECT DISTINCT session_id, and no evaluation.

Pytest

Command:

python3 -m pytest -q tests/test_cli_evalbench_import.py tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py

Result: 205 passed in 3.99s.

What can wait

Additional defense-in-depth for other manifest fields, CLI flag-name wording, and one more end-to-end real-import mismatch test are P2/P3-level follow-ups. They are not counted as findings in this P0/P1-only pass because none leaves the reported SQL injection/confused-deputy path open.

Coverage

  • Reviewers: correctness, testing, security, maintainability, and prior-comments verification.
  • Independent adversarial pass: cross_model_route=claude; model_requested=claude-opus-5; model_actual=claude-opus-5; effort_requested=high; effort_actual=unverified; receipt_supported=true; independence_verified=true.
  • Project standards: not run because no applicable CODING_STANDARDS.md, CLAUDE.md, or AGENTS.md file governs the changed files.
  • Requirements settlement: not evaluated because no plan artifact was found.
  • Validator batch: not run because no P0/P1 or actionable findings survived synthesis.
  • Suppressed or malformed findings: 0.
  • Working tree remained clean at HEAD cf3fa8482e674b387d37ca780bb26f903d14d007.

Actionable Findings

None.


Verdict: LGTM (Ready to merge)

Reasoning: The persisted manifest table is now validated and target-bound before SQL formatting or submission, the CLI supplies its expected table before the events read, and the required hostile-payload regressions pass. No P0 or P1 remains.

Fix order: None.

Actionable findings: none.

@caohy1988
caohy1988 force-pushed the feat/435-evalbench-score branch from cf3fa84 to 77f1a85 Compare August 30, 2026 15:09

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Kimi

Re-review: PR 453 rebase — 77f1a85 onto PR 451 merge 2459c0f / PR 452 head d681d54

Verdict: APPROVE

No remaining P0. No remaining P1. P2s not assessed as blockers per instructions.

Rebase integrity (the only thing that changed since cf3fa84)

  • Tree-identical to the dual-approved head. git rev-parse cf3fa84^{tree} 77f1a85^{tree} both return bb904e6acad62cb91748c717e0d9b3826cc57ca5. The rebase changed commit SHAs/parents only — zero content drift from what Kimi and Codex approved on cf3fa84.
  • Parent chain is correct: 77f1a85 → 088d56d → 26019be → d681d54 (PR 452 head) → … → 2459c0f (PR 451 merge). Both stated bases are ancestors of the new head.
  • Scope held: git diff --stat d681d54..77f1a85 touches exactly 7 files, all slice-3: src/bigquery_agent_analytics/cli.py, src/bigquery_agent_analytics/evalbench.py, tests/test_cli_evalbench_score.py, tests/test_evalbench_import_sessions.py, docs/evalbench.md, examples/evalbench_score_gate.sh, CHANGELOG.md. No slice-2 files touched; failed_sessions interpolation not re-litigated.
  • No conflict markers in evalbench.py / cli.py.

Prior P1 fixes — confirmed still holding at 77f1a85

  1. --threshold validation (088d56d, cli.py:2614-2624): rejects non-finite and out-of-[0.0, 1.0] thresholds with exit 2 before judge/client construction. Present, unchanged. Boundaries 0.0/1.0 and omitted default pass through.
  2. Manifest events_table revalidation (77f1a85):
    • _validate_manifest_events_table() (evalbench.py:3102-3143) requires exactly 3 segments, table segment through _validate_destination_table (charset + reserved agent_events), project/dataset pinned to the scored target — raises before any events-table statement is built. Closes the confused-deputy multi-statement vector Codex flagged on c11551e.
    • import_sessions(events_table=...) validates the expected mirror table before any BigQuery call; mismatch with the manifest raises after the manifest lookup, before the session query. --table-id is threaded through from the CLI; post-pin comparison retained as second line of defense.

Tests

Re-run independently in the slice-3 worktree at 77f1a85:

.venv/bin/python -m pytest -q tests/test_cli_evalbench_import.py \
  tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py \
  tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py
→ 205 passed in 10.61s

Matches the 205-passed count from the cf3fa84 review.

Environment note (not a PR issue)

uv sync --frozen in this worktree fails building cryptography==50.0.1 from sdist (missing x86_64-apple-darwin Rust target on this host). Worked around with uv pip install --only-binary :all: -e . pytest pytest-mock. Local toolchain gap only — no action requested on the PR.

New P0/P1 from the rebase

None. Identical tree to a previously approved head + green tests + correct parentage = nothing new to block on.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Kimi

Re-review: PR 453 rebase — 77f1a85 onto PR 451 merge 2459c0f / PR 452 head d681d54

Verdict: APPROVE

No remaining P0. No remaining P1. P2s not assessed as blockers per instructions.

Rebase integrity (the only thing that changed since cf3fa84)

  • Tree-identical to the dual-approved head. git rev-parse cf3fa84^{tree} 77f1a85^{tree} both return bb904e6acad62cb91748c717e0d9b3826cc57ca5. The rebase changed commit SHAs/parents only — zero content drift from what Kimi and Codex approved on cf3fa84.
  • Parent chain is correct: 77f1a85 → 088d56d → 26019be → d681d54 (PR 452 head) → … → 2459c0f (PR 451 merge). Both stated bases are ancestors of the new head.
  • Scope held: git diff --stat d681d54..77f1a85 touches exactly 7 files, all slice-3: src/bigquery_agent_analytics/cli.py, src/bigquery_agent_analytics/evalbench.py, tests/test_cli_evalbench_score.py, tests/test_evalbench_import_sessions.py, docs/evalbench.md, examples/evalbench_score_gate.sh, CHANGELOG.md. No slice-2 files touched; failed_sessions interpolation not re-litigated.
  • No conflict markers in evalbench.py / cli.py.

Prior P1 fixes — confirmed still holding at 77f1a85

  1. --threshold validation (088d56d, cli.py:2614-2624): rejects non-finite and out-of-[0.0, 1.0] thresholds with exit 2 before judge/client construction. Present, unchanged. Boundaries 0.0/1.0 and omitted default pass through.
  2. Manifest events_table revalidation (77f1a85):
    • _validate_manifest_events_table() (evalbench.py:3102-3143) requires exactly 3 segments, table segment through _validate_destination_table (charset + reserved agent_events), project/dataset pinned to the scored target — raises before any events-table statement is built. Closes the confused-deputy multi-statement vector Codex flagged on c11551e.
    • import_sessions(events_table=...) validates the expected mirror table before any BigQuery call; mismatch with the manifest raises after the manifest lookup, before the session query. --table-id is threaded through from the CLI; post-pin comparison retained as second line of defense.

Tests

Re-run independently in the slice-3 worktree at 77f1a85:

.venv/bin/python -m pytest -q tests/test_cli_evalbench_import.py \
  tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py \
  tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py
→ 205 passed in 10.61s

Matches the 205-passed count from the cf3fa84 review.

Environment note (not a PR issue)

uv sync --frozen in this worktree fails building cryptography==50.0.1 from sdist (missing x86_64-apple-darwin Rust target on this host). Worked around with uv pip install --only-binary :all: -e . pytest pytest-mock. Local toolchain gap only — no action requested on the PR.

New P0/P1 from the rebase

None. Identical tree to a previously approved head + green tests + correct parentage = nothing new to block on.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Codex

Code Review Results

Scope: PR 453 slice 3 only, d681d548519c94b25072088cf898680d43e9bb8f -> 77f1a85a7073bd59527aaf5c5cd8723a27e66eb0. Reviewed evalbench-score in cli.py, import_sessions and its direct support code in evalbench.py, and the two dedicated test files.

Intent: Confirm that the rebase onto current PR 452, including PR 451 merge 2459c0f, preserved the previously approved slice-3 behavior and introduced no new P0/P1 defect.

Mode: Report-only P0/P1 re-review. No GitHub action or repository mutation was performed.

Reviewers: correctness, security, testing, reliability, performance, maintainability, previous-feedback, and agent-native.

Findings

No P0 or P1 findings.

Actionable Findings

None.

Coverage

  • Head and ancestry: the worktree and PR 453 both resolve to 77f1a85a7073bd59527aaf5c5cd8723a27e66eb0; PR 452 resolves to d681d548519c94b25072088cf898680d43e9bb8f; PR 451 merge 2459c0f is an ancestor of that base.
  • Rebase integrity: git range-diff matched all three slice-3 commits one-for-one, and all three stable patch IDs match the previously approved series ending at cf3fa84.
  • Content integrity: old approved head cf3fa84 and new head 77f1a85 have the same repository tree object, bb904e6acad62cb91748c717e0d9b3826cc57ca5. The rebase changed ancestry and commit SHAs, not file contents.
  • Implementation review: the CLI validates evaluator, destination table, and finite threshold before evaluation; import_sessions revalidates the manifest table reference before formatting the events query; the resulting TraceFilter fails closed on an empty session set and pins both the job and exact versioned session IDs.
  • Prior feedback: no previously approved P0/P1 fix was lost in the rebase.
  • Independent validation: one reviewer proposed failing whenever Client.evaluate successfully uses its documented API fallback. A fresh validator rejected that candidate because fallback is an intentional, auditable success mode inherited by this thin wrapper. It is not counted as a finding or test gap.
  • Cross-model adversarial coverage: requested claude-opus-5 at high reasoning through the Claude CLI. The job timed out without a usable artifact, so no cross-model agreement was credited and this coverage is recorded as degraded.
  • Project standards: not run because no applicable CODING_STANDARDS.md, CLAUDE.md, or AGENTS.md governs the scoped files.
  • Plan settlement checks: no applicable plan was discovered.
  • Explicit exclusions: slice-2 failed_sessions interpolation and all P2/P3 nits were not reviewed as blockers.
  • Pytest: python3 -m pytest -q tests/test_cli_evalbench_import.py tests/test_cli_evalbench_failed_sessions.py tests/test_cli_evalbench_score.py tests/test_evalbench_importer.py tests/test_evalbench_import_sessions.py -> 205 passed in 3.82s.

Verdict

LGTM

P0 count: 0

P1 count: 0

Pytest result: 205 passed in 3.82s

Reasoning: The rebased head is content-identical to the previously approved head, the current stacked ancestry is correct, the scoped implementation remains fail-closed at its manifest and session boundaries, and the required tests pass.

Actionable findings: none.

…lbench-score

`evalbench-score --threshold` accepted any float, so `-0.1`, `1.1`, `nan`,
and `inf` reached judge construction and `Client.evaluate`; with
`--exit-code`, a negative threshold made every session pass and could
green-gate CI. Validate the value is finite and within [0.0, 1.0] before
the judge or client is built, exiting 2 with an `Error:` line like the
other invalid-input paths. Boundaries 0.0 and 1.0 and the omitted default
are unchanged.
…ssions queries it

import_sessions() formatted manifest["events_table"] straight into
_IMPORT_SESSIONS_QUERY and submitted it before evalbench-score compared the
stored binding with --table-id. The manifest is written by the importer and
read under the scorer's identity, so a persisted value that closed the
identifier and appended statements could run as a multi-statement script
(confused deputy; Codex P1 on c11551e).

- _validate_manifest_events_table(): the stored value must be exactly
  target_project.target_dataset.<table> with the table segment passing
  _validate_destination_table (charset + reserved agent_events); anything
  else raises before any events-table statement is built.
- import_sessions(events_table=...): optional expected mirror table,
  validated before any BigQuery call; a mismatch with the manifest raises
  after the manifest lookup and before the session query.
- evalbench-score passes --table-id through; the post-pin comparison stays
  as a second line of defense.
- Regression tests: hostile backtick/semicolon, cross-project/dataset,
  non-canonical and reserved payloads at both the library and CLI level
  assert a ValueError / exit 2 with only the manifest lookup submitted.
@caohy1988
caohy1988 force-pushed the feat/435-evalbench-score branch from 77f1a85 to 186c5e7 Compare August 30, 2026 16:06
@haiyuan-eng-google
haiyuan-eng-google merged commit a18ee18 into GoogleCloudPlatform:main Aug 30, 2026
15 checks passed

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: Kimi

Re-review: PR 453 post-rebase onto main @ 2779b7e (PR 452 squash)

Verdict: APPROVE — P0 = 0, P1 = 0. No new findings from the rebase; prior P1 fixes confirmed still in place.

Scope & method

  • HEAD: 186c5e7 — 3 commits on top of 2779b7e (PR 452 squash merge); merge-base verified as exactly 2779b7e.
  • Slice 3 only vs new main; slice-2 failed_sessions not re-litigated.
  • Diff vs 2779b7e: 7 files, +1456/−4 — cli.py, evalbench.py, CHANGELOG.md, docs/evalbench.md, examples/evalbench_score_gate.sh, tests/test_cli_evalbench_score.py, tests/test_evalbench_import_sessions.py. No slice-2 files touched.

Rebase integrity — zero drift (strongest possible signal)

git rev-parse 77f1a85^{tree} 186c5e7^{tree} → both are bb904e6a…. The rebased HEAD is byte-identical to the previously dual-approved 77f1a85. No conflict-resolution edits, no content drift; the old approvals' code analysis carries over in full, and the slice-2 content in the tree now comes from main's 2779b7e unchanged.

Tests (re-run independently, worktree .venv, pytest 9.1.1)

python3 -m pytest -q tests/test_cli_evalbench_import.py \
  tests/test_cli_evalbench_failed_sessions.py \
  tests/test_cli_evalbench_score.py \
  tests/test_evalbench_importer.py \
  tests/test_evalbench_import_sessions.py
→ 205 passed, 1 warning in 1.26s

Same 205-pass count as the approved review; includes the slice-2 failed_sessions CLI tests against the squashed base.

Prior P1 fixes — both still hold

  • 71e5ec0 threshold guard: evalbench-score rejects non-finite / out-of-[0.0, 1.0] --threshold with exit 2 before any BigQuery call (cli.py, math.isfinite check). Present and covered by tests.
  • 186c5e7 manifest events_table revalidation: _validate_manifest_events_table treats the persisted manifest value as untrusted — requires a canonical 3-segment project.dataset.table, re-runs _validate_destination_table on the table segment (charset + reserved agent_events rejection), and requires project/dataset equality with the already-validated target_project/target_dataset. Because the caller-supplied segments pass _validate_source_segment first, the equality check closes any injection/cross-dataset path; the formatted _IMPORT_SESSIONS_QUERY can only ever contain validated-segment references. Sound.

New-P0/P1 sweep on the rebased tree (spot re-checks)

  • Version pin correctness: TraceFilter(experiment_id=job_id, session_ids=…, limit=count); versioned session identities can't collide across retained versions; empty session set raises instead of silently widening to all versions (CLI maps to exit 2, documented).
  • CLI consistency: _LLM_JUDGES, _build_client, format_output, _emit_evaluate_failures reused from evaluate; exit codes 0/1/2 match docs and the gate script's comments; --table-id mismatch with the manifest binding raises before the events table is queried (with a second defense-in-depth check on the returned pin).
  • report.details["evalbench"] in-place dict mutation matches existing codebase usage (feedback.py, trace_evaluator.py).
  • CHANGELOG keeps both the 452 (failed-session view) and 453 (evalbench-score) entries, correctly ordered; docs/evalbench.md removes the stale "There is no evalbench-score command" line and documents the new command, exit codes, and trace_filter() semantics.
  • examples/evalbench_score_gate.sh: set -euo pipefail, required-env guards, passes --exit-code; consistent with documented behavior.

P2 (non-blocking, noted only)

None worth recording beyond what prior rounds already covered.

Approve.

caohy1988 added a commit to caohy1988/BQAA-SDK-fork that referenced this pull request Aug 30, 2026
… bullet

Addresses Codex review 5061312355 on GoogleCloudPlatform#454 (two P1s):
- docs/agentforensics_mvp_plan.md: PRs GoogleCloudPlatform#451, GoogleCloudPlatform#452, GoogleCloudPlatform#453 are all merged on
  main (2459c0f, 2779b7e, a18ee18); the status list no longer calls
  452/453 open.
- CHANGELOG.md: add the missing Unreleased/Added bullet for GoogleCloudPlatform#451
  (materialize() versioned snapshots + W0.4 failed-session contract),
  above the existing slice-2 and slice-3 bullets.
caohy1988 added a commit to caohy1988/BQAA-SDK-fork that referenced this pull request Aug 30, 2026
…ons → score (GoogleCloudPlatform#435, GoogleCloudPlatform#97)

Slice 5: `examples/evalbench_mvp_e2e.sh` walks `bq-agent-sdk
evalbench-import` → `evalbench-failed-sessions` → `evalbench-score` in
order on one EvalBench job, one banner per step, driven by `BQ_AGENT_*` /
`EVALBENCH_*` environment variables (optional `EVALBENCH_IMPORT_VERSION`
pins all three steps). `--fixture` / `EVALBENCH_FIXTURE=1` never touches
BigQuery or the live CLI and prints annotated sample output (import
result with manifest + failed_sessions_view, a failed-sessions table, a
score report with details.evalbench), exit 0, so the demo is recordable
and CI-safe.

`examples/evalbench_mvp_e2e.md` explains each step, what to expect, env
vars, fixture vs live, and gemini-cli-tools as the intended job family.
Pointers in docs/evalbench.md and examples/README.md; CHANGELOG bullet.
`tests/test_evalbench_mvp_e2e.py` runs the fixture path via subprocess.

No Python/CLI behavior changes; examples/evalbench_score_gate.sh stays
the CI gate. Stacked on GoogleCloudPlatform#453 (evalbench-score) over merged GoogleCloudPlatform#452.
caohy1988 added a commit to caohy1988/BQAA-SDK-fork that referenced this pull request Aug 30, 2026
…ons → score (GoogleCloudPlatform#435, GoogleCloudPlatform#97)

Slice 5: `examples/evalbench_mvp_e2e.sh` walks `bq-agent-sdk
evalbench-import` → `evalbench-failed-sessions` → `evalbench-score` in
order on one EvalBench job, one banner per step, driven by `BQ_AGENT_*` /
`EVALBENCH_*` environment variables (optional `EVALBENCH_IMPORT_VERSION`
pins all three steps). `--fixture` / `EVALBENCH_FIXTURE=1` never touches
BigQuery or the live CLI and prints annotated sample output (import
result with manifest + failed_sessions_view, a failed-sessions table, a
score report with details.evalbench), exit 0, so the demo is recordable
and CI-safe.

`examples/evalbench_mvp_e2e.md` explains each step, what to expect, env
vars, fixture vs live, and gemini-cli-tools as the intended job family.
Pointers in docs/evalbench.md and examples/README.md; CHANGELOG bullet.
`tests/test_evalbench_mvp_e2e.py` runs the fixture path via subprocess.

No Python/CLI behavior changes; examples/evalbench_score_gate.sh stays
the CI gate. Stacked on GoogleCloudPlatform#453 (evalbench-score) over merged GoogleCloudPlatform#452.
haiyuan-eng-google pushed a commit that referenced this pull request Aug 30, 2026
…→ score (#435, #97) (#455)

* docs(evalbench): add recordable MVP e2e demo of import → failed-sessions → score (#435, #97)

Slice 5: `examples/evalbench_mvp_e2e.sh` walks `bq-agent-sdk
evalbench-import` → `evalbench-failed-sessions` → `evalbench-score` in
order on one EvalBench job, one banner per step, driven by `BQ_AGENT_*` /
`EVALBENCH_*` environment variables (optional `EVALBENCH_IMPORT_VERSION`
pins all three steps). `--fixture` / `EVALBENCH_FIXTURE=1` never touches
BigQuery or the live CLI and prints annotated sample output (import
result with manifest + failed_sessions_view, a failed-sessions table, a
score report with details.evalbench), exit 0, so the demo is recordable
and CI-safe.

`examples/evalbench_mvp_e2e.md` explains each step, what to expect, env
vars, fixture vs live, and gemini-cli-tools as the intended job family.
Pointers in docs/evalbench.md and examples/README.md; CHANGELOG bullet.
`tests/test_evalbench_mvp_e2e.py` runs the fixture path via subprocess.

No Python/CLI behavior changes; examples/evalbench_score_gate.sh stays
the CI gate. Stacked on #453 (evalbench-score) over merged #452.

* feat(evalbench): --synth builds the MVP e2e job from real agent traces (#435, #97)

examples/evalbench_mvp_e2e.sh --synth (or EVALBENCH_SYNTH=1) adds a step 0
before import → failed-sessions → score: examples/evalbench_synth_from_traces.py
folds a real BQAA agent_events table into EvalBench-shaped configs/results/
scores tables, one scenario per session. Every prompt and response is the
session's real USER_MESSAGE_RECEIVED / AGENT_RESPONSE text; sessions without
a prompt are skipped, never invented. The only synthesized value is
goal_completion = 1.0 when the session reached AGENT_COMPLETED, else 0.0.
Rows are deterministic so a re-run reproduces the importer's fingerprints
(status: unchanged). Defaults target bqaa_e2e_real.agent_events →
bqaa_evalbench_mvp_demo → bqaa_evalbench_mvp_mirror, job mvp-e2e-real-traces,
and the script refuses to write into the source or agent_analytics datasets.

--fixture stays offline. tests/test_evalbench_synth_from_traces.py exercises
the mapping on stubbed events and round-trips the rows through
EvalBenchRun.to_agent_event_rows / to_score_rows; the fixture tests gain two
offline --synth guards. Recorded live run on test-project-0728-467323:
77 events → 7 scenarios (6 completed, 1 stuck), 27 mirrored events, one
failed session listed, judge over all 7 pinned sessions.

* fix(evalbench): synth groups on full trace identity, reads LLM_RESPONSE, validates identifiers (#435, #97)

Addresses the three Codex P1 findings on PR #455 (2e5a7f4):

- LLM_RESPONSE is folded as the real-response event (the SDK contract in
  event_semantics.RESPONSE_EVENT_TYPES); AGENT_RESPONSE stays as a
  compatibility alias. An ordinary USER_MESSAGE_RECEIVED -> LLM_RESPONSE ->
  contentless AGENT_COMPLETED trace now yields final_response/stdout
  instead of a completed-but-never-answered row.
- Traces are grouped on the full BQAA identity
  (session_id, user_id, root_agent_name), matching Client.list_traces,
  so a reused session id can no longer splice user A's prompt onto user
  B's answer. The reader selects user_id and root_agent_name; scenario
  ids escalate short -> full session id -> session_id:user_id:root_agent_name
  until unique; results/scores carry source_user_id/source_root_agent_name.
- --source-table, --project, --evalbench-dataset and --mirror-dataset are
  validated segment by segment against ^[A-Za-z0-9_-]+$ before the
  BigQuery client is created or any SQL is formatted; load_events
  re-validates for direct callers.

Regression tests: LLM_RESPONSE + contentless AGENT_COMPLETED, AGENT_RESPONSE
alias, three identities sharing one session id (through the importer),
hostile identifiers rejected before client.query() with a fake client and
before bigquery.Client() is constructed. Docs and CHANGELOG updated.

* fix(evalbench): exact-string trace identity and injective scenario ids in --synth (#435, #97)

Codex round-2 P1s on PR #455:

- Identity dimensions (session_id, user_id, root_agent_name) are now read
  as exact strings via _identity_text(), matching the SDK's TraceIdentity:
  whitespace is preserved and SQL NULL stays distinct from "". _text()
  trimming applies to content fields only, so a NULL-user trace and an
  empty-string-user trace on the same session can no longer be spliced
  into one scenario.
- The full-identity scenario id is now injective: components are
  percent-escaped (% -> %25, : -> %3A, ~ -> %7E) and NULL is written as ~,
  so ("shared","a:b","c") and ("shared","a","b:c") get distinct ids
  instead of colliding and aborting. Blank candidate ids are skipped
  because the importer rejects them.

Regressions cover NULL-vs-empty and whitespace-distinct identities
(prompts/responses stay paired, importer sessions stay separate) and
delimiter-bearing identities through EvalBenchRun.to_agent_event_rows().
Docs and CHANGELOG describe the encoding.

* docs(evalbench): tell the widget-stock session story in the MVP e2e demo (#435, #97)

The --fixture walkthrough of examples/evalbench_mvp_e2e.sh now follows one
real failed session instead of touring CLI flags: support_agent session
7e352c34 ("How many widgets are in stock?", trace stops after
AGENT_STARTING, no answer) through import -> its one failed_sessions row
-> score, ending on the punchline goal_completion=0.0. Fixture defaults
now match the --synth run (job mvp-e2e-real-traces, 7 scenarios, 1
failed). Each story beat keeps its `=== Step N ===` banner so the live
and --synth paths and their early-exit tests are unchanged.

tests/test_evalbench_mvp_e2e.py asserts the six beats in order and the
session's fields; the md leads with the session and moves the env-var
reference after it; README/docs pointers and a CHANGELOG bullet follow.

* fix(evalbench): completed source errors stay failed sessions in --synth (#435, #97)

A trace that reached AGENT_COMPLETED with a non-tool status=ERROR or an
error_message was folded into results.error_message only, which
EvalBenchRun._source_error_fields() does not read, so it imported as a
clean AGENT_COMPLETED (status=OK) and failed_sessions reported
process_failed=false.

The synthesizer now tracks the first non-tool source error while folding
and emits it as the importer-recognized results.error field, keeping
error_message verbatim for provenance. Tool outcome events stay on
tool_calls[].error (replayed as TOOL_ERROR rows) and are not promoted to
a trace-level error. returncode and goal_completion remain tied to
completion only.

Regression: an AGENT_COMPLETED(status=ERROR, error_message=...) trace
with no TOOL_ERROR round-trips through to_agent_event_rows() with the
terminal row status=ERROR and classify_sessions() process_failed=True.
caohy1988 added a commit to caohy1988/BQAA-SDK-fork that referenced this pull request Aug 30, 2026
Two Codex P1s on GoogleCloudPlatform#454 were left unshipped when GoogleCloudPlatform#454 squash-merged:

- docs/agentforensics_mvp_plan.md still listed GoogleCloudPlatform#452 and GoogleCloudPlatform#453 as open.
  Mark GoogleCloudPlatform#451–GoogleCloudPlatform#454 merged with merge SHAs; note GoogleCloudPlatform#455 (e2e demo) is open at
  a8c694c and not on main.
- CHANGELOG Unreleased had GoogleCloudPlatform#452 and GoogleCloudPlatform#453 bullets but no dedicated GoogleCloudPlatform#451
  bullet. Add one covering EvalBenchRun.materialize() into BQAA-owned
  evalbench_* tables (never ADK agent_events), staging + single
  transaction on (job_id, import_version), the W0.4 failed-session
  contract (returncode == 0 means completed, not passed), and the
  bq-agent-sdk evalbench-import CLI.

Docs only. Six-week clock not started; partner job / D4 / taxonomy parked.
caohy1988 added a commit that referenced this pull request Sep 4, 2026
…456)

Two Codex P1s on #454 were left unshipped when #454 squash-merged:

- docs/agentforensics_mvp_plan.md still listed #452 and #453 as open.
  Mark #451–#454 merged with merge SHAs; note #455 (e2e demo) is open at
  a8c694c and not on main.
- CHANGELOG Unreleased had #452 and #453 bullets but no dedicated #451
  bullet. Add one covering EvalBenchRun.materialize() into BQAA-owned
  evalbench_* tables (never ADK agent_events), staging + single
  transaction on (job_id, import_version), the W0.4 failed-session
  contract (returncode == 0 means completed, not passed), and the
  bq-agent-sdk evalbench-import CLI.

Docs only. Six-week clock not started; partner job / D4 / taxonomy parked.
caohy1988 added a commit that referenced this pull request Sep 5, 2026
…luators

Version bump 0.5.1 -> 0.5.2 and the changelog cut for everything merged
since v0.5.1 (2026-08-29), 19 commits.

In the wheel: the versioned EvalBench import pipeline (#451-#453: immutable
snapshots with the W0.4 failed-session contract, the version-pinned
failed_sessions view, evalbench-score), the native agent_events snapshot
writer (#464), the failure taxonomy frozen at G1 v0.1.0 and its span-level
localisation layer with persisted span labels (#467, #470), the evaluator
API unification behind PerformanceEvaluator with compatibility aliases
(#123), and the canonical metric factories plus opt-in policy scorecard
(#91). Repo side: skill-evolution host hooks and auditable patch provenance
(#395, #477), the scheduled skill-evolution Cloud Run Job (#472), the OKF
adapter example (#474), the AgentForensics Week 0 freeze and sealed
preregistration (#435, #473), and the EvalBench demo and CLI-discoverability
follow-ups.

Entries the Unreleased section lacked are added in this cut: #91, #123 (its
bullets move under Changed with the PR number), #395, #472, #474, #476.
haiyuan-eng-google pushed a commit that referenced this pull request Sep 5, 2026
…478)

* chore(release): 0.5.2 — EvalBench snapshots, G1 taxonomy, unified evaluators

Version bump 0.5.1 -> 0.5.2 and the changelog cut for everything merged
since v0.5.1 (2026-08-29), 19 commits.

In the wheel: the versioned EvalBench import pipeline (#451-#453: immutable
snapshots with the W0.4 failed-session contract, the version-pinned
failed_sessions view, evalbench-score), the native agent_events snapshot
writer (#464), the failure taxonomy frozen at G1 v0.1.0 and its span-level
localisation layer with persisted span labels (#467, #470), the evaluator
API unification behind PerformanceEvaluator with compatibility aliases
(#123), and the canonical metric factories plus opt-in policy scorecard
(#91). Repo side: skill-evolution host hooks and auditable patch provenance
(#395, #477), the scheduled skill-evolution Cloud Run Job (#472), the OKF
adapter example (#474), the AgentForensics Week 0 freeze and sealed
preregistration (#435, #473), and the EvalBench demo and CLI-discoverability
follow-ups.

Entries the Unreleased section lacked are added in this cut: #91, #123 (its
bullets move under Changed with the PR number), #395, #472, #474, #476.

* chore(release): file the skill-evolution bullets as repo-side

scripts/skill_evolution.py is not in the wheel (which ships only
src/bigquery_agent_analytics and src/bigquery_ontology), so the #395 and
#397 entries move from Added to their own repo-side section, matching the
Deploy section this cut already uses for #472.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants