Skip to content

Strip OpenClaw channel metadata from chat turn user text#388

Open
Jurij89 wants to merge 3 commits intomainfrom
codex/openclaw-strip-channel-metadata
Open

Strip OpenClaw channel metadata from chat turn user text#388
Jurij89 wants to merge 3 commits intomainfrom
codex/openclaw-strip-channel-metadata

Conversation

@Jurij89
Copy link
Copy Markdown
Contributor

@Jurij89 Jurij89 commented May 4, 2026

Summary

Related

Files changed

File What
packages/adapter-openclaw/src/ChatTurnWriter.ts Adds Telegram-gated stripChannelMetadata and applies it before W4a user pairing and W4b inbound queueing so persisted user text and content-derived identity use stripped text for Telegram runtime wrappers.
packages/adapter-openclaw/test/ChatTurnWriter.test.ts Adds T380 regressions for Telegram metadata stripping, preservation of real user text, W4b paths, stripped-text turnId hashing, and top-pasted metadata-shaped content safety.

Metadata stripping behavior

  • Runs only when trusted OpenClaw channel context identifies the source as Telegram.
  • Removes contiguous leading fenced JSON metadata blocks labelled Conversation info and optional Sender when they use the (untrusted metadata) heading form.
  • Removes separator blank lines after stripped blocks, while preserving indentation on the first real user line.
  • Preserves pure user text, multi-line text, metadata-shaped content in the middle, leading metadata-shaped content outside Telegram, repeated metadata labels after the Telegram wrapper, and broader labels such as Channel context after the wrapper.
  • Does not strip Channel context or Message context without a concrete trusted wrapper source; those labels remain extensibility points rather than active stripping rules.
  • Does not change the OpenClaw Telegram channel plugin or the raw runtime context seen by the agent before persistence.

Watermark/hash decision and migration note

  • Stripping happens before W4a pending-user storage and before W4b inbound queueing for Telegram, so deterministicTurnId, contentHash, cross-path stamps, and typed W4b markers use the stripped persisted user text going forward.
  • Numeric W4a watermarks and W4b counts are unchanged because they are pair-index/count based, not text-hash based.
  • Existing persisted turns are not rewritten. If reset/compaction or state loss leaves only pre-fix metadata-hashed durable markers, those legacy markers may not suppress a stripped replay; PR Fix Telegram chat turn persistence #362's cold-start clamp still bounds W4a state-loss replay to the latest pair.
  • Known ambiguity: without changing the Telegram plugin to add an out-of-band sentinel, a Conversation-only runtime wrapper followed immediately by user text that starts with a first Sender metadata-shaped block is indistinguishable from the current Conversation info + Sender runtime wrapper shape. The implementation chooses the issue's required wrapper stripping while bounding repeated/broader-label loss cases in tests.

Privacy notes

Known risks or follow-ups

Test plan

  • pnpm install - completed; emitted non-blocking dkg-mcp bin warnings for an unbuilt MCP package and pnpm ignored-build-script notices.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts -t T380 - passed, 16 tests.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts - passed, 187 tests.
  • pnpm --filter @origintrail-official/dkg-core run build - passed.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw run build - passed.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts test/ChatTurnWriter.crashRecovery.test.ts test/ChatTurnWriter.sanitize.test.ts - passed, 198 tests.
  • git diff --check - passed with Windows LF-to-CRLF checkout warnings only.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw test - ran 984 tests: 981 passed, 1 skipped, 2 failed in unrelated baseline tests: test/adapter-openclaw-extra.test.ts > plugin id equals package name expects @origintrail-official/dkg-adapter-openclaw but receives adapter-openclaw; test/setup.test.ts > writeDkgConfig > mirrors only autoUpdate.enabled from network default and preserves existing pins expects autoUpdate.repo to remain present.

Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
@Jurij89 Jurij89 force-pushed the codex/openclaw-strip-channel-metadata branch from e735088 to 070825e Compare May 5, 2026 11:12

private stripChannelMetadata(text: string): string {
if (!text) return "";
const metadataBlock =
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: This heuristic strips any Telegram message that starts with one of these fenced blocks, even if the user authored it intentionally. A user debugging Telegram metadata and pasting a single Conversation info ... block as the first part of their message will have that content silently removed from persistence. Please gate stripping on a trusted adapter signal (or validate the parsed block against envelope metadata) instead of matching only on user-writable text.

@Jurij89 Jurij89 force-pushed the codex/openclaw-strip-channel-metadata branch from 070825e to 871cb89 Compare May 5, 2026 17:45
@Jurij89 Jurij89 force-pushed the codex/openclaw-strip-channel-metadata branch from 871cb89 to 6815ae9 Compare May 6, 2026 11:22
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.

Telegram chat turns persist OpenClaw channel metadata blocks alongside user text, polluting chat-turn memory and recall

1 participant