Skip to content

fix: validate completed OpenAI-compatible model probes - #658

Merged
mateaix merged 2 commits into
mateaix:devfrom
RobinZhiBin:codex/fix-model-probe-validation
Oct 9, 2026
Merged

mateaix merged 2 commits into
mateaix:devfrom
RobinZhiBin:codex/fix-model-probe-validation

Conversation

@RobinZhiBin

Copy link
Copy Markdown
Contributor

An OpenAI-compatible endpoint can return HTTP 200 with malformed JSON, an error envelope, empty text or a reasoning-only response. Model tests currently report success anyway; malformed/missing content even gets a fabricated success message. A ten-token budget also prevents some reasoning-capable models from reaching their final answer.

This change requires a valid completion with nonblank textual message.content and finish_reason: stop. Incomplete, filtered, tool-only and invalid replies fail visibly without copying raw provider payloads into the new validation errors. The same validation covers single-model tests, provider connection fallback and discovery probes. Discovery retains failed entries with an error and excludes them from new-model suggestions.

Probe budgets are bounded at 512 tokens for unrecognized/standard families and 4096 for recognized reasoning families. Existing OpenAI max_completion_tokens, sampling restrictions and provider passthrough behavior remain intact. A token-limit failure explicitly says it does not establish that the model is unavailable; there are no automatic retries.

Compatibility and scope

  • This PR covers OpenAI-compatible chat probes only. Native Gemini, Anthropic and DashScope parsers are unchanged.
  • A compatible gateway must supply a normal finish_reason: stop; omitted or nonstandard completion markers now fail rather than claiming a completed answer.
  • Probes, including existing discovery probes, can consume more output tokens and take longer than before (10 → 512 for standard/unknown families; 10 → 4096 for recognized non-OpenAI reasoning families). Limits are ceilings, not a guarantee that every reasoning model finishes.
  • A provider connection test that only lists models still verifies connectivity, not a completed chat reply. No DTO/API shape or runtime chat configuration changes.

Validation

  • Regression baseline: 30 tests, 27 expected failures, no errors/skips.
  • Fixed branch: 55 tests passed, no failures/errors/skips (Java 21, Maven).
  • Review added two trailing-JSON regressions; both failed before strict per-reader parsing and pass after it.
  • Loopback HTTP covers actual public test-model, connection-fallback and discovery paths: malformed/empty/error HTTP 200, trailing garbage or a second JSON value, missing/blank/non-text content, reasoning-only output, token limits, non-stop completion, and a valid completed reply with the outbound budget checked.
  • Existing OAuth discovery, embedding detection, model-family and passthrough tests also pass.
mvn -B -o -pl mateclaw-server -am \
  '-Dtest=ModelDiscovery*Test,ModelFamilyTest,ProviderGenerateKwargsTest' \
  -Dsurefire.failIfNoSpecifiedTests=false test

Tests use a loopback server and synthetic data. No live model credentials, external model calls or production changes.

@mateaix
mateaix merged commit 6365f0a into mateaix:dev Oct 9, 2026
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.

2 participants