Skip to content

Hard crash on GLM-4.6/5.2 (Fireworks): tool-call arguments rejected as 'invalid JSON', session dies #3153

Description

@fishloa

Summary

Running an agentic coding session with a newer model on an OpenAI-compatible provider (GLM 5.2 via Fireworks AI), Crush hard-exits mid-session whenever the model emits an edit/write tool call, with:

ERROR  Agent processing failed: failed to start agent processing stream:
bad request: Invalid tool call in messages:
tool_calls[].function.arguments for function 'edit' must be a JSON object string (or an object), got invalid JSON.

The whole crush run process dies (exit 1). The model's accumulated progress in that turn is lost.

Environment

  • Crush v0.76.0 (also nothing relevant in v0.77.0 changelog).
  • Provider: custom fireworks (OpenAI-compatible, https://api.fireworks.ai/inference/v1).
  • Model: accounts/fireworks/models/glm-5p2 (GLM 5.2). Headless crush run -m … -c … --quiet.

Key observation

It crashes only on tool calls with large/complex string argumentsedit and write (which carry code blobs with newlines/quotes/special chars). The same model's read/grep/reasoning tool calls in the same session work fine, and it produces excellent diagnoses. So GLM 5.2 is emitting the arguments field in a shape Crush's strict parser rejects (e.g. not a JSON-stringified object, or with unescaped content), specifically when the payload is big.

Other models on the same Fireworks provider (DeepSeek V4 Pro, Kimi K2.7) emit clean tool args and never hit this — resuming the same session on one of those lets the edit go through, which confirms it's a per-model tool-arg-serialization mismatch, not a session/config problem.

Impact

The model can't apply any file edit → unusable for coding with GLM 5.2, and a single bad tool-call kills the run rather than being recoverable/retried.

Suggested fix

Be lenient when normalizing tool_calls[].function.arguments from OpenAI-compatible providers:

  • If arguments is a string that fails JSON.parse, attempt a repair pass (strip markdown fences, fix common escaping) before rejecting.
  • Treat a malformed tool-call as a recoverable turn error (feed the parse error back to the model to retry) instead of a fatal stream error that exits the process.

Happy to provide a fuller repro (the GLM 5.2 raw tool-call payload) if useful.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions