Repository navigation
Conversation
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 free
to 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 #25430
Type of change
What does this PR do?
format.json_schema.retryCountwas defined in the API schema (message-v2.ts) but never read inprompt.ts. When the model failed to produce structured output, the code always setretries: 0in theStructuredOutputErrorregardless of what the caller passed, and never actually retried.There was also a second bug: because
OutputFormatJsonSchemawas defined as aSchema.Class, the HTTP response serialization (encode direction) would crash with aSchemaErrorwheneverretryCountwas present in the stored message. This causedGET /session/:id/messageto return 400 for any session that usedjson_schemaformat with an explicitretryCount.Changes:
packages/opencode/src/session/message-v2.ts— convertedOutputFormatTextandOutputFormatJsonSchemafromSchema.ClasstoSchema.Struct(consistent with the rest of the file).Schema.Classrequires a class instance for encoding;Schema.Structhandles plain objects correctly, which is what the DB returns.packages/opencode/src/session/prompt.ts— added aretryAttemptcounter alongside the existingstepcounter. When the model finishes without producing structured output, the code now checksformat.retryCount(defaulting to 2) and retries up to that many times before setting the error. Theretriesfield inStructuredOutputErrornow reflects the actual number of attempts made.How did you verify your code works?
Ran the server locally (
bun dev serve) and tested via Postman:POST /session— created a new sessionPOST /session/:id/prompt_asyncwithformat.retryCount: 1and a prompt designed to avoid structured outputGET /session/:id/message— previously returned 400 due to the schema bug; now returns 200Also ran
bun typecheck— no errors.Screenshots / recordings
Screenshot 1 —
POST /sessionreturning 200 with the new session ID:Screenshot 2 —
POST /session/:id/prompt_asyncrequest body showingretryCount: 1:Screenshot 3 — Server logs showing
GET /messagereturning 200 (previously 400):