Skip to content

fix: stop semantic ingestion retry loop on context_length_exceeded - #1259

Merged
o-love merged 1 commit into
mainfrom
fix/1252-context-length-ingestion
Mar 27, 2026
Merged

o-love merged 1 commit into
mainfrom
fix/1252-context-length-ingestion

Conversation

@o-love

@o-love o-love commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Purpose of the change

Prevent semantic ingestion from retrying indefinitely on messages that can never be processed because they exceed the model context window.

Description

This change treats context_length_exceeded failures as non-retryable during semantic ingestion. When that error is detected (including wrapped exception chains), the message is skipped and marked ingested so it does not remain in the dirty set forever.

It also adds a regression test that reproduces a wrapped external API error with underlying context_length_exceeded and verifies the message is marked ingested.

Fixes/Closes

Fixes #1252

Type of change

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

How Has This Been Tested?

  • Unit Test

Test Results:

  • uv run ruff check packages/server/src/memmachine_server/semantic_memory/semantic_ingestion.py packages/server/server_tests/memmachine_server/semantic_memory/test_semantic_ingestion.py
  • uv run pytest packages/server/server_tests/memmachine_server/semantic_memory/test_semantic_ingestion.py packages/server/server_tests/memmachine_server/semantic_memory/test_semantic_memory_background.py -q

Checklist

  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own 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

Screenshots/Gifs

N/A

Further comments

None

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

Updates the semantic ingestion pipeline to avoid infinite retries for messages that exceed an LLM’s context window, by detecting context_length_exceeded (including wrapped exception chains) and marking such messages as ingested so they don’t remain “dirty” forever.

Changes:

  • Add _is_context_length_exceeded_error() helper to detect context-length failures across exception chains.
  • Treat context_length_exceeded as non-retryable during ingestion: skip the message and mark it ingested.
  • Add a regression unit test covering wrapped external API errors with an underlying context_length_exceeded.

Reviewed changes

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

File Description
packages/server/src/memmachine_server/semantic_memory/semantic_ingestion.py Detects context-length errors and skips/marks messages ingested instead of repeatedly retrying.
packages/server/server_tests/memmachine_server/semantic_memory/test_semantic_ingestion.py Adds a regression test ensuring wrapped context_length_exceeded errors result in the message being marked ingested.

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

@xiongzubiao
xiongzubiao requested a review from a team March 25, 2026 20:23

@sscargal sscargal 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.

LGTM

@sscargal sscargal added this to the v0.3.3 milestone Mar 27, 2026
@o-love
o-love force-pushed the fix/1252-context-length-ingestion branch from d5a02c0 to 31f042c Compare March 27, 2026 17:57
@o-love
o-love force-pushed the fix/1252-context-length-ingestion branch from 31f042c to c3aa294 Compare March 27, 2026 17:57
@o-love
o-love merged commit bed055d into main Mar 27, 2026
67 of 68 checks passed
@o-love
o-love deleted the fix/1252-context-length-ingestion branch March 27, 2026 18:22
):
return True

current = current.__cause__ or current.__context__

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.

Can both of these be truthy simultaneously?

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.

Semantic ingestion retries forever on context_length_exceeded errors

5 participants