GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(openai-chat): log redacted invalid tool-call shape by Ingwannu · Pull Request #1530 · lidge-jun/opencodex

Conversation

@Ingwannu

@Ingwannu Ingwannu commented Aug 12, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Owner

Summary

  • add opt-in structural diagnostics at the existing fail-closed OpenAI Chat tool_calls validation boundary
  • record only a finite reason code, stream/non-stream mode, array member index, and JavaScript value type
  • never retain tool-call IDs, function names, tool arguments, request bodies, credentials, or account data
  • preserve current parsing behavior; this PR gathers evidence for [Compatibility] Xiaomi MiMo v2.5 fails on 2.12.0 with invalid tool calls and an incorrect reasoning ladder #1483 and does not guess at a permissive Xiaomi MiMo compatibility mapping

Closes no issue; supports diagnosis of #1483.

Verification

  • bun scripts/test.ts tests/openai-chat-hardening.test.ts tests/issue-452-empty-503.test.ts tests/debug.test.ts (66 passed, 0 failed)
  • bun run typecheck
  • bun run privacy:scan
  • git diff --check

To capture one redacted reproduction after this lands:

ocx debug provider on
ocx debug provider logs -f
# reproduce once
ocx debug provider off

Expected diagnostic shape:

[ocx:openai-chat:invalid-tool-calls] {"mode":"stream","reason":"tool_call_not_object","callIndex":1,"valueType":"null"}

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. No user-visible behavior/configuration changes; existing provider-debug commands expose the diagnostic.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. Diagnostics remain opt-in and values are never serialized.

Summary by CodeRabbit

  • Bug Fixes
    • Improved diagnostics when malformed tool-call data is received.
    • Added clearer identification of the processing mode, validation reason, item position, and value type.
    • Ensured sensitive tool-call values are never included in diagnostic logs.
    • Preserved existing invalid tool-call error behavior and validation precedence.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chatgpt-codex-connector[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Ingwannu Ingwannu mentioned this pull request Aug 12, 2026
[Compatibility] Xiaomi MiMo v2.5 fails on 2.12.0 with invalid tool calls and an incorrect reasoning ladder #1483
Closed
3 tasks done
@github-actions github-actions Bot added the bug Something isn't working label Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The OpenAI adapter now classifies malformed streamed and buffered tool-call payloads. It logs shape-only diagnostics before returning the existing invalid-tool-calls error. Tests cover logging, redaction, disabled defaults, validation precedence, and streaming metadata.

Changes

Tool-call diagnostics

Layer / File(s) Summary
Diagnosis and validation instrumentation
src/adapters/openai-chat.ts
The adapter classifies malformed tool-call containers, identifiers, names, arguments, and function fields. Streaming and buffered paths log the mode, reason, index, and value type without logging payload values. Existing fail-closed rejection behavior remains unchanged.
Diagnostic behavior tests
tests/openai-chat-hardening.test.ts
Tests verify diagnostic output, sensitive-value redaction, disabled default logging, validation precedence, streaming metadata, and cleanup of debug state between tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • lidge-jun/opencodex#1468: Modifies the same adapter and hardening tests for malformed tool-call validation and diagnostics.
  • lidge-jun/opencodex#800: Addresses malformed OpenAI tool-call stream handling in the same adapter.
  • lidge-jun/opencodex#1531: Changes rejection and termination behavior in the same tool-call validation paths.

Suggested reviewers: lidge-jun, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding redacted logging for invalid OpenAI Chat tool-call shapes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/diagnose-1483-openai-chat-shape

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Ingwannu and others added 3 commits August 12, 2026 23:19
@Ingwannu @lidge-jun
fix(openai-chat): log redacted invalid tool-call shape
933d009
@lidge-jun
fix(openai-chat): align the tool-call diagnostic with the current val…
d8fe122
…idation

Rebase follow-up on top of @Ingwannu's diagnostic commit. #1531 landed
between this PR being written and being rebased, and it moved the
validation the diagnostic describes.

The streamed path now validates function/name/arguments/id at ingest
rather than only checking container and member shapes, so the diagnostic
no longer skips per-member inspection in stream mode, and the three new
ingest rejections log through the same helper. Blank and whitespace-only
names are now rejected on the buffered path; reporting that as
name_invalid would claim a type problem for a correctly-typed value, so
it gets its own reason code.

A diagnostic that describes a boundary the code no longer has is worse
than none: it would send provider-compatibility work after the wrong
shape.
@lidge-jun
fix(openai-chat): match diagnostic precedence to the validator
be101c3
Review follow-up. The buffered validator checks the function container
first, then id/name/arguments types together, and only then the blank
name. The diagnostic checked id before the container and blank name
before arguments, so a payload carrying two defects at once was reported
under the wrong reason.

That matters precisely because of what this diagnostic is for: it exists
to point provider-compatibility work at the shape that was rejected. A
wrong reason code sends that work after the wrong shape.

Four tests each carry two defects at once, so only the matching order
produces the expected reason.
@lidge-jun
lidge-jun force-pushed the agent/diagnose-1483-openai-chat-shape branch from fdb26c6 to be101c3 Compare August 12, 2026 14:37
@lidge-jun

lidge-jun commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Rebased onto current dev (d03755ee9) and pushed two commits on top of yours; your commit 933d00974 is preserved.

Why it conflicted. #1531 merged between this being written and being rebased, and it changed the exact validation this diagnostic describes. Two consequences:

The streamed path now validates function/name/arguments/id at ingest rather than only checking container and member shapes. diagnoseInvalidToolCalls explicitly continued in stream mode, which was right against the old code and wrong against the new — the three new ingest rejections would have produced no diagnostic at all. Stream mode now inspects those same fields and all three sites log through the helper.

The buffered path now rejects blank and whitespace-only names. The diagnostic would have reported that as tool_call_function_name_invalid — a type problem for a correctly-typed value — so it gets its own tool_call_function_name_blank code.

A second review round then caught a precedence bug in my own follow-up. The validator checks the function container first, then id/name/arguments types together, and only then the blank name. My diagnosis checked id before the container and blank name before arguments, so a payload carrying two defects at once reported the wrong reason. That is exactly the failure this diagnostic is supposed to prevent — a wrong reason code sends provider-compatibility work after the wrong shape. Fixed, with four tests that each carry two defects simultaneously so only the matching order passes.

Privacy was re-verified independently: reason codes and modes are finite literals, valueType is a fixed label or a bare typeof, and the buffer stores only the already-redacted serialized line. No caller-controlled string reaches the log.

On whether this is still worth landing now that #1531 fixed #1514: yes. #1531 fixed one known shape; this records which check rejected a payload, which is what makes the next provider incompatibility diagnosable instead of a guess. It stays opt-in and off by default.

Verification at be101c32b on a Linux runner (Bun 1.3.14): bun x tsc --noEmit exit 0; openai-chat-hardening + eof + parallel-stream 91 pass / 0 fail; 11-file adapter sweep 165 pass / 0 fail; privacy:scan passed. Your tests remain valid post-rebase and go red on dev without the source change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lidge-jun
lidge-jun marked this pull request as ready for review August 12, 2026 14:38
@lidge-jun
lidge-jun requested review from Wibias and lidge-jun as code owners August 12, 2026 14:38
coderabbitai[bot]
coderabbitai Bot reviewed Aug 12, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/adapters/openai-chat.ts`:
- Around line 295-298: Update logInvalidToolCalls to return immediately when
isDebugEnabled() is false, before calling diagnoseInvalidToolCalls; retain the
existing diagnostic classification and debugProviderDiagnostic behavior when
debugging is enabled.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 83f1de84-cbf2-46c8-8095-70c0202ce456

📥 Commits

Reviewing files that changed from the base of the PR and between d03755e and be101c3.

📒 Files selected for processing (2)
  • src/adapters/openai-chat.ts
  • tests/openai-chat-hardening.test.ts

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/adapters/openai-chat.ts
Comment on lines +295 to +298
function logInvalidToolCalls(mode: "stream" | "response", rawToolCalls: unknown): void {
const diagnostic = diagnoseInvalidToolCalls(rawToolCalls, mode);
if (diagnostic) debugProviderDiagnostic("openai-chat", "invalid-tool-calls", { mode, ...diagnostic });
}

@coderabbitai coderabbitai Bot Aug 12, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Gate classification when debug diagnostics are disabled.

Line 296 calls diagnoseInvalidToolCalls before debugProviderDiagnostic checks the debug setting. A malformed array is already scanned by the validator. This adds a second scan even when diagnostics are disabled. Return before classification when isDebugEnabled() is false.

Proposed fix
 function logInvalidToolCalls(mode: "stream" | "response", rawToolCalls: unknown): void {
+  if (!isDebugEnabled()) return;
   const diagnostic = diagnoseInvalidToolCalls(rawToolCalls, mode);
   if (diagnostic) debugProviderDiagnostic("openai-chat", "invalid-tool-calls", { mode, ...diagnostic });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function logInvalidToolCalls(mode: "stream" | "response", rawToolCalls: unknown): void {
const diagnostic = diagnoseInvalidToolCalls(rawToolCalls, mode);
if (diagnostic) debugProviderDiagnostic("openai-chat", "invalid-tool-calls", { mode, ...diagnostic });
}
function logInvalidToolCalls(mode: "stream" | "response", rawToolCalls: unknown): void {
if (!isDebugEnabled()) return;
const diagnostic = diagnoseInvalidToolCalls(rawToolCalls, mode);
if (diagnostic) debugProviderDiagnostic("openai-chat", "invalid-tool-calls", { mode, ...diagnostic });
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/adapters/openai-chat.ts` around lines 295 - 298, Update
logInvalidToolCalls to return immediately when isDebugEnabled() is false, before
calling diagnoseInvalidToolCalls; retain the existing diagnostic classification
and debugProviderDiagnostic behavior when debugging is enabled.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lidge-jun

lidge-jun commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Full-suite result at be101c32b on the Linux runner (Bun 1.3.14):

11341 pass
0 fail
EXIT=0

All four Linux CI shards are green here as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lidge-jun
lidge-jun merged commit ccd3a25 into dev Aug 12, 2026
65 of 69 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@Wibias
Wibias deleted the agent/diagnose-1483-openai-chat-shape branch August 12, 2026 21:34
This was referenced Aug 15, 2026
fix(openai-chat): tolerate null tool delta padding #1754
Merged
[Provider] OpenCode Free DeepSeek V4 Flash streams object-valued function.name #1824
Closed
fix(openai-chat): classify and fingerprint malformed tool calls #1825
Merged
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
@lidge-jun
Merge pull request lidge-jun#1530 from lidge-jun/agent/diagnose-1483-…
73c4cc6
…openai-chat-shape

fix(openai-chat): log redacted invalid tool-call shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@lidge-jun lidge-jun Awaiting requested review from lidge-jun lidge-jun is a code owner
@Wibias Wibias Awaiting requested review from Wibias

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bug Something isn't working

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Ingwannu @lidge-jun
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.