fix(api): return 413 content_too_long instead of 500 when embedder co…#18
Merged
Merged
Conversation
…ntext exceeded Closes ourmem#15. Embedding content longer than the configured embedder's context window is a client-input problem, but it surfaced as 500 internal_error with the real cause buried inside a stringified upstream embedder error (callers had to substring-match "exceeds the context window"). Add OmemError::ContentTooLong { length, hint }, map it to 413 Payload Too Large in the IntoResponse impl, and recognize the over-context signature at the content embed call sites (create + update). Response now: {"error":{"code":"content_too_long", "message":"content too long: 7410 chars exceed the embedder's context window", "hint":"split the content into smaller memories or configure a longer-context embedder"}} Other embed failures still map to Embedding/500. This is Option A from the issue; pre-flight token estimate (Option B) left as a possible follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Merged and deployed! Clean implementation of Option A. The |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ntext exceeded
Closes #15.
Embedding content longer than the configured embedder's context window is a client-input problem, but it surfaced as 500 internal_error with the real cause buried inside a stringified upstream embedder error (callers had to substring-match "exceeds the context window").
Add OmemError::ContentTooLong { length, hint }, map it to 413 Payload Too Large in the IntoResponse impl, and recognize the over-context signature at the content embed call sites (create + update). Response now:
{"error":{"code":"content_too_long",
"message":"content too long: 7410 chars exceed the embedder's context window",
"hint":"split the content into smaller memories or configure a longer-context embedder"}}
Other embed failures still map to Embedding/500. This is Option A from the issue; pre-flight token estimate (Option B) left as a possible follow-up.