{"record":{"id":"22e850500881d80d","repo":"OtterMind/Chat2DB","slug":"delivery-id-is-invalid","errorCode":null,"errorMessage":"delivery_id is invalid","messagePattern":"delivery_id is invalid","errorType":"http","errorClass":"RequestError","httpStatus":400,"severity":"error","filePath":"script/github/qq_relay/relay_server.py","lineNumber":223,"sourceCode":"        except ValueError as error:\n            raise RequestError(HTTPStatus.LENGTH_REQUIRED, \"Content-Length is required\") from error\n        if content_length < 1 or content_length > MAX_REQUEST_BYTES:\n            raise RequestError(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, \"request body is too large\")\n        try:\n            payload = json.loads(self.rfile.read(content_length).decode(\"utf-8\"))\n        except (UnicodeDecodeError, json.JSONDecodeError) as error:\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"request body is not valid JSON\") from error\n        if not isinstance(payload, Mapping):\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"request body must be a JSON object\")\n        return payload\n\n    def _validate_payload(self, payload: Mapping[str, Any]) -> tuple[str, str]:\n        config = self.relay_state.config\n        if payload.get(\"repository\") != config.repository:\n            raise RequestError(HTTPStatus.FORBIDDEN, \"repository is not allowed\")\n        delivery_id = payload.get(\"delivery_id\")\n        if not isinstance(delivery_id, str) or not DELIVERY_ID_PATTERN.fullmatch(delivery_id):\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"delivery_id is invalid\")\n        message = payload.get(\"message\")\n        if not isinstance(message, str) or not message.strip():\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"message must be non-empty text\")\n        if len(message) > config.max_message_length:\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"message is too long\")\n        if CONTROL_CHARACTER_PATTERN.search(message):\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"message contains control characters\")\n        return delivery_id, message\n\n    def do_GET(self) -> None:  # noqa: N802\n        if self.path == \"/healthz\":\n            self._send_json(HTTPStatus.OK, {\"ok\": True})\n            return\n        self._send_json(HTTPStatus.NOT_FOUND, {\"error\": \"not found\"})\n\n    def do_POST(self) -> None:  # noqa: N802\n        delivery_id = \"\"\n        reserved = False","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/script/github/qq_relay/relay_server.py#L205-L241","documentation":"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.","triggerScenarios":"delivery_id omitted; empty string; contains spaces, slashes, '=', '+', or quotes; longer than 160 chars; or sent as a number instead of a string.","commonSituations":"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).","solutions":["Provide a string delivery_id that fully matches '^[A-Za-z0-9._:-]{1,160}$'.","Use the GitHub delivery UUID as-is, or uuid4().hex (32 lowercase hex chars).","If you need base64, use url-safe without padding and drop any '='."],"exampleFix":"# before\npayload[\"delivery_id\"] = base64.b64encode(os.urandom(16)).decode()  # may contain \"=\" / \"+\"\n# after\npayload[\"delivery_id\"] = uuid.uuid4().hex  # always valid","handlingStrategy":"validation","validationCode":"import re\nDELIVERY_ID_PATTERN = re.compile(r'^[A-Za-z0-9._:-]{1,160}$')\ndid = payload.get('delivery_id')\nif not isinstance(did, str) or not DELIVERY_ID_PATTERN.fullmatch(did):\n    raise ValueError('delivery_id is invalid')","typeGuard":"import re\n_DID = re.compile(r'^[A-Za-z0-9._:-]{1,160}$')\ndef is_valid_delivery_id(value: object) -> bool:\n    return isinstance(value, str) and bool(_DID.fullmatch(value))","tryCatchPattern":"resp = requests.post(url, json=payload)\nif resp.status_code == 400 and resp.json().get('error') == 'delivery_id is invalid':\n    payload['delivery_id'] = uuid.uuid4().hex  # regenerate a valid id","preventionTips":["Prefer uuid4().hex or the GitHub delivery UUID.","Avoid standard base64; if needed, use url-safe without padding."],"tags":["http","validation","regex","qq-relay"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}