Repository navigation
Keep OpenAI error descriptions when requests fail - #343
Merged
HamptonMakes merged 4 commits intoNov 23, 2026
Merged
Conversation
- Faraday's message is only the HTTP status; OpenAI's body says why (type, code, message). - Append those, truncated to 300 characters, for chat and transcription. Never the request.
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Collaborator
|
I'd prefer to not hardcode acceptable error messages... we should be able to trust that the provider is going to provide safe text descriptoins of error for saving. |
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
HamptonMakes
approved these changes
Nov 23, 2026
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.
What changed and why
When OpenAI rejects a request, Coplan logs only Faraday's message: "the server responded with status 400". The reason is in the response body, and we drop it.
In production,
SummarizePlanJobdiscarded 33 summaries with HTTP 400 in the last 14 days. The last 10 came from two plans. We can't tell why from the logs. A context-length limit is likely, but that's a guess.Now
AiProviders::OpenAiadds the provider's error type, code and message to the error it raises, for both chat and transcription. It accepts gateway-specific reasons without an allowlist. The combined diagnostic is limited to 300 characters and normalized to one line. Only string diagnostic fields are appended; request objects and other fields are omitted. The job log then says, for example:This PR only fixes the diagnosis. Summary failure-state handling (finding identity-ai-5) remains a separate follow-up to #342.
Found in the Coplan STPA review (finding identity-ai-5): https://coplan.sqprod.co/dgrochowski/reliability-analyses/coplan-stamp-stpa-analysis-service-review
Evidence
spec/services/ai_providers/open_ai_spec.rbcovers chat and transcription with decoded and JSON error bodies, gateway-specific reasons, length limits, whitespace and encoding, malformed fields, string-only gateway errors, and malformed JSON raised by Faraday's middleware. Unusable details add nothing; the original provider failure remains the exception cause.How to try it
With a real key this raises
Coplan::Ai::Errorthat ends with OpenAI's reason, such as(invalid_request_error/model_not_found: The model ... does not exist ...).Testing
Generated with Codex