From 82d67156cd0c519561c5f167b7ae5cd962b5faa0 Mon Sep 17 00:00:00 2001 From: xmanrui <841206367@qq.com> Date: Mon, 2 Mar 2026 01:24:03 +0800 Subject: [PATCH] fix(test-agent): mark embedded HTTP 4xx/5xx replies as failure --- app/api/test-sessions/route.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/api/test-sessions/route.ts b/app/api/test-sessions/route.ts index 01fac41..e3ec043 100644 --- a/app/api/test-sessions/route.ts +++ b/app/api/test-sessions/route.ts @@ -5,6 +5,11 @@ import path from "path"; const OPENCLAW_HOME = path.join(process.env.HOME || "/root", ".openclaw"); const CONFIG_PATH = path.join(OPENCLAW_HOME, "openclaw.json"); +function hasEmbeddedHttpError(reply: string): boolean { + // Some providers return error text in content while gateway still returns HTTP 200. + return /\bHTTP\s*(4\d{2}|5\d{2})\b/i.test(reply); +} + export async function POST() { try { const raw = fs.readFileSync(CONFIG_PATH, "utf-8"); @@ -51,7 +56,13 @@ export async function POST() { results.push({ agentId, ok: false, error: data.error?.message || "API error", elapsed }); } else { const reply = data.choices?.[0]?.message?.content || ""; - results.push({ agentId, ok: true, reply: reply.slice(0, 200) || "(no reply)", elapsed }); + const clippedReply = reply.slice(0, 200) || "(no reply)"; + const embeddedHttpErr = hasEmbeddedHttpError(reply); + if (embeddedHttpErr) { + results.push({ agentId, ok: false, error: clippedReply, elapsed }); + } else { + results.push({ agentId, ok: true, reply: clippedReply, elapsed }); + } } } catch (err: any) { const elapsed = Date.now() - startTime; @@ -69,3 +80,7 @@ export async function POST() { return NextResponse.json({ error: err.message }, { status: 500 }); } } + +export async function GET() { + return POST(); +}