Skip to content

Support grok-superimage and improve image streaming/retry, SSE error handling, proxy and config safety#52

Merged
lijirou12 merged 2 commits intomainfrom
codex/migrate-imagine-to-grok-superimage-1.0-b6oi4l
Feb 27, 2026
Merged

Support grok-superimage and improve image streaming/retry, SSE error handling, proxy and config safety#52
lijirou12 merged 2 commits intomainfrom
codex/migrate-imagine-to-grok-superimage-1.0-b6oi4l

Conversation

@lijirou12
Copy link
Copy Markdown
Owner

Motivation

  • Add first-class support for a server-controlled image model (grok-superimage-1.0) that uses server-side image parameters and behaves differently in streaming chat output.
  • Make streaming endpoints more resilient by returning SSE error events instead of transport-level 5xx, and improve retry behavior for transient upstream and image-block scenarios.
  • Harden reverse proxy handling for app-chat requests and avoid accidentally overwriting remote config with empty sources during bootstrap.
  • Expose new configuration controls in admin UI and defaults for blocked-image recovery and superimage settings.

Description

  • Introduced SUPERIMAGE_MODEL_ID = "grok-superimage-1.0", added the model to ModelService, and added server-side superimage config defaults in config.defaults.toml plus corresponding admin UI controls and readme documentation.
  • Added _superimage_server_image_config() to enforce server-controlled n/size/response_format for grok-superimage-1.0 and applied it in request validation paths so client image_config is ignored for that model.
  • Implemented SSE-safe streaming helpers _safe_sse_stream and _streaming_error_response and used them to ensure streams yield structured event: error payloads for Chat, Image, ImageEdit, and Video streaming flows instead of a raw 5xx transport break. Video/Chat service calls are wrapped to return SSE error responses when streaming.
  • Enhanced image generation robustness by adding configurable parallel recovery attempts when final images appear to be blocked (image.blocked_parallel_attempts) and by passing a max_retries hint to the WebSocket reverse; failure after recovery raises an UpstreamException with structured details.
  • Adjusted WebSocket imagine reverse logic to detect suspected review/block conditions more reliably and to return an informative error payload when retries exhausted, and refined final-image classification to use byte-size threshold logic only.
  • Updated Image WS/stream processors to emit only final images for chat completions (no previews for grok-superimage-1.0), ensure a final empty chat chunk is emitted when nothing else was streamed, and preserve original image filenames for grok-superimage-1.0 URL outputs (no -final suffix).
  • Added transient upstream detection (transient_upstream) and made token-retry defaults tolerant (get_config("retry.max_retry") or 3), and added retry-on-transient behavior in ChatService to rotate tokens when upstream errors are transient and alternative tokens exist.
  • Normalized and improved proxy handling for app-chat reverse requests by converting SOCKS scheme variants and supplying proxy vs proxies to curl_cffi appropriately; also adjusted timeout selection logic.
  • Improved config bootstrap persistence logic to avoid overwriting remote storage with defaults when both remote and local sources are empty and added logging to clarify actions; renamed get_storage import to avoid name clash and renamed the route helper to get_storage_mode.

Testing

  • Ran the project's automated test suite with pytest -q and the modified unit/integration tests, and all tests passed.
  • Executed automated streaming/image-related integration smoke tests (chat with image generation and image-edit streams) which verified SSE error payloads and the grok-superimage-1.0 behavior, and they passed.

Codex Task

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
grok2api Ready Ready Preview, Comment Feb 27, 2026 5:15am

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@lijirou12 lijirou12 merged commit 4f80bba into main Feb 27, 2026
3 of 4 checks passed
@lijirou12 lijirou12 deleted the codex/migrate-imagine-to-grok-superimage-1.0-b6oi4l branch February 27, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant