Skip to content

bug(kb): every knowledge upload over 1 MiB gets 413 — the app-wide validation middleware's JSON cap applies to multipart uploads, and the 10 MB limit is hardcoded in 3 more places #19712

Open

Description

@mrveiss

Problem

Uploading any knowledge file larger than 1 MiB fails with 413 Content Too Large, even though the upload route allows 10 MB. Seen on 2026-10-26 on a node updated to be85b7e1ed: POST /api/knowledge_base/upload returned 413. The frontend RUM log recorded the same 413 at 22:19:12.

Root cause

  • autobot-backend/middleware/validation_middleware.py:56 sets MAX_BODY_BYTES: Final[int] = 1 * 1024 * 1024. ValidationMiddleware is registered app-wide by initialization/middleware.py:configure_validation, and its docstring says it "Rejects oversized bodies (> 1 MiB) with HTTP 413".
  • The only exemptions are _EXEMPT_PREFIXES (health, docs and static) and _BODY_SCAN_EXEMPT_RE, which matches only ^/api/chats/[^/]+/save$. Neither covers multipart upload routes, so the 1 MiB perimeter cap wins over every route's own limit.
  • The upload limit is also defined three more times, as hardcoded literals that are not config:
    • autobot-backend/api/knowledge.py:135 MAX_FILE_SIZE_MB = 10
    • autobot-frontend/src/constants/knowledgeUpload.ts KNOWLEDGE_UPLOAD_MAX_MB = 10 (a hand-kept mirror)
    • web server client_max_body_size 10m on most locations

Fix

Acceptance criteria

  • A 5 MB PDF uploads through the Knowledge upload dialog and is chunked into the KB. A test posts a body larger than 1 MiB to /api/knowledge_base/upload and gets no 413 from the middleware.
  • A JSON body larger than 1 MiB to a non-upload route still gets 413. A test pins this.
  • MAX_FILE_SIZE_MB is read from one config/env value. knowledgeUpload.ts no longer hardcodes 10, and gets the value from the backend.
  • The web server body limit for the upload route comes from the same value.
  • Host: after the builtin update, a 5 MB upload succeeds on the node.

Activity

  1. mrveiss commented on Nov 1, 2026

    @mrveiss
    OwnerAuthor

    The 1 MiB cap applies to every multipart route, not only this one. The PR for this issue lifts it only for /api/knowledge_base/upload, whose limit is confirmed. Read by grep of each route file on main, not traced through helpers and not run:

    File Limit of its own, by grep
    api/files.py, api/conversation_file_upload.py 50 MB
    api/voice.py, api/multimodal.py read_capped_audio
    transcriber/routes/recordings.py MAX_FILE_SIZE, streamed
    llc/api/agent_api.py, llc/api/work_items.py 413 raised
    api/chat_knowledge.py, api/conversation_files.py, api/themes.py, media/image_upload.py None found; a helper may hold one

    Each stays capped at 1 MiB until checked and added to _OWN_LIMIT_MULTIPART_RE, so this issue stays open for them.

  2. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Verified against main at the merge train (PR #20661), merge 6c34ee1. Members touching this issue: #20544.

    AC Evidence
    A 5 MB PDF uploads through the dialog; a test posts over 1 MiB to /api/knowledge_base/upload and gets no 413 NOT ticked. Middleware now exempts multipart to that route (middleware/validation_middleware.py:80, _OWN_LIMIT_MULTIPART_RE, used at line 229) and validation_middleware_test.py:341 pins it, but with a lowered test cap and 100-byte file, not a real 5 MB body, and the dialog path is not tested end to end.
    A JSON body over 1 MiB to a non-upload route still gets 413, pinned Ticked. validation_middleware_test.py:190 (test_oversized_body_rejected), :346 (JSON to the upload route keeps the cap), :350 (multipart to another route keeps it).
    MAX_FILE_SIZE_MB from one env value; knowledgeUpload.ts no longer hardcodes 10 and gets it from the backend Ticked. knowledge/upload_limit.py:16: env_int("AUTOBOT_KB_UPLOAD_MAX_MB", 10), imported by api/knowledge.py:113; served at GET /knowledge_base/upload/limit (api/knowledge_upload_limit.py); autobot-frontend/src/constants/knowledgeUpload.ts no longer defines it and composables/knowledge/useKnowledgeUploadLimit.ts reads it.
    Web server body limit for the upload route comes from the same value NOT ticked. client_max_body_size 10m is still a literal in autobot-slm-backend/ansible/roles/slm_manager/templates/autobot-slm.conf.j2:65 and the proxy configs; nothing generates it from AUTOBOT_KB_UPLOAD_MAX_MB.
    Host: after the builtin update, a 5 MB upload succeeds on the node NOT ticked. Host behaviour; a merge is not host evidence.

    The issue stays open: 3 criteria remain.

  3. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Host check on 2026-11-02, read-only, on the local node after its update to 6c34ee1:

    • The deployed validation_middleware.py is byte-identical to that commit and holds the upload route's exemption (_OWN_LIMIT_MULTIPART_RE).
    • The recent lines of the backend log show no upload and no 413.

    That shows the code is deployed, not that the criterion is met. No upload has been tried: it writes to the knowledge base, so the 5 MB upload stays with the owner, and the host criterion stays open.

    The web server's body limit wasn't checked: the search of its enabled sites returned nothing, which may mean no access rather than no setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't workingfrontendphase:M1.8Knowledge base: upload, web sources and chat retrieval work end to endpriority: high

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions