Commit 52872b9
committed
fix(live): yield tool_call events immediately to prevent Gemini 3.1 deadlock
GeminiLlmConnection.receive() accumulated tool_call messages in a
tool_call_parts buffer and only yielded them when server_content.turn_complete
arrived. This pattern deadlocks run_live() on gemini-3.1-flash-live-preview,
which does NOT send turn_complete until AFTER it receives the tool response:
ADK waits for turn_complete → 3.1 waits for tool_response →
tool never dispatched → WebSocket times out (1000 close) ~15s later
This was the pre-1.28 behavior; the accumulation pattern was introduced
recently and broke 3.1 Live compatibility.
Fix: yield tool_call messages as LlmResponse events immediately, one per
incoming message. 2.5 and other models are unaffected — the flow layer
handles yielded function_call content identically regardless of whether
it arrives before or after turn_complete.
Confirmed in production: after this fix, audio returns ~1150ms after
tool response on 3.1 (matching the direct SDK timing). Without the fix,
every tool call hangs until the WebSocket times out.
Tests updated:
- test_receive_multiple_tool_call_messages_yielded_immediately (renamed
from ...buffered_until_turn_complete) — asserts each tool_call yields
its own LlmResponse
- test_receive_tool_call_and_grounding_metadata_with_native_audio —
updated expected response ordering (tool_call now yields before the
subsequent audio/grounding message instead of after it)
- test_receive_tool_call_yielded_without_turn_complete (new) — regression
test for the 3.1 deadlock: asserts tool_call yields even when no
turn_complete is ever sent1 parent 1af1b4a commit 52872b9
2 files changed
Lines changed: 95 additions & 45 deletions
File tree
- src/google/adk/models
- tests/unittests/models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
191 | 190 | | |
192 | 191 | | |
193 | 192 | | |
| |||
327 | 326 | | |
328 | 327 | | |
329 | 328 | | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | 329 | | |
339 | 330 | | |
340 | 331 | | |
| |||
362 | 353 | | |
363 | 354 | | |
364 | 355 | | |
365 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
366 | 363 | | |
367 | 364 | | |
368 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
| |||
383 | 385 | | |
384 | 386 | | |
385 | 387 | | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | 388 | | |
395 | 389 | | |
396 | 390 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1023 | 1023 | | |
1024 | 1024 | | |
1025 | 1025 | | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
| 1026 | + | |
| 1027 | + | |
1029 | 1028 | | |
1030 | 1029 | | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
| 1030 | + | |
1037 | 1031 | | |
1038 | | - | |
| 1032 | + | |
1039 | 1033 | | |
1040 | 1034 | | |
1041 | | - | |
| 1035 | + | |
1042 | 1036 | | |
1043 | 1037 | | |
1044 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1045 | 1045 | | |
1046 | 1046 | | |
1047 | 1047 | | |
1048 | 1048 | | |
1049 | 1049 | | |
1050 | 1050 | | |
1051 | | - | |
| 1051 | + | |
1052 | 1052 | | |
1053 | 1053 | | |
1054 | | - | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
1055 | 1060 | | |
1056 | 1061 | | |
1057 | 1062 | | |
| |||
1120 | 1125 | | |
1121 | 1126 | | |
1122 | 1127 | | |
1123 | | - | |
1124 | | - | |
| 1128 | + | |
| 1129 | + | |
1125 | 1130 | | |
1126 | | - | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1127 | 1188 | | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1137 | 1193 | | |
1138 | 1194 | | |
1139 | 1195 | | |
| |||
0 commit comments