Skip to content

feat(evalbench): native agent_events snapshot writer (#463) - #464

Merged
haiyuan-eng-google merged 8 commits into
GoogleCloudPlatform:mainfrom
caohy1988:feat/463-native-agent-events-writer
Aug 31, 2026
Merged

haiyuan-eng-google merged 8 commits into
GoogleCloudPlatform:mainfrom
caohy1988:feat/463-native-agent-events-writer

Conversation

@caohy1988

Copy link
Copy Markdown
Collaborator

Implements #463 (parent: #435): a native agent_events snapshot writer — the EvalBench-adapter exit ramp. The evalbench-import adapter (#97) stays as an optional on-ramp; nothing is deleted.

Stacking (do not merge; review only)

What it does

bigquery_agent_analytics.native_events.NativeAgentEventsRun (plus thin CLI bq-agent-sdk evalbench-native-import) starts from production ADK agent_events rows and publishes the same BQAA-owned contract EvalBenchRun.materialize already produces — it subclasses EvalBenchRun and inherits materialize verbatim (staging, lock, publish transaction, manifest, view sync), overriding only the inputs:

  • Pin identity: the same (job_id, import_version) tuple on snapshot event rows, score rows, and the manifest row; the failed_sessions view body is failed_sessions_sql with the pin rendered as literals for the latest successful native publication (newest committed manifest row; generation_id + view_policy pin the body exactly as the adapter does). Job for this slice: mvp-e2e-real-traces.
  • No EvalBench source tables in the path: no configs / results / scores reads anywhere; the constructor fail-closes if EvalBench source rows are passed. evalbench-import remains untouched.
  • Joinable identity: scenario id / eval_id is the first eight characters of the ADK session_id (7e352c34 from 7e352c34-4c1c-4395-acd5-fb3c8f215346), falling back to the full id on collision; published rows keep the real ADK session_id, so the same session is the same object with or without the adapter.
  • Native scores + policy: score rows live in the BQAA-owned snapshot scores table (same schema the adapter writes) and are derived deterministically from the session — goal_completion is 1.0 iff the session logged AGENT_COMPLETED, 0.0 otherwise (completed, not passed). The gate is the existing EvalScorePolicy — goal_completion / min_score 1.0 / missing_score_fails: true per the frozen rubric (examples/fixtures/week0_real_rubric.json) — persisted as canonical JSON on the manifest view_policy. A never-completed session publishes the same ERROR-status prompt-row marker the adapter publishes for returncode != 0, so process_failed holds.
  • G1 mapping (frozen v0.1.0, imported, not reimplemented): missing_completion → finalization, process_failed → tool blockers, score_failed → task/planning; names come back in frozen order. The widget-stock silence session 7e352c34 yields task/planning, finalization, tool blockers, and the deterministic punchline next-action names the missing answer and the never-called check_inventory.
  • Never writes production agent_events: the source table is only read (SELECT-only), and the inherited reserved-name guard rejects agent_events as a destination before any BigQuery call.

Tests

Fixture-only, offline — tests/test_native_events_writer.py + tests/test_cli_evalbench_native_import.py (19 new tests; 331 pass across the evalbench suites). No live BigQuery, no jobs, no IAM, no live/LLM judge, no --synth. Covered: the widget-stock acceptance (all three G1 names), pin identity on events/scores/manifest, view pinned to the latest successful native publication, the frozen policy pin, first-8 identity with collision fallback, no-EvalBench-tables and no-agent_events-writes guards, skipped promptless sessions, and clock-not-started.

Boundaries

  • Clock OFF: this PR does not start the six-week clock, seal the preregistration, or kick a Week 1 snapshot job.
  • D4 fail-closed: consumer remains Hai-Yuan Cao only.
  • Docs: one short exit-ramp pointer in docs/agentforensics_mvp_plan.md; CHANGELOG bullet at the top of Unreleased → Added.
…sion flags (GoogleCloudPlatform#435)

New failure_taxonomy module: versioned scaffold config (0.0.0-scaffold,
g1_frozen: false) in the GoogleCloudPlatform#431 metric-config schema shape, three mechanical
core categories mapped 1:1 from the landed failed-session flags
(process_failed / missing_completion / score_failed), an empty D2 dialects
slot, and a pure deterministic categorize_failed_session() over dict or
SessionVerdict rows. No BigQuery, no LLM, no network. NOT G1: no names
frozen; six-week clock not started; partner/D4/live traces stay parked.
…n rows (GoogleCloudPlatform#435)

Consume the slice-8 failure_taxonomy scaffold from the failed-sessions
path: EvalBenchSession exposes taxonomy_categories as a property computed
from its three mechanical flags via categorize_failed_session, and
to_dict() serializes it as a list, so failed_sessions() rows and the
evalbench-failed-sessions CLI JSON/text output carry the tripped scaffold
ids. EvalBenchFailedSessions.to_dict() now serializes nested sessions
through EvalBenchSession.to_dict (asdict only sees stored fields).

All-flags-false rows (--include-passed) emit [] rather than an invented
unknown bucket. Pure Python over flags already returned -- no extra
BigQuery round-trip, no SQL changes, fixture/unit tests only. Still NOT
G1: ids stay the unfrozen flag names, clock not started, partner/D4/
live-trace work parked.
…AgentForensics idea (GoogleCloudPlatform#435)

All five Week 0 human gates of docs/agentforensics_mvp_plan.md as one
concrete EXAMPLE story on the widget-stock failed session: partner+SANA
(example partner Acme Retail Support), runtime+route, pilot-benchmark
rubric, D4 boundary memo, preregistration floors — then the session, its
mechanical taxonomy_categories, and an EXAMPLE mapping onto SANA-seeded
names (fixtures only, never src/). Not a freeze: g1_frozen stays false,
the six-week clock has not started, Week 0 remains human-gated.
--fixture offline only; no BigQuery, no network.
…v0.1 (GoogleCloudPlatform#435)

Record Google Cloud BigQuery Agent Analytics as the real pilot partner,
land the fail-closed D4 memo for this project's EvalBench datasets, and
freeze production failure_taxonomy at v0.1.0 (g1_frozen true) with the
SANA seven + unknown. Mechanical flags map to frozen names in frozen
order. The 460 example pack stays illustrative. Clock not started.
…1 freeze (GoogleCloudPlatform#435/GoogleCloudPlatform#461)

The example pack's narrative still described the pre-freeze production
scaffold (0.0.0-scaffold, g1_frozen false, flag ids in
taxonomy_categories). Add a banner and inline caveats to the .md and .sh
stating production froze taxonomy v0.1.0 (g1_frozen true) in GoogleCloudPlatform#461 and
now emits the frozen names (task/planning, finalization, tool blockers).
The pack stays illustrative; fixtures and script output are unchanged.
…er exit ramp) (GoogleCloudPlatform#463)

NativeAgentEventsRun starts from production ADK agent_events rows and
publishes the same BQAA-owned contract EvalBenchRun.materialize already
produces -- pinned (job_id, import_version) snapshot events, deterministic
goal_completion score rows, manifest with the view_policy pin, and the
failed_sessions view pinned to the latest successful native publication --
with no EvalBench configs/results/scores tables anywhere in the path.

- Identity: scenario id is the first eight characters of the ADK
  session_id (7e352c34), falling back to the full id on collision; event
  and score rows keep the real session_id so the session is the same
  object with or without the adapter.
- Scores: derived from the session alone (1.0 iff AGENT_COMPLETED --
  completed, not passed; the EvalScorePolicy gate decides passed). A
  never-completed session publishes the same ERROR-status prompt-row
  marker the adapter publishes for returncode != 0, so process_failed
  holds and the widget-stock silence session 7e352c34 yields the frozen
  G1 v0.1.0 names task/planning, finalization, tool blockers.
- Thin CLI on-ramp: bq-agent-sdk evalbench-native-import, mirroring
  evalbench-import; the adapter (GoogleCloudPlatform#97) stays optional and untouched.
- Production agent_events is never written (reserved-name guard); the
  source table is only read. Offline fixture tests only; no live BQ.
- The six-week clock has still NOT started.

@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
Include: verdict (LGTM/APPROVE or REQUEST_CHANGES), P0 count, P1 count, P2 count (informational), HEAD SHA e438c0e, findings with file:line, what can wait.
Also print the full review body to stdout.
Do NOT run gh pr review yourself. Do not push. Do not post to GitHub.
warning: Skill descriptions were shortened to fit the skills context budget. Codex can still see every skill, but some descriptions are shorter. Disable unused skills or plugins to leave more room for the rest.
codex
I’m using the structured code-review skill because this is a diff-scoped PR review. I’ll inspect only 2c4804b..e438c0e, verify the specified P0/P1 invariants with offline checks, and write plus print the requested review—without touching GitHub or any branch state.
exec
/bin/zsh -lc 'cat /Users/haiyuancao/.codex/plugins/cache/compound-engineering-plugin/compound-engineering/3.23.4/skills/ce-code-review/SKILL.md' in /Users/haiyuancao/BigQuery-Agent-Analytics-SDK/.worktrees/issue-435-native-writer
succeeded in 1ms:

name: ce-code-review
description: "Structured code review for bugs, regressions, tests, and standards. Use before PRs or when asked to review code. Use when the user asks to apply this review's findings locally. Not for resolving feedback already left on a PR; that is ce-resolve-pr-feedback."
argument-hint: "[mode:agent] [apply:local] [blank to review current branch, or provide PR link]"

Code Review

Artifact Root

Resolve the CE artifact root <root> before composing any artifact path.

  • Read docs_root from <repo-root>/.compound-engineering/config.yaml only (<repo-root> = git rev-parse --show-toplevel). Do not read it from config.local.yaml. Unset -> <root> is docs, exactly as before.
  • Validate a set value: a repo-relative directory whose real, symlink-resolved path stays inside the repo and is neither the repo root nor under .git/. Otherwise stop with an error naming docs_root and the value -- never fall back to docs.
  • Use <root> as the sole artifact location: create it if absent, compose each path as <root>/<subdir> with this skill's own subdirectory, and never also read docs.

Execution spine

Follow these steps in order; the references supply the detail but never change the order. Each reference named below is a required read for its step: load it before doing that step's work.

  1. Read references/modes-and-output.md first. It settles what the arguments mean, which argument conflicts stop the run before any reviewer is dispatched, whether the quick-review short-circuit applies, and what this invocation returns.
  2. Stage 1. Read references/scope.md and resolve the reviewed diff, the scope mode, and the deterministic scope signals.
  3. Stage 2. Read references/intent-and-plan.md, write the intent summary every reviewer receives, and discover the plan Stage 6 verifies requirements against.
  4. Stage 3. Read references/persona-catalog.md and references/select-and-route.md, then select the risk-driven reviewer roster, discover applicable standards paths, and bind the adversarial route.
  5. Stage 3d. When adversarial is selected for a local reviewed tree, start and persist the sanctioned cross-model job that references/cross-model-review.md defines, before any local persona dispatch. Invoking this skill is itself the authorization for its configured or allowlisted peer route, once you have made the required disclosure of the recipient and of the code that leaves the machine. Do not ask the user to confirm a second time, and do not skip the peer because the user did not repeat that authorization. An explicit user prohibition on external review overrides it, as does a checkout that sets cross_model_review_mode: off with no live opt-in; both are resolved before you bind a route. This pass's skip and target-selection keys are cross_model_review_mode and cross_model_peer. Missing files or unset keys take the default auto route; they are not a skip. Another skill's engine preference is not this gate. Model and effort overrides stay with the bound target as the reference states. A started peer replaces the local adversarial persona at this stage, and only a real failure to scope, allowlist, reach, authenticate, or start it leaves the local fallback in the roster; a later stage may still restore the local reviewer under the conditions that reference states.
  6. Stage 4. Read references/dispatch-reviewers.md. Dispatch the materialized local roster as one foreground concurrent batch sized to the host's active-agent cap. Every successful launch is collected when its terminal outcome is in hand: consume valid compact returns, classify a terminal tool error or malformed output as a failed reviewer, and keep launch receipts uncollected. Use the host's blocking collection capability for asynchronous receipts, and do not synthesize until every successful launch is collected. If launched work cannot be collected reliably, stop it, discharge any persisted peer through its owning cleanup before returning the failure result, and never emit progress or wait for a notification. Detaching local review into a polled background job is forbidden. The cross-model peer is the only detached work, and it may overlap this batch.
  7. Stages 5 and 6. Once the reviewer returns are ready, read references/finish-review.md. Fold in the peer once, run the documented findings mechanics, and run every validator the reference selects; only then return the report. Never synthesize directly from raw reviewer artifacts. In the multi-agent path, emit only this skill's report: do not also invoke a harness-native findings or reporting tool, which belongs to the quick-review short-circuit alone.

Operating principles

  • Report-only by default; never push. A bare ce-code-review invocation produces findings and does not apply them. Entering the apply stage requires apply:local, or an explicit user request in the invoking prompt to apply or fix this review's findings; a deprecated mode:autofix token is neither. mode:agent never mutates the tree, even when nested inside a workflow that later applies findings. Never push, open PRs, or file tickets in any mode.
  • No blocking prompts. Never use AskUserQuestion, request_user_input, ask_user, or other blocking question tools. Infer intent, plan, and scope from explicit tokens, git state, PR metadata, and conversation. Note uncertainty in Coverage or the verdict — do not stop to ask.
  • Explicit mutations only. Never run gh pr checkout, git checkout, git switch, or similar branch-switch commands. Passing a PR number, URL, or branch name selects review scope, not permission to mutate the working tree. Uncommitted work can only be reviewed from the checkout that holds it, so to review it on a feature branch, stay on that branch (or check it out yourself) and pass base: or no target.
  • Report outcomes, not machinery. What you show the user is about the review: what is being examined, which coverage is included and the one-line reason for each conditional lens, the independent cross-model pass, and the findings. Name what the user would recognize — a PR number, a reviewer's concern, a peer model — rather than this skill's plumbing, whose internal labels, dispatch bookkeeping, and setup narration stay out of user-facing text. Never claim more about the peer than its receipt attests. This governs what you surface and suppress, not the wording; use your own voice.

Task Visibility

For the multi-agent path, once the review scope is resolved, use the platform's task-tracking capability when available to show a short user-facing view derived from the execution spine. Track review outcomes, not individual personas, setup mechanics, or tool calls; add conditional work only when its gate fires, and update the view at meaningful transitions. If no task-tracking capability is available, continue with the normal progress and final report without simulating a task list in chat.

@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 #464 — Native agent_events snapshot writer (EvalBench-adapter exit ramp)

  • Verdict: LGTM / APPROVE
  • HEAD reviewed: e438c0e84709bc8ac0a76c65353b774f250584fe (unique commit; range 2c4804b..e438c0e, stacked on #461 freeze HEAD 2c4804b)
  • P0 count: 0
  • P1 count: 0
  • P2 count (informational): 3
  • Scope note: Diff reviewed is git diff 2c4804b..HEAD only — 6 files, +1368/-0, fully additive. GitHub's 455–461 file display is stacking, not a defect. #462 (post-freeze e2e) is correctly absent.

Verification performed

  • git log 2c4804b..HEAD — exactly one commit, e438c0e.
  • Full diff read: src/bigquery_agent_analytics/native_events.py (new, 549 lines), cli.py (+155, additive), tests/test_native_events_writer.py (new, 467), tests/test_cli_evalbench_native_import.py (new, 167), CHANGELOG.md (+21, additive), docs/agentforensics_mvp_plan.md (+9, additive).
  • Offline tests run: pytest tests/test_native_events_writer.py tests/test_cli_evalbench_native_import.py — 19 passed; regression pytest tests/test_evalbench_importer.py tests/test_cli_evalbench_import.py — 144 passed. No live BigQuery touched (all fake clients / in-memory fixtures).
  • Conflict-marker scan on all touched files: clean. g1_frozen: True still set in failure_taxonomy.py:145. No 456/457/462-branch files modified.

P0 checklist — all clear

  • Production agent_events never written. The native read path is SELECT-only (native_events.py:204 from_bigquery builds a single SELECT ... FROM {source_table} with FOR SYSTEM_TIME AS OF / session filter; test test_from_bigquery_reads_only_the_agent_events_table pins this). The reserved-name guard _validate_destination_table rejects agent_events before any BigQuery call in the inherited materialize (evalbench.py:984-987, guard at evalbench.py:3108-3120), and the CLI pre-validates all three destination names before even reading the source (cli.py:2547-2550). Tests test_reserved_agent_events_destination_is_rejected, test_nothing_is_written_into_an_agent_events_table, and test_publish_never_touches_the_source_dataset cover the guard from three angles.
  • evalbench-import intact. The #97 on-ramp command is untouched (cli.py:2430 region unchanged; the diff only appends evalbench-native-import at cli.py:2433). Nothing deleted anywhere in the range.
  • Clock not started. No Week 1 / preregistration / six-week-clock code. test_native_publication_does_not_start_the_clock asserts the result payload contains no "clock" and the frozen rubric still has clock_started: false.
  • No live BQ requirement. from_agent_events is pure/in-memory; from_bigquery is opt-in and injectable (bq_client=). CLI has no --synth default that would hit production. All tests run against _FakeWriteClient / _FakeReadClient.
  • Taxonomy v0.1.0 names. test_widget_stock_session_fails_with_all_three_g1_names asserts session 7e352c34 yields exactly ("task/planning", "finalization", "tool blockers") in frozen order against failure_taxonomy.TAXONOMY_VERSION == "0.1.0". Freeze flag untouched.
  • No conflict markers; no cross-branch files; taxonomy not unfrozen.

P1 checklist — all clear

  • Inheritance, not rewrite. NativeAgentEventsRun(EvalBenchRun) (native_events.py:125) inherits materialize verbatim — pin identity, lock, publish transaction, manifest with view_policy, view sync all come from evalbench.py:874 and are polymorphic over self.fingerprints() / self.to_agent_event_rows() / self.to_score_rows() (evalbench.py:1003,1024,1026). Only inputs are overridden (native_events.py:280,325,355) plus the replaced reader from_bigquery (native_events.py:204).
  • No EvalBench source tables, fail-closed. Constructor __post_init__ (native_events.py:148-158) raises if results / scores / config_rows are passed; test_native_run_refuses_evalbench_source_rows pins it. The read query provably contains no .configs / .results / .scores reference.
  • Deterministic session-derived scores. goal_completion is 1.0 iff AGENT_COMPLETED (native_events.py:325-352, facts at _score_facts_with_prompts), explicitly completed, not passed. Never-completed sessions publish their first prompt row as status=ERROR with the original status preserved in attributes.bqaa_native_source_status (native_events.py:315-321), which the acceptance test shows drives process_failed=True through the real failed_sessions view path.
  • Identity. _native_scenario_ids (native_events.py:461-476) is first-8 with full-id fallback on prefix collision; published event and score rows keep the real ADK session_id (test_events_scores_and_manifest_all_carry_the_pin, test_identity_is_first_8_with_collision_fallback_to_full_id).
  • Required tests all present: widget-stock three G1 names; pin identity on events/scores/manifest; view pinned to latest successful publication (test_view_is_pinned_to_the_latest_successful_native_publication, v1→v2 advance); no-agent_events-writes guard; clock-not-started; evalbench-import still present (144 importer/CLI tests green).
  • CHANGELOG kept all 455/460/461 bullets (diff is +21/-0) and adds the #463 entry with the clock-still-off statement. plan.md adds a nine-line note describing the native writer as an exit ramp; it does not reopen parked partner/D4/clock work.
  • CLI evalbench-native-import (cli.py:2433) mirrors evalbench-import options, defaults destinations to evalbench_agent_events / evalbench_scores_imported, and does not mutate the existing command. Reserved-destination and bad---snapshot-at rejections exit 2 before any client call (CLI tests confirm calls == []).

P2 (informational, non-blocking — can wait)

  1. native_events.py:305-312 — marker_index falls back to 0 when no prompt event exists, but _kept_and_skipped guarantees every kept session has a prompt, so the fallback is unreachable. Harmless dead branch; could be an assertion for documentation value.
  2. native_events.py:483-496 — _prompt_text gives up on the first USER_MESSAGE_RECEIVED whose content mapping lacks text/text_summary keys instead of scanning later prompt events in the same session. Only affects the informational source_row.prompt field, never the score or the failure marker.
  3. native_events.py:125-145 — the inherited field names evalbench_dataset / manifest results_count=0, configs_count=0 are EvalBench-shaped labels carrying native-source meaning. Documented in the class docstring, and renaming would forfeit the frozen manifest contract; noted only so future readers aren't surprised.

What can wait

  • All three P2s above.
  • Any live-BQ smoke of from_bigquery / the CLI against the real test-project-0728-467323 table — correctly out of scope here; belongs with post-freeze e2e (#462 lineage), not this PR.

Recommendation: APPROVE. The exit ramp lands the frozen contract with zero EvalBench tables in the path, zero writes to production agent_events, the clock still off, and the adapter on-ramp intact. 19 new + 144 existing tests pass offline.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Scratch review 5062853153 — that was a premature Codex stdout dump (skill text), not a review of e438c0e. Real Codex/Kimi COMMENTED reviews of this HEAD are still running and will post when they finish. Ignore that dump.

@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

PR: 464
Verdict: REQUEST_CHANGES
HEAD SHA: e438c0e (e438c0e84709bc8ac0a76c65353b774f250584fe)
Counts: P0: 0 | P1: 2 | P2: 1 (informational)

Scope: Only git diff 2c4804b..e438c0e and git log 2c4804b..e438c0e; one commit, six files. The stacked GitHub diff and #462 are excluded as directed.
Intent: Add an offline-testable native agent_events snapshot writer that reuses EvalBenchRun.materialize, preserves the optional evalbench-import path, retains real ADK session IDs, and leaves the Week 1 clock off.
Mode: markdown report-only. No fixes, pushes, GitHub writes, live BigQuery calls, or branch mutations.

Reviewers: correctness, testing, maintainability, API contract, reliability, and an independent Claude adversarial pass. Testing covered the new offline fixtures and CLI. API-contract review covered version pins and published identities. Reliability covered fail-fast and inherited publication behavior.

P1 -- High

# File Issue Reviewer Confidence
1 src/bigquery_agent_analytics/native_events.py:117 Native source boundary accepts prohibited tables correctness, adversarial-claude 100
2 src/bigquery_agent_analytics/native_events.py:443 Native versions lose consumer snapshot isolation api-contract 75
  • #1 - Fail closed on the source table before any query. _parse_source_table checks only identifier syntax, so p.d.configs, p.d.results, and p.d.scores reach the SELECT at native_events.py:255-261. This directly violates the no-EvalBench-source-table contract. The same gap also allows a non-reserved source such as p.d.evalbench_agent_events to resolve to the inherited default destination and feed retained rows back into itself (evalbench.py:981,1009-1011). Require the source basename to be agent_events. If alternate production event-table names are intentional, explicitly reject the three EvalBench basenames and compare every fully qualified destination with source_table. Add fake-client tests that assert zero queries and zero writes.

  • #2 - Add import_version to inherited trace/evaluation selectors. Native event rows correctly preserve the real ADK session_id, but retained v1 and v2 rows therefore share both session_id and the job-scoped experiment_id. EvalBenchSession.trace_selector() uses only those fields (evalbench.py:2207), and EvalBenchImportSessions.trace_filter() also omits the top-level version pin (evalbench.py:2446-2450). A caller that selects v2 can replay or score rows from v1 and v2 together. Keep the real session ID, add an import_version predicate to the trace/filter query paths, and add a two-publication isolation test.

P2 -- Moderate (informational)

# File Issue Reviewer Confidence
3 src/bigquery_agent_analytics/native_events.py:103 Whole-table native reads are unbounded when no session filter is supplied adversarial-claude 75

Actionable Findings

# File Issue Route Notes
1 src/bigquery_agent_analytics/native_events.py:117 Constrain native sources and reject source/destination overlap gated_auto -> downstream-resolver Suggested fix present; add zero-query/zero-write tests
2 src/bigquery_agent_analytics/native_events.py:443 Preserve snapshot isolation in trace and evaluation consumers manual -> downstream-resolver Suggested fix present; requires a shared filter-contract change and a two-version test

What Can Wait

  • #3 is not a merge blocker for this offline, pre-clock PR. Before any production-scale rollout, require a session or time-window bound, or make whole-table import an explicit opt-in with a row-count guard. The current query otherwise loads the complete source into memory at native_events.py:260-262.
  • Other adversarial suggestions about grace periods and G1 flag correlation were not counted. They conflict with the frozen rule that a snapshot session scores 1.0 iff it contains AGENT_COMPLETED, and that a never-completed snapshot session receives the ERROR prompt marker.

Coverage

  • P0 checks passed: the reserved agent_events destination guard remains; evalbench-import and its adapter tests remain; no Week 1 or clock-start action was added; G1 stays frozen at v0.1.0 with task/planning, finalization, tool blockers in frozen order; no conflict markers or #456/#457/#462 files are in scope.
  • The constructor rejects non-empty inherited results, scores, and config_rows. The native class inherits EvalBenchRun.materialize unchanged.
  • Widget-stock G1 output, event/score/manifest pins, latest-successful view pinning, real session IDs, collision fallback, no-source-write guards, clock-off state, and the old evalbench-import CLI are covered by offline tests.
  • Independent validation accepted the source-boundary, self-feeding, and cross-version-isolation defects. These became two findings after semantic deduplication. It rejected one proposed P1 about in-flight sessions because that proposal contradicted the frozen completion contract.
  • Cross-model pass: route claude; requested/served model claude-opus-5; requested effort high; actual effort unverified; receipt supported; independence verified.
  • Verification: focused suite 29 passed; full intended-environment suite 4430 passed, 72 skipped; git diff --check passed; Pyink and isort checks passed. No live BigQuery was used.
  • Two anchor-50 peer observations were suppressed. No reviewer failed. The only worktree item outside the reviewed diff was the pre-existing untracked .venv symlink.

Verdict

REQUEST_CHANGES

P0: 0 | P1: 2 | P2: 1 informational. Fix #1 and #2 before approval. The required source-table boundary is not fail-closed, and retained native versions are not isolated in inherited trace/evaluation consumers. #3 can wait until production rollout planning. The six-week clock remains off.

Actionable Findings (recap)

  • #1 - P1 - src/bigquery_agent_analytics/native_events.py:117 - gated auto: restrict the native source boundary and prove prohibited tables cause zero reads/writes.
  • #2 - P1 - src/bigquery_agent_analytics/native_events.py:443 - manual: add version-aware trace/evaluation filtering while retaining the real ADK session ID, then prove v1/v2 isolation.

Run artifacts: /tmp/compound-engineering-501/ce-code-review/20260830-201749-9ba2c7ca

… on traces (GoogleCloudPlatform#464)

Reject non-agent_events native sources (including EvalBench configs/results/scores)
before any query, and isolate retained native versions in trace/filter consumers.

@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: APPROVE (LGTM)

P0 count: 0

P1 count: 0

HEAD SHA: f5c6109

Findings

No P0 or P1 findings remain on this HEAD.

  • The first prior P1 is closed. src/bigquery_agent_analytics/native_events.py:128 validates the fully qualified source before client creation; src/bigquery_agent_analytics/native_events.py:139 explicitly rejects configs, results, and scores; and src/bigquery_agent_analytics/native_events.py:145 admits only the exact agent_events basename. src/bigquery_agent_analytics/native_events.py:200 also rejects any source/destination identity before delegating to publication. The fake-client regressions at tests/test_native_events_writer.py:403, tests/test_native_events_writer.py:425, and tests/test_native_events_writer.py:441 assert zero queries and writes on these failures.
  • The second prior P1 is closed. src/bigquery_agent_analytics/evalbench.py:2197 adds import_version to each failed session's trace selector, while src/bigquery_agent_analytics/evalbench.py:2439 pins it in the import's TraceFilter. src/bigquery_agent_analytics/trace.py:860 emits the candidate predicate and src/bigquery_agent_analytics/trace.py:1008 reapplies it to fetched rows. src/bigquery_agent_analytics/client.py:976 exposes the pin on get_session_trace, and the selector-discovery and scoped/mixed fetch paths carry it through, including the authoritative scoped fetch at src/bigquery_agent_analytics/client.py:1825. Native publication still preserves the real source session ID at src/bigquery_agent_analytics/native_events.py:522. The retained-v1/v2 regressions at tests/test_native_events_writer.py:603 and tests/test_native_events_writer.py:655 prove v2 selector and filter reads do not widen into v1.
  • The P0 guardrails remain intact. The inherited reserved-destination check at src/bigquery_agent_analytics/evalbench.py:3124 prevents writes to production agent_events; the existing adapter command remains registered at src/bigquery_agent_analytics/cli.py:2285; the native command is additive at src/bigquery_agent_analytics/cli.py:2433; the frozen taxonomy order includes task/planning, finalization, and tool blockers at src/bigquery_agent_analytics/failure_taxonomy.py:71; and src/bigquery_agent_analytics/native_events.py:55 keeps the six-week clock and Week 1 off. The full delta has no conflict markers.
  • The reviewed stack is exactly e438c0e followed by f5c6109; the expected stacked history is not treated as a P0, and #462 is not part of this two-commit delta.

Verification

  • Targeted offline regression suite: 729 passed.
  • Full offline suite: 4,435 passed, 72 skipped. Live BigQuery tests stayed skipped; no live BigQuery access was used.
  • git diff --check 2c4804b..HEAD passed.
  • The worktree was not modified; the pre-existing untracked .venv remained the only status entry.

What can wait

P2 documentation polish or additional non-blocking edge-case coverage can wait. Nothing found at P0/P1 severity blocks merge.

@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 #464 @ f5c6109 — native agent_events snapshot writer (P1 fix round)

  • Verdict: LGTM / APPROVE
  • P0 count: 0
  • P1 count: 0 (both prior P1s from the e438c0e review are closed; no new merge-blocking defects found)
  • HEAD SHA reviewed: f5c6109
  • Fix delta reviewed: git diff e438c0e..f5c6109; full native-writer delta: git diff 2c4804b..f5c6109
  • Prior Kimi review on e438c0e does not count for this HEAD; this is a fresh per-SHA review.
  • Stacking note: GitHub's PR-vs-main view shows the #455–#461 ancestor chain; that is expected stacking on this branch, not a P0. The delta does not include #462.

Prior P1s — resolution check

Prior P1-1: _parse_source_table fail-open (CLOSED)

Confirmed fixed:

  • src/bigquery_agent_analytics/native_events.py:122-125 — _SOURCE_TABLE_BASENAME = "agent_events" and _EVALBENCH_SOURCE_BASENAMES = frozenset({"configs", "results", "scores"}).
  • src/bigquery_agent_analytics/native_events.py:139-150 — _parse_source_table rejects EvalBench basenames by name, then rejects any basename other than agent_events, raising before any BigQuery client is created or any query is built. Both constructors (from_agent_events, from_bigquery) and __post_init__ route through it.
  • src/bigquery_agent_analytics/native_events.py:200-247 — NativeAgentEventsRun.materialize override compares every fully-qualified destination (events, scores, manifest, lock, failed-sessions view) against source_table and refuses source==destination before any BigQuery call — defense in depth over the inherited reserved-agent_events-destination check.
  • Fake-client tests prove zero queries / zero writes on every rejection path: tests/test_native_events_writer.py:403-423 (configs/results/scores fail closed on both read and offline paths), :426-439 (non-agent_events basename e.g. evalbench_agent_events refused at parse), :442-457 (destination == source refused, all fake stores empty).

Prior P1-2: retained-version mixing on trace reads (CLOSED)

Confirmed fixed:

  • src/bigquery_agent_analytics/evalbench.py:2197-2217 — EvalBenchSession.trace_selector() now returns import_version alongside the real session_id and job-scoped experiment_id; docstring correctly states the pin is redundant on the adapter path but load-bearing on the native path.
  • src/bigquery_agent_analytics/evalbench.py:2439-2468 — EvalBenchImportSessions.trace_filter() pins import_version on the TraceFilter.
  • src/bigquery_agent_analytics/trace.py:468-479, 579, 606-610, 857-869, 1001-1009 — TraceFilter.import_version field with two-state validation (_validated_import_version_pin, revalidated at the SQL boundary against vars() bypass), added to both to_sql_conditions() (import_version = @import_version) and row_scope_where() ({alias}.import_version = @import_version) with an explicit no-shared-row-escape-hatch comment.
  • src/bigquery_agent_analytics/client.py:987-1060, 1109-1113, 1300-1330, 1392-1410, 1453-1570, 1667-1690, 1797-1834 — import_version plumbed through get_session_trace → get_trace_by_selector → _selector_pushdown_pins, _discover_session_identities, _fetch_mixed_scope_trace (metadata AND row fetch via version_where), _real_candidates_for_identities, and _fetch_resolved_trace (anchored row fetch appends e.import_version = @pin_import_version). Every discovery and fetch statement of a pinned lookup carries the predicate; non-string values raise TypeError. Real session_id is kept — native rows publish the real ADK id (native_events.py:522).
  • Isolation tests prove v2 cannot see v1: tests/test_native_events_writer.py:516-688. _publish_v1_and_v2 retains both versions under one real session id; test_two_publications_v2_trace_selector_returns_no_v1_rows runs the real Client.get_session_trace against _VersionPredicateFake, which returns BOTH versions' rows if the SQL omits the pin — so the assertion {span.span_id} == {"v2-span"} proves the pin is honored in emitted SQL, not merely forwarded. test_two_publications_v2_trace_filter_cannot_widen_to_v1 shows session_ids alone match both retained versions and the version pin is what isolates v2.

P0 checklist — all clear

  • Writes production agent_events: No. Read-only source enforced at parse (native_events.py:145-150); reserved destination name rejected by inherited _validate_destination_table; destination==source rejected at native_events.py:228-235; CLI validates destination names before any BQ call (cli.py new evalbench-native-import command).
  • Deletes evalbench-import: No. Adapter stays as optional on-ramp (native_events.py:22-23, CLI docstring, CHANGELOG).
  • Starts clock / Week 1: No. Explicitly documented as not starting (native_events.py:55-56, CHANGELOG: "the six-week clock has still NOT started"). No cron/schedule/snapshot-job code anywhere in the delta.
  • Live BQ required: No. from_agent_events is pure/offline; all new tests use fakes. Full offline suite: 4429 passed, 24 skipped, 0 failed.
  • Taxonomy G1 frozen names: Yes — task/planning, finalization, tool blockers asserted via the unchanged classify_sessions/failed_sessions consumers (tests/test_native_events_writer.py:178-180, 212-214).
  • Conflict markers: None in any changed file.

What can wait (non-blocking, P2)

  • CHANGELOG entry (#463) still cites only the "reserved-name guard"; f5c6109 adds the parse-time basename guard and the destination==source guard — worth a one-line doc touch-up later, not a blocker.
  • TraceFilter.import_version is documented as mirror-only and fails loudly on the production table (no such column) rather than silently widening — the intended fail-closed behavior, but the error surface is a raw BigQuery NOT FOUND column error; a friendlier message can wait.
  • _VersionPredicateFake is intentionally minimal (honors only the predicates the reader actually emits). That is good test design for this contract; extending it is optional.
  • Parameter naming uses two distinct names (@pin_import_version in the selector pushdown path, @import_version in TraceFilter); no collision today since the anchored fetch's filter never carries the pin. Fine as-is.

Verification performed

  • git diff e438c0e..f5c6109 and git diff 2c4804b..HEAD read in full.
  • pytest tests/test_native_events_writer.py tests/test_evalbench_importer.py — 155 passed.
  • pytest tests/test_cli_evalbench_native_import.py tests/test_trace_filter_factory.py tests/test_trace_identity_u2.py tests/test_client_labels.py — 179 passed.
  • Full offline suite (live tests excluded) — 4429 passed, 24 skipped, 0 failed.
  • Worktree unmodified; no pushes, no posts, no git mutations.
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.
caohy1988 added a commit to caohy1988/BQAA-SDK-fork that referenced this pull request Oct 4, 2026
… import_version pin

Review round (Fable P1): two UNCHANGED sentences in the passages PR GoogleCloudPlatform#508
edits contradicted the new import_version text.

- trace_filter() refusal: dropped the stale consequence 'silently widen
  the evaluation to every retained version of the job'. The filter
  carries import_version (applied to both the candidate WHERE and the
  row scope, trace.py), so an empty session set would still stay inside
  the pinned version. The refusal itself (ValueError, nothing to score)
  is unchanged.
- Drill-down opening paragraph: scoped the version-specific
  evalbench-import:{job_id}:{import_version}:{scenario_id} identity to
  rows converted from EvalBench source tables. Native agent_events
  imports (GoogleCloudPlatform#463) keep the real ADK session_id/trace_id
  (native_events.py _native_event_row), so the selector's
  import_version pin is what isolates one version there.

Docs only; no code change.
haiyuan-eng-google pushed a commit that referenced this pull request Oct 5, 2026
…s (nightly docs drift) (#508)

* audit: document the import_version pin in EvalBench drill-down helpers (nightly docs drift)

docs/evalbench.md still described the pre-#464 return shapes of the two
EvalBench drill-down helpers:

- trace_selector() was documented as returning only session_id and
  experiment_id ("the session id already pins the import version").
  EvalBenchSession.trace_selector() (src/bigquery_agent_analytics/
  evalbench.py:2427-2431) also returns import_version.
- EvalBenchImportSessions.trace_filter() was documented as returning
  TraceFilter(experiment_id, session_ids, limit) because "TraceFilter has
  no import-version dimension". TraceFilter has an import_version field
  (trace.py:578), and trace_filter() sets it (evalbench.py:2674-2679).

Both paragraphs now list the import_version pin and, following the
helpers' docstrings, say why it is redundant for imports converted from
EvalBench source tables but load-bearing for native agent_events imports
(#463), whose retained versions share the real ADK session ids.

Docs only; no code change.

* docs: fix two pre-#464 sentences contradicting the import_version pin

Review round (Fable P1): two UNCHANGED sentences in the passages PR #508
edits contradicted the new import_version text.

- trace_filter() refusal: dropped the stale consequence 'silently widen
  the evaluation to every retained version of the job'. The filter
  carries import_version (applied to both the candidate WHERE and the
  row scope, trace.py), so an empty session set would still stay inside
  the pinned version. The refusal itself (ValueError, nothing to score)
  is unchanged.
- Drill-down opening paragraph: scoped the version-specific
  evalbench-import:{job_id}:{import_version}:{scenario_id} identity to
  rows converted from EvalBench source tables. Native agent_events
  imports (#463) keep the real ADK session_id/trace_id
  (native_events.py _native_event_row), so the selector's
  import_version pin is what isolates one version there.

Docs only; no code change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants