Skip to content

fix(copilot): normalize equivalent Chat output limits - #4

Draft
billxc wants to merge 1 commit into
mainfrom
user/xiaocw/fix-exclusive-chat-output-limit
Draft

billxc wants to merge 1 commit into
mainfrom
user/xiaocw/fix-exclusive-chat-output-limit

Conversation

@billxc

@billxc billxc commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Normalize equivalent max_tokens and max_completion_tokens only at the Copilot Chat target boundary, keeping the combined cap and removing the redundant legacy field.
  • Leave single, missing, and distinct caller limits unchanged so upstream validation still owns invalid or unrepresentable combinations.
  • Preserve the original payload object and upstream result.

Reproduced problem

Upstream Menci#673's input IR Chat writer emits both cap spellings for compatibility. Copilot rejects an equal pair such as max_tokens=32000 and max_completion_tokens=32000 with:

max_tokens and max_completion_tokens cannot both be set

All three Gemini Chat models currently advertised by the tested Copilot account reproduced the same HTTP 400 with equal dual caps and accepted a modern-only control. A real original Anthropic Messages request also reproduced the rejection.

When both bounds are equal, the combined reasoning-plus-visible cap already implies the same visible cap. Removing the legacy constraint therefore preserves the effective budget without guessing how to reconcile distinct values.

Why the fix is Copilot-scoped

The initial candidate removed the legacy spelling from generic translation and added an Ollama adapter. Adversarial review and a deterministic reproduction showed that this would silently drop budgets on legacy-only custom endpoints. This revision instead follows Copilot's established provider-owned boundary pattern.

There are no changes to generic translation, Ollama, custom or Azure runtime behavior, configuration, flags, or migrations. A translated legacy-custom regression verifies that its existing legacy cap still reaches the non-Copilot target.

Pre-existing dual-cap rejection on strict non-Copilot targets is outside this narrowly scoped fix; this PR does not claim a universal token-cap dialect migration.

Verification

  • 176 tests passed across six explicitly named provider/gateway/protocol files.
  • Unit cases cover equal numeric, zero and null caps; either single spelling; distinct numeric and mixed-null caps; absent caps; input non-mutation; and result passthrough.
  • A real provider-chain test verifies the new interceptor is registered and the serialized Copilot request contains only the combined cap.
  • A real gateway translation test preserves the legacy cap for a custom Chat target.
  • ESLint passed for the five changed files. TypeScript passed for Copilot, gateway and the Node runtime. Diff whitespace checks passed.
  • Original request replay through an independent Node process, fresh migrated SQLite database and loopback listener:
    • Source request unchanged, HTTP 200, real tool output and completed SSE without an error event.
    • max_completion_tokens=32000 on actual outgoing traffic; max_tokens absent.
    • All six screenshots retained as WebP image_url inputs.
    • Actual input usage 104,370 tokens, versus the preceding original request's 1,048,204.
    • No runtime payload override, feature-flag workaround, retry or token exchange; returned tool calls were not executed.

Scope

One commit, five files, no playground changes. This is a downstream preview PR against synchronized main; no upstream PR or merge has been performed.

@billxc
billxc force-pushed the user/xiaocw/fix-exclusive-chat-output-limit branch from 03bf4a2 to 1ed785b Compare November 13, 2026 12:01
@billxc billxc changed the title fix(translate): emit mutually exclusive Chat output limits fix(copilot): normalize equivalent Chat output limits Nov 13, 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.

1 participant