mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2026-07-19 14:13:35 -04:00
[GH-ISSUE #4105] [BUG]: BigInt Serialization Error with OpenRouter LLMs causing chat failures #2615
Closed
opened 2026-02-22 18:30:28 -05:00 by yindo
·
4 comments
No Branch/Tag Specified
master
5846-bug-when-scrolling-up-scrolling-jumps
refactor-remove-workspace-pfp
5969-bug-stopgenerationbutton-disappears-on-the-first-prompt-that-initiates-an-agent-session
2235-bug-how-to-upload-a-folder-with-subfolders-with-files-to-anythingllm
5990-workspace-update-fails-with-unknown-argument-router_id-v1130v1150-intel-mac
opencomputer-examples
pg
feat/image-generation-translations
feat/image-generation
5924-bug-meeting-summary-fails-with-sincludes-is-not-a-function-when-default-llm-is-anthropic-claude
render
feat/uniform-modal-component
5883-bug-unescaped-content-in-json-strings-being-passed-to-document-generator-tools
5901-bug-api-update-embeddings-fails-prisma-argument-filename-is-missing-on-workspace_documentscreate-desktop-windows-v1141
hybrid-search
1981-translations
5752-bug-prompts-to-local-jan-endpoint-unresponsive
feat-disable-native-tool-calling-env-var
5676-bug-non-ollama-agent-providers-do-not-parse-and-present-reasoning-content
feat/markdown-web-scraping
5717-bug-apiv1documentupload-silently-drops-metadata-field-in-desktop-1130-arg-count-mismatch-nested-payload-key
fix/aibitat-context-overflow
5711-bug-erratic-deepseek-v4-flash-the-agent-model-failed-to-respond-400-the-reasoning_content
5631-feat-custom-api-request-timeouts-for-ai-providers
feat-reasoning-control
feat-agent-clarifying-questions-translations
5583-bug-lm-studio-provider-does-not-present-reasoning-output
5313-normalize-translations
feat/memory-translations
5305-lemonade-embedding-engine-swallows-errors-falsely-reports-documents-as-embedded
5060-bug-agent-interactions-agent-are-not-persisted-to-thread-history-via-api
pptx-subagent
feat-render-images-from-mcp-tool-results
stt-provider-expansion-openai-api-compatible
feat-file-search-agent-tool
feat-native-embedder-job-queue
5189-normalize-translations
feat-file-search-agent-tool-translations
i18n-eslint
5140-auto-migration
5112-bug-openrouter-failed-message-bug
3506-feat-parameters-for-openrouter-models
4992-feat-preserve-scroll-position
4973-bug-markdown-numbered-list-display-in-reasoning-pane
desktop
4938-bug-pending-chat-rerendering-ui-bug
quickstart-env
node-llama-cpp-in-container-cuda
node-llama-cpp-in-container
ollama-in-container
4817-feat-set-cooldown-per-mcp-server
4845-keyboard-shortcuts-to-navigate-in-chat
4844-feat-reorder-threads-by-latest-interaction
standardize-username-constraints-normalize-translations
4792-feat-refactor-workspacepfp-image
1382-embed-ip-improvements
1382-bug-embed-api-improvements
refactor-eslint-frontend
4687-feat-refactor-vector-db-providers
4615-feat-disable-apidocs-with-environment-variable
4559-feat-agent-web-search-enable-ordering-of-results
4599-bug-ollama-race-condition-bug
4572-bug-lmstudio-provided-llm-stopped-working-with-anything-llm-after-upgrading-to-190
4508-agent-youtube-transcript-analysis
4497-feat-workspace-names
frontend-eslint
ollama-lmstudio-auto-context-window
4431-validate-vector-database-connectioN
2019-slash-command-keyboard-selection
microsoft-foundry-provider
4431-validate-vector-database-connection
4325-sys-prompt-var-improvements
3209-feat-apiv1workspacestream-chat-sources-citations
4210-bug-voice-to-text-overwrite
4136-feat-jan-as-a-backend-server-option
4172-feat-openai-o3-support
1.8.3-rerelease
web-push-notifications-service
tasks
3955-feat-jinaai-embedder-provider-support
3921-feat-agent-skills-uiux-improvements
3901-bug-validfunccall-checks-optional-arguments
keyboard-dev
1787-custom-roles-and-permissions
add-jira-slack-data-connector
office-extension-wip
lightmode-dropdown-color-update
3586-bug-agent-flow-function-description-provided-by-user-is-not-seen-in-the-llm-query
3463-bug-agent-continues-to-run-if-request-failed-even-after-exit
3439-feat-call-variables-within-the-flow-api-block-url-field
3282-manager-view-models-workspace
3280-token-counting-server-side-truncation-improvements
3147-bug-embedded-chat-widget---not-considering-query-mode-option-always-working-in-chat-mode
2995-feat-disable-temperature-setting-for-deepseek-r1-deepseek-reasoner-model
2827-feat-perplexity-citations
2866-feat-finally-a-gemini-models-endpoint
2647-feat-hpp-header-for-a-c++-code-file-mime-addition
lancedb-revert
1656-feat-implement-tooltip-ui-designs
2011-feat-bump-perplexity-models
1873-feat-auto-add-and-watch-folder-for-document-uploads
1297-feat-gemini-agent-support
1759-bug-ui-bug-fixes
1686-feat-implement-winston-for-logging
1536-bug-toggling-on-users-can-delete-workspaces-does-not-take-effect
agent-ui-mobile-styles
1522-feat-chromadb-support
1595-bug-unable-to-get-live-web-search-and-browsing-agent-working-using-google-custom-search-engine-error-getaddrinfo-enotfound-http-errno-3008
1582-bug-lm-studio-does-not-allow-for-different-model-selection
1312-bug-usernames-should-not-be-case-sensitive-when-logging-in
1029-feat-hf-serverless-inference-api
1086-feat-implement-normalized-input-fields
knowledge-graph-support
644-bug-uploaded-file-name-does-not-match-the-displayed-file-name-after-the-upload
v1.15.0
v1.14.2
v1.14.1
v1.14.0
v1.13.0
v1.12.1
v1.12.0
v1.11.2
v1.11.1
v1.11.0
v1.10.0
v1.9.1
v1.9.0
v1.8.5
v1.8.4
v1.8.3
v1.8.2
v1.8.1
v1.8.0
v1.7.8
v1.7.6
v1.7.5
v1.7.4
v1.4.0
v1.3.0
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.1.1
v1.1.0
v1.0.0
Labels
Clear labels
Desktop
Docker
Integration Request
Integration Request
OS: Linux
OS: Mobile
OS: Windows
UI/UX
blocked
bug
bug
core-team-only
documentation
duplicate
embed-widget
enhancement
feature request
github_actions
good first issue
investigating
needs info / can't replicate
possible bug
pull-request
question
stage: specifications
wontfix
Mirrored from GitHub Pull Request
No Label
needs info / can't replicate
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Mintplex-Labs/anything-llm#2615
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @drockthedoc on GitHub (Jul 8, 2025).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/4105
Originally assigned to: @shatfield4 on GitHub.
How are you running AnythingLLM?
Docker (local)
What happened?
BigInt Serialization Error in AnythingLLM with OpenRouter LLMs
Bug Description
AnythingLLM crashes with BigInt serialization errors when using certain LLM providers (particularly OpenRouter with models like
deepseek/deepseek-r1-distill-llama-70b:free) due to multipleJSON.stringify()calls throughout the codebase that cannot handle BigInt values.Error Messages
Environment
14fa079)deepseek/deepseek-r1-distill-llama-70b:freeRoot Cause
The issue occurs because several parts of the codebase use
JSON.stringify()without handling BigInt values properly. When LLM responses contain BigInt values (common with token counts, timestamps, or other numeric metadata), these calls fail and prevent chat creation, leading to null chat objects and subsequent errors.Affected Files
The following files contain
JSON.stringify()calls that need BigInt handling:/app/server/models/workspaceChats.js- Critical: Chat creation fails here/app/server/models/embedChats.js- Embed chat responses/app/server/utils/logger/index.js- Logger formatting/app/server/utils/helpers/chat/responses.js- Chat response handling/app/server/utils/chats/openaiCompatible.js- OpenAI compatibility layer/app/server/utils/helpers/chat/convertTo.js- Chat conversion utilities/app/server/utils/AiProviders/openRouter/index.js- OpenRouter provider/app/server/utils/chats/stream.js- Null safety for chat.idSolution
Replace all instances of
JSON.stringify(obj)withJSON.stringify(obj, (key, value) => typeof value === "bigint" ? value.toString() : value)to safely convert BigInt values to strings during serialization.Specific Fixes Applied
1. Fix Chat Creation (Critical)
File:
/app/server/models/workspaceChats.js2. Fix Embed Chats
File:
/app/server/models/embedChats.js3. Fix Logger
File:
/app/server/utils/logger/index.js4. Fix Stream Null Safety
File:
/app/server/utils/chats/stream.js5. Fix Other Response Handlers
Similar fixes needed in:
/app/server/utils/helpers/chat/responses.js/app/server/utils/chats/openaiCompatible.js/app/server/utils/helpers/chat/convertTo.js/app/server/utils/AiProviders/openRouter/index.jsTesting
After applying these fixes:
sent_chateventsImpact
This bug prevents AnythingLLM from working with several popular LLM providers that return BigInt values in their responses, particularly:
Reproduction Steps
deepseek/deepseek-r1-distill-llama-70b:freeSuggested Implementation
Consider creating a utility function for BigInt-safe JSON serialization:
Then replace all
JSON.stringify()calls withsafeJsonStringify()throughout the codebase.Priority
High - This bug prevents AnythingLLM from functioning with popular LLM providers and causes complete chat failure rather than graceful degradation.
Are there known steps to reproduce?
No response
@shatfield4 commented on GitHub (Jul 8, 2025):
I'm unable to replicate this bug using the OpenRouter provider and the same deepseek model you said you used here. Is there any specific message you sent to get this error to replicate consistently?
@drockthedoc commented on GitHub (Jul 8, 2025):
Um... i'm using my self-patched version of anythingllm at the moment, and i've changed things iteratively to refine the original prompt since I self-patched, but i'll give you the broad strokes:
here's my current system prompt for my workspace -- the one that was giving me problems may have differed a bit but was substantially similar (please don't judge me):
You are an expert in healthcare administration and psychometrics. Your task is to write one high-quality, multiple-choice question (MCQ) for a professional certification exam that tests higher-order thinking.
Primary Goal:
Generate a single MCQ that requires the test-taker to first, analyze a scenario containing specific data points to diagnose a problem, and second, apply a formal standard or regulation to determine the single, factually correct response.
Core Psychometric Principle: Test Diagnosis and Application
The question must be structured to differentiate candidates who can accurately interpret operational data from those who cannot. The thinking process is a two-step sequence: data analysis, then rule application.
How to Construct the Question Stem:
Present a Data-Driven Scenario: The stem MUST describe a realistic administrative or operational challenge by providing 2-3 specific, quantitative or qualitative data points (e.g., performance metrics, survey results, incident reports, budget figures, staff complaints).
Imply a Core Problem: These data points, when synthesized, must point to a clear underlying problem (e.g., a patient safety decline, a compliance gap, a workforce issue).
Ask for a Required Action: The question must ask for a specific, required action or process that follows from a correct diagnosis of the data, based on an explicit standard, law, or regulation.
Example of the Principle (Transforming a Type I to a Type II Question):
AVOID (Type I - Simple Recall): "According to the WHO, which strategy is recommended to mitigate burnout?"
This only tests knowledge of a fact.
EMPHASIZE (Type II - Analysis + Application): "A hospital's annual report reveals a 20% increase in nursing turnover, a significant rise in medication errors, and survey data showing widespread emotional exhaustion. Citing the WHO's definition of burnout as an occupational phenomenon, the hospital's strategic plan must primarily focus on which area?"
This forces the test-taker to first diagnose the problem from the data, then apply the WHO principle to find the correct answer.
Exam Blueprint:
[The blueprint list remains the same and would be inserted here]
Required Output Format:
Generate the MCQ using the exact structure below, with no additional commentary.
QUESTION STEM:
[Write a scenario containing 2-3 specific data points that imply a core problem. End with a direct question asking for a required action or process based on a specific standard or regulation.]
ANSWER OPTIONS:
[Provide four plausible options (A-D). They must be concise (1-7 words) and grammatically parallel. Foils should be plausible actions if one misinterprets the data or the governing standard.]
A. [Plausible but incorrect option]
B. [Plausible but incorrect option]
C. [The single correct option]
D. [Plausible but incorrect option]
CORRECT ANSWER:
[Provide only the letter of the correct answer.]
TESTING POINT:
[State the two-part skill being tested. Format as: "Can the candidate analyze [summary of data] and apply [the specific rule or standard] to determine the required action?"]
COGNITIVE LEVEL:
Type II
BLUEPRINT DOMAIN:
[List the full code and label for the chosen subdomain.]
REFERENCE:
[Provide a direct quote from an authoritative source (e.g., a law, regulatory body, or national standard) that provides the factual basis for the right answer.]
Blueprint Domains:
6.0 Human Resource Management and Workforce Development
6.1 Compensation and benefits practices
6.2 Conflicts and dualities of interest (e.g., industry relationships)
6.3 Conflict resolution and grievance procedures
6.4 Diversity, inclusion, and equity strategies
6.5 Employee safety, security, and health issues (e.g., OSHA, workplace violence)
6.6 Employee satisfaction assessment, engagement, motivation, and career development tools
6.7 Labor relations and laws (e.g., FMLA, FLSA, EEOC, ERISA, worker compensation)
6.8 Performance management systems (e.g., performance-based evaluation, rewards systems, disciplinary policies, and procedures)
6.9 Physician satisfaction assessment and engagement tools and techniques
6.10 Recruitment and retention approaches and techniques
6.11 Staffing models, productivity management, and the impact of changes on the quality of care
6.12 Interprofessional care delivery teams
6.13 Succession planning models
6.14 Workforce cultural competency strategies
6.15 Workforce wellness
6.16 Burnout mitigation
6.17 Impaired individuals
6.18 Utilization and impact of external staffing agencies
7.0 Leadership in Patient Safety and Quality Improvement
7.1 Benchmarking standards to define, monitor, and assure evidence-based, efficient, timely, appropriate, cost-effective, equitable, patient-centered care
7.2 High-reliability care organizational (HRO) principles, tools, and monitoring processes (e.g., error reduction, serious safety event and near-miss reporting, just culture, root cause analysis, regulatory safety event reporting requirements, corrective action plans, and error disclosure)
7.3 Performance standard-setting, documentation, measurement, and monitoring (e.g., evidence-based clinical pathways, value-based care, population health, pay-for-performance, patient satisfaction)
7.4 Principles of patient safety, methods, and legal aspects of medical staff credentialing and peer review, including OPPE and FPPE
7.5 Process and quality improvement principles, measurement tools, and techniques (e.g., plan-do-study-act, lean daily management, Six Sigma)
7.6 Quality program leadership, strategic planning, operations, and financing
7.7 Risk management principles and programs (e.g., insurance, education, workplace safety, injury management, patient complaints, patient and staff safety, and security)
7.8 Utilization review and leadership of case management teams
7.9 Education in identifiable gaps in system-based practice
7.10 Longitudinal understanding of the system-wide organizational structure
7.11 Community initiatives (e.g., violence prevention)
7.12 External agency engagement (e.g., NAHQ, AHRQ, NAM, etc.)
...then i just used "@rag-search write a question about burnout mitigation" as the user prompt.... this was before I realized that I didn't need to use "@ anything" in order for it to search the vectorDB
@drockthedoc commented on GitHub (Jul 8, 2025):
If it helps.... i could see the "thinking" portion stream onto the screen and then, at the end of the "think" it displayed the question, answers, etc. and then (when it finished displaying all of that) is when the red error box popped up on the screen and crashed the whole program, necessitating a restart.
@timothycarambat commented on GitHub (Jul 8, 2025):
This seems to just be some kind of serialization issue when it comes to the chunk handler. Some metric field OR reports back comes across as a bigint instead of a normal JS
Numberso we just need to handle that edge case.[BUG]: BigInt Serialization Error with OpenRouter LLMs causing chat failuresto [GH-ISSUE #4105] [BUG]: BigInt Serialization Error with OpenRouter LLMs causing chat failures