Repository navigation
Commit e6739e5
committed
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.
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`.1 parent 03735ec commit e6739e5
3 files changed
Lines changed: 266 additions & 9 deletions
File tree
- docs-site/src/content/docs/reference
- src/adapters
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
375 | 436 | | |
376 | 437 | | |
377 | 438 | | |
| |||
684 | 745 | | |
685 | 746 | | |
686 | 747 | | |
687 | | - | |
| 748 | + | |
688 | 749 | | |
689 | 750 | | |
690 | 751 | | |
| |||
693 | 754 | | |
694 | 755 | | |
695 | 756 | | |
696 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
697 | 775 | | |
698 | 776 | | |
699 | 777 | | |
| |||
924 | 1002 | | |
925 | 1003 | | |
926 | 1004 | | |
927 | | - | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
928 | 1014 | | |
929 | 1015 | | |
930 | 1016 | | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
931 | 1025 | | |
932 | 1026 | | |
933 | | - | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
934 | 1035 | | |
935 | 1036 | | |
936 | 1037 | | |
937 | 1038 | | |
938 | 1039 | | |
939 | 1040 | | |
940 | | - | |
| 1041 | + | |
941 | 1042 | | |
942 | 1043 | | |
943 | | - | |
| 1044 | + | |
944 | 1045 | | |
945 | 1046 | | |
946 | 1047 | | |
| |||
979 | 1080 | | |
980 | 1081 | | |
981 | 1082 | | |
982 | | - | |
983 | | - | |
| 1083 | + | |
| 1084 | + | |
984 | 1085 | | |
985 | 1086 | | |
986 | 1087 | | |
987 | 1088 | | |
988 | 1089 | | |
989 | 1090 | | |
990 | 1091 | | |
991 | | - | |
| 1092 | + | |
992 | 1093 | | |
993 | 1094 | | |
994 | 1095 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
130 | 280 | | |
131 | 281 | | |
132 | 282 | | |
| |||
0 commit comments