fix: resolve image generation 429 cascade returning 502 to clients
xbang
3ae55b5
Concurrent /v1/images/edits and /v1/images/generations requests were returning
502 Bad Gateway to clients even though images were successfully generated on
the user's ChatGPT account (quota consumed). Three layered bugs caused every
image request to fail:
Bug A (root cause) - stream parser dropped file_ids
update_conversation_state gated file_id extraction on is_image_tool_event
which requires the full {author.role: tool, metadata.async_task_type:
image_gen} structure. ChatGPT delivers asset_pointer via subsequent patch
events that lack those fields, so file_ids were extracted by regex but
silently discarded. Every image request was forced into the polling
fallback path, which then hammered /backend-api/conversation/{id} and
tripped upstream rate limits.
Fix: open the gate when state.tool_invoked is True (set by an earlier
server_ste_metadata event) OR when the event is itself a patch event whose
payload references asset_pointer / file-service://. The patch-event-…
fix: raise clear error message on image poll timeout
Fengsuid
f5971d0
- Add ImagePollTimeoutError with actionable message including
current timeout value and config fix instructions
- In stream_image_outputs_with_pool, don't mark account as
failed on timeout (timeout is not an account issue)
- The error now clearly says "ChatGPT 生图超时(已等待 X 秒)"
instead of the generic "image generation failed"
fix: improve error message when image generation returns no data
Fengsuid
90fd59c
- Replace generic "image task returned no image data" with actionable
message about checking account pool quota and rate-limit status
- Add fallback error text when all accounts silently fail to generate
fix(text-stream): auto-rotate accounts on invalid token
lottshin
8fb5dc7
Previously stream_text_deltas used a single backend/token; once that
token became invalid mid-stream the entire response would 502 to the
client, with no fallback to other available accounts in the pool.
The fix:
- iterates available text accounts via get_text_access_token(excluded)
- removes invalidated tokens via remove_invalid_token() (gated by config)
- only swaps to a new account if no content has been emitted yet, to
avoid concatenating partial deltas from different accounts
- marks the successfully used account via mark_text_used() so the pool
can rotate by recency
account_service.get_text_access_token() now accepts excluded_tokens to
let the caller skip already-tried tokens, and filters out 限流 status
in addition to 禁用/异常.
feat(chat): support image input in chat completions
lottshin
9ead365
OpenAI's official chat completions accepts list-form content with
mixed text and image parts. The previous implementation hard-rejected
non-string content with "only string message content is supported",
making it impossible to forward multimodal client requests upstream.
Changes:
- _chat_messages_to_conversation_messages now accepts list-form content,
extracting text parts and image parts ({"type": "image", "data": bytes,
"mime": str}). Images are uploaded via _upload_image() and stitched
into the upstream multimodal_text payload with file-service refs and
attachment metadata.
- normalize_messages preserves multimodal content for user messages so
downstream code can see both text and image parts.
This unblocks vision-capable use cases (e.g. asking the model to
describe or analyze an attached image) while keeping the legacy
text-only path unchanged.