{"record":{"id":"44d6f7f9d06be0ce","repo":"Panniantong/Agent-Reach","slug":"polish-response-exceeds-32-mib-limit","errorCode":null,"errorMessage":"polish response exceeds 32 MiB limit","messagePattern":"polish response exceeds 32 MiB limit","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"agent_reach/scripts/transcribe_xiaoyuzhou.sh","lineNumber":326,"sourceCode":"    body = json.dumps({\n        \"model\": MODEL,\n        \"temperature\": 0.2,\n        \"max_completion_tokens\": 8192,\n        \"messages\": [{\"role\": \"user\", \"content\": PROMPT_TMPL.format(text)}],\n    }).encode()\n    req = urllib.request.Request(\n        \"https://api.groq.com/openai/v1/chat/completions\",\n        data=body,\n        headers={\n            \"Authorization\": f\"Bearer {KEY}\",\n            \"Content-Type\": \"application/json\",\n            \"User-Agent\": \"agent-reach-xiaoyuzhou/1.0\",\n        },\n    )\n    with urllib.request.urlopen(req, timeout=180) as r:\n        payload = r.read(32 * 1024 * 1024 + 1)\n    if len(payload) > 32 * 1024 * 1024:\n        raise ValueError(\"polish response exceeds 32 MiB limit\")\n    resp = json.loads(payload)\n    return (\n        resp[\"choices\"][0][\"message\"][\"content\"].strip(),\n        resp[\"choices\"][0].get(\"finish_reason\"),\n    )\n\ndef polish(text, depth=0):\n    try:\n        out, fr = call_groq(text)\n    except urllib.error.HTTPError as e:\n        sys.stderr.write(f\"polish HTTP {e.code}: {e.read().decode(errors='replace')[:200]}\\n\")\n        return text  # fallback to raw\n    except Exception as e:\n        sys.stderr.write(f\"polish error: {e}\\n\")\n        return text\n    if fr != \"length\" or depth >= MAX_DEPTH:\n        return out\n    # 输出被截断：从中点切两半递归处理","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/Panniantong/Agent-Reach/blob/93ae1d18c37b707dec053c7c4f9d91cd8ef8943d/agent_reach/scripts/transcribe_xiaoyuzhou.sh#L308-L344","documentation":"In scripts/transcribe_xiaoyuzhou.sh's embedded Python polish step: the Groq chat-completion response body exceeded 32 MiB (the script deliberately reads limit+1 bytes to detect overflow). A polish call should return a few KB of improved text; a 32 MiB body means something is pathologically wrong with the response, so it refuses to parse it.","triggerScenarios":"call_groq() posting an extremely large transcript to groq.com/openai/v1/chat/completions and the model/API returning a gigantic body (runaway repetition, degenerate output). Note polish() catches HTTPError but NOT this ValueError, so it propagates and kills the script.","commonSituations":"Very long episode transcripts (hours of text) sent in one polish request; a model looping/repeating tokens; upstream API misbehavior. Rare in practice — the 32 MiB cap is a defensive ceiling.","solutions":["Split long transcripts into sections and polish each separately (polish already supports iterative depth, but call it on smaller inputs)","Retry once — a runaway generation is usually transient","If reproducible, reduce the input text size passed to call_groq (summarize or trim before polishing)","Wrap the polish call in your own try/except ValueError to fall back to the raw transcript, mirroring the HTTPError fallback already in polish()"],"exampleFix":"# before (inside polish)\n    try:\n        out, fr = call_groq(text)\n    except urllib.error.HTTPError as e:\n        ...\n        return text  # fallback to raw\n# ValueError from the 32 MiB check is uncaught -> script dies\n\n# after\n    try:\n        out, fr = call_groq(text)\n    except (urllib.error.HTTPError, ValueError) as e:\n        sys.stderr.write(f\"polish failed ({e}); using raw transcript\\n\")\n        return text  # fallback to raw","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"# inside polish()\ntry:\n    out, fr = call_groq(text)\nexcept (urllib.error.HTTPError, ValueError) as e:\n    sys.stderr.write(f\"polish failed ({e}); using raw transcript\\n\")\n    return text  # fallback to raw","preventionTips":["Cap the transcript size sent to polish(); split long episodes into sections","Catch ValueError alongside HTTPError whenever calling call_groq directly","Treat a >32 MiB LLM response as a runaway generation — retry once at most, then fall back to raw text"],"tags":["transcription","groq","llm","limits","shell-script"],"backgroundTag":null,"analyzedSha":"93ae1d18c37b707dec053c7c4f9d91cd8ef8943d","analyzedAt":"2026-08-14T22:54:06.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}