Skip to content

#92589: fix(internal-runtime-context): wrap prompt-preface runtime context body in delimiters - #92593

Merged
BunsDev merged 4 commits into
openclaw:mainfrom
zhangqueping:fix/issue-92589-feishu-channel-leaks-system-runtime-cont
Jun 13, 2026
Merged

BunsDev merged 4 commits into
openclaw:mainfrom
zhangqueping:fix/issue-92589-feishu-channel-leaks-system-runtime-cont

Conversation

@zhangqueping

@zhangqueping zhangqueping commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Wrap the runtime context body in buildRuntimeContextMessageContent with INTERNAL_RUNTIME_CONTEXT_BEGIN / END delimiters so stripInternalRuntimeContext can fully remove leaked runtime context from user-visible surfaces.

Root Cause

buildRuntimeContextMessageContent (in runtime-context-prompt.ts) constructs hidden runtime context prompt blocks using the "prompt preface" format. When the model echoes this context back in its reply, stripInternalRuntimeContext strips the header and notice lines via stripRuntimeContextPromptPreface, but the body (containing sensitive data like <relevant-memories>, Sender (untrusted metadata), Conversation info) was not wrapped in delimiters that stripDelimitedBlock handles. The body leaked through into Feishu streaming cards.

Fix: Wrap the runtime context body in <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>> / <<<END_OPENCLAW_INTERNAL_CONTEXT>>> delimiters (3 lines added). stripInternalRuntimeContext already processes delimited blocks first, so the entire context block is removed.

Real behavior proof

Behavior or issue addressed: When a runtime context block (containing <relevant-memories>, Sender (untrusted metadata), Conversation info, system timestamps) is echoed in a reply, stripInternalRuntimeContext now completely removes the entire block instead of leaving the context body visible.

Real environment tested: Linux x64, kernel 4.19.112-2.el8, Node.js v24.13.1, tsx v4.22.3, openclaw at a0f8095 on top of origin/main (6cf06e8).

Exact steps or command run after this patch:

  1. Checkout fix/issue-92589-* branch in openclaw workspace
  2. Build runtime context with sensitive metadata via production buildRuntimeContextSystemContext
  3. Run: npx tsx scripts/repro-92589.mjs
  4. Verify stripInternalRuntimeContext removes all sensitive data from a simulated leaked reply

Evidence after fix:

========================================================================
Real behavior proof — #92589
========================================================================

Built runtime context (delimiters now wrap the body):
---
OpenClaw runtime context for the immediately preceding user message.
This context is runtime-generated, not user-authored. Keep internal details private.

<<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>
Sender (untrusted metadata):
{"open_id": "ou_abc123", "name": "Alice"}
Conversation info (untrusted metadata):
{"chat_id": "oc_xyz789", "message_id": "om_456"}
<relevant-memories>
Memory: Bob uses Python for backend work.
</relevant-memories>
<<<END_OPENCLAW_INTERNAL_CONTEXT>>>
---

Contains BEGIN delimiter: ✅ YES
Contains END delimiter:   ✅ YES

After stripInternalRuntimeContext (simulated leaked reply):
---
Here is my analysis of the data:

Would you like me to proceed further?
---

All sensitive data stripped: ✅ YES
Actual reply text preserved: ✅ YES
========================================================================

Observed result after fix: All sensitive runtime context data (<relevant-memories>, Sender (untrusted metadata), Conversation info, user open_id, context header) is completely removed. The actual user-visible reply text is preserved intact. Fix adds 3 lines: INTERNAL_RUNTIME_CONTEXT_BEGIN, the existing body, INTERNAL_RUNTIME_CONTEXT_END.

What was not tested: Live Feishu gateway with streaming cards (requires API keys and real channel setup). Verified via production-import tsx execution and existing test suite.

Regression Test Plan

  • runtime-context-prompt.test.ts — 21/21
  • replay-history.test.ts — passed
  • sanitizeuserfacingtext.test.ts — 142/142
  • internal-runtime-context.test.ts — 5/5
  • No changes to stripping logic

AI-assisted: built with Claude Code

…dy in delimiters

When buildRuntimeContextMessageContent constructs the hidden
runtime context prompt block, the body (which may contain
sensitive metadata like relevant-memories, sender info, and
conversation metadata) was not wrapped in the standard
INTERNAL_RUNTIME_CONTEXT_BEGIN/END delimiters.  If the model
echoed this context back in its reply, stripInternalRuntimeContext
could only remove the header and notice lines — the sensitive
body leaked through to user-visible surfaces like Feishu
streaming cards.

Wrap the runtime context body in BEGIN/END delimiters so the
existing stripInternalRuntimeContext (which handles delimited
blocks first) can fully remove the entire block.

Closes openclaw#92589
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 13, 2026
@clawsweeper

clawsweeper Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 13, 2026, 12:30 AM ET / 04:30 UTC.

Summary
The PR wraps generated embedded-agent runtime context prompt bodies in existing internal-context delimiters and updates prompt tests.

PR surface: Source +7, Tests +6. Total +13 across 2 files.

Reproducibility: yes. source-reproducible. Current main and v2026.6.6 build prompt-preface runtime context with an unwrapped body, while stripInternalRuntimeContext removes delimiter blocks and only the header/notice preface.

Review metrics: 1 noteworthy metric.

  • Prompt context fences: 1 prompt builder changed. This changes the hidden runtime-context prompt shape for both next-turn and runtime-event contexts.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Add a redacted live Feishu streaming-card smoke only if maintainers want channel-level proof before merge.

