HKUDS/DeepTutor · warning · HTTPException

No sessions to import

Error message

No sessions to import

What it means

HTTP 400 raised by the import endpoint in deeptutor/api/routers/imports.py:77 when the ImportRequest contains an empty sessions list. There is nothing to persist, so instead of creating zero sessions the request is rejected and the client is told to supply at least one ImportedSession.

Solutions

  1. Include at least one ImportedSession in the request body
  2. Fix the exporter that produced an empty session list
  3. Return a client-side message that no sessions were selected for import

Example fix

// before
await client.post('/imports/chat-history', json={'source':'claude','sessions':sessions})
// after
if sessions:
    await client.post('/imports/chat-history', json={'source':'claude','sessions':sessions})
Defensive patterns

Strategy: validation

Validate before calling

if not sessions:
    return  # nothing to import — skip the call entirely

Type guard

def has_sessions(payload: dict) -> bool:
    return bool(payload.get('sessions'))

Try / catch

resp = client.post('/imports/chat-history', json=payload)
if resp.status_code == 400 and 'No sessions' in resp.text:
    return {'imported': 0}

Prevention

When it happens

Trigger: POSTing {"source":"claude","sessions":[]} or omitting the sessions field if it defaults to empty.

Common situations: Upstream export produced zero sessions (filter bug, wrong file parsed) and the client forwards it blindly; test asserting rejection of empty bodies.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/223320e358235a7c. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/api/routers/imports.py:77

    # a source folder). Empty when the client hasn't adopted the agent model yet
    # — the backend stays backwards-compatible by simply omitting attribution.
    agent_id: str = Field(default="", max_length=256)
    agent_name: str = Field(default="", max_length=256)
    sessions: list[ImportedSession] = Field(default_factory=list)

    @field_validator("source")
    @classmethod
    def _normalize_source(cls, value: str) -> str:
        normalized = (value or "").strip().lower()
        if normalized not in _ALLOWED_SOURCES:
            raise ValueError(f"Unsupported import source: {value!r}")
        return normalized


@router.post("/chat-history")
async def import_chat_history(payload: ChatHistoryImportRequest) -> dict[str, Any]:
    if not payload.sessions:
        raise HTTPException(status_code=400, detail="No sessions to import")
    if len(payload.sessions) > _MAX_SESSIONS_PER_REQUEST:
        raise HTTPException(
            status_code=413,
            detail=f"Too many sessions in one request (max {_MAX_SESSIONS_PER_REQUEST})",
        )

    store = get_sqlite_session_store()
    imported = 0
    skipped = 0
    results: list[dict[str, Any]] = []

    for incoming in payload.sessions:
        # Drop content-less rows (e.g. tool-only turns the adapter could not
        # reduce to text) so the transcript stays a clean human conversation.
        messages = [m for m in incoming.messages if (m.content or "").strip()]
        if not messages:
            skipped += 1
            results.append(

View on GitHub (pinned to 3e82f13042)