fix(core): read a JSON answer fenced as ```JSON or ```jsonc

AA
2h ago
+45-1

What

A judgment answer read from reply text may be fenced as ```JSON, ```Json, or ```jsonc, as well as ```json or untagged. That is every answer from an executor's answer(), and the built-in model's reply when agent.extract has no JSON Schema to send.

Why

The fence check stripped a lowercase json tag only, so any other spelling stayed in the body and the answer failed as MODEL_OUTPUT_INVALID. A deterministic executor sends the same text each try, so agent.waitFor used up its 25 calls on it.

How it works

  1. parseJsonObject strips a fence tagged json or jsonc in any case (packages/core/src/agent/model/adapter.ts). fenceTagLength checks the tags in JSON_FENCE_TAGS, longest first, lowercased, and keeps main's linear-time slicing with no regex. I kept the tag list closed instead of skipping any info string, because on a one-line fence a bare word can be the value (```true```), and main reads that as true. A jsonc body with comments still fails at JSON.parse. The tag has to end at a character that can't be part of one, so ```json{...}``` reads as on main, while jsontrue or json5 stays an unknown tag in the body (main stripped any json prefix).
  2. docs/executors.mdx names the accepted fence tags and says jsonc doesn't allow comments.

Issue

Fixes #2720

Verified

Ran it locally: yes

Testbed, built CLI, a custom executor whose answer() returns a valid agent-judgment-2 reply fenced with FENCE_TAG, e2e run on a test that calls agent.waitFor:

fence tagmainthis PR
jsonpasses, 1 model callpasses, 1 model call
JSONMODEL_OUTPUT_INVALID: response text is not a single JSON value, 25 model calls failedpasses, 1 model call
JsonMODEL_OUTPUT_INVALID, 25 model calls failedpasses, 1 model call
jsoncMODEL_OUTPUT_INVALID, 25 model calls failedpasses, 1 model call
  • packages/e2e/tests/unit/parse-validated.test.ts, beside the parser's existing cases: JSON, Json, jsonc, JSON with CRLF line ends, a one-line ```json {...}```, and one-line json{...} / jsonc{...} with no space all read. jsontrue, jsoncfalse, json5, and text after the closing fence fail as MODEL_OUTPUT_INVALID. With main's adapter.ts, 6 of the 13 fail (JSON, Json, jsonc, CRLF, one-line jsonc{...}, jsontrue).

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

Summary by CodeRabbit

  • Bug Fixes
    • JSON responses now recognize case-insensitive JSON and jsonc code fences, reducing invalid-output errors when models use these formats.
    • Fence tags with extra text and responses with trailing text after the closing fence remain invalid.
  • Documentation
    • Clarified support for jsonc fences in executor responses and noted that comments are not allowed.
  • Tests
    • Added coverage for varied tag casing, line endings, and spacing.