fix: filter delivery-mirror from all consumer paths (LLM context, webchat, API)#223
Open
BingqingLyu wants to merge 2 commits into
Open
fix: filter delivery-mirror from all consumer paths (LLM context, webchat, API)#223BingqingLyu wants to merge 2 commits into
BingqingLyu wants to merge 2 commits into
Conversation
…PI responses delivery-mirror entries (provider=openclaw, model=delivery-mirror) are internal cross-channel delivery audit records written by appendAssistantMessageToSessionTranscript(). They use appendMessage() which creates type:"message" entries indistinguishable from real LLM responses, causing them to leak into buildSessionContext() and API responses. This causes duplicate assistant messages in the LLM context window (escalating from 2x to 6-8x over a session), duplicate renders in webchat UI, and raw audit entries in API responses. Fix: filter delivery-mirror messages at the three consumer points: - transformContext pipeline (LLM context) - chat.history handler (webchat UI) - sessions.get handler (API) Add isDeliveryMirrorMessage() predicate co-located with the write path in transcript.ts. Add regression tests for all filter paths. The write path (appendMessage) is intentionally unchanged - delivery-mirror entries remain in the JSONL as an audit trail. appendCustomEntry() was considered but _persist() in SessionManager defers writes until an assistant message exists, making it unreliable for standalone audit entries. Fixes openclaw#33263, openclaw#38061, openclaw#39469 Related: openclaw#30316, openclaw#39795
- Move delivery-mirror filter before slice/byte-budget in chat.history so internal entries do not consume bounded window slots - Drop unnecessary .toLowerCase() on role check for consistent strict equality across all three predicate fields - Add symmetric test case for model match with provider mismatch
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.
Problem
Internal
delivery-mirroraudit entries (provider=openclaw,model=delivery-mirror) leak into all three consumer paths, causing escalating duplicate assistant messages that degrade over the life of a session:thinkingblocks with errors visible to end users (BUG: Control UI (webchat) double-records assistant messages in session JSONL openclaw/openclaw#39469)Fixes openclaw#33263, openclaw#38061, openclaw#39469.
Related: openclaw#30316, openclaw#39795.
Changes
tool-result-context-guard.tstransformContextpipelinechat.tssessions.tssessions.gethandlertranscript.tsisDeliveryMirrorMessage()usinginnarrowing (zero type assertions)The write path is intentionally unchanged — delivery-mirror entries remain in session JSONL as an audit trail.
appendCustomEntry()was investigated butSessionManager._persist()defers writes until atype:"message"+role:"assistant"entry exists, making it unreliable for standalone entries. Existing session files already contain old-format entries, so consumer-side filters are needed regardless.Tests
7 new tests across 2 files covering the predicate (positive match, role/provider/model mismatches, non-object input) and the
transformContextintegration (strips delivery-mirror; preserves array identity when none present).Unrelated
Commit
f5c618ebfixes a pre-existing oxfmt formatting issue insrc/cli/daemon-cli/lifecycle.test.ts.