Skip to content

fix(embedder): always chunk text before cluster_texts() when max_input t_length is None - #1328

Merged
sscargal merged 1 commit into
MemMachine:mainfrom
sscargal:bugfix/1298-missing-max-input-length-guard
Apr 16, 2026
Merged

sscargal merged 1 commit into
MemMachine:mainfrom
sscargal:bugfix/1298-missing-max-input-length-guard

Conversation

@sscargal

Copy link
Copy Markdown
Contributor

Purpose of the change

OpenAIEmbedder._embed() previously skipped chunk_text_balanced() when self._max_input_length was None (the default across every embedder conf). Any single input longer than cluster_texts()'s hard-coded 75,000-char ceiling then raised an unhandled ValueError, surfacing as HTTP 500 on ingestion of long messages.

Description

Replace the conditional guard with an unconditional split that falls back to max_total_input_length_per_request (the same 75,000-char bound cluster_texts() enforces) when max_input_length is None. Every text is now guaranteed to fit before cluster_texts() sees it.

Scope is limited to OpenAIEmbedder per architect review: Bedrock and SentenceTransformer embedders do not call cluster_texts() and have no equivalent crash path. Conf defaults remain None by design — no single Unicode code-point value is correct across all supported models.

Adds regression test test_embed_oversized_input_with_no_max_input_length covering an 80,000-char input with max_input_length=None.

Fixes/Closes

Fixes #1298

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

  • Unit Test

Checklist

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

Screenshots/Gifs

N/A

Further comments

None

…t_length is None

OpenAIEmbedder._embed() previously skipped chunk_text_balanced()
when self._max_input_length was None (the default across every embedder conf).
Any single input longer than cluster_texts()'s hard-coded 75,000-char ceiling
then raised an unhandled ValueError, surfacing as HTTP 500 on ingestion of long messages.

Replace the conditional guard with an unconditional split that falls
back to max_total_input_length_per_request (the same 75,000-char bound
cluster_texts() enforces) when max_input_length is None. Every text is
now guaranteed to fit before cluster_texts() sees it.

Scope is limited to OpenAIEmbedder per architect review: Bedrock and
SentenceTransformer embedders do not call cluster_texts() and have no
equivalent crash path. Conf defaults remain None by design — no single
Unicode code-point value is correct across all supported models.

Adds regression test test_embed_oversized_input_with_no_max_input_length
covering an 80,000-char input with max_input_length=None.

Refs: #1298
Signed-off-by: Steve Scargall <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash path in the server’s OpenAI embedder by ensuring long inputs are always chunked before being passed into the clustering step, preventing unhandled ValueError and resulting HTTP 500s during ingestion of very long messages.

Changes:

  • Always chunk inputs in OpenAIEmbedder._embed() using a fallback bound when max_input_length is None.
  • Add a regression test covering an 80,000-character input with max_input_length=None.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/server/src/memmachine_server/common/embedder/openai_embedder.py Ensures inputs are chunked with an effective max length before calling cluster_texts().
packages/server/server_tests/memmachine_server/common/embedder/test_openai_embedder.py Adds regression test for oversized single input when max_input_length is unset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@junttang

Copy link
Copy Markdown
Contributor

I've tested this PR locally and confirmed the crash described in the issue #1298 is fixed now. I've gone ahead and closed the issue. Thanks.

@sscargal sscargal added this to the v0.3.5 milestone Apr 16, 2026
@sscargal
sscargal merged commit 1194e53 into MemMachine:main Apr 16, 2026
48 checks passed
@sscargal
sscargal deleted the bugfix/1298-missing-max-input-length-guard branch April 16, 2026 16:11
edwinyyyu pushed a commit to edwinyyyu/MemMachine that referenced this pull request Apr 20, 2026
…t t_length is None (MemMachine#1328)

fix(embedder): always chunk text before cluster_texts() when max_input_length is None

OpenAIEmbedder._embed() previously skipped chunk_text_balanced()
when self._max_input_length was None (the default across every embedder conf).
Any single input longer than cluster_texts()'s hard-coded 75,000-char ceiling
then raised an unhandled ValueError, surfacing as HTTP 500 on ingestion of long messages.

Replace the conditional guard with an unconditional split that falls
back to max_total_input_length_per_request (the same 75,000-char bound
cluster_texts() enforces) when max_input_length is None. Every text is
now guaranteed to fit before cluster_texts() sees it.

Scope is limited to OpenAIEmbedder per architect review: Bedrock and
SentenceTransformer embedders do not call cluster_texts() and have no
equivalent crash path. Conf defaults remain None by design — no single
Unicode code-point value is correct across all supported models.

Adds regression test test_embed_oversized_input_with_no_max_input_length
covering an 80,000-char input with max_input_length=None.

Refs: MemMachine#1298

Signed-off-by: Steve Scargall <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Missing default max_input_length causes unhandled ValueError when ingesting long single messages

4 participants