OtterMind/Chat2DB · error · RequestError

delivery_id is invalid

Error message

delivery_id is invalid

What it means

Raised at relay_server.py:222 when "delivery_id" is missing, not a str, or fails the regex ^[A-Za-z0-9._:-]{1,160}$ (DELIVERY_ID_PATTERN, relay_server.py:23). The id must be 1-160 characters of letters, digits, dot, underscore, colon, or hyphen. It dedupes deliveries in the DeliveryStore, so it must be a stable printable identifier. Returned as HTTP 400.

Source

Thrown at script/github/qq_relay/relay_server.py:223

        except ValueError as error:
            raise RequestError(HTTPStatus.LENGTH_REQUIRED, "Content-Length is required") from error
        if content_length < 1 or content_length > MAX_REQUEST_BYTES:
            raise RequestError(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, "request body is too large")
        try:
            payload = json.loads(self.rfile.read(content_length).decode("utf-8"))
        except (UnicodeDecodeError, json.JSONDecodeError) as error:
            raise RequestError(HTTPStatus.BAD_REQUEST, "request body is not valid JSON") from error
        if not isinstance(payload, Mapping):
            raise RequestError(HTTPStatus.BAD_REQUEST, "request body must be a JSON object")
        return payload

    def _validate_payload(self, payload: Mapping[str, Any]) -> tuple[str, str]:
        config = self.relay_state.config
        if payload.get("repository") != config.repository:
            raise RequestError(HTTPStatus.FORBIDDEN, "repository is not allowed")
        delivery_id = payload.get("delivery_id")
        if not isinstance(delivery_id, str) or not DELIVERY_ID_PATTERN.fullmatch(delivery_id):
            raise RequestError(HTTPStatus.BAD_REQUEST, "delivery_id is invalid")
        message = payload.get("message")
        if not isinstance(message, str) or not message.strip():
            raise RequestError(HTTPStatus.BAD_REQUEST, "message must be non-empty text")
        if len(message) > config.max_message_length:
            raise RequestError(HTTPStatus.BAD_REQUEST, "message is too long")
        if CONTROL_CHARACTER_PATTERN.search(message):
            raise RequestError(HTTPStatus.BAD_REQUEST, "message contains control characters")
        return delivery_id, message

    def do_GET(self) -> None:  # noqa: N802
        if self.path == "/healthz":
            self._send_json(HTTPStatus.OK, {"ok": True})
            return
        self._send_json(HTTPStatus.NOT_FOUND, {"error": "not found"})

    def do_POST(self) -> None:  # noqa: N802
        delivery_id = ""
        reserved = False

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Provide a string delivery_id that fully matches '^[A-Za-z0-9._:-]{1,160}$'.
  2. Use the GitHub delivery UUID as-is, or uuid4().hex (32 lowercase hex chars).
  3. If you need base64, use url-safe without padding and drop any '='.

Example fix

# before
payload["delivery_id"] = base64.b64encode(os.urandom(16)).decode()  # may contain "=" / "+"
# after
payload["delivery_id"] = uuid.uuid4().hex  # always valid
Defensive patterns

Strategy: validation

Validate before calling

import re
DELIVERY_ID_PATTERN = re.compile(r'^[A-Za-z0-9._:-]{1,160}$')
did = payload.get('delivery_id')
if not isinstance(did, str) or not DELIVERY_ID_PATTERN.fullmatch(did):
    raise ValueError('delivery_id is invalid')

Type guard

import re
_DID = re.compile(r'^[A-Za-z0-9._:-]{1,160}$')
def is_valid_delivery_id(value: object) -> bool:
    return isinstance(value, str) and bool(_DID.fullmatch(value))

Try / catch

resp = requests.post(url, json=payload)
if resp.status_code == 400 and resp.json().get('error') == 'delivery_id is invalid':
    payload['delivery_id'] = uuid.uuid4().hex  # regenerate a valid id

Prevention

When it happens

Trigger: delivery_id omitted; empty string; contains spaces, slashes, '=', '+', or quotes; longer than 160 chars; or sent as a number instead of a string.

Common situations: Sender uses standard base64 (contains '=' and '+'); wraps a UUID in braces; passes a numeric epoch; or copies a URL containing '/'. GitHub's X-GitHub-Delivery UUID is valid (hyphens are allowed).

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/22e850500881d80d. Report an issue: GitHub.