Commit 78c56d7
authored
fix(gemini): round-trip functionCall.id through tool-call response serialization (#199)
## Summary
`parseToolCallPart` in `src/gemini.ts` was dropping the fixture's
`tool_call.id` when constructing the Gemini response body. This silently
breaks any client that preserves the id across the round trip (real
Gemini's session correlator, ADK-style clients, any proxy that needs to
match a follow-up `functionResponse` back to the originating
`functionCall`).
The aimock `geminiToCompletionRequest` translator then has to fall back
to `call_gemini_<name>_<i>`, which means any fixture chain keyed on a
specific `toolCallId` never advances past the first leg — aimock
re-matches the same `userMessage`-keyed leg-1 fixture in a loop while
the client keeps sending what looks like the same context.
## Change
- Add the optional `id` field on `GeminiPart.functionCall` and
`GeminiPart.functionResponse` shapes.
- Emit `id` on `parseToolCallPart` when the fixture sets one.
Backward-compatible: fixtures without an id continue to serialize
without one.
## How this was found
While porting `showcase/google-adk` to D5 parity with
`langgraph-python`, the `tool-rendering-reasoning-chain` demo's three
chained pills (AAPL→MSFT, d20→d6, flights+weather) kept stalling after
the first tool call. Dumping the request body aimock received showed the
`model` content had `functionCall: { name, args }` with no `id`. Tracing
back through `parseToolCallPart` revealed the id was being dropped on
serialization.
## Test plan
- [ ] Existing aimock tests still pass.
- [ ] Curl probe with a multi-leg fixture chain (one fixture keyed on
`userMessage`, follow-up keyed on `toolCallId`) advances past leg 1 when
the client preserves and re-sends the id.
🤖 Generated with [Claude Code](https://claude.com/claude-code)4 files changed
Lines changed: 119 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
115 | 136 | | |
116 | 137 | | |
117 | 138 | | |
| |||
133 | 154 | | |
134 | 155 | | |
135 | 156 | | |
| 157 | + | |
| 158 | + | |
136 | 159 | | |
137 | 160 | | |
138 | 161 | | |
| |||
511 | 534 | | |
512 | 535 | | |
513 | 536 | | |
514 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
515 | 542 | | |
516 | 543 | | |
517 | 544 | | |
| |||
521 | 548 | | |
522 | 549 | | |
523 | 550 | | |
524 | | - | |
525 | 551 | | |
526 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
527 | 589 | | |
528 | 590 | | |
529 | 591 | | |
| |||
583 | 645 | | |
584 | 646 | | |
585 | 647 | | |
586 | | - | |
| 648 | + | |
587 | 649 | | |
588 | 650 | | |
589 | 651 | | |
| |||
596 | 658 | | |
597 | 659 | | |
598 | 660 | | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
599 | 664 | | |
600 | 665 | | |
601 | 666 | | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
602 | 692 | | |
603 | 693 | | |
604 | 694 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
322 | 340 | | |
323 | 341 | | |
324 | 342 | | |
| |||
0 commit comments