Skip to content

Add grok-superimage, robust image streaming/retries, SSE error handling, proxy and config safety#54

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

Add grok-superimage, robust image streaming/retries, SSE error handling, proxy and config safety#54
lijirou12 merged 2 commits intomainfrom
codex/migrate-imagine-to-grok-superimage-1.0-jp2fkc

Conversation

@lijirou12
Copy link
Copy Markdown
Owner

Motivation

  • Improve reliability of image generation when upstream returns previews or is intermittently blocked and provide a server-side grok-superimage-1.0 that uses centralized image parameters.
  • Make streaming endpoints return well-formed SSE error payloads instead of transport-level 5xx breaks for better client behavior.
  • Harden token retry behavior and transient upstream handling to reduce failed requests due to transient network/upstream issues.
  • Add small operational safety and UX improvements such as proxy normalization, config bootstrap protection, and admin UI/config defaults for new features.

Description

  • Introduced grok-superimage-1.0 in ModelService and server-side image parameters via _superimage_server_image_config used when that model is requested, and added superimage config defaults in config.defaults.toml and UI fields in app/static/admin/js/config.js and numeric handling.
  • Implemented robust image-generation recovery flow: WebSocket client class ImagineWebSocketReverse now classifies preview/medium/final by byte-size thresholds and can perform parallel recovery attempts when blocked, and ImageGenerationService will run extra parallel recovery attempts using distinct tokens and fail with a clear UpstreamException if no final images are produced.
  • Modified streaming behavior across chat/video/image paths to wrap upstream streams with _safe_sse_stream that encodes exceptions as SSE event: error JSON payloads and added _streaming_error_response to return one-shot SSE errors for streaming requests; also ensured chat-style image streams always emit a final empty chat chunk and data: [DONE].
  • Added transient upstream detection in app/services/grok/utils/retry.py and integrated it into ChatService to retry with different tokens on transient errors, and added safer fallbacks when get_config("retry.max_retry") may be unset.
  • Hardened config bootstrap in app/core/config.py to avoid overwriting remote storage with defaults when the remote returned None and no local seed existed, and renamed get_storage import to avoid collision in admin API and exposed storage detection.
  • Normalized proxy handling in app/services/reverse/app_chat.py including SOCKS scheme normalization and using proxy vs proxies based on scheme, and adjusted timeout selection logic.
  • Several image stream/processors updated to only expose final images for chat-format streams, preserve original imagine image names for grok-superimage-1.0 URL outputs, and emit correct SSE finalization; introduced logging changes and limits for parallel attempts and retries.
  • Documentation update in readme.md listing grok-superimage-1.0 and behavior notes for streaming and blocked-image recovery.

Testing

  • Ran the project's unit and integration test suite and basic API smoke tests locally including POST /v1/chat/completions flows for text, image, and streaming scenarios, and observed no regressions.
  • Exercised image generation paths with simulated WS responses to validate final/preview classification, parallel recovery attempts, and SSE error emission, and confirmed expected SSE error events and data: [DONE] termination for streaming clients.
  • Verified admin UI renders new superimage fields and blocked_parallel_attempts numeric input in the configuration page and that default config values load from config.defaults.toml.

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:09am

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