Skip to content

Replay malformed or folded historical tool arguments as valid JSON - #422

Merged
Phantivia merged 4 commits into
Pal-AI-Lab:mainfrom
jcs130:fix/unexecuted-arguments-replay-20261118
Nov 19, 2026
Merged

Phantivia merged 4 commits into
Pal-AI-Lab:mainfrom
jcs130:fix/unexecuted-arguments-replay-20261118

Conversation

@jcs130

@jcs130 jcs130 commented Nov 18, 2026 •

Copy link
Copy Markdown

A strict compatible endpoint can reject an entire stateless conversation because one historical function call no longer has parseable JSON arguments. We reproduced this with a truncated call, and with the same call after a Persona added a note to the corresponding non-execution receipt. The latter failed even after a fix that matched the original receipt text exactly.

At the native transport boundary, project malformed historical arguments as a valid JSON object describing their condition. Distinguish the host's folded-arguments marker from invalid source JSON. Preserve valid argument strings byte-for-byte, item identities, provider metadata and all result items. The result remains authoritative about execution. The persistent transcript and live dispatch never pass through this historical edit.

The tests exercise native Responses and Chat Completions, annotated, folded and genuine results, raw request input and context-record input, and a second call interleaved with an interrupted one. A synthetic annotated-receipt replay with the same endpoint and prompt failed before the fix and returned the correct non-execution outcome afterward.

@jcs130 jcs130 changed the title Preserve interrupted tool-call history in strict provider requests Replay malformed or folded historical tool arguments as valid JSON Nov 18, 2026
Phantivia and others added 2 commits November 18, 2026 21:48
- 替换值 REPLAY_ARGS_FOLDED、REPLAY_ARGS_INVALID 是模型看得到的结构标记,和
  FOLD_ARGS_PLACEHOLDER 放在一起;native-input.ts 只做替换,函数头注释写替换的条件与不变量。
- 测试改名 native-input.test.ts,断言对照导出的记号而不是字面值;删去回执原样保留那组用例:
  替换只看 arguments,回执不经过这段代码,第一组用例已经断言回执和 session 记录不变。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
两页的 owner 行补上 src/providers/transport/native-input.ts。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Phantivia
Phantivia merged commit 66cc011 into Pal-AI-Lab:main Nov 19, 2026
3 checks passed
@Phantivia

Copy link
Copy Markdown
Member

Thanks @jcs130, merged. Before merging we pushed two commits to your branch:

  • The two replacement values are now REPLAY_ARGS_FOLDED and REPLAY_ARGS_INVALID in src/core/markers.ts, next to FOLD_ARGS_PLACEHOLDER; that file holds the structural markers the model sees. The comment on requestContext() states when the replacement applies and what stays unchanged.
  • The test file is renamed tests/providers/transport/native-input.test.ts, after the file it covers, and the assertions compare against the exported markers. We dropped the cases that checked receipts are kept as they are: the replacement reads only arguments, so receipts never pass through it, and the first case already asserts that the receipts and the session record are unchanged.
  • docs/providers.md (the replay paragraph) and src/providers/README.md now say that a call whose arguments is not valid JSON goes out as an object with only the _cortico_replay field, and that the session record is not changed.

One of the reasons we took this: llama.cpp parses every historical tool_calls[].function.arguments when the chat template reads arguments as objects, and fails the whole request on one that does not parse (func_args_not_string, called when supports_object_arguments is set).

It ships with the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants