Skip to content

Follow-up for #601 at ff0ebe78: invocation scoping edge cases, structured parts, and Python/SQL parity gaps #603

Backlog

Description

@caohy1988

Follow-up from the review of #601 at ff0ebe7. The core producer shapes behave correctly and the final-response tests pass, but these edge cases reproduce offline (Python accessors plus the SQLite shim used by tests/test_final_response_sql.py). The first four are the important ones.

A new turn can still return the previous turn's answer

_current_invocation (trace.py ~L391-411, SQL mirror ~L669) trusts a non-ADK invocation id only once it repeats or shows up on a response row. A completed first turn followed by a new user message with a fresh id meets neither condition, so all three paths return the first turn's answer for the unanswered second request. The merge base returned None for the compatibility-view version of this. A mixed-stamping variant (USER inv-1, answer inv-1, USER inv-2, id-less empty response) does the same. Treating an explicit user message or invocation start as a boundary, and honoring the writer's invocation id on its opening LLM_REQUEST, would cover both while keeping the exception for an isolated trailing tool event.

Nested invocations deeper than one level

SQL maps each row to its immediate parent once (~L569-575) while Python walks the chain to the root (~L377-382). For A -> B -> C with a C row last, SQL picks B as the current run and returns NULL where Python returns the parent's answer. Separately, the nested-reply exclusion (~L442, ~L597) is decided from the reply's own metadata, so a child reply that only carries the child's invocation id is treated as top-level: when the parent ends on a tool call, all three paths return the child's internal result. Building the parent relation once per session and using it for both root selection and eligibility would fix both.

JSON-string answers can lose fields when loaded from rows

The row loader (~L902) and its evaluator counterpart (performance_evaluator.py ~L118) can decode a JSON scalar string a second time, which trace.py ~L305 then reads as an event envelope. With AGENT_RESPONSE now taking precedence, an answer like {"response":"inner","count":2} comes back as just inner from both Python accessors, while SQL and the merge base keep the full string. The SQL parity fixture (~L175 of the test) re-encodes the cell before loading, which hides the production shape.

Native model content is scored as JSON, including tool calls

When a custom formatter keeps a model content object or a list of parts, ~L323 and the SQL fallback at ~L619 treat it as an answer. A content object holding only a function call gets serialized and handed to the judge (the merge base gave NULL there), two text parts come back as [{"text":"A"},{"text":"B"}], and a top-level list differs between Python and SQL. Recognizing content objects and typed part lists before the generic JSON fallback (join text, classify calls, skip function responses) would keep structured final-tool arguments working.

Call-part parsing

  • A logged function name that doesn't start with a letter or underscore (123, -lookup) is returned as the answer call: 123 (~L106, ~L471).
  • A visible AGENT_RESPONSE text that quotes a call between two text parts returns None, since call detection runs on text that the producer already filtered (~L326, ~L649). The merge base handled both correctly.
  • Calls whose arguments contain | or a newline aren't parsed as calls in Python (call: lookup(q='a | b') becomes the answer), and SQL only handles the pipe case.

Smaller items

  • Equal timestamps. The SQL run bounds use strict > (~L711-714) and the recency windows order by timestamp only (~L658, ~L722, ~L734). A user message and its reply at the same timestamp give Answer in Python and NULL in SQL; ordering by the same tiebreak columns the client uses (client.py ~L218) would align them.
  • text: wrappers in SQL. The non-verbatim SQL branch (~L626-639) strips only text: ', so text: "foo" and text: foo keep the wrapper and a truncated text: ...[TRUNCATED] last turn becomes the answer. Routing those through _sql_unwrap_text_field would match Python.
  • Summary type and producer markers. SQL stringifies a non-string text_summary (~L588), so false or 42 can override the real response. Bare [FORMATTER_FAILED] and [REDACTED] markers are graded as replies on both paths.
  • Parse cache size. The lru_cache(maxsize=256) at ~L255 is bounded by count, not bytes; 16 distinct 256 KiB answers left about 8 MB retained after the traces were released. Skipping the cache for large payloads would avoid that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions