fix: skip ingesting empty error/aborted assistant messages#172
Merged
jalehman merged 3 commits intoApr 9, 2026
Merged
Conversation
When an API call returns a 500 or similar transient error, OpenClaw appends an assistant message with stopReason "error" and empty content to the session. LCM ingests these into the database, and on retry the accumulated empty messages are assembled into context — creating a positive feedback loop where each retry sends a larger, malformed payload that continues to fail. This commit adds two defenses: 1. engine.ts (ingestSingle): Skip assistant messages where stopReason is "error" or "aborted" AND content is empty ([], "", null). Messages with actual partial content before the error are still preserved. 2. assembler.ts (resolveMessageItem): Defense-in-depth — skip empty assistant messages during context assembly when both the stored content text and message_parts are empty. This catches any previously-ingested empty messages without affecting legitimate assistant messages that have tool calls (which have empty text content but non-empty parts). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Accept both stopReason and stop_reason when filtering empty assistant error/aborted turns during ingest. Extend the engine regression test to cover the snake_case field so the guard matches the finish-reason normalization already used elsewhere in the codebase. Regeneration-Prompt: |\n Review PR Martian-Engineering#172 after rebasing against origin/main and verify whether its empty-assistant ingest guard still misses any finish-reason spellings used elsewhere in this repository. Keep the fix narrow: preserve the PR's behavior, but make the ingest guard recognize both camelCase stopReason and snake_case stop_reason for assistant messages with empty content and error or aborted stop reasons. Add regression coverage in test/engine.test.ts for the snake_case variant and rerun the focused engine test file before pushing the result back to the contributor branch.
Contributor
|
Thank you! |
Merged
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.
Summary
ingestSinglenow skips assistant messages wherestopReasonis"error"or"aborted"and content is empty ([],"",null). Messages with partial content before the error are still preserved.resolveMessageItemskips empty assistant messages during context assembly when both the stored content text andmessage_partsare empty — catching any previously-ingested empty messages without affecting tool-call-only assistant turns.Problem
When a cloud LLM provider returns a transient 500 error, OpenClaw appends an assistant message with
stopReason: "error"and empty content to the session JSONL. LCM ingests these into the database. On retry, the accumulated empty messages are assembled into context, creating a positive feedback loop:In production, this manifested as a permanently broken agent where the LCM database had accumulated 175 messages (dozens empty/duplicated) in a 31KB system prompt with 32 tools — the cloud model API rejected every request with a 500. The only recovery was manual database surgery.
Test plan
skips ingest for assistant messages with stopReason error and empty content— covers empty array, empty string, aborted, normal messages, and error-with-content (all should behave correctly)🤖 Generated with Claude Code