You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4dd570b
Browse filesBrowse the repository at this point in the historyBrowse files
fix(google): validate candidate, content and part containers
#1332 made a malformed nested candidate terminal on the streaming path, on the
rule that a claimed response is not padding. Three containers in the same
adapter never got that rule, and each fails a different way.
`content.parts` is read straight into a `for...of` in both parsers, so a
container that is not an array of objects escapes as a raw `TypeError` —
`{} is not iterable`, or `null is not an object` on `part.thoughtSignature`.
The buffered `parseResponse` call site in `src/server/responses/core.ts` wraps
the call in try/finally with no catch, so the exception leaves the turn
unstructured. A `parts: "txt"` is worse than a crash: a string is iterable, so
it is consumed character by character and the turn completes empty.
`candidate.content` was never inspected at all. `content?.parts` reads
`undefined` from any non-record, so a candidate shaped
`content: [{ parts: [...] }]` — a plausible shape from anything that mirrors the
request's repeated `contents` — dropped its own text and reported success.
The buffered parser also never checked `candidates[0]`. `[null]`, `[5]` and
`["x"]` all reached a bare `done`, reporting a claimed-but-malformed candidate
to the caller as a successful empty turn — the opposite of what the same adapter
does when streaming. A non-array `candidates` was not checked either: `"abc"`
passed the emptiness check because its `length` is 3, and `{}`/`5` were reported
as an absent candidate list rather than a malformed one.
All three now terminate through the existing adapter error channel, carrying the
structural reason, the part index and the offending value's type — never its
contents. The two candidate errors #1332 already emitted get the same treatment,
so one diagnostic type covers every rung; the wording #1332 chose is kept as the
message prefix, so an existing log grep still matches.
Going the other way, the streaming parser was treating a `null` `candidates`
container as corruption and terminating on it. That is the #1219 failure mode one
rung in: a `{"candidates":null}` frame between a content delta and the finish
chunk killed a turn whose answer had already fully arrived, while the same stream
with the key absent or the array empty completed. `null` now joins absence, as it
already does on the buffered side.
Absence stays legal, including the encodings of it that are not records: an
absent, `null` or empty `parts`; an absent, `null` or empty-array `content`
(`[]` is how a JSON writer with no distinct empty-object form spells an empty
object, and it already means "no parts"); and an absent, `null` or empty
`candidates` — while a non-null, non-array `candidates` stays terminal.
0 commit comments