Skip to content

fix(workbuddy): adapt gateway compliance headers and tool schema contracts (#16978) - #17046

Merged
diegosouzapw merged 2 commits into
cheaper-inference:release/v3.8.52from
Junior-HJ:fix/workbuddy-gateway-compliance
Oct 18, 2026
Merged

diegosouzapw merged 2 commits into
cheaper-inference:release/v3.8.52from
Junior-HJ:fix/workbuddy-gateway-compliance

Conversation

@Junior-HJ

Copy link
Copy Markdown
Contributor

Summary

Adapt WorkBuddy AI reverse-proxy gateway compliance by porting battle-tested headers, tool schema contracts, and turn order alignment from Magpie to resolve error codes 10085, 11101, 11128, 11133, and 11153 (#16978).

Changes

  • Client Identity & Mandatory Headers (Fixes 10085):
    • Added required static headers to workbuddyProvider: User-Agent: WorkBuddy/5.5.6, X-IDE-Type: WorkBuddy, X-IDE-Name: WorkBuddy, X-IDE-Version: 5.5.6, X-Requested-With: XMLHttpRequest, X-Agent-Intent: craft, X-Agent-Purpose: conversation, X-Agent-Type: main, and X-Domain: www.workbuddy.ai.
    • Added User-Agent and X-Domain to token refresh requests.
    • Added short alias wbai pointing to workbuddy.
  • Turn & Conversation Correlation IDs:
    • Implemented withWorkbuddyHeaders: assigns 32-hex X-Conversation-ID (derived stably from session key or first user message) and X-Conversation-Request-ID (derived from turn key / last user message so tool loops stay in one turn).
    • Generates per-call X-Conversation-Message-ID mirrored on X-Request-ID.
  • System Prompt & Parameter Normalization (Fixes 11101 & First Message Error):
    • Normalizes max_completion_tokens to max_tokens and role developer to system.
    • Guarantees the first message is a system prompt.
    • Aligns turn ordering after tool calls before subsequent user messages with an empty assistant message (Fixes Gemini 11153 error).
  • Tool Schema Sanitization (Fixes 11133 on DeepSeek/Kimi/GLM):
    • Sanitizes tool names with non-standard characters to _ (safeToolName) and updates historical messages.
    • Cleans regex \0 patterns to \u0000.
    • Normalizes boolean schemas and heterogenous enums.
    • Converts OpenAI object tool_choice format to upstream string format, stripping tool_choice: none.
  • Prompt Anti-Ban Sanitization (Fixes 11128):
    • Strips x-anthropic-billing-header: and neutralizes competitor client markers.
  • Tests & Changelog:
    • Added unit test suite tests/unit/workbuddy-gateway-compliance.test.ts (8/8 pass).
    • Added changelog fragment changelog.d/fixes/16978-workbuddy-gateway-compliance.md.

Fixes #16978.

fitSchema, fitEnum, fitShape and fitTools exceeded the cognitive-complexity
ratchet (20/24/41/42 > 15), pushing the repo past its 1437 baseline. Extract
per-concern helpers with identical behavior (differential fuzz against the
original: 60,000 random schemas/tool bodies, byte-identical results and
change flags). Drop the unused randomUUID import, type the test's any casts
and cover fitSchema/fitShape directly.
@diegosouzapw
diegosouzapw merged commit edc79d9 into cheaper-inference:release/v3.8.52 Oct 18, 2026
8 checks passed
diegosouzapw added a commit that referenced this pull request Oct 18, 2026
…te-path golden

#17046 (gateway compliance for WorkBuddy, #16978) deliberately changed the
headers the WorkBuddy executor sends: User-Agent WorkBuddy/5.5.6, the X-Agent-*
and X-IDE-* set, X-Domain and X-Requested-With. It shipped its own test but did
not regenerate tests/snapshots/provider/translate-path.json, so
provider-translate-path-golden has been red on the release branch since it
merged (19:03Z).

Regenerated with UPDATE_GOLDEN=1: the only provider entry that changed is
"workbuddy" (apiKey, nonStream and oauth header blocks). The golden and
workbuddy-gateway-compliance suites pass together (12/12).

Refs #15306
diegosouzapw added a commit that referenced this pull request Oct 18, 2026
…stry test

#17046 (#16978) placed four gateway-compliance rewrites ahead of the generic
Codex/OpenAI pairs in the WorkBuddy registry entry: the Anthropic billing
header is dropped, and the Claude Code and Codex CLI identity sentences are
reworded. It did not touch workbuddy-provider.test.ts, whose
bodyStringReplacements assertion still listed only the four old pairs, so the
suite has been red on the release branch since 19:03Z.

The assertion now pins all eight pairs in order: the long Codex sentence must
be rewritten whole before the generic "Codex CLI" / "OpenAI" pairs touch it.
workbuddy-provider + workbuddy-gateway-compliance + provider-translate-path
golden: 40/40.

Refs #15306
diegosouzapw added a commit that referenced this pull request Oct 18, 2026
…and two WorkBuddy contracts left by #17046 (#17102)

* test(quota): time the shared throttle, not the first fetch's start-up (#6911)

Since #15885 every quota fetcher calls fetchWithConnectionProxy() between the
throttle's acquire() and the upstream fetch. The first call of the process pays
one-time costs inside that window: it lazily imports the proxy transport and
the error helpers, then imports the DB settings module and opens SQLite with
every migration to look up the connection's proxy (first lookup measured at
~4.9 s, the next ones 6-12 ms). The second call, released 200 ms later, waits
on the same imports, so both fetches left together (spread 20-50 ms) and the
first test of the file, DeepSeek, failed whatever the throttle did.

The suite now answers the proxy lookup through the documented
connectionProxyTestOverride (as the proxy suites do) and pays the lazy imports
once in test.before, so the spread it measures is the throttle's again. The
assertions are unchanged; removing `await throttleQuotaFetch()` from the
DeepSeek fetcher still fails the suite (spread 3 ms).

Refs #15306

* test(providers): record WorkBuddy's compliance headers in the translate-path golden

#17046 (gateway compliance for WorkBuddy, #16978) deliberately changed the
headers the WorkBuddy executor sends: User-Agent WorkBuddy/5.5.6, the X-Agent-*
and X-IDE-* set, X-Domain and X-Requested-With. It shipped its own test but did
not regenerate tests/snapshots/provider/translate-path.json, so
provider-translate-path-golden has been red on the release branch since it
merged (19:03Z).

Regenerated with UPDATE_GOLDEN=1: the only provider entry that changed is
"workbuddy" (apiKey, nonStream and oauth header blocks). The golden and
workbuddy-gateway-compliance suites pass together (12/12).

Refs #15306

* test(providers): pin WorkBuddy's compliance body rewrites in the registry test

#17046 (#16978) placed four gateway-compliance rewrites ahead of the generic
Codex/OpenAI pairs in the WorkBuddy registry entry: the Anthropic billing
header is dropped, and the Claude Code and Codex CLI identity sentences are
reworded. It did not touch workbuddy-provider.test.ts, whose
bodyStringReplacements assertion still listed only the four old pairs, so the
suite has been red on the release branch since 19:03Z.

The assertion now pins all eight pairs in order: the long Codex sentence must
be rewritten whole before the generic "Codex CLI" / "OpenAI" pairs touch it.
workbuddy-provider + workbuddy-gateway-compliance + provider-translate-path
golden: 40/40.

Refs #15306
diegosouzapw added a commit that referenced this pull request Oct 18, 2026
… registry entry

"workbuddy registry entry › declares the replayed-history flags and the
streaming requirement" pinned the original four bodyStringReplacements;
#17046 prepended the billing-header line, the Claude Code self-description,
the branch hint and the Codex project blurb. The fixture now lists the eight
pairs the registry ships, in order. Same root cause as the golden in this PR.
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.

feat(providers): adapt WorkBuddy AI reverse proxy & gateway compliance (ref Magpie implementation)

2 participants