Skip to content

Commit a871cc9

Browse files
committed
fix(server): revert structured validation error wire format (anomalyco#26457)
PR anomalyco#26457 changed the 400 wire format on the HTTP API in three ways: 1. \`Effect.catch(HttpApiError.BadRequest)\` → \`{ data: {}, errors: [], success: false }\` 2. \`HttpApiSchemaError\` defect → same shape 3. \`normalizeEmptyBadRequest\` post-processor that rewrites ANY empty 400 into the same shape In v1.14.42 (post-Hono-deletion) at least one external plugin (\`opencode-gemini-auth\`, per anomalyco#26546 reports) makes an HTTP API call during startup that hits one of these paths and breaks on the new body shape — the unparseable JSON ends up printed to stdout and the TUI never starts. \`opencode --pure\` works (no plugins), \`opencode run\` works (no in-process server interaction), but \`opencode\` (TUI) crashes. Revert all three changes from anomalyco#26457. The default HttpApi serialization of typed errors comes back, matching v1.14.41 wire format. We can re-introduce structured validation responses behind an opt-in or contract change once plugin authors have a chance to migrate. Closes anomalyco#26546.
1 parent 4000ccb commit a871cc9

2 files changed

Lines changed: 1 addition & 47 deletions

File tree

‎packages/opencode/src/server/routes/instance/httpapi/middleware/error.ts‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,13 @@ import { NamedError } from "@opencode-ai/core/util/error"
66
import * as Log from "@opencode-ai/core/util/log"
77
import { Cause, Effect } from "effect"
88
import { HttpRouter, HttpServerError, HttpServerRespondable, HttpServerResponse } from "effect/unstable/http"
9-
import { HttpApiError } from "effect/unstable/httpapi"
10-
import { HttpApiSchemaError } from "effect/unstable/httpapi/HttpApiError"
119

1210
const log = Log.create({ service: "server" })
1311

14-
function badRequestResponse() {
15-
return HttpServerResponse.jsonUnsafe(
16-
{
17-
data: {},
18-
errors: [],
19-
success: false,
20-
},
21-
{ status: 400 },
22-
)
23-
}
24-
25-
function normalizeEmptyBadRequest(response: HttpServerResponse.HttpServerResponse) {
26-
if (response.status !== 400 || response.body._tag !== "Empty") return response
27-
return badRequestResponse()
28-
}
29-
3012
// Keep typed HttpApi failures on their declared error path; this boundary only replaces defect-only empty 500s.
3113
export const errorLayer = HttpRouter.middleware<{ handles: unknown }>()((effect) =>
3214
effect.pipe(
33-
Effect.catch((error) => {
34-
if (error instanceof HttpApiError.BadRequest) return Effect.succeed(badRequestResponse())
35-
return Effect.fail(error)
36-
}),
37-
Effect.map(normalizeEmptyBadRequest),
3815
Effect.catchCause((cause) => {
39-
const schemaError = cause.reasons.filter(Cause.isDieReason).find((reason) => HttpApiSchemaError.is(reason.defect))
40-
if (schemaError) return Effect.succeed(badRequestResponse())
41-
4216
const defect = cause.reasons.filter(Cause.isDieReason).find((reason) => {
4317
if (HttpServerResponse.isHttpServerResponse(reason.defect)) return false
4418
if (HttpServerError.isHttpServerError(reason.defect)) return false

‎packages/opencode/test/server/httpapi-sync.test.ts‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { afterEach, describe, expect, mock, spyOn, test } from "bun:test"
2-
import { Context, Effect } from "effect"
2+
import { Effect } from "effect"
33
import { Flag } from "@opencode-ai/core/flag/flag"
44
import { Instance } from "../../src/project/instance"
55
import { WithInstance } from "../../src/project/with-instance"
66
import { Server } from "../../src/server/server"
77
import { SyncPaths } from "../../src/server/routes/instance/httpapi/groups/sync"
8-
import { ExperimentalHttpApiServer } from "../../src/server/routes/instance/httpapi/server"
98
import { Session } from "@/session/session"
109
import * as Log from "@opencode-ai/core/util/log"
1110
import { resetDatabase } from "../fixture/db"
@@ -14,7 +13,6 @@ import { disposeAllInstances, tmpdir } from "../fixture/fixture"
1413
void Log.init({ print: false })
1514

1615
const originalWorkspaces = Flag.OPENCODE_EXPERIMENTAL_WORKSPACES
17-
const context = Context.empty() as Context.Context<unknown>
1816

1917
function app() {
2018
return Server.Default().app
@@ -121,22 +119,4 @@ describe("sync HttpApi", () => {
121119
expect(response.status).toBe(400)
122120
}
123121
})
124-
125-
test("returns structured validation errors", async () => {
126-
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
127-
const response = await ExperimentalHttpApiServer.webHandler().handler(
128-
new Request(`http://localhost${SyncPaths.history}`, {
129-
method: "POST",
130-
headers: { "x-opencode-directory": tmp.path, "content-type": "application/json" },
131-
body: JSON.stringify({ aggregate: -1 }),
132-
}),
133-
context,
134-
)
135-
136-
expect(response.status).toBe(400)
137-
expect(response.headers.get("content-type") ?? "").toContain("application/json")
138-
const body = (await response.json()) as Record<string, unknown>
139-
expect(body.success).toBe(false)
140-
expect(Array.isArray(body.error) || Array.isArray(body.errors)).toBe(true)
141-
})
142122
})

0 commit comments

Comments
 (0)