Repository navigation
fix(outbound): strip inbound metadata before delivery - #50520
vincentkoc merged 1 commit into
Conversation
Greptile SummaryThis PR fixes issue #39847 by calling
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/infra/outbound/payloads.ts
Line: 62-63
Comment:
**`stripInboundMetadata` always strips timestamp prefix, not just when sentinels are present**
`stripInboundMetadata` unconditionally applies `LEADING_TIMESTAMP_PREFIX_RE` before checking for sentinels and returns `withoutTimestamp` even on the fast path (when no sentinel is found):
```ts
const withoutTimestamp = text.replace(LEADING_TIMESTAMP_PREFIX_RE, "");
if (!SENTINEL_FAST_RE.test(withoutTimestamp)) {
return withoutTimestamp; // timestamp already stripped
}
```
Before this PR, `parseReplyDirectives` received the raw `payload.text`. After it, any LLM response whose first characters happen to match `[Mon 2024-03-15 08:30] ` will have that prefix silently removed from delivery. Since the pattern is quite specific to OpenClaw's injected format this is very unlikely to affect real LLM output, but it is a subtle behavioural change beyond the stated goal of stripping inbound metadata blocks. Worth being aware of, and potentially worth a dedicated `cleanText` test for the timestamp-only path.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "fix(outbound): strip..." |
| const cleanText = stripInboundMetadata(payload.text ?? ""); | ||
| const parsed = parseReplyDirectives(cleanText); |
There was a problem hiding this comment.
stripInboundMetadata always strips timestamp prefix, not just when sentinels are present
stripInboundMetadata unconditionally applies LEADING_TIMESTAMP_PREFIX_RE before checking for sentinels and returns withoutTimestamp even on the fast path (when no sentinel is found):
const withoutTimestamp = text.replace(LEADING_TIMESTAMP_PREFIX_RE, "");
if (!SENTINEL_FAST_RE.test(withoutTimestamp)) {
return withoutTimestamp; // timestamp already stripped
}Before this PR, parseReplyDirectives received the raw payload.text. After it, any LLM response whose first characters happen to match [Mon 2024-03-15 08:30] will have that prefix silently removed from delivery. Since the pattern is quite specific to OpenClaw's injected format this is very unlikely to affect real LLM output, but it is a subtle behavioural change beyond the stated goal of stripping inbound metadata blocks. Worth being aware of, and potentially worth a dedicated cleanText test for the timestamp-only path.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/outbound/payloads.ts
Line: 62-63
Comment:
**`stripInboundMetadata` always strips timestamp prefix, not just when sentinels are present**
`stripInboundMetadata` unconditionally applies `LEADING_TIMESTAMP_PREFIX_RE` before checking for sentinels and returns `withoutTimestamp` even on the fast path (when no sentinel is found):
```ts
const withoutTimestamp = text.replace(LEADING_TIMESTAMP_PREFIX_RE, "");
if (!SENTINEL_FAST_RE.test(withoutTimestamp)) {
return withoutTimestamp; // timestamp already stripped
}
```
Before this PR, `parseReplyDirectives` received the raw `payload.text`. After it, any LLM response whose first characters happen to match `[Mon 2024-03-15 08:30] ` will have that prefix silently removed from delivery. Since the pattern is quite specific to OpenClaw's injected format this is very unlikely to affect real LLM output, but it is a subtle behavioural change beyond the stated goal of stripping inbound metadata blocks. Worth being aware of, and potentially worth a dedicated `cleanText` test for the timestamp-only path.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Good catch on the timestamp prefix behavior. A few points:
-
The
[Day YYYY-MM-DD HH:MM]timestamp prefix is injected by OpenClaw's owninjectTimestamp(ininbound-meta.ts) — it's not user-authored content. An LLM response beginning with that exact format would be extremely unlikely. -
stripInboundMetadataalready runs on TUI display and session cost paths with the same unconditional timestamp strip, so this PR is consistent with existing usage. -
The regex is narrow (
/^\[Day YYYY-MM-DD HH:MM...\] */) — it only matches the specific OpenClaw envelope format at the start of the string, not arbitrary bracketed text.
That said, if maintainers prefer a more surgical approach (e.g., only strip the timestamp when a sentinel is also present), I'm happy to adjust.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad14976ebe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| continue; | ||
| } | ||
| const parsed = parseReplyDirectives(payload.text ?? ""); | ||
| const cleanText = stripInboundMetadata(payload.text ?? ""); |
There was a problem hiding this comment.
Restrict metadata stripping to avoid deleting real timestamp text
Applying stripInboundMetadata to every outbound payload now removes leading bracketed timestamps even when no injected metadata block is present, so assistant replies that intentionally begin with log/timestamp text (for example, [Thu 2026-03-12 07:00 UTC] ...) are silently altered before delivery. This regression comes from sanitizing all outgoing text with a helper that also strips timestamp prefixes; using a leading-block-only sanitizer or gating on actual metadata sentinels would avoid dropping legitimate content.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same concern as above — addressed in my reply to the Greptile comment. The timestamp regex is OpenClaw's own envelope format injected by injectTimestamp, and this function is already used on TUI/session-cost paths with the same behavior. Happy to adjust if maintainers want a tighter guard.
|
Thanks for the review feedback from both @greptile-apps and @chatgpt-codex-connector. Re: Valid concern. The current implementation applies the timestamp regex before checking for sentinels, which means a reply that legitimately starts with The fix is straightforward — only apply the timestamp strip when a metadata sentinel is actually detected: // Before (current)
const withoutTimestamp = text.replace(LEADING_TIMESTAMP_PREFIX_RE, "");
if (!SENTINEL_FAST_RE.test(withoutTimestamp)) return withoutTimestamp;
// After (proposed)
if (!SENTINEL_FAST_RE.test(text)) return text;
const withoutTimestamp = text.replace(LEADING_TIMESTAMP_PREFIX_RE, "");This way, the timestamp prefix is only stripped as part of the metadata cleanup path, not on clean text. Will push a fix commit. |
|
To use Codex here, create an environment for this repo. |
|
Perfect solution! Moving the sentinel check before the timestamp strip is exactly right — it ensures legitimate timestamps are preserved when no metadata is present, and the timestamp removal only happens as part of the actual metadata cleanup path. The early return when no sentinel is detected also makes the fast path cleaner. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27b4344d32
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| continue; | ||
| } | ||
| const parsed = parseReplyDirectives(payload.text ?? ""); | ||
| const cleanText = stripInboundMetadata(payload.text ?? ""); |
There was a problem hiding this comment.
Limit outbound metadata stripping to leading echoed blocks
normalizeReplyPayloadsForDelivery now applies stripInboundMetadata to every assistant payload, but that helper removes any matching metadata block anywhere in the text, not just echoed prefixes. This causes legitimate responses to be altered when the model is asked to show those sentinel headers/JSON blocks verbatim (for example in docs or debugging output), because the block is silently deleted before delivery. In this path, using a leading-only sanitizer (the existing stripLeadingInboundMetadata) would still fix echoed prompt prefixes without corrupting intentional mid-message content.
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 7:30 AM ET / 11:30 UTC. ClawSweeper reviewWhat this changesThe PR removes only leading OpenClaw-generated inbound metadata from assistant reply text before reply directives are parsed, and adds regression tests for directive preservation and intentional later metadata examples. Merge readinessThis remains a focused candidate fix for the linked outbound metadata-leak problem. The branch now uses the leading-only sanitizer, preserving intentional metadata examples after visible text and avoiding the earlier timestamp/broad-removal concerns; the PR also contains exact-head mock-gateway proof. It should stay open for a maintainer to refresh the three-way merge and required lint gate before landing. Priority: P1 Review scores
Verification
How this fits togetherThe outbound payload planner converts an agent’s reply into text, reply targets, media, and other channel-ready instructions. Sanitizing at this shared boundary protects Telegram, Discord, and other channel deliveries before their adapters render the reply. flowchart LR
A[Model reply payload] --> B[Outbound delivery planner]
B --> C[Leading inbound metadata sanitizer]
C --> D[Reply and media directive parser]
D --> E[Channel-ready payload]
E --> F[Telegram Discord and other channels]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1, Tests +38. Total +39 across 2 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the narrow leading-only sanitizer after rebasing or otherwise validating the actual merge result, with the focused outbound tests and required lint job green on that exact head. Do we have a high-confidence way to reproduce the issue? Yes for the proposed path: the PR supplies an exact-head ephemeral-Gateway qa-channel run with echoed leading metadata and confirms that only the visible reply was delivered. This review did not independently execute that scenario. Is this the best way to solve the issue? Yes: using the existing leading-only sanitizer at the shared outbound planning boundary is narrower than per-channel filtering and directly preserves directive parsing and later intentional examples. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 95df2dfd6a61. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
27b4344 to
2bb1de9
Compare
|
Refreshed in Review response:
Local verification passed:
Pushed with |
2bb1de9 to
d2a6a68
Compare
|
Rebased again onto current Additional review response:
Local verification:
|
d2a6a68 to
6af0292
Compare
|
Rebased again onto current New head: Local checks:
The only conflict in this refresh was the Unreleased changelog entry; I kept the new upstream entries and retained this PR's Outbound/security note. |
6af0292 to
86e7d99
Compare
|
Rebased onto current Review response:
Local checks passed:
CI should rerun on the refreshed branch. |
86e7d99 to
94781b4
Compare
|
Rebased once more onto the latest Only conflict in this refresh was the Unreleased changelog ordering; I kept the new upstream Local checks passed again:
CI should rerun on the latest branch. |
|
Friendly check-in — branch is conflicted again. Latest revision narrows stripping to leading-only metadata per earlier review feedback (ClawSweeper notes no concrete blocker remaining). Happy to rebase if this is still in pipeline; otherwise OK to close. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
@openclaw-mantis telegram desktop proof: verify on the current PR head that a leading echoed location metadata block is removed while the visible reply is delivered unchanged. |
|
@clawsweeper re-review Exact-head real-behavior proof is now in the PR body: mock provider + ephemeral Gateway + qa-channel passed on |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Rebased to current
The PR body contains the full proof metadata and verdict JSON. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Closes #39847
What Problem This Solves
Fixes an issue where users could receive OpenClaw-injected inbound context, such as location or plugin metadata, when a model echoed those blocks at the start of its reply.
Why This Change Was Made
The shared outbound payload planner now removes only leading marker-backed inbound metadata before parsing reply directives. It reuses the current
stripLeadingInboundMetadata()contract, so newer message-tool and chat-window protections remain untouched and marked examples after visible reply text are preserved.User Impact
Telegram, Discord, and other channel users receive the intended reply without internal inbound context leaking into the delivered message.
Evidence
5b8854e7896ebbd84b98c55c7a4138e4adbd6f50: Blacksmith Testboxtbx_01kyvz3a1hftmy3f9adem2dxc3, https://github.com/openclaw/openclaw/actions/runs/306273354520d40cfbb538dd10bcdbd42fb2e0f51cba7c0bf76and synchronized the rebased commit tree plus the temporary QA scenario. The proof ranmock-openaithrough an ephemeral Gateway andqa-channel; the delivered channel text was exactlyVisible reply delivered unchanged.with both leading marker-backed metadata blocks absent.node scripts/run-vitest.mjs src/infra/outbound/payloads.test.ts src/auto-reply/reply/strip-inbound-meta.test.ts- 94 tests passed.node scripts/run-vitest.mjs src/gateway/chat-sanitize.test.ts src/tui/tui-formatters.test.ts- 78 tests passed.git diff --checkpassed.Rebased-head gateway verdict
{ "headSha": "5b8854e7896ebbd84b98c55c7a4138e4adbd6f50", "baseSha": "0d40cfbb538dd10bcdbd42fb2e0f51cba7c0bf76", "provider": "mock-openai", "gateway": "ephemeral", "channel": "qa-channel", "scenario": "outbound-leading-inbound-metadata-strip", "input": "leading marker-backed Location and Plugin context blocks followed by a visible reply", "observedDelivery": "Visible reply delivered unchanged.", "counts": { "passed": 1, "failed": 0, "skipped": 0 }, "result": "pass", "testbox": "tbx_01kyvz3a1hftmy3f9adem2dxc3", "runUrl": "https://github.com/openclaw/openclaw/actions/runs/30627335452" }