← Lesson
Timeouts, Retries, and Size Caps
Joeven
Run
Reset
Python loads on first run
import json LIMIT_MS = 200 LIMIT_BYTES = 40 def run_tool(name, duration_ms, body): if duration_ms > LIMIT_MS: return {"error": "timeout", "name": name, "limit_ms": LIMIT_MS} text = json.dumps(body) if len(text) > LIMIT_BYTES: return { "error": "too_large", "name": name, "truncated": text[:LIMIT_BYTES], "size": len(text), } return {"ok": True, "result": body} def should_retry(name, err, idempotent): if err == "timeout" and name in {"get_job", "search"}: return True if err == "timeout" and name == "refund": return bool(idempotent) return False print(run_tool("get_job", 50, {"status": "ok"})) print(run_tool("get_job", 500, {"status": "ok"})) print(run_tool("get_logs", 10, {"log": "n" * 80})) print("retry get", should_retry("get_job", "timeout", False)) print("retry refund no key", should_retry("refund", "timeout", False)) print("retry refund keyed", should_retry("refund", "timeout", True))
Run to execute this in your browser. Nothing is sent to a server.