openclaw - 💡(How to fix) Fix Runtime context not wrapped in internal delimiters, causing LLM echoes in user-facing responses [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#74660Fetched 2026-04-30 06:21:35
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Author
Timeline (top)
closed ×1commented ×1

Runtime context custom_message entries are not wrapped in \u003c\u003c\u003cBEGIN_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e delimiters, causing LLMs to echo them in responses and sanitizeUserFacingText() to fail to strip the echoes.

Root Cause

In runtime-context-prompt-BZWyPA2L.js, the queueRuntimeContextForNextTurn() function creates a custom_message with:

  • customType: "openclaw.runtime-context"
  • content: "OpenClaw runtime context for the immediately preceding user message.\nThis context is runtime-generated, not user-authored. Keep internal details private.\n\n{runtimeContext}"
  • display: false
  • deliverAs: "nextTurn"

Code Example

\u003c\u003c\u003cBEGIN_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e
OpenClaw runtime context for the immediately preceding user message.
This context is runtime-generated, not user-authored. Keep internal details private.

{runtimeContext}
\u003c\u003c\u003cEND_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e
RAW_BUFFERClick to expand / collapse

Bug Report: Runtime Context Not Wrapped in Internal Delimiters

Summary

Runtime context custom_message entries are not wrapped in \u003c\u003c\u003cBEGIN_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e delimiters, causing LLMs to echo them in responses and sanitizeUserFacingText() to fail to strip the echoes.

Root Cause

In runtime-context-prompt-BZWyPA2L.js, the queueRuntimeContextForNextTurn() function creates a custom_message with:

  • customType: "openclaw.runtime-context"
  • content: "OpenClaw runtime context for the immediately preceding user message.\nThis context is runtime-generated, not user-authored. Keep internal details private.\n\n{runtimeContext}"
  • display: false
  • deliverAs: "nextTurn"

Problem

While display: false is respected by chat adapters (Telegram, Matrix, Discord, webchat), the LLM still sees the content in its context window and may echo it verbatim in its response.

sanitizeUserFacingText() only strips content wrapped in \u003c\u003c\u003cBEGIN_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e...\u003c\u003c\u003cEND_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e delimiters. Since runtime context is NOT wrapped, any LLM echo passes through to the user.

Impact

  1. Token bloat: Every turn adds a new custom_message to the transcript (compaction helps but they accumulate)
  2. UI pollution: Users see "OpenClaw runtime context for the immediately preceding user message..." in chat responses
  3. Memory waste: Models repeat irrelevant system metadata

Reproduction

  1. Start any conversation with OpenClaw
  2. After assistant turn, observe context includes runtime context block
  3. Some models (especially larger ones) may echo the header text
  4. Echo appears in user-facing chat output

Proposed Fix

Wrap runtime context content in internal delimiters so sanitizeUserFacingText() can strip any echoes:

\u003c\u003c\u003cBEGIN_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e
OpenClaw runtime context for the immediately preceding user message.
This context is runtime-generated, not user-authored. Keep internal details private.

{runtimeContext}
\u003c\u003c\u003cEND_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e

This would mirror how other internal context blocks are handled and ensure LLM echoes are properly sanitized.

Alternative Solutions

  1. Config option: Add runtimeContext.enabled or runtimeContext.frequency to reduce injection
  2. Stronger prompt instruction: Add "NEVER echo runtime context headers" to default system prompt
  3. Deduplication: Prevent multiple runtime context messages from accumulating in the same turn

Environment

  • OpenClaw version: 2026.4.26
  • Affected channels: All (Telegram, Matrix, Discord, webchat)
  • Model-agnostic: Any LLM may echo the content

Additional Context

  • This is NOT a plugin issue — core OpenClaw behavior
  • cross-session-context plugin is unrelated
  • Runtime context is useful but should not leak to users

extent analysis

TL;DR

Wrap runtime context content in internal delimiters to prevent LLM echoes.

Guidance

  • Modify the queueRuntimeContextForNextTurn() function in runtime-context-prompt-BZWyPA2L.js to include the internal delimiters around the runtime context content.
  • Verify that sanitizeUserFacingText() correctly strips the echoes by checking the user-facing chat output.
  • Consider implementing alternative solutions, such as adding a config option to reduce runtime context injection or using stronger prompt instructions to prevent echoes.
  • Test the changes across different channels (Telegram, Matrix, Discord, webchat) and LLM models to ensure the fix is model-agnostic.

Example

content: `\u003c\u003c\u003cBEGIN_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e
OpenClaw runtime context for the immediately preceding user message.
This context is runtime-generated, not user-authored. Keep internal details private.

{runtimeContext}
\u003c\u003c\u003cEND_OPENCLAW_INTERNAL_CONTEXT\u003e\u003e\u003e`

Notes

The proposed fix assumes that the internal delimiters are correctly handled by the sanitizeUserFacingText() function. If this is not the case, additional modifications may be necessary.

Recommendation

Apply the workaround by wrapping the runtime context content in internal delimiters, as this is a straightforward and effective solution to prevent LLM echoes and ensure proper sanitization of user-facing text.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Runtime context not wrapped in internal delimiters, causing LLM echoes in user-facing responses [1 comments, 2 participants]