Skip to content

Add grok-superimage server-side image flow, robust image retries and SSE error handling#55

Merged
lijirou12 merged 1 commit intomainfrom
codex/migrate-imagine-to-grok-superimage-1.0-zc14eb
Feb 27, 2026
Merged

Add grok-superimage server-side image flow, robust image retries and SSE error handling#55
lijirou12 merged 1 commit intomainfrom
codex/migrate-imagine-to-grok-superimage-1.0-zc14eb

Conversation

@lijirou12
Copy link
Copy Markdown
Owner

Motivation

  • Introduce a server-controlled SuperImage model (grok-superimage-1.0) with consistent server-side image generation parameters and safer streaming semantics.
  • Make image generation more robust against upstream review/blocking by adding detection, parallel recovery attempts and configurable thresholds.
  • Improve streaming reliability by converting transport failures into SSE error events so clients receive structured error payloads instead of raw 5xx breaks.
  • Harden a few infrastructure areas: safer config bootstrap/persistence, proxy handling for app-chat, and retry behavior for transient upstream errors.

Description

  • Added a new model entry grok-superimage-1.0 in ModelService and a server-side image config loader _superimage_server_image_config() in the chat API to enforce server superimage settings for that model.
  • Implemented _safe_sse_stream() and _streaming_error_response() in app/api/v1/chat.py to catch exceptions during streaming and emit SSE error events (uses orjson), and wrapped streaming returns to use the safe wrapper.
  • Updated image and image-edit services to use a fallback default for retry.max_retry, propagate tried_tokens, and add recovery logic: additional parallel recovery attempts configured by image.blocked_parallel_attempts and image.blocked_parallel_enabled; image collectors now only accept images meeting final_min_bytes and run extra attempts when finals are insufficient.
  • Enhanced WebSocket reverse (ws_imagine) with blocked-detection tuning (blocked_grace_seconds), parallel retry collection when blocked is suspected, and clearer logging; adjusted classification rules to use a byte-size threshold for final images.
  • Modified image stream processors (ImageWSStreamProcessor, ImageWSCollectProcessor, ImageStreamProcessor) to only expose final results for chat-formatted streaming, ensure a final empty chat chunk if none were emitted, and preserve original image names for grok-superimage-1.0 URL outputs (no -final suffix).
  • Added transient upstream detection in app/services/grok/utils/retry.py (transient_upstream) and use it in ChatService to retry with alternate tokens on likely transient errors; also defaulted retry.max_retry fallback to 3 where used.
  • Improved app chat proxy handling in app/services/reverse/app_chat.py by normalizing SOCKS schemes and using the proxy parameter for SOCKS proxies while using proxies for HTTP proxies, plus better timeout source selection.
  • Made config bootstrap safer in app/core/config.py to avoid overwriting remote config with empty data during initialization and log when skipping persistence.
  • UI and defaults: added new config keys and UI support for image.blocked_grace_seconds, image.blocked_parallel_attempts, image.blocked_parallel_enabled, and a new [superimage] section in config.defaults.toml; updated readme.md and admin JS (app/static/admin/js/config.js) to expose the new options and document grok-superimage-1.0 behavior.
  • Minor renames and imports: get_storage import renamed to resolve_storage in admin config to avoid name clash with endpoint function.

Testing

  • Ran the project's automated test suite with pytest (existing tests) and the suite completed without failures.
  • Executed a local smoke test of the POST /v1/chat/completions flow for grok-superimage-1.0 including streaming and non-streaming image responses and observed correct server-controlled n/size/response_format and final-only streaming behavior.
  • Performed integration checks for WebSocket image generation against the reverse ws_imagine path to validate blocked-detection and parallel recovery logic under simulated preview-only responses.
  • Built and exercised the admin UI (npm build/static serve) to confirm new config fields are visible and editable in the admin panel.

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 6:21am

@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 b128139 into main Feb 27, 2026
3 of 4 checks passed
@lijirou12 lijirou12 deleted the codex/migrate-imagine-to-grok-superimage-1.0-zc14eb branch February 27, 2026 06:21
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