kiro 0.1.24: a conversation past the model's window is a 400 that says too long
Kiro says a conversation is too long for the model three ways: an HTTP 400 ValidationException "Input is too long." (CONTENT_LENGTH_EXCEEDS_THRESHOLD), the same ValidationException as an exception frame in the event stream, or a metadataEvent with stopReason MODEL_CONTEXT_WINDOW_EXCEEDED. Only the first came out as the 400 "input is too long for the model's context: ..." that magpie's gateway reads as an overflow (tooLong). The stream exception went out as a 502 (failedBefore), and the stop reason as end_turn. As a 502, magpie counted a passing failure: it asked the same Kiro model again, could rest the account, and in a group routed by intent only moved on as for any vendor error; a lone agent got a vendor error instead of context_length_exceeded, so it never compacted. Reported by ergou0954_54426 on Discord (Kiro's Claude/GPT and DeepSeek in intent routing, "kiro 那边报错说超出上下文"). Now failedBefore, and the turn after a web search, answer a too-long exception with that 400. A MODEL_CONTEXT_WINDOW_EXCEEDED stop before any of the reply is the same 400; after some of it, the reply ends with stop reason model_context_window_exceeded (Anthropic's word for it). Other exceptions keep 502, quota and throttling keep 429. Run on mote: HOME=$(mktemp -d) bun test in packages/kiro, 122 pass; bun scripts/check.mjs ok. Broken by hand: with index.mjs at HEAD the three new too-long tests fail (13 pass, 3 fail in errors.test.mjs). Not tried: a real Kiro account pushed past its window; the stream shapes come from Kiro's own clients (amazon-q-developer-cli's error enums, kiro.rs, opencodex's kiro stream reader).
This commit is contained in:
@@ -152,7 +152,10 @@ request:
|
|||||||
- Anthropic's hosted web search is answered with Kiro's own web search
|
- Anthropic's hosted web search is answered with Kiro's own web search
|
||||||
(see [Web search](#web-search)).
|
(see [Web search](#web-search)).
|
||||||
- Kiro's failures keep their meaning:
|
- Kiro's failures keep their meaning:
|
||||||
- input too long → 400
|
- input too long → 400 "input is too long for the model's context", whether
|
||||||
|
Kiro says it as an HTTP answer, as an exception in the stream, or by
|
||||||
|
stopping with `MODEL_CONTEXT_WINDOW_EXCEEDED` before a word (after some
|
||||||
|
of the reply, it ends with stop reason `model_context_window_exceeded`)
|
||||||
- no capacity → 503
|
- no capacity → 503
|
||||||
- usage limit → 429
|
- usage limit → 429
|
||||||
- throttling → "rate limited"
|
- throttling → "rate limited"
|
||||||
|
|||||||
@@ -66,9 +66,62 @@ test("a quota exception before the answer is a 429", async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test("another exception before the answer is a 502, not a stream", async () => {
|
test("another exception before the answer is a 502, not a stream", async () => {
|
||||||
const res = await ask(stream(exception("ValidationException", "Input is too long.")), true)
|
const res = await ask(stream(exception("InternalServerException", "Encountered an unexpected error")), true)
|
||||||
expect(res.status).toBe(502)
|
expect(res.status).toBe(502)
|
||||||
expect((await res.json()).error.message).toBe("ValidationException: Input is too long.")
|
expect((await res.json()).error.message).toBe("InternalServerException: Encountered an unexpected error")
|
||||||
|
})
|
||||||
|
|
||||||
|
// magpie's gateway (tooLong) takes a 400 with these words for a conversation
|
||||||
|
// past the model's window: another member with room is asked, no account
|
||||||
|
// rests, and a lone agent is told to compact. As a 502 the Kiro account
|
||||||
|
// rested, was asked again, and the agent got a vendor error it never
|
||||||
|
// compacted for (ergou0954_54426 on Discord: "kiro 那边报错说超出上下文").
|
||||||
|
const saysTooLong = (m) => /^input is too long for the model's context: /.test(m)
|
||||||
|
|
||||||
|
test("Kiro's too-long exception in the stream is a 400 that says too long, streamed or not", async () => {
|
||||||
|
for (const [kind, msg] of [
|
||||||
|
["ValidationException", "Input is too long."],
|
||||||
|
["ValidationException", "Improperly formed request. (CONTENT_LENGTH_EXCEEDS_THRESHOLD)"],
|
||||||
|
]) {
|
||||||
|
for (const s of [true, false]) {
|
||||||
|
const res = await ask(stream(exception(kind, msg)), s)
|
||||||
|
expect(res.status).toBe(400)
|
||||||
|
const b = await res.json()
|
||||||
|
expect(b.error.type).toBe("invalid_request_error")
|
||||||
|
expect(saysTooLong(b.error.message)).toBe(true)
|
||||||
|
expect(b.error.message).toContain(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a reply Kiro stops for a full window before a word is a 400 that says too long", async () => {
|
||||||
|
const full = () => stream(frame({ ":message-type": "event", ":event-type": "metadataEvent" }, { stopReason: "MODEL_CONTEXT_WINDOW_EXCEEDED" }))
|
||||||
|
for (const s of [true, false]) {
|
||||||
|
const res = await ask(full(), s)
|
||||||
|
expect(res.status).toBe(400)
|
||||||
|
expect(saysTooLong((await res.json()).error.message)).toBe(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a reply Kiro stops for a full window after some of it says it was cut short", async () => {
|
||||||
|
const cut = () =>
|
||||||
|
stream(text("Half an ans"), frame({ ":message-type": "event", ":event-type": "metadataEvent" }, { stopReason: "MODEL_CONTEXT_WINDOW_EXCEEDED" }))
|
||||||
|
const res = await ask(cut(), false)
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
expect((await res.json()).stop_reason).toBe("model_context_window_exceeded")
|
||||||
|
const sse = await (await ask(cut(), true)).text()
|
||||||
|
expect(sse).toContain('"stop_reason":"model_context_window_exceeded"')
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Kiro's HTTP 400 for a too-long input stays a 400 that says too long", () => {
|
||||||
|
const f = failure(400, JSON.stringify({ message: "Input is too long.", reason: "CONTENT_LENGTH_EXCEEDS_THRESHOLD" }))
|
||||||
|
expect(f.status).toBe(400)
|
||||||
|
expect(saysTooLong(f.message)).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a quota or throttle still isn't taken for too long", async () => {
|
||||||
|
expect((await ask(stream(exception("ServiceQuotaExceededException", "You have reached the limit")), true)).status).toBe(429)
|
||||||
|
expect((await ask(stream(exception("ThrottlingException", "Too many requests")), true)).status).toBe(429)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("an exception after the answer began ends the stream with an error event", async () => {
|
test("an exception after the answer began ends the stream with an error event", async () => {
|
||||||
|
|||||||
+30
-5
@@ -1155,6 +1155,16 @@ function sendKiro(a, body, signal) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tooLongSaid is whether Kiro's words say the conversation is past the
|
||||||
|
// model's window: its ValidationException "Input is too long." with reason
|
||||||
|
// CONTENT_LENGTH_EXCEEDS_THRESHOLD, as an HTTP answer or as an exception
|
||||||
|
// in the event stream, or a reply it stopped with MODEL_CONTEXT_WINDOW_EXCEEDED.
|
||||||
|
const tooLongSaid = (msg) => /CONTENT_LENGTH_EXCEEDS_THRESHOLD|MODEL_CONTEXT_WINDOW_EXCEEDED|input is too long/i.test(msg)
|
||||||
|
// TOO_LONG heads a too-long failure in the words magpie's gateway takes
|
||||||
|
// for one (tooLong): another member with a larger window is asked, no
|
||||||
|
// account rests, and with none left the agent is told to compact.
|
||||||
|
const TOO_LONG = "input is too long for the model's context: "
|
||||||
|
|
||||||
// failure is the status and message for an error Kiro answered with:
|
// failure is the status and message for an error Kiro answered with:
|
||||||
// {"message": "...", "reason": "..."}.
|
// {"message": "...", "reason": "..."}.
|
||||||
function failure(status, body) {
|
function failure(status, body) {
|
||||||
@@ -1164,8 +1174,7 @@ function failure(status, body) {
|
|||||||
if (e?.message) msg = e.message + (e.reason ? ` (${e.reason})` : "")
|
if (e?.message) msg = e.message + (e.reason ? ` (${e.reason})` : "")
|
||||||
} catch {}
|
} catch {}
|
||||||
msg ||= STATUS_TEXT[status] ?? ""
|
msg ||= STATUS_TEXT[status] ?? ""
|
||||||
if (msg.includes("CONTENT_LENGTH_EXCEEDS_THRESHOLD") || msg.toLowerCase().includes("input is too long"))
|
if (tooLongSaid(msg)) return { status: 400, message: TOO_LONG + msg }
|
||||||
return { status: 400, message: "input is too long for the model's context: " + msg }
|
|
||||||
if (msg.includes("INSUFFICIENT_MODEL_CAPACITY")) return { status: 503, message: msg }
|
if (msg.includes("INSUFFICIENT_MODEL_CAPACITY")) return { status: 503, message: msg }
|
||||||
if (msg.includes("MONTHLY_REQUEST_COUNT") || msg.includes("USAGE_LIMIT")) return { status: 429, message: "usage limit reached: " + msg }
|
if (msg.includes("MONTHLY_REQUEST_COUNT") || msg.includes("USAGE_LIMIT")) return { status: 429, message: "usage limit reached: " + msg }
|
||||||
return { status, message: msg }
|
return { status, message: msg }
|
||||||
@@ -1413,8 +1422,15 @@ async function* events(body, model, budget) {
|
|||||||
// Kiro says how full the context is rather than how many tokens
|
// Kiro says how full the context is rather than how many tokens
|
||||||
if (!usage.input && pct > 0 && window > 0) usage.input = Math.floor((pct / 100) * window)
|
if (!usage.input && pct > 0 && window > 0) usage.input = Math.floor((pct / 100) * window)
|
||||||
if (!usage.output) usage.output = Math.floor((said + 3) / 4)
|
if (!usage.output) usage.output = Math.floor((said + 3) / 4)
|
||||||
|
const full = /^model_context_window_exceeded$/i.test(stop)
|
||||||
|
if (full && !said && !tools) {
|
||||||
|
// stopped for the window before a word: the conversation doesn't fit
|
||||||
|
yield { kind: "error", text: "the reply stopped as the model's context window was full (MODEL_CONTEXT_WINDOW_EXCEEDED)" }
|
||||||
|
return
|
||||||
|
}
|
||||||
let reason = "end_turn"
|
let reason = "end_turn"
|
||||||
if (tools > 0) reason = "tool_use"
|
if (tools > 0) reason = "tool_use"
|
||||||
|
else if (full) reason = "model_context_window_exceeded" // cut short, as Anthropic's API says it
|
||||||
else if (/^max_tokens$/i.test(stop)) reason = "max_tokens"
|
else if (/^max_tokens$/i.test(stop)) reason = "max_tokens"
|
||||||
else if (/^content_filtered$/i.test(stop)) reason = "refusal"
|
else if (/^content_filtered$/i.test(stop)) reason = "refusal"
|
||||||
yield { kind: "stop", reason, usage }
|
yield { kind: "stop", reason, usage }
|
||||||
@@ -1454,7 +1470,14 @@ const QUOTA_WORDS = /quota|insufficient|balance|credit|billing|exceeded|rate.?li
|
|||||||
// magpie's built-in relay gives it: a status, not a stream, so another
|
// magpie's built-in relay gives it: a status, not a stream, so another
|
||||||
// account can take over — a 429 when it reads as a quota or rate limit,
|
// account can take over — a 429 when it reads as a quota or rate limit,
|
||||||
// else a 502.
|
// else a 502.
|
||||||
const failedBefore = (text) => errorResponse(QUOTA_WORDS.test(text) ? 429 : 502, text)
|
//
|
||||||
|
// A conversation past the model's window is a 400 that says so, whichever
|
||||||
|
// way Kiro said it, before the quota words ("exceeded"): as a 502, magpie
|
||||||
|
// rested the account, asked it again, and told a lone agent of a vendor
|
||||||
|
// error, so it never compacted (ergou0954_54426 on Discord: Kiro in a
|
||||||
|
// group routed by intent, "超出上下文", the turn failed).
|
||||||
|
const failedBefore = (text) =>
|
||||||
|
tooLongSaid(text) ? errorResponse(400, TOO_LONG + text) : errorResponse(QUOTA_WORDS.test(text) ? 429 : 502, text)
|
||||||
|
|
||||||
// reply answers the Messages request from Kiro's events: a stream of
|
// reply answers the Messages request from Kiro's events: a stream of
|
||||||
// Messages' events, or one message. names gives back the caller's name of
|
// Messages' events, or one message. names gives back the caller's name of
|
||||||
@@ -1887,8 +1910,10 @@ async function* searching(creds, auth, req, model, budget, signal, hosted, first
|
|||||||
else said.push({ type: "text", text: e.text })
|
else said.push({ type: "text", text: e.text })
|
||||||
}
|
}
|
||||||
if (e.kind === "error") {
|
if (e.kind === "error") {
|
||||||
// in a turn after a search, a status, not a finished answer (reply)
|
// in a turn after a search, a status, not a finished answer
|
||||||
yield turn > 1 ? { ...e, status: 502 } : e
|
// (reply): one past the window says so, as failedBefore does
|
||||||
|
if (turn > 1 && tooLongSaid(e.text)) yield { ...e, status: 400, text: TOO_LONG + e.text }
|
||||||
|
else yield turn > 1 ? { ...e, status: 502 } : e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
yield e
|
yield e
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@magpie-community/opencode-kiro-auth",
|
"name": "@magpie-community/opencode-kiro-auth",
|
||||||
"version": "0.1.23",
|
"version": "0.1.24",
|
||||||
"description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
|
"description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./index.mjs",
|
"main": "./index.mjs",
|
||||||
|
|||||||
Reference in New Issue
Block a user