Files
plugins/packages/factory/testdata
yetone ec1c675f72 factory: a Gemini request opens with its model, as droid's does (0.1.49)
marovole on X, on 0.1.48 (magpie v0.1.4504, Droid BYOK, Factory API key
sign-in): three gemini-4-hydrogen requests came back 400 "Invalid model
ID in request body", each again on 2 or 3 retries, while the same setup
went through 83 times on hydrogen and 28 each on carbon and sonnet that
day. The failing bodies were 0.6 to 1.6 MB, long Droid sessions. 0.1.48's
per-conversation x-session-id did not change it.

What differs from droid, and grows with the body, is where the model
sits. droid 1.14.0 builds its Gemini request as {model, contents,
systemInstruction, tools, generationConfig} (testdata/droid-1.14.0-
gemini-body.txt, from the release binary). magpie's gateway marshals a
Gemini body from a Go map, so its keys come sorted: contents,
generationConfig, model, ... The plugin's geminiBody set m.model on that
object, which keeps the key where it was, after the contents; a body
from the AI SDK's Google package has no model, so it went last. Either
way the model came after the whole conversation. A route that
reads the model from the first part of a body would find droid's at
once and miss ours past some size, every retry alike, which is the
reported pattern.

geminiBody now writes the fields in droid's order (GEMINI_ORDER), the
model first, and any other field (toolConfig, safetySettings) after them
in its own order. Only the Gemini route changes; droid's Chat body puts
messages before model, so the other routes keep theirs.

Not proven: there is no Factory account here, so the 400 was not
reproduced against Factory, and Factory's server code is not readable.
The cause is the one byte-layout difference from droid that matches
"Gemini only, large only, every retry". The reporter is asked for the
raw lines to confirm.

Run (HOME a fresh folder; the focused runs on mote, the suite on the
Linux box, magpie-desktop, as mote and mica each had a full Go suite
running):
- bun test packages/factory/gemini.test.mjs size.test.mjs
  session.test.mjs request.test.mjs: 86 pass, 0 fail.
- The new test on the old index.mjs: red (the body did not open with
  {"model":"gemini-4-hydrogen","contents":), the other 5 Gemini tests
  green.
- The root bun test (Bun 1.4.2): 9060 pass, 19 skip, 0 fail (9079
  tests, 636 files); scripts/check.mjs ok.
2026-11-19 12:06:22 +08:00
..