Repository navigation
Description
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 answercall: 123(~L106, ~L471). - A visible
AGENT_RESPONSEtext that quotes a call between two text parts returnsNone, 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 giveAnswerin 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 onlytext: ', sotext: "foo"andtext: fookeep the wrapper and a truncatedtext: ...[TRUNCATED]last turn becomes the answer. Routing those through_sql_unwrap_text_fieldwould match Python.- Summary type and producer markers. SQL stringifies a non-string
text_summary(~L588), sofalseor42can 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