Uh oh!
There was an error while loading. Please reload this page.
fix: make OutputFormat schemas encodable from persisted plain objects (#26929) - #43721
Closed
padraig-myers-sh wants to merge 1 commit into
Closed
Conversation
Fixesanomalyco#26929 OutputFormatText and OutputFormatJsonSchema were declared with Schema.Class, which only encodes genuine class instances. When a format object is persisted onto a user message and read back from MessageTable, the row's data column holds a plain object (message-v2.ts info() spreads row.data). The GET /session/:id/message endpoint validates its response against Schema.Array(SessionV1.WithParts), so re-encoding the stored format through Schema.Class fails and the entire response returns 400. Converting both schemas to Schema.Struct makes encode accept plain objects while preserving all decode validation (negative retryCount is still rejected, json_schema without schema is still rejected). Neither schema is ever constructed with new() or checked with instanceof, so dropping the class identity is safe. Added encode regression tests that fail without the fix (3 of 4 new tests fail on Schema.Class) and pass with Schema.Struct.
Contributor
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Contributor
The following comment was made by an LLM, it may be inaccurate: Potential duplicate found:
This PR appears to be addressing the same issue: encoding persisted output formats that are read back as plain objects. It likely attempted a similar fix for the You should review PR #37541 to understand what approach was taken previously and why the current fix (switching from |
padraig-myers-sh
commented
Aug 20, 2026
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes#26929
Type of change
What does this PR do?
GET /session/:id/messagereturns HTTP 400 whenever a session contains a message withformat.type = "json_schema":OutputFormatTextandOutputFormatJsonSchemawere declared withSchema.Class. An EffectSchema.Classonly encodes genuine class instances. When a format object is persisted onto a user message and read back fromMessageTable, the row data holds a plain object (message-v2.tsinfo()spreadsrow.data). The GET endpoint validates its response againstSchema.Array(SessionV1.WithParts), so re-encoding the stored format throughSchema.Classfails — one bad message rejects the entire array with a 400.Converting both to
Schema.Structmakes encode accept plain objects. All decode validation is preserved (negativeretryCountstill rejected,json_schemawithoutschemastill rejected). Neither schema is constructed withnew()or checked withinstanceofanywhere, so dropping class identity is safe.How did you verify your code works?
Added 4 encode regression tests in
packages/opencode/test/session/structured-output.test.ts:retryCountretryCountWithout the fix, 3 of 4 new tests fail. With the fix, all 26 tests pass:
Also verified end-to-end in our downstream product (StubHub Shift): the GET endpoint was returning 400 on every structured-output turn, causing cost/usage tracking to report $0. After applying this patch, the 400 is gone and usage data is correctly reported.
Screenshots / recordings
N/A — no UI changes.
Checklist