Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,29 @@ async def load(self):

# 自动回填缺失配置到存储
# 或迁移了配置后需要更新
# 保护:当远程存储返回 None 且本地也没有可迁移配置时,不覆盖远程配置,避免误重置。
has_local_seed = bool(config_data)
allow_bootstrap_empty_remote = (
(not from_remote) and has_local_seed
)
should_persist = (
(not from_remote) or (merged != config_data) or deprecated_sections
allow_bootstrap_empty_remote
or (merged != config_data and bool(config_data))
or deprecated_sections
)
if should_persist:
async with storage.acquire_lock("config_save", timeout=10):
await storage.save_config(merged)
if not from_remote:
if not from_remote and has_local_seed:
logger.info(
f"Initialized remote storage ({storage.__class__.__name__}) with config baseline."
)
if deprecated_sections:
logger.info("Configuration automatically migrated and cleaned.")
elif not from_remote and not has_local_seed:
logger.warning(
"Skip persisting defaults: empty config source detected, keep runtime merged config only."
)

self._config = merged
except Exception as e:
Expand Down
10 changes: 9 additions & 1 deletion app/services/grok/services/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ async def _stream_ws(
) -> ImageGenerationResult:
if enable_nsfw is None:
enable_nsfw = bool(get_config("image.nsfw"))
stream_retries = int(get_config("image.blocked_parallel_attempts") or 5) + 1
stream_retries = max(1, min(stream_retries, 10))
upstream = image_service.stream(
token=token,
prompt=prompt,
aspect_ratio=aspect_ratio,
n=n,
enable_nsfw=enable_nsfw,
max_retries=stream_retries,
)
processor = ImageWSStreamProcessor(
model_info.model_id,
Expand Down Expand Up @@ -287,10 +290,15 @@ async def _fetch_batch(call_target: int):
break
if len(all_images) >= n:
break
logger.info(
f"Image recovery attempts completed: finals={len(all_images)}/{n}, "
f"attempts={extra_attempts}"
)

if len(all_images) < n:
logger.error(
f"Image generation failed after recovery attempts: finals={len(all_images)}/{n}"
f"Image generation failed after recovery attempts: finals={len(all_images)}/{n}, "
f"blocked_parallel_attempts={int(get_config('image.blocked_parallel_attempts') or 5)}"
)
raise UpstreamException(
"Image generation blocked or no valid final image",
Expand Down
21 changes: 12 additions & 9 deletions app/services/reverse/ws_imagine.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ async def stream(
yield item
return
except _BlockedError:
if yielded_any or attempt + 1 >= retries:
if not yielded_any:
yield {
"type": "error",
"error_code": "blocked",
"error": "blocked_no_final_image",
}
return
logger.warning(f"WebSocket blocked, retry {attempt + 1}/{retries}")
if attempt + 1 < retries:
logger.warning(
f"WebSocket blocked/reviewed, retry {attempt + 1}/{retries}"
)
continue
yield {
"type": "error",
"error_code": "blocked",
"error": "blocked_no_final_image",
"yielded_partial": yielded_any,
}
return
except Exception as e:
logger.error(f"WebSocket stream failed: {e}")
yield {
Expand Down
Loading