Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix: surface Codex extension image generation failures

Soohong Kimb47fb312b177
diff --git a/sprite_gen/gen/codex_provider.py b/sprite_gen/gen/codex_provider.py
index 3c43911..af9fdae 100644
--- a/sprite_gen/gen/codex_provider.py
+++ b/sprite_gen/gen/codex_provider.py
@@ -177,13 +177,19 @@ def _collect_inline_results(rollout: Path) -> list[str]:
payload = record.get("payload", {}) or {}
if payload.get("type") == "item_completed":
item = payload.get("item", {}) or {}
- if (
- item.get("type") == "Extension"
- and item.get("kind") == _IMAGE_GEN_EXTENSION_KIND
- and item.get("status") == "completed"
- and item.get("result")
- ):
- results.append(item["result"])
+ if item.get("type") != "Extension" or item.get("kind") != _IMAGE_GEN_EXTENSION_KIND:
+ continue
+ status = item.get("status")
+ if status != "completed":
+ raise SystemExit(
+ f"codex-gen: image_gen call ended with status={status!r} in {rollout}"
+ )
+ result = item.get("result")
+ if not result:
+ raise SystemExit(
+ f"codex-gen: completed image_gen call has no result in {rollout}"
+ )
+ results.append(result)
continue
if payload.get("type") not in _RESULT_TYPES or not payload.get("result"):
continue
diff --git a/tests/gen/test_gen.py b/tests/gen/test_gen.py
index 468776a..538e90d 100644
--- a/tests/gen/test_gen.py
+++ b/tests/gen/test_gen.py
@@ -215,17 +215,6 @@ def test_codex_inline_extraction_reads_0149_imagegen_extension(tmp_path: Path) -
},
}
},
- {
- "payload": {
- "type": "item_completed",
- "item": {
- "type": "Extension",
- "kind": "image_gen.generation",
- "status": "failed",
- "result": b64,
- },
- }
- },
{
"payload": {
"type": "item_completed",
@@ -245,6 +234,42 @@ def test_codex_inline_extraction_reads_0149_imagegen_extension(tmp_path: Path) -
assert results == [b64]
+ ("status", "result", "expected_message"),
+ [
+ ("failed", "failure details", "status='failed'"),
+ ("completed", None, "completed image_gen call has no result"),
+ ],
+)
+def test_codex_inline_extraction_rejects_failed_or_empty_0149_imagegen_extension(
+ tmp_path: Path,
+ status: str,
+ result: str | None,
+ expected_message: str,
+) -> None:
+ rollout = tmp_path / "rollout-codex-0149-invalid.jsonl"
+ rollout.write_text(
+ json.dumps(
+ {
+ "payload": {
+ "type": "item_completed",
+ "item": {
+ "type": "Extension",
+ "kind": "image_gen.generation",
+ "status": status,
+ "result": result,
+ },
+ }
+ }
+ )
+ + "\n",
+ encoding="utf-8",
+ )
+
+ with pytest.raises(SystemExit, match=expected_message):
+ codex_provider._collect_inline_results(rollout)
+
+
def test_codex_inline_extraction_rejects_failed_status(tmp_path: Path) -> None:
b64 = base64.b64encode(_png_bytes()).decode()
rollout = tmp_path / "rollout-fail.jsonl"