OtterMind/Chat2DB · critical · RuntimeError

ONEBOT_TOKEN must contain at least 32 characters

Error message

ONEBOT_TOKEN must contain at least 32 characters

What it means

Raised by RelayConfig.from_environment (relay_server.py:62) as a RuntimeError when ONEBOT_TOKEN has fewer than 32 characters. The relay forwards messages to the NapCat/OneBot backend using this token; a short token is treated as misconfiguration and the server refuses to start.

Source

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

class RelayConfig:
    relay_token: str
    onebot_token: str
    onebot_url: str
    repository: str
    group_id: int
    max_message_length: int = 900
    rate_limit: int = 30
    rate_window_seconds: int = 60

    @classmethod
    def from_environment(cls) -> "RelayConfig":
        relay_token = os.environ.get("RELAY_TOKEN", "")
        onebot_token = os.environ.get("ONEBOT_TOKEN", "")
        group_id = os.environ.get("QQ_GROUP_ID", "")
        if len(relay_token) < 32:
            raise RuntimeError("RELAY_TOKEN must contain at least 32 characters")
        if len(onebot_token) < 32:
            raise RuntimeError("ONEBOT_TOKEN must contain at least 32 characters")
        if not group_id.isdigit():
            raise RuntimeError("QQ_GROUP_ID must be a numeric QQ group number")
        return cls(
            relay_token=relay_token,
            onebot_token=onebot_token,
            onebot_url=os.environ.get("ONEBOT_URL", "http://napcat:3000"),
            repository=os.environ.get("RELAY_REPOSITORY", "OtterMind/Chat2DB"),
            group_id=int(group_id),
            max_message_length=int(os.environ.get("RELAY_MAX_MESSAGE_LENGTH", "900")),
            rate_limit=int(os.environ.get("RELAY_RATE_LIMIT", "30")),
        )


class RateLimiter:
    def __init__(self, limit: int, window_seconds: int):
        self.limit = limit
        self.window_seconds = window_seconds
        self._timestamps: deque[float] = deque()

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Generate a OneBot access token of at least 32 characters.
  2. Configure the same token in NapCat/OneBot and set ONEBOT_TOKEN in the relay environment.
  3. Restart the relay after updating the env.

Example fix

ONEBOT_TOKEN=$(python -c 'import secrets;print(secrets.token_urlsafe(48))')
Defensive patterns

Strategy: validation

Validate before calling

import os
token = os.environ.get("ONEBOT_TOKEN", "")
if len(token) < 32:
    raise SystemExit("ONEBOT_TOKEN must be >= 32 chars; set the NapCat access token")

Type guard

def is_strong_token(value: str) -> bool:
    return len(value) >= 32

Prevention

When it happens

Trigger: Starting the relay with ONEBOT_TOKEN unset, empty, or shorter than 32 chars. Checked at startup in from_environment, so it is fatal before serving.

Common situations: ONEBOT_TOKEN not set; the OneBot access token changed but the relay env was not updated; a placeholder used during setup; NapCat deployed without an access token.

Related errors


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