bytedance/deer-flow · warning · HTTPException

system_already_initialized

system_already_initialized

Error message

System already initialized

What it means

409 from POST /api/auth/initialize: count_admin_users() returned > 0, so the first-admin bootstrap endpoint refuses to run — the system already has an admin and initialize is a once-only operation. Subsequent admins must be created by an authenticated admin.

Source

Thrown at backend/app/gateway/routers/auth.py:543

    password: str = Field(..., min_length=8)
    remember_me: bool = True

    _strong_password = field_validator("password")(classmethod(lambda cls, v: _validate_strong_password(v)))


@router.post("/initialize", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
async def initialize_admin(request: Request, response: Response, body: InitializeAdminRequest):
    """Create the first admin account on initial system setup.

    Only callable when no admin exists. Returns 409 Conflict if an admin
    already exists.

    On success, the admin account is created with ``needs_setup=False`` and
    the session cookie is set.
    """
    admin_count = await get_local_provider().count_admin_users()
    if admin_count > 0:
        raise HTTPException(
            status_code=status.HTTP_409_CONFLICT,
            detail=AuthErrorResponse(code=AuthErrorCode.SYSTEM_ALREADY_INITIALIZED, message="System already initialized").model_dump(),
        )

    try:
        user = await get_local_provider().create_user(email=body.email, password=body.password, system_role="admin", needs_setup=False)
    except ValueError:
        admin_count = await get_local_provider().count_admin_users()
        if admin_count == 0:
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail=AuthErrorResponse(code=AuthErrorCode.EMAIL_ALREADY_EXISTS, message="Email already registered").model_dump(),
            )
        raise HTTPException(
            status_code=status.HTTP_409_CONFLICT,
            detail=AuthErrorResponse(code=AuthErrorCode.SYSTEM_ALREADY_INITIALIZED, message="System already initialized").model_dump(),
        )

View on GitHub (pinned to 1dd6ba1acb)

Solutions

  1. Log in as the existing admin instead of re-initializing
  2. To start over on a throwaway instance, wipe the user store (delete the DB/users file) so admin count returns to 0
  3. Make setup scripts idempotent: treat 409 SYSTEM_ALREADY_INITIALIZED as success

Example fix

# before
resp = post("/api/auth/initialize", json=admin_payload)
resp.raise_for_status()

# after
resp = post("/api/auth/initialize", json=admin_payload)
if resp.status_code == 409:
    log.info("already initialized; skipping bootstrap")
else:
    resp.raise_for_status()
Defensive patterns

Strategy: try-catch

Validate before calling

const admins = await countAdmins(); // if exposed
if (admins > 0) skipBootstrap();

Try / catch

try { await initializeAdmin(payload); } catch (e) { if (e.status === 409 && e.body?.code === 'system_already_initialized') { log.info('bootstrap already done'); return; } throw e; }

Prevention

When it happens

Trigger: Calling /initialize a second time (page reload + resubmit, or scripted setup re-run) after an admin already exists.

Common situations: Setup wizard double-submits; operators re-running bootstrap automation against an already-initialized instance; replayed HTTP requests.

Related errors


AI-assisted analysis of bytedance/deer-flow@1dd6ba1acb (2026-08-14). Data as JSON: /api/errors/6f22fba7e1f71ff9. Report an issue: GitHub.