{"record":{"id":"b33cadd3589de970","repo":"BerriAI/litellm","slug":"failed-to-set-gc-thresholds-e","errorCode":null,"errorMessage":"Failed to set GC thresholds: {e}","messagePattern":"Failed to set GC thresholds: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/common_utils/debug_utils.py","lineNumber":659,"sourceCode":"    curl -X POST \"http://localhost:4000/debug/memory/gc/configure?generation_0=500\" -H \"Authorization: Bearer sk-1234\"\n\n    Example for less aggressive collection:\n    curl -X POST \"http://localhost:4000/debug/memory/gc/configure?generation_0=1000\" -H \"Authorization: Bearer sk-1234\"\n\n    Monitor memory usage with GET /debug/memory/summary after changes.\n    \"\"\"\n    # Get current thresholds for logging\n    old_thresholds: Final = gc.get_threshold()\n\n    # Set new thresholds with error handling\n    try:\n        gc.set_threshold(generation_0, generation_1, generation_2)\n        verbose_proxy_logger.info(\n            \"GC thresholds updated from %s to (%s, %s, %s)\", old_thresholds, generation_0, generation_1, generation_2\n        )\n    except Exception as e:\n        verbose_proxy_logger.error(\"Failed to set GC thresholds: %s\", e)\n        raise HTTPException(status_code=500, detail=f\"Failed to set GC thresholds: {e}\")\n\n    # Get current object count to show immediate impact\n    current_count: Final = gc.get_count()[0]\n\n    return {\n        \"message\": \"GC thresholds updated\",\n        \"previous_thresholds\": f\"{old_thresholds[0]}, {old_thresholds[1]}, {old_thresholds[2]}\",\n        \"new_thresholds\": f\"{generation_0}, {generation_1}, {generation_2}\",\n        \"objects_awaiting_collection\": current_count,\n        \"tip\": f\"Next collection will run after {generation_0 - current_count} more allocations\",\n    }\n\n\n@router.get(\n    \"/otel-spans\",\n    dependencies=[Depends(user_api_key_auth)],\n    include_in_schema=False,\n)","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/common_utils/debug_utils.py#L641-L677","documentation":"The admin endpoint POST /debug/memory/gc/configure calls gc.set_threshold(generation_0, generation_1, generation_2). If Python rejects the values (classically a negative integer, since gc.set_threshold requires non-negative ints), the wrapper converts the exception into HTTPException 500 with detail 'Failed to set GC thresholds: {e}'. The old thresholds stay in effect; nothing is mutated.","triggerScenarios":"Call POST /debug/memory/gc/configure?generation_0=-1 (any negative value for generation_0/1/2). Non-integer input is normally caught earlier by FastAPI as 422, so negative ints are the usual trigger. Custom GC tooling that computes thresholds can also pass negative values after drift.","commonSituations":"Tuning memory with the debug endpoint and typing a negative number. A script copies an example query and edits values by hand. An automated tuner probes limits and hits the invalid range.","solutions":["Retry the call with non-negative integers, e.g. POST /debug/memory/gc/configure?generation_0=700&generation_1=10&generation_2=10.","If values came from a script, clamp them to >= 0 before the request.","Check the response detail text: it embeds the Python error, which confirms which value was rejected."],"exampleFix":"# before\ncurl -X POST \"http://localhost:4000/debug/memory/gc/configure?generation_0=-500\" -H \"Authorization: Bearer sk-1234\"\n# 500 Failed to set GC thresholds\n\n# after\ncurl -X POST \"http://localhost:4000/debug/memory/gc/configure?generation_0=500\" -H \"Authorization: Bearer sk-1234\"","handlingStrategy":"validation","validationCode":"def valid_gc_params(g0: int, g1: int, g2: int) -> bool:\n    vals = [g0, g1, g2]\n    return all(isinstance(v, int) and not isinstance(v, bool) and v >= 0 for v in vals)\n\nassert valid_gc_params(700, 10, 10)\n# only then call POST /debug/memory/gc/configure","typeGuard":null,"tryCatchPattern":"import httpx\n\nresp = httpx.post(f\"{base}/debug/memory/gc/configure\", params={\"generation_0\": g0, \"generation_1\": g1, \"generation_2\": g2}, headers=headers)\nif resp.status_code == 500 and \"Failed to set GC thresholds\" in resp.text:\n    # thresholds unchanged; fix values and retry once with valid input\n    resp = httpx.post(f\"{base}/debug/memory/gc/configure\", params={\"generation_0\": max(g0, 0), \"generation_1\": max(g1, 0), \"generation_2\": max(g2, 0)}, headers=headers)\nresp.raise_for_status()","preventionTips":["Clamp tuner output to non-negative ints before calling the endpoint.","Read the previous_thresholds field of a successful response and keep it for rollback.","Treat 500 from this endpoint as a rejected value, not a server fault: the old thresholds stay active."],"tags":["litellm","gc","debug-endpoint","admin","invalid-argument","python"],"backgroundTag":"invalid-parameter-value","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}