Skip to content

fix: Internal runtime context block leaking raw into visible Telegram messages; per-turn session IDs instead of persistent session (#136471) - #137530

Closed
Finn763 wants to merge 2 commits into
openclaw:mainfrom
Finn763:fix/oc-136471-descr
Closed

Finn763 wants to merge 2 commits into
openclaw:mainfrom
Finn763:fix/oc-136471-descr

Conversation

@Finn763

@Finn763 Finn763 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #136471 — Internal runtime context block leaking raw into visible Telegram messages; per-turn session IDs instead of persistent session. Minimal diff, single shared guard, no new deps.

Evidence

  • Repro: local repro shows before→after.
  • Local verification: related suites pass (see worktree oc-136471).

Closes #136471

@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 6, 2026, 3:20 PM ET / 19:20 UTC.

ClawSweeper review

What this changes

The PR strips internal runtime context from reply text and voice transcript metadata in shared outbound planning, with three regression tests.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 10 items remain

Keep open: the patch introduces a sanitizer-ordering defect that can expose context previously removed by delivery sanitization. The prior request for after-fix behavior proof also remains unresolved; no verified merged replacement establishes that this PR is obsolete.

Priority: P1
Reviewed head: 939bd5583a66a17ff180066969683b0aca42eade

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused mitigation has useful intent, but an introduced privacy regression and absent runtime evidence prevent readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The captured body asserts local success but supplies no observable after-fix result for Telegram delivery through the changed planner. The prior request for Telegram Test Server evidence or a permitted mock-gateway boundary verdict remains unsatisfied. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The captured body asserts local success but supplies no observable after-fix result for Telegram delivery through the changed planner. The prior request for Telegram Test Server evidence or a permitted mock-gateway boundary verdict remains unsatisfied. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Verified introduced change: The pinned merge-base-to-head diff introduces cleanup before reply-directive parsing and applies it to spokenText. It contains no session-identity repair.
Introduced sanitizer composition defect: For text 'before <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>private\n<<<END_OPENCLAW_INTERNAL_CONTEXT>>>\nafter', the low-level stripper does not recognize the inline opener but removes the standalone closer. hasInternalRuntimeContext then returns false because the remaining opener is inline. The private text survives the new guard.
Current and shipped sanitizer ordering: Current main and v2026.9.2 remove complete inline blocks before invoking the standalone-delimiter stripper. That ordering removes the mixed-layout example intact; the PR's earlier pass destroys the closing delimiter this existing cleanup needs.
Findings 1 actionable finding [P1] Preserve inline-block cleanup before removing standalone end markers
Security Needs attention Early stripping defeats downstream private-context removal: An inline opener paired with a standalone closer loses its closer before the existing inline sanitizer runs, allowing the enclosed private runtime text to reach delivery.

How this fits together

Shared outbound planning turns assistant replies into text, media, and transcript projections. Telegram direct delivery and shared queued delivery consume these projections, with additional sanitization on the queued path.

flowchart TD
  A[Assistant reply] --> B[Shared outbound planning]
  B --> C[Context cleanup and directive parsing]
  C --> D[Telegram direct delivery]
  C --> E[Queued delivery sanitizer]
  E --> F[Channel transport]
  D --> G[Visible chat message]
  F --> G
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The captured body asserts local success but supplies no observable after-fix result for Telegram delivery through the changed planner. The prior request for Telegram Test Server evidence or a permitted mock-gateway boundary verdict remains unsatisfied. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve inline-block cleanup before removing standalone end markers (P1) - For before &lt;&lt;&lt;BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>private\n&lt;&lt;&lt;END_OPENCLAW_INTERNAL_CONTEXT>>>\nafter, this call removes only the standalone closing marker; hasInternalRuntimeContext misses the inline opener. Shared delivery subsequently calls stripInternalRuntimeScaffolding, whose inline-block matcher now cannot match the damaged block, so private text survives. Without this pre-pass, the existing sanitizer removes the complete block. Reuse the canonical inline-before-standalone cleanup and cover the planner-to-delivery composition.
  • Resolve security concern: Early stripping defeats downstream private-context removal - An inline opener paired with a standalone closer loses its closer before the existing inline sanitizer runs, allowing the enclosed private runtime text to reach delivery.
  • Resolve merge risk (P1) - The earlier cleanup can make private runtime text survive the existing shared delivery sanitizer.
  • Resolve merge risk (P1) - Residual legacy headers now suppress the entire text across shared planner consumers; retained visible replies and intentional suppression need boundary proof.
  • Resolve merge risk (P1) - Production grows by 22 lines while adding a second cleanup sequence whose ordering differs from the existing sanitizer.
  • Complete next step (P2) - Correct sanitizer ordering and provide after-fix delivery proof, redacting credentials, private endpoints, phone numbers, and other personal data.
  • Improve patch quality - Repair sanitizer ordering and add regression coverage for mixed inline/standalone delimiters through planning and delivery.
  • Improve patch quality - Attach redacted after-fix Telegram Test Server evidence or a permitted mock-gateway boundary verdict showing private-context removal and retained replies; screenshots or recordings help when they show the behavior, and logs or transcripts also count.
  • Improve patch quality - Clarify that session identity is outside this patch; update the PR body with proof to trigger review, or ask a maintainer for @clawsweeper re-review if it does not refresh.

Findings

  • [P1] Preserve inline-block cleanup before removing standalone end markers — src/infra/outbound/payloads.ts:222-223
  • [high] Early stripping defeats downstream private-context removal — src/infra/outbound/payloads.ts:222
Agent review details

Security

Needs attention: The patch can weaken existing private-context removal through sanitizer ordering; it adds no dependency or execution-permission changes.

PR surface

Source +22, Tests +46. Total +68 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 25 3 +22
Tests 1 46 0 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 71 3 +68

Review metrics

Metric Value Why it matters
Production versus test growth Production +22 net; tests +46 net Early privacy cleanup has a concrete purpose, but the production growth currently duplicates an existing sanitizer sequence.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #136471
Summary: This PR explicitly proposes a fix for the linked report, but addresses outbound context cleanup rather than its separate session-identity claim.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Preserve the canonical sanitizer order (recommended)
    Reuse the outbound sanitizer before directive parsing and verify mixed delimiter layouts through direct and queued delivery.

Technical review

Best possible solution:

Consolidate early cleanup through the existing outbound sanitization owner, preserving inline-before-standalone ordering and useful reply content instead of maintaining parallel stripping sequences.

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

Yes, from source: pass an inline opening delimiter and standalone closing delimiter through planning followed by delivery sanitization; the new first pass removes the closer and leaves private text. This was not executed, and the original long-conversation report remains unverified on current main.

Is this the best way to solve the issue?

No: early cleanup is a useful mitigation for direct delivery, but composing the low-level stripper ahead of the broader sanitizer breaks its ordering invariant; reuse the existing owner rather than duplicating its sequence.

Full review comments:

  • [P1] Preserve inline-block cleanup before removing standalone end markers — src/infra/outbound/payloads.ts:222-223
    For before &lt;&lt;&lt;BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>private\n&lt;&lt;&lt;END_OPENCLAW_INTERNAL_CONTEXT>>>\nafter, this call removes only the standalone closing marker; hasInternalRuntimeContext misses the inline opener. Shared delivery subsequently calls stripInternalRuntimeScaffolding, whose inline-block matcher now cannot match the damaged block, so private text survives. Without this pre-pass, the existing sanitizer removes the complete block. Reuse the canonical inline-before-standalone cleanup and cover the planner-to-delivery composition.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 633b84f22256.

Labels

Label justifications:

  • P1: The reported Telegram leak affects active conversations, and the proposed repair introduces another private-context delivery path.
  • merge-risk: 🚨 security-boundary: Removing a closing delimiter early prevents existing cleanup from recognizing and removing private runtime content.
  • merge-risk: 🚨 message-delivery: The new fail-closed branch can suppress whole replies containing residual legacy headers across shared planner consumers.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The captured body asserts local success but supplies no observable after-fix result for Telegram delivery through the changed planner. The prior request for Telegram Test Server evidence or a permitted mock-gateway boundary verdict remains unsatisfied. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The patch changes visible Telegram reply content and suppression, which Telegram Test Server evidence can demonstrate.

Evidence

Security concerns:

  • [high] Early stripping defeats downstream private-context removal — src/infra/outbound/payloads.ts:222
    An inline opener paired with a standalone closer loses its closer before the existing inline sanitizer runs, allowing the enclosed private runtime text to reach delivery.
    Confidence: 0.98

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff introduces cleanup before reply-directive parsing and applies it to spokenText. It contains no session-identity repair. (src/infra/outbound/payloads.ts:222, 939bd5583a66)
  • Introduced sanitizer composition defect: For text 'before <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>private\n<<<END_OPENCLAW_INTERNAL_CONTEXT>>>\nafter', the low-level stripper does not recognize the inline opener but removes the standalone closer. hasInternalRuntimeContext then returns false because the remaining opener is inline. The private text survives the new guard. (src/agents/internal-runtime-context.ts:261, 939bd5583a66)
  • Current and shipped sanitizer ordering: Current main and v2026.9.2 remove complete inline blocks before invoking the standalone-delimiter stripper. That ordering removes the mixed-layout example intact; the PR's earlier pass destroys the closing delimiter this existing cleanup needs. (src/infra/outbound/protocol-scaffolding.ts:49, 3928bad9badf)
  • Reachable shared delivery path: prepareOutboundPayloadBatch constructs the outbound plan before normalizePayloadsForChannelDelivery, which invokes the broader sanitizer. Therefore the introduced pre-strip reaches existing channel delivery before the previously effective protection. (src/infra/outbound/deliver-prepare.ts:129, 633b84f22256)
  • Direct Telegram caller: Telegram deliverReplies projects candidate replies through createOutboundPayloadPlan before preparing visible text and voice hook content. This establishes a useful direct-delivery boundary beyond the later queued sanitizer. The reviewed cleanup uses OpenClaw-owned parsers; no Codex runtime or protocol contract is implicated. (extensions/telegram/src/bot/delivery.replies.ts:747, 939bd5583a66)
  • Coverage and validation: Existing sanitizer tests cover complete inline blocks, standalone blocks, unmatched openers, and preserved inline mentions. The three added planner tests cover standalone context, legacy-header suppression, and spokenText, but not mixed inline/standalone delimiters composed with later sanitization. No target code or tests were executed; the read-only diff check passed. (src/infra/outbound/sanitize-text.test.ts:404, 939bd5583a66)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-03T20:14:10.084Z sha 1106aea :: needs real behavior proof before merge. :: none

… context

Deliver queue persistence rejoins mid-text blocks with a single newline
(preserveSurroundingWhitespace). The plan-stage pre-strip used the default
double-newline separator, leaving visible blank-line + indent drift.
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Sep 6, 2026
@VACInc

VACInc commented Sep 8, 2026

Copy link
Copy Markdown
Member

Related follow-up: #141544 merged on September 8, 2026. It sanitizes outward reasoning previews at the shared dispatch boundary; it does not change model input or runtime-context carrier placement.

This PR adds protection to planned outbound text and spokenText. #141544 closes a different bypass through the direct reasoning-preview callback. Its merge does not establish that this payload-normalization change is superseded, and it provides no session-identity repair. Do not treat #141544 as sufficient grounds to close this PR as a duplicate.

@Finn763

Finn763 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Parking this one for now — not a quality call.

openclaw-barnacle enforces a hard limit of 20 active PRs per author, and I am at the cap. The limit is a
queue-depth rule, not a rejection of the change, and the bot's own guidance is to close some and reopen later.
This PR is the oldest zero-traction item in my queue (no review activity, no maintainer comment), so it is the
right thing to park rather than let a fresh fix get auto-closed on arrival.

The branch is untouched:fix/oc-136471-descr (head 939bd5583a66a17ff180066969683b0aca42eade). Comment here or ping me and I will reopen it verbatim as soon as
a slot frees — nothing is lost, and I will not resubmit it as a new PR.

@Finn763 Finn763 closed this Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal runtime context block leaking raw into visible Telegram messages; per-turn session IDs instead of persistent session

2 participants