factory 0.1.23: a streamed Claude Code request with context management is no longer refused (#71, Vigilans)

Claude Code with the context-management beta sends context_management
(here clear_thinking_20251015, keep all). Factory's streaming route
answers it with 400 "context_management: Extra inputs are not permitted";
the same body with stream false, or without the field, gets 200 (the
reporter's three cases). A streamed /messages request now goes without
the field; an unstreamed one keeps it. The server then clears nothing,
and Claude Code's own compaction still runs.

The version bump also releases the previous commit's #72 fix.

Run: HOME=<tmp> bun test in packages/factory, 119 pass (1 new from the
reporter's body; the existing all-fields test now expects the field gone
on its streamed request). With the deletion disabled by hand both go red.
Not sent to Factory: no Factory account here.
This commit is contained in:
yetone
2026-10-10 17:55:54 +08:00
parent 9d4bc83400
commit 07897c8c58
4 changed files with 36 additions and 3 deletions
+5 -1
View File
@@ -181,7 +181,11 @@ Use magpie's Claude Code integration to select the Factory provider.
magpie manages the provider-specific client settings, including capability
and permission configuration. Fields such as `safeguards` and
`context_management` are forwarded for Factory to validate; the request
adapter preserves them along with the other request options.
adapter preserves them along with the other request options. One exception:
Factory's streaming route refuses `context_management` ("Extra inputs are
not permitted") while its non-streaming route takes it, so a streamed
request is sent without it. The server then clears nothing from the
context; Claude Code's own compaction still runs.
The same metadata adaptation applies to `/messages` and
`/messages/count_tokens`, so token counting sees the prompt used for
+8
View File
@@ -1069,6 +1069,14 @@ function anthropicBody(body) {
}
}
}
// Factory's streaming route refuses context_management ("Extra inputs
// are not permitted", #71) while its non-streaming route takes it. A
// streamed request goes without it: the server then edits nothing out of
// the context, and the client's own compaction still runs.
if (request.stream === true && "context_management" in request) {
delete request.context_management
changed = true
}
return changed ? JSON.stringify(request) : body
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-factory-auth",
"version": "0.1.22",
"version": "0.1.23",
"description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie",
"type": "module",
"main": "./index.mjs",
+22 -1
View File
@@ -55,7 +55,9 @@ test("adapts Claude Code metadata, preserving instructions, tool turns, images a
expect(sent.messages[0].content[1].text).toContain("Model knowledge cutoff: January 2025.")
expect(sent.messages[0].content.slice(2)).toEqual(request.messages[0].content.slice(2))
expect(sent.messages.slice(1)).toEqual(request.messages.slice(1))
for (const field of ["model", "tools", "metadata", "max_tokens", "thinking", "output_config", "stream", "context_management", "safeguards"]) expect(sent[field]).toEqual(request[field])
for (const field of ["model", "tools", "metadata", "max_tokens", "thinking", "output_config", "stream", "safeguards"]) expect(sent[field]).toEqual(request[field])
// streamed: Factory's streaming route refuses context_management (#71)
expect("context_management" in sent).toBe(false)
expect(seen[0].headers.get("content-length")).toBeNull()
expect(seen[0].headers.get("Authorization")).toBe("Bearer factory-token")
expect(seen[0].headers.get("x-api-key")).toBe("placeholder")
@@ -1296,3 +1298,22 @@ test("only a system message that is a skill list is adapted (#72)", async () =>
expect(JSON.parse(seen.at(-1).body).messages[1].content).toBe(text)
}
})
// #71 (Vigilans): Factory's streaming route answers context_management with
// 400 "Extra inputs are not permitted"; the same body unstreamed, or
// without it, gets 200. The reporter's body, byte for byte.
test("a streamed request goes without context_management, an unstreamed one keeps it (#71)", async () => {
const { l, seen } = await loaded()
const request = {
model: "factory/claude-opus-5-5",
max_tokens: 32,
stream: true,
messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
context_management: { edits: [{ keep: "all", type: "clear_thinking_20251015" }] },
}
await l.fetch(url, { method: "POST", headers: { "anthropic-beta": "context-management-2025-06-27" }, body: JSON.stringify(request) })
const { context_management, ...rest } = request
expect(JSON.parse(seen.at(-1).body)).toEqual({ ...rest, system: [{ type: "text", text: droid }] })
await l.fetch(url, { method: "POST", body: JSON.stringify({ ...request, stream: false }) })
expect(JSON.parse(seen.at(-1).body).context_management).toEqual(request.context_management)
})