lfnovo/open-notebook · error · HTTPException

Error building context: {str(e)}

Error message

Error building context: {str(e)}

What it means

Generic 500 from POST /chat/context when build_notebook_context or downstream processing throws an unexpected exception. Cause logged as 'Error building context: ...'.

Source

Thrown at api/routers/chat.py:416

            raise HTTPException(status_code=404, detail="Notebook not found")

        context_data, total_content = await build_notebook_context(
            notebook, request.context_config
        )

        char_count = len(total_content)
        estimated_tokens = token_count(total_content) if total_content else 0

        return BuildContextResponse(
            context=context_data, token_count=estimated_tokens, char_count=char_count
        )
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error building context: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Error building context: {str(e)}")

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check the API log for the exact exception during context build
  2. Inspect the notebook's sources/notes for failed or malformed entries and remove/reprocess them
  3. Verify provider credentials and that the worker is running
  4. Try a context config with fewer sources to isolate the failing item
Defensive patterns

Strategy: fallback

Validate before calling

const sources = await fetchSources(notebookId);
if (sources.some(s => s.processing_status === 'failed')) throw new Error('Fix failed sources first');

Try / catch

catch (e) { if (e.status === 500) fallbackToSmallerContext(); else throw e; }

Prevention

When it happens

Trigger: Corrupt source/note content failing during context assembly, embedding provider failures when notes need vectors, or DB errors reading notebook entries.

Common situations: A source stuck in a failed processing state; provider credentials missing for embeddings; very large notebooks hitting memory/timeout limits.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/0dbebdf988f84e10. Report an issue: GitHub.