Skip to content

bug(agents): OpenAI function-call replay silently replaces malformed arguments with {} — silent data loss on tool replay #61478

Closed

Description

@100yenadmin

Bug

In src/agents/openai-ws-message-conversion.ts:527-533, buildAssistantMessageFromResponse() silently replaces function-call arguments with {} when JSON.parse() fails:

arguments: (() => {
  try { return JSON.parse(item.arguments) } catch { return {} }
})(),

Impact

  • The original malformed-but-real argument payload is irrecoverably lost
  • Later replay back into OpenAI converts non-string arguments via JSON.stringify(block.arguments ?? {}) (:425-428), producing "{}" where the original content was something else
  • Tool replay fidelity breaks: downstream behavior can differ from the original turn
  • Especially problematic when arguments were partial/non-JSON from provider quirks or streaming interruptions

Suggested fix

Preserve the original string as-is when JSON parsing fails, rather than replacing with {}. The replay path should handle the raw string gracefully rather than silently destroying data.

Severity

P2 — silent data loss on a non-happy path.

Code location

  • src/agents/openai-ws-message-conversion.ts:527-533, 425-428

Related

  • Found during post-merge review of #59643
  • Not phase-related, but in the same file family

Activity

  1. 100yenadmin commented on Apr 5, 2026

    @100yenadmin
    ContributorAuthor

    Part of the post-#59643 adversarial review family. See #61474 for the full list. This one is independent of phase handling — it is a data-loss issue in buildAssistantMessageFromResponse() affecting OpenAI function-call replay fidelity.

  2. changed the title [-]bug(agents): function-call replay silently replaces malformed arguments with empty object[/-] [+]bug(agents): OpenAI function-call replay silently replaces malformed arguments with {} — silent data loss on tool replay[/+] on Apr 5, 2026
  3. locked as resolved and limited conversation to collaborators on Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions