HKUDS/DeepTutor · warning · HTTPException

Source '{source_id}' not found

Error message

Source '{source_id}' not found

What it means

HTTP 404 from DELETE /{kb_name}/github-source/{source_id} when manager.remove_github_source returns falsy — no GitHub source with that id is registered on the KB.

Source

Thrown at deeptutor/api/routers/knowledge.py:3408

@router.get("/{kb_name}/github-sources", response_model=list[GitHubSourceInfo])
async def get_github_sources(kb_name: str):
    try:
        manager, resolved_name, _ = _writable_kb(kb_name)
        return [GitHubSourceInfo(**s) for s in manager.get_github_sources(resolved_name)]
    except HTTPException:
        raise
    except ValueError:
        raise HTTPException(status_code=404, detail=f"KB '{kb_name}' not found")
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))


@router.delete("/{kb_name}/github-source/{source_id}")
async def remove_github_source(kb_name: str, source_id: str):
    try:
        manager, resolved_name, _ = _writable_kb(kb_name)
        if not manager.remove_github_source(resolved_name, source_id):
            raise HTTPException(status_code=404, detail=f"Source '{source_id}' not found")
        return {"message": "Removed", "source_id": source_id}
    except HTTPException:
        raise
    except ValueError:
        raise HTTPException(status_code=404, detail=f"KB '{kb_name}' not found")
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))


@router.post("/{kb_name}/sync-github")
async def sync_github_sources(kb_name: str):
    try:
        manager, resolved_name, kb_base_dir = _writable_kb(kb_name)
        sources = manager.get_github_sources(resolved_name)
        if not sources:
            return {"message": "No GitHub sources", "results": []}
        from deeptutor.services.github_source.sync import sync_source

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Refresh the GitHub sources list and confirm source_id is present
  2. Treat 404 on remove as already-removed (idempotent) when appropriate
  3. Update the UI to remove the row optimistically and ignore 404

Example fix

# before
DELETE /kb/my-kb/github-source/src-9  -> 404 Source 'src-9' not found
# after
if resp.status_code == 404:
    pass  # already removed; nothing to do
Defensive patterns

Strategy: try-catch

Validate before calling

src_ids = {s['id'] for s in client.get(f'/api/v1/knowledge/{kb}/github-sources').json()}
if source_id not in src_ids: return

Try / catch

try:
    client.delete(f'/api/v1/knowledge/{kb}/github-source/{source_id}')
except HTTPError as e:
    if e.response.status_code == 404 and "Source" in e.response.json()['detail']:
        pass  # already removed
    else: raise

Prevention

When it happens

Trigger: Removing a source_id that was already removed, belongs to another KB, or was never added; remove_github_source returns False/None.

Common situations: Duplicate remove clicks; stale sources list in the UI; source removed by a sync job concurrently.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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