robustness: vision/depth render off the event loop (deepcopy snapshot), chat auto-reconnect + friendly errors, demo catches connection failures
This commit is contained in:
+28
-6
@@ -191,12 +191,34 @@ async def chat_loop(client: AICCClient, manifest, args: argparse.Namespace) -> i
|
||||
|
||||
|
||||
async def run(args: argparse.Namespace) -> int:
|
||||
transport = WebSocketClientTransport(args.url)
|
||||
async with AICCClient(transport) as client:
|
||||
manifest = await client.handshake()
|
||||
print(f"[handshake] session {manifest.session_id} world {manifest.world.name}")
|
||||
print(f"[handshake] tools: {[t.id for t in manifest.tools]}")
|
||||
return await chat_loop(client, manifest, args)
|
||||
"""Run the chat session, reconnecting to the bridge if the connection dies."""
|
||||
attempts = 0
|
||||
while True:
|
||||
try:
|
||||
transport = WebSocketClientTransport(args.url)
|
||||
async with AICCClient(transport) as client:
|
||||
manifest = await client.handshake()
|
||||
print(
|
||||
f"[handshake] session {manifest.session_id} world {manifest.world.name}"
|
||||
)
|
||||
print(f"[handshake] tools: {[t.id for t in manifest.tools]}")
|
||||
return await chat_loop(client, manifest, args)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except Exception as exc: # noqa: BLE001 - connection lost: reconnect
|
||||
attempts += 1
|
||||
print(f"\n[chat] connection lost ({type(exc).__name__}: {exc})")
|
||||
if attempts >= 3:
|
||||
print(
|
||||
"[chat] giving up after 3 attempts — is the bridge running? (scripts/run_bridge.sh)"
|
||||
)
|
||||
return 1
|
||||
print(
|
||||
"[chat] reconnecting in 2 seconds… (the room keeps its state on the bridge)"
|
||||
)
|
||||
await asyncio.sleep(2.0)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
|
||||
Reference in New Issue
Block a user