Risk before merge

  • [P1] Live Feishu streaming cards were not exercised; the proof covers production context construction and stripping, not Feishu API rendering.

Maintainer options:

  1. Decide the mitigation before merge
    Land the narrow core prompt-boundary fix with the existing tests and passing checks, then let Feishu channel leaks system runtime context (relevant-memories, sender metadata) into user-visible reply #92589 close after merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No ClawSweeper repair job is needed because the PR is already narrow, proof-supplied, and has no actionable findings.

Security
Cleared: The diff reuses existing internal delimiter constants and adds tests; it introduces no dependency, workflow, or secret-handling change and reduces a privacy leak surface.

Review details

Best possible solution:

Land the narrow core prompt-boundary fix with the existing tests and passing checks, then let #92589 close after merge.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible. Current main and v2026.6.6 build prompt-preface runtime context with an unwrapped body, while stripInternalRuntimeContext removes delimiter blocks and only the header/notice preface.

Is this the best way to solve the issue?

Yes. Wrapping at context creation is the narrowest maintainable fix because every user-visible sanitizer path already honors the internal delimiter contract, while a Feishu-only filter would leave other surfaces dependent on heuristics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4a6666796f46.

Label changes

Label changes:

  • add P1: The PR addresses a user-visible privacy leak of internal runtime context and sender metadata in channel replies.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal proof using production build/strip helpers after the patch and shows sensitive runtime context removed while visible reply text remains.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal proof using production build/strip helpers after the patch and shows sensitive runtime context removed while visible reply text remains.
  • remove rating: 🌊 off-meta tidepool: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The PR addresses a user-visible privacy leak of internal runtime context and sender metadata in channel replies.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal proof using production build/strip helpers after the patch and shows sensitive runtime context removed while visible reply text remains.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal proof using production build/strip helpers after the patch and shows sensitive runtime context removed while visible reply text remains.
Evidence reviewed

PR surface:

Source +7, Tests +6. Total +13 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 0 +7
Tests 1 6 0 +6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 13 0 +13

What I checked:

Likely related people:

  • Ayaan Zaidi: git blame on the current prompt builder and internal-runtime-context stripper points to this author for the relevant current-main lines. (role: introduced current main behavior; confidence: high; commits: 4a3d06ee3785; files: src/agents/embedded-agent-runner/run/runtime-context-prompt.ts, src/agents/internal-runtime-context.ts)
  • Alix-007: Merged work on embedded prompt hook context touched runtime-context-prompt and internal-runtime-context in the same feature area. (role: adjacent feature contributor; confidence: medium; commits: 8189c2f8419d, 9715d3a01a52; files: src/agents/embedded-agent-runner/run/runtime-context-prompt.ts, src/agents/internal-runtime-context.ts)
  • SYU8384: Merged runtime-context-before-active-user-turn work touched internal-runtime-context and sibling runtime-context prompt surfaces. (role: adjacent runtime-context contributor; confidence: medium; commits: 83d6ea979c15, 7fdef7ffdf7d, aec7d6a746b8; files: src/agents/internal-runtime-context.ts, src/agents/pi-embedded-runner/run/runtime-context-prompt.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label Jun 13, 2026
@zhangqueping

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@zhangqueping

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@zhangqueping

Copy link
Copy Markdown
Contributor Author

proof updated

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 13, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 13, 2026
@BunsDev
BunsDev merged commit 21aa8fa into openclaw:main Jun 13, 2026
199 of 205 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 14, 2026
…ntime context body in delimiters (openclaw#92593)

* fix(internal-runtime-context): wrap prompt-preface runtime context body in delimiters

When buildRuntimeContextMessageContent constructs the hidden
runtime context prompt block, the body (which may contain
sensitive metadata like relevant-memories, sender info, and
conversation metadata) was not wrapped in the standard
INTERNAL_RUNTIME_CONTEXT_BEGIN/END delimiters.  If the model
echoed this context back in its reply, stripInternalRuntimeContext
could only remove the header and notice lines — the sensitive
body leaked through to user-visible surfaces like Feishu
streaming cards.

Wrap the runtime context body in BEGIN/END delimiters so the
existing stripInternalRuntimeContext (which handles delimited
blocks first) can fully remove the entire block.

Closes openclaw#92589

* chore: retrigger CI for proof check

* chore: retrigger CI with corrected proof format

* chore: retrigger CI with corrected proof field format
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Jun 17, 2026
…ntime context body in delimiters (openclaw#92593)

* fix(internal-runtime-context): wrap prompt-preface runtime context body in delimiters

When buildRuntimeContextMessageContent constructs the hidden
runtime context prompt block, the body (which may contain
sensitive metadata like relevant-memories, sender info, and
conversation metadata) was not wrapped in the standard
INTERNAL_RUNTIME_CONTEXT_BEGIN/END delimiters.  If the model
echoed this context back in its reply, stripInternalRuntimeContext
could only remove the header and notice lines — the sensitive
body leaked through to user-visible surfaces like Feishu
streaming cards.

Wrap the runtime context body in BEGIN/END delimiters so the
existing stripInternalRuntimeContext (which handles delimited
blocks first) can fully remove the entire block.

Closes openclaw#92589

* chore: retrigger CI for proof check

* chore: retrigger CI with corrected proof format

* chore: retrigger CI with corrected proof field format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants