mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-22 19:55:11 +00:00
fix(question): surface schema failures as friendly tool errors (#28563)
Some checks are pending
containers / build (push) Waiting to run
deploy / deploy (push) Waiting to run
docs-locale-sync / sync-locales (push) Waiting to run
generate / generate (push) Waiting to run
nix-eval / nix-eval (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
nix-hashes / compute-hash (macos-15-intel, x86_64-darwin) (push) Waiting to run
nix-hashes / compute-hash (macos-latest, aarch64-darwin) (push) Waiting to run
nix-hashes / update-hashes (push) Blocked by required conditions
publish / version (push) Waiting to run
publish / build-cli (push) Blocked by required conditions
publish / sign-cli-windows (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=arm64 host:macos-26 platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=x64 host:macos-26-intel platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404-arm platform_flag:--linux --arm64 target:aarch64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-electron (map[host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish (push) Blocked by required conditions
storybook / storybook build (push) Waiting to run
test / unit (linux) (push) Waiting to run
test / unit (windows) (push) Waiting to run
test / e2e (linux) (push) Waiting to run
test / e2e (windows) (push) Waiting to run
typecheck / typecheck (push) Waiting to run
Some checks are pending
containers / build (push) Waiting to run
deploy / deploy (push) Waiting to run
docs-locale-sync / sync-locales (push) Waiting to run
generate / generate (push) Waiting to run
nix-eval / nix-eval (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
nix-hashes / compute-hash (macos-15-intel, x86_64-darwin) (push) Waiting to run
nix-hashes / compute-hash (macos-latest, aarch64-darwin) (push) Waiting to run
nix-hashes / update-hashes (push) Blocked by required conditions
publish / version (push) Waiting to run
publish / build-cli (push) Blocked by required conditions
publish / sign-cli-windows (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=arm64 host:macos-26 platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=x64 host:macos-26-intel platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404-arm platform_flag:--linux --arm64 target:aarch64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-electron (map[host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish (push) Blocked by required conditions
storybook / storybook build (push) Waiting to run
test / unit (linux) (push) Waiting to run
test / unit (windows) (push) Waiting to run
test / e2e (linux) (push) Waiting to run
test / e2e (windows) (push) Waiting to run
typecheck / typecheck (push) Waiting to run
This commit is contained in:
parent
6e177ee84a
commit
26008696e1
2 changed files with 56 additions and 2 deletions
|
|
@ -146,12 +146,26 @@ export const layer = Layer.effect(
|
|||
log.info("asking", { id, questions: input.questions.length })
|
||||
|
||||
const deferred = yield* Deferred.make<ReadonlyArray<Answer>, RejectedError>()
|
||||
const info = Schema.decodeUnknownSync(Request)({
|
||||
// Use the Effect-returning decode so a schema failure surfaces as a
|
||||
// typed error the tool wrap can turn into a "rewrite the input" tool
|
||||
// result. The previous `decodeUnknownSync` would throw uncaught, which
|
||||
// crashed the assistant turn for any payload that slipped past the
|
||||
// wrap-level validation (#28438).
|
||||
const info = yield* Schema.decodeUnknownEffect(Request)({
|
||||
id,
|
||||
sessionID: input.sessionID,
|
||||
questions: input.questions,
|
||||
tool: input.tool,
|
||||
})
|
||||
}).pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new Error(
|
||||
`The question tool was called with invalid arguments: ${error}.\nPlease rewrite the input so it satisfies the expected schema.`,
|
||||
{ cause: error },
|
||||
),
|
||||
),
|
||||
Effect.orDie,
|
||||
)
|
||||
pending.set(id, { info, deferred })
|
||||
yield* bus.publish(Event.Asked, info)
|
||||
|
||||
|
|
|
|||
|
|
@ -416,6 +416,46 @@ it.live("pending question rejects on instance dispose", () =>
|
|||
}),
|
||||
)
|
||||
|
||||
// Regression for #28438: when an invalid payload reaches `Question.ask`
|
||||
// (one that's missing a required field like `question`), the previous
|
||||
// `Schema.decodeUnknownSync` would throw uncaught and crash the whole
|
||||
// assistant turn. The fix routes the failure through `Effect.orDie` with a
|
||||
// "rewrite the input" Error so the surrounding tool wrap can hand it back to
|
||||
// the model as a tool-call error rather than killing the session.
|
||||
it.instance(
|
||||
"ask - invalid payload surfaces as a friendly defect, not a thrown SchemaError",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const exit = yield* askEffect({
|
||||
sessionID: SessionID.make("ses_invalid"),
|
||||
// Cast: bypassing the public type to simulate an upstream caller
|
||||
// (or a future schema divergence) that lets a missing required
|
||||
// field reach the decode boundary.
|
||||
questions: [
|
||||
{
|
||||
header: "Pick mode",
|
||||
options: [
|
||||
{ label: "A", description: "x" },
|
||||
{ label: "B", description: "y" },
|
||||
],
|
||||
} as unknown as Question.Info,
|
||||
],
|
||||
}).pipe(Effect.exit)
|
||||
|
||||
expect(Exit.isFailure(exit)).toBe(true)
|
||||
if (Exit.isFailure(exit)) {
|
||||
const message = exit.cause.toString()
|
||||
// Friendly preamble the AI SDK feeds back to the model so it can retry.
|
||||
expect(message).toContain("invalid arguments")
|
||||
expect(message).toContain("Please rewrite the input")
|
||||
// The exact JSON path pinpointing the missing field, so the model
|
||||
// knows which question and which field to fix.
|
||||
expect(message).toContain(`["questions"][0]["question"]`)
|
||||
}
|
||||
}),
|
||||
{ git: true },
|
||||
)
|
||||
|
||||
it.live("pending question rejects on instance reload", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue