Handle native structured-format incompatibility and preserve failure evidence

This commit is contained in:
2026-10-10 00:01:02 +01:00
parent 16389b8270
commit a1c0eb4a72
21 changed files with 800 additions and 42 deletions
+13
View File
@@ -79,6 +79,19 @@ the step transcript. Credentials are redacted, but project/provider messages may
still contain private context: review before sharing. Older failures cannot gain
discarded subprocess output retroactively; Debug attempts retained session reads.
Native OpenCode schema support is checked with a retained, deny-all, no-inference
POST/readback probe. OpenCode 1.18.35 accepts explicit formats but rejects their
stored messages on readback; affected backends omit `format` and require the same
strict local `{outcome, output}` validation. Compatible backends retain schema
mode with no automatic tool-replaying schema retries. The compatibility decision
and probe session are recorded, without rewriting published definitions/history.
For old format-bearing sessions whose HTTP readback fails, Debug uses read-only
`opencode export` with an exact session-ID check to recover original messages.
`StructuredOutputError` is surfaced directly; DSML/tool-call markup and flattened
results are rejected and retained, never silently interpreted as successful tool
execution or wrapped into a guessed result. Native HTTP evidence distinguishes
adapter/HTTP failures from actual subprocess exit codes.
To validate a model on the execution computer, run:
```sh
+24 -4
View File
@@ -5,13 +5,24 @@ Every model result must be one object containing exactly `outcome` and `output`.
(including nested output keys), missing fields, unknown fields and invalid
outcomes are rejected. Free-form `output` contract prose is not a JSON Schema.
The native stable OpenCode adapter requests `format.type=json_schema` with this
envelope schema and `retryCount=0`, reads the returned structured result when
available, and preserves the original tool transcript. Local validation remains
mandatory. V2's published prompt/generate API does not accept a schema-output
The native stable OpenCode adapter first checks the complete format POST/readback
contract in a separate retained, deny-all, no-inference session. Compatible native
backends request `format.type=json_schema` with this envelope and `retryCount=0`.
OpenCode 1.18.35 accepts a format but rejects its stored messages with
`Expected OutputFormatJsonSchema` (even explicit `text` fails). For that specific
incompatibility, requests omit `format`; strict local validation remains mandatory.
Other probe failures, such as authentication or network errors, are not silently
downgraded. Returned structured results remain preferred when available, and tool
transcripts are preserved. V2's published prompt/generate API does not accept a schema-output
field; that adapter retains local validation instead of sending unsupported
fields or claiming provider-side schema enforcement.
Output-contract prose describes the map **inside** `output`; it never overrides
the runtime `{outcome, output}` envelope. Printed DSML or other tool-call markup
is not evidence of a real tool invocation and cannot be accepted as a result.
Flattened output fields are rejected, not guessed into a new envelope. Invalid
responses are retained even when they are not eligible for syntax repair.
## Format recovery is not execution retry
Parser errors retain their diagnostic and byte offset: for example, `missing
@@ -46,6 +57,15 @@ and a recognized safe error category (such as session not found or service
unavailable). Arbitrary stderr, provider messages and response bodies are not
copied into the diagnostic. A `/wait` command failure is not evidence that the
agent prompt failed to start, and does not trigger replay of stage work.
Native `StructuredOutputError` is named directly, rather than reduced to a generic
command failure. Native HTTP evidence records the actual HTTP operation/status;
an `exit_code` of -1 there is explicitly marked as not a subprocess exit.
Cleanup failures preserve the original generation error and active ownership.
For existing native sessions with format-bearing messages, the HTTP readback
workaround is read-only CLI `opencode export`. The exported session ID must match
the requested ID. Nothing is rewritten or removed from the database/history.
Debug receives the original messages plus a note identifying that recovery path.
## Optional machine-readable restrictions
+58
View File
@@ -0,0 +1,58 @@
# Native structured-output regression (2026-10-09)
The supplied `~/findings.md` describes Math Demo run #12 on another computer,
using OpenCode 1.18.35 and `opencode-go/deepseek-v4.1-flash`. Its recorded response
contains `StructuredOutputError` and DSML as text, with flattened output fields.
The supplied evidence does not identify the component responsible for converting
that provider tool call into text. That upstream cause remains unconfirmed.
## Confirmed independently
On a fresh `ghcr.io/anomalyco/opencode:1.18.35` container, without credentials or
inference:
- `POST /session/ID/message` with `noReply:true` and an explicit JSON-schema
format succeeds, but subsequent HTTP message readback fails with HTTP 400.
- Omitting `retryCount` does not fix it. Explicit `format:{type:"text"}` also fails.
- Omitting `format` makes both POST and message readback succeed.
- `opencode export ID` recovers the original format-bearing messages which the
HTTP readback cannot encode. No stored message needs to be modified.
The adapter now probes this contract without inference. Affected native backends
omit the incompatible field and enforce the outcome/output envelope locally.
Compatible native schema mode is retained and covered by the mock HTTP contract
tests; a real schema-tool invocation on a compatible native release is **not tested**.
No automatic stage/tool replay or DSML-to-result interpretation was added.
## Real provider regression
The opt-in server test uses an equivalent math graph, not a copy of the remote
immutable definition (its complete source was not supplied). It deliberately
uses small-map output-contract prose to exercise the envelope clarification.
Using the existing local native OpenCode 1.18.35/OpenCode Go credentials, it passed:
- `7 + 2`: sum → multiply → parity → add_one → report; result **28**;
`7 + 2 = 9; 9 * 3 = 27; 27 + 1 = 28 (odd branch)`.
- `7 + 3`: sum → multiply → parity → halve → report; result **15**;
`7 + 3 = 10; 10 * 3 = 30; 30 / 2 = 15 (even branch)`.
- Native retained-session readback through server evidence retrieval passed.
The first inference check reached result 28 but caught an ambiguous *test prompt*
that yielded the literal word `previous` in an equation. The fixture now explicitly
specifies numeric substitutions; the full odd/even check then passed. Published
pipeline definitions were not rewritten.
Commands (supply a native CLI path on your computer):
```sh
PIPELINES_TEST_OPENCODE_V1=/path/to/opencode-1.18.35 \
go test -count=1 -run TestStableNativeSessionContractLive -v ./internal/opencode
# Explicit opt-in: existing credentials, ten small paid-provider calls,
# retained stage/probe sessions, and no project tools.
PIPELINES_TEST_OPENCODE_V1=/path/to/opencode-1.18.35 \
PIPELINES_TEST_NATIVE_INFERENCE=1 \
go test -count=1 -run TestNativeMathDemoLive -v ./internal/server
```
The other computer's original run/session was not accessed or modified here.