BerriAI/litellm · error · RuntimeError

Mavvrik FOCUS destination: GCS chunk upload failed

Error message

Mavvrik FOCUS destination: GCS chunk upload failed (chunk offset={offset}, expected={expected_statuses}, got={resp.status_code}): {resp.text[:400]}

What it means

RuntimeError raised while PUTting an 8 MB chunk of the gzip-compressed CSV to the GCS resumable session URI: the response status did not match the expectation (308 Resume Incomplete for intermediate chunks, 200/201 for the final chunk). The message embeds the chunk offset, the expected status set, the actual status, and 400 chars of the body. On failure the destination DELETEs the session so it does not linger for ~1 week.

Solutions

  1. Retry the whole deliver() run — it re-fetches a fresh signed URL and starts a new session; GCS assembles the object server-side so a clean re-run produces one correct file
  2. 5xx/429 -> back off exponentially and let the next export cycle retry; missed windows are backfilled
  3. If persistent, inspect resp.text in the message (e.g. 'Invalid request') and raise proxy/body-size/timeout limits for PUTs to storage.googleapis.com
Defensive patterns

Strategy: retry

Try / catch

import asyncio, re

async def deliver_with_retry(destination, *, content, time_window, filename, attempts=3):
    for i in range(attempts):
        try:
            await destination.deliver(content=content, time_window=time_window, filename=filename)
            return
        except RuntimeError as e:
            if "chunk upload failed" not in str(e):
                raise
            m = re.search(r"got=(\d+)", str(e))
            status = int(m.group(1)) if m else 0
            if i < attempts - 1 and (status >= 500 or status == 429):
                await asyncio.sleep(5 * 2**i)  # chunk failures benefit from longer backoff
                continue
            raise

Prevention

When it happens

Trigger: Mid-upload failures in deliver(): GCS 5xx/503 transient errors, 429 throttling, the session URI expiring during a very long multi-chunk upload, a proxy closing long-lived PUTs (>120s timeout in the request), or a Content-Range/offset mismatch after a partial retry.

Common situations: Large FOCUS exports producing many 8 MB chunks, flaky networks, aggressive proxy idle timeouts, Google transient incidents.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/f161dd3cb3844f3a. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/focus/destinations/mavvrik_destination.py:226

            while offset < total:
                chunk = gzip_bytes[offset : offset + _GCS_CHUNK_SIZE]
                chunk_end = offset + len(chunk) - 1
                is_final = (offset + len(chunk)) >= total
                content_range = f"bytes {offset}-{chunk_end}/{total}" if is_final else f"bytes {offset}-{chunk_end}/*"
                expected_statuses = {200, 201} if is_final else {308}

                resp = await self._http.client.request(
                    method="PUT",
                    url=session_uri,
                    headers={
                        "Content-Type": "application/gzip",
                        "Content-Range": content_range,
                    },
                    content=chunk,
                    timeout=120.0,
                )
                if resp.status_code not in expected_statuses:
                    raise RuntimeError(
                        f"Mavvrik FOCUS destination: GCS chunk upload failed "
                        f"(chunk offset={offset}, expected={expected_statuses}, "
                        f"got={resp.status_code}): {resp.text[:400]}"
                    )
                offset += len(chunk)
                verbose_logger.debug(
                    "Mavvrik FOCUS destination: uploaded chunk offset=%d/%d",
                    offset,
                    total,
                )
        except Exception:
            # Cancel the open GCS session so it doesn't linger for up to 1 week.
            try:
                await self._http.client.request(method="DELETE", url=session_uri, timeout=10.0)
                verbose_logger.debug("Mavvrik FOCUS destination: cancelled GCS session after error")
            except Exception:
                pass
            raise

View on GitHub (pinned to 77b7c6c40c)