Skip to content

fix(openai-compat): recover from malformed tool calls#64

Open
xjdr-noumena wants to merge 1 commit into
mainfrom
fix/openai-compat-malformed-tool-recovery-48
Open

fix(openai-compat): recover from malformed tool calls#64
xjdr-noumena wants to merge 1 commit into
mainfrom
fix/openai-compat-malformed-tool-recovery-48

Conversation

@xjdr-noumena

Copy link
Copy Markdown
Contributor

Summary

Clean malformed OpenAI-compatible tool-call recovery for #48 and the useful part of #52.

  • adds a pre-send history sanitizer that strips malformed assistant tool_use blocks with blank, missing, or non-string names
  • removes matching tool_result blocks so bad tool-call history does not poison every later OpenAI-compatible request
  • adds schema-confusion detection for likely sibling-tool argument swaps across Bash, Grep, Glob, Read, WebFetch, and Write
  • appends targeted model-facing hints to the existing Zod validation error instead of silently rerouting tool calls
  • emits structured telemetry for rejected schema leaks via ncode_schema_leak_rejected
  • adds focused tests for sanitizer behavior, schema-confusion hinting, and telemetry shape

Scope intentionally excluded from this PR:

This should be treated as partial #48 coverage plus the real #52 history-sanitizer fix.

Validation

Focused recovery tests:

/home/xjdr/.bun/bin/bun test \
  src/services/api/openAICompatInferenceClient.test.ts \
  src/services/tools/schemaConfusionHint.test.ts \
  src/services/tools/schemaLeakTelemetry.test.ts

Result: 93 pass, 0 fail.

Contracts:

PATH="$HOME/.bun/bin:$PATH" timeout 120s /home/xjdr/.bun/bin/bun run test:contracts

Result: 238 pass, 0 fail.

Package smoke:

PATH="$HOME/.bun/bin:$PATH" timeout 180s /home/xjdr/.bun/bin/bun run test:package-smoke

Result: passed. Security audit OK; native probe OK with documented sharp-fallback image mode.

Diff check:

git diff --cached --check

Result: passed before commit.

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.

1 participant