Repository navigation
Commit 898ec06
* fix(task): clear nativeArgs when tool-call finalize fails (#1221)
finalizeStreamingToolCall() returns null when a streamed native tool
call's arguments are truncated (e.g. the model hits max_tokens mid
write_to_file content). Task.ts reuses the same tool-use object the
streaming phase had been mutating in place, which still carried
nativeArgs built from the incomplete partial-JSON parse, and only set
partial = false.
presentAssistantMessage.ts already guards against exactly this case
(isKnownTool && !block.nativeArgs && !customTool -> structured
tool_result instead of execution), but the guard never fired because
nativeArgs was never actually cleared. Truncated arguments (e.g. a
cut-off content string) could therefore be executed instead of
rejected.
Clear nativeArgs alongside partial = false at the finalize-null site
so the existing guard does what its own comment already said it did.
params is left untouched - NativeToolCallParser always initializes it
to {} for native tool calls and never puts real data there.
Adds truncated-native-tool-args.spec.ts, mirroring the exact Task.ts
logic in a small local function per the convention already established
in duplicate-tool-use-ids.spec.ts.
* test(task): add integration coverage for truncated write_to_file finalize (#1221)
Adds an integration-level regression test alongside the existing
simulation-based unit tests in truncated-native-tool-args.spec.ts.
Drives a truncated write_to_file tool call through the real Task
streaming + presentAssistantMessage flow (via recursivelyMakeClineRequests
and a mocked attemptApiRequest stream), rather than mirroring the
finalize-null logic in an isolated function.
Spies on writeToFileTool.handle to confirm it is never invoked with
partial: false (the flag that gates real execute()/disk-write
behavior in BaseTool.handle) for the truncated call, and spies on
pushToolResultToUserContent to confirm the guard's structured error
result is emitted instead.
Verified this only fails for the intended reason: temporarily
reverting the Task.ts fix makes writeToFileTool.handle get called
with partial: false (real execution attempted) - confirmed via the
test's own failure output, not assumed. An earlier version of this
test used a .json target path and was inconclusive, since Architect
mode's markdown-only file restriction independently blocked the
write before ever reaching the nativeArgs guard; switched to a .md
path so the guard under test is what's actually being exercised.
Full core/task suite: 27 files, 382 tests, all passing.
* fix(task): also clear params on truncated tool-call finalize (#1221)
Clearing nativeArgs alone left a second gap: Task.ts records each
tool_use into apiConversationHistory via toolUse.nativeArgs ||
toolUse.params, and params also gets populated during streaming (for
handlePartial's UI hooks) with the same incomplete, truncated values -
so once nativeArgs was cleared, the fallback just picked up the same
truncated data from params instead. Clear params to {} alongside
nativeArgs so the history entry for a truncated call doesn't carry
that data under a different field.
Execution itself was never at risk from this gap - BaseTool.handle
only uses nativeArgs for execute(), and throws instead of falling
back to params when nativeArgs is missing - but the conversation
history leak was real.
Adds an assertion to the Task.spec.ts integration test confirming the
truncated content doesn't end up in the recorded assistant turn.
* test(task): update safeEnsureModelFetched mock after rebase
safeEnsureModelFetched's return type changed to Promise<ModelInfo>
upstream while this branch was in flight; the new integration test
still had mockResolvedValue(undefined) from before that change,
which the type checker caught after rebasing onto main. Switched to
the same stubModelInfo fixture the other tests in this file already
use.
---------
Co-authored-by: Can <[email protected]>
Co-authored-by: T <[email protected]>
1 parent eb83244 commit 898ec06
3 files changed
Lines changed: 223 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3826 | 3826 | | |
3827 | 3827 | | |
3828 | 3828 | | |
3829 | | - | |
3830 | | - | |
3831 | | - | |
| 3829 | + | |
| 3830 | + | |
| 3831 | + | |
| 3832 | + | |
| 3833 | + | |
| 3834 | + | |
| 3835 | + | |
| 3836 | + | |
| 3837 | + | |
| 3838 | + | |
| 3839 | + | |
3832 | 3840 | | |
3833 | 3841 | | |
3834 | 3842 | | |
| 3843 | + | |
| 3844 | + | |
3835 | 3845 | | |
3836 | 3846 | | |
3837 | 3847 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
750 | 751 | | |
751 | 752 | | |
752 | 753 | | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
753 | 850 | | |
754 | 851 | | |
755 | 852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
0 commit comments