robustness: vision/depth render off the event loop (deepcopy snapshot), chat auto-reconnect + friendly errors, demo catches connection failures

This commit is contained in:
opencode
2026-08-08 12:33:30 +03:00
parent 346d918118
commit f4cb04a47f
5 changed files with 54 additions and 13 deletions
+14 -5
View File
@@ -11,6 +11,7 @@ from __future__ import annotations
import asyncio
import base64
import copy
import io
import math
from typing import Any
@@ -206,11 +207,18 @@ class RoomBridge(Bridge):
)
async def vision() -> VisionOutput:
tick = self._tick()
img, _ = renderer.render(world)
buf = io.BytesIO()
img.save(buf, format="PNG")
# Render off the event loop so frames never stall the bridge under
# load; deepcopy keeps the snapshot consistent with this tool call.
snapshot = copy.deepcopy(world)
img, _ = await asyncio.to_thread(renderer.render, snapshot)
def _encode() -> str:
buf = io.BytesIO()
img.save(buf, format="PNG")
return base64.b64encode(buf.getvalue()).decode("ascii")
return VisionOutput(
png_b64=base64.b64encode(buf.getvalue()).decode("ascii"),
png_b64=await asyncio.to_thread(_encode),
width=VISION_WIDTH,
height=VISION_HEIGHT,
tick=tick,
@@ -222,7 +230,8 @@ class RoomBridge(Bridge):
)
async def depth(max_depth: float = 10.0) -> DepthOutput:
tick = self._tick()
_, grid = renderer.render(world, max_depth=max_depth)
snapshot = copy.deepcopy(world)
_, grid = await asyncio.to_thread(renderer.render, snapshot, max_depth)
return DepthOutput(
width=DEPTH_WIDTH,
height=DEPTH_HEIGHT,