google-gemini / google-gemini/gemini-cli

bug(sdk): unguarded JSON.parse on tool-call args kills sendStream (session.ts)

Open Beginner friendly
#29,308 2 comments 0 reactions 0 assignees View on GitHub
area/non-interactive effort/small kind/bug priority/p2 status/bot-triaged status/need-information
Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 3h
Merged PRs (30d)
45

Description

## What happened?

`packages/sdk/src/session.ts:252-258` calls `JSON.parse` on model-provided args inside the stream loop with no `try/catch`:

```ts
let args = toolCall.args;
if (typeof args === 'string') {
args = JSON.parse(args);
}
```

A single malformed `ToolCallRequest.args` string throws inside `sendStream()`, killing the entire `for await` loop instead of returning a tool error the model can retry. One bad tool call poisons the whole turn.

## What did you expect to happen?

Malformed args should produce a `functionResponse` error part (model-visible) and continue processing remaining events, matching normal tool-error semantics.

## Client information

- Repo: `google-gemini/gemini-cli` @ `main` `9c1b0a610`
- Area: `packages/sdk/src/session.ts:252-264`
- Platform: source checkout, SDK `sendStream` path

## Login information

N/A — reproducible with a unit test feeding `ToolCallRequest` with `args: "{bad json"`.

## Anything else we need to know?

**Fix direction:** wrap in `try/catch`; on failure push error `functionResponse` and continue; add `session.test.ts` malformed-args case asserting stream survives + error part emitted. Also consider length cap on string args before parse.

Contributor guide

Open the contributing guide

Research direction

Start at packages/sdk/src/session.ts:252-264 and trace how sendStream handles ToolCallRequest arguments and tool errors. Run the session tests, then add the malformed-args case in session.test.ts described in the issue. Done means malformed JSON emits a model-visible functionResponse error and later stream events continue processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.