Skip to content

fix(telegram): dedupe visible assistant prompt context#100573

Merged
clawsweeper[bot] merged 2 commits into
mainfrom
feature/issue-99117-telegram-context-dedupe
Jul 6, 2026
Merged

fix(telegram): dedupe visible assistant prompt context#100573
clawsweeper[bot] merged 2 commits into
mainfrom
feature/issue-99117-telegram-context-dedupe

Conversation

@momothemage

@momothemage momothemage commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #99117.
Alternative to #100571 with a narrower dedupe key and handler/dispatch regression coverage.
AI-assisted: yes

What Problem This Solves

Fixes an issue where Telegram DM follow-up prompts could include the same assistant reply twice when the session transcript retained inline reply directives but the Telegram message cache contained the visible delivered text. The duplicated context made the assistant see both a synthetic session: transcript row and the real Telegram cache row for the same reply.

Why This Change Was Made

The shipped change keeps the existing timestamp-aligned dedupe boundary and normalizes body text through the same inline directive stripping used for delivery. The follow-up commit also applies the same delivery-visible comparison when copying the transcript timestamp into outbound Telegram prompt-context cache entries, so replies like [[reply_to_current]]Final answer still get the transcript timestamp even though Telegram receives only Final answer.

That lets the Telegram cache row win over the transcript-only row for the same delivered reply without merging repeated assistant messages that happen to have the same visible text at different times.

User Impact

Telegram DM follow-up prompts no longer repeat assistant replies just because transcript text still contains tags such as [[reply_to_current]]. Prompt context stays closer to what the user actually saw in Telegram, while preserving distinct replies sent at different timestamps.

Evidence

head=5c4cc7245ef0ea1bee514d41b48bc1aa0f44bf6a
session.body=[[reply_to_current]]Yep - I'm here now.
cache.body=Yep - I'm here now.
session.key=1778474700000:Yep - I'm here now.
cache.key=1778474700000:Yep - I'm here now.
session.rows.retained.after.cache.dedupe=0
final.prompt.messages=[{"role":"assistant","body":"Yep - I'm here now.","timestamp_ms":1778474700000,"source":"telegram-message-cache"}]
visible.assistant.context.rows=1
PASS hidden prompt-context dedupe: one visible assistant row remains
  • node scripts/run-vitest.mjs run extensions/telegram/src/bot.test.ts extensions/telegram/src/bot-message-dispatch.test.ts -t 'dedupes direct assistant transcript context|marks directive-tagged durable finals' - passed, 2 tests; 258 skipped
  • pnpm lint:extensions:telegram-grammy-types - passed
  • git diff --check - passed
  • Earlier full Telegram-focused runs also passed:
    • node scripts/run-vitest.mjs run extensions/telegram/src/bot-message-dispatch.test.ts extensions/telegram/src/bot.test.ts -t "prompt-context timestamp|stripping directives" - passed
    • node scripts/run-vitest.mjs run extensions/telegram/src/bot-message-dispatch.test.ts extensions/telegram/src/bot.test.ts - passed, 260 tests
    • pnpm tsgo:test:extensions - passed

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S maintainer Maintainer-authored PR labels Jul 6, 2026
@momothemage
momothemage marked this pull request as ready for review July 6, 2026 03:09
@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 6, 2026, 3:40 AM ET / 07:40 UTC.

Summary
The PR strips Telegram inline directive tags before session/cache prompt-context dedupe and aligns outbound prompt-context cache timestamps for directive-tagged final replies, with handler and dispatch regression tests.

PR surface: Source +11, Tests +131. Total +142 across 4 files.

Reproducibility: yes. source-reproducible. Current main dedupes Telegram session/cache prompt rows by exact timestamp plus raw body, and the linked issue provides concrete installed-release duplicate context rows.

Review metrics: 1 noteworthy metric.

  • Prompt-context normalization points: 2 changed. The diff changes both the session/cache dedupe key and the outbound timestamp handoff, which together decide which Telegram context rows reach the model.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99117
Summary: This PR is a candidate fix for the canonical Telegram duplicate assistant prompt-context issue; the open sibling PRs overlap the same root cause with different fix shapes or proof states.

Members:

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

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦞 diamond lobster
Result: blocked until stronger real behavior proof is added.

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

Rank-up moves:

  • [P1] Add redacted live Telegram, QA transcript, runtime log, or terminal output from the current head showing only one prior visible assistant context row after a directive-tagged reply.
  • Update the PR body after adding proof so ClawSweeper can re-review automatically; if it does not, ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The linked current-head Mantis artifact reports pass/fixed but explicitly skipped visible proof, and the job log says no Crabbox session or worktree was started, so it does not show the hidden prompt-context behavior after the fix. 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.

Risk before merge

  • [P1] The current-head Mantis artifact is a skipped/no-op hidden-context manifest rather than a live Telegram or QA transcript showing the duplicate prompt row is gone.
  • [P1] The diff changes which Telegram session/cache rows are retained in model-visible prompt context, so an incorrect merge could suppress or preserve the wrong assistant history.
  • [P1] Several open PRs target the same canonical Telegram duplicate-context issue; maintainers should land one canonical timestamp-preserving branch and supersede the overlapping alternatives.

Maintainer options:

  1. Require Hidden-Context Proof (recommended)
    Ask for a redacted live Telegram, QA transcript, or runtime log on the current head showing a directive-tagged assistant reply appears only once in prompt context.
  2. Accept Test-Only Confidence
    Maintainers may intentionally merge on focused handler/dispatch tests, but they own the remaining live session/cache uncertainty.
  3. Pause For Canonical Branch Choice
    If another overlapping branch becomes preferred, pause this PR until the chosen branch has the timestamp-preserving fix shape and positive proof.

Next step before merge

  • [P1] Manual review remains because the external PR needs real hidden-context proof and has a protected maintainer label; I did not find a narrow code defect for an automated repair lane.

Security
Cleared: No concrete security or supply-chain concern found; the diff is limited to Telegram runtime/tests and does not change dependencies, workflows, permissions, credentials, downloads, or lockfiles.

Review details

Best possible solution:

Land one timestamp-preserving directive-strip dedupe fix with handler/dispatch regression coverage and redacted live or QA hidden-context proof, then close the canonical issue and supersede overlapping PRs.

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

Yes, source-reproducible. Current main dedupes Telegram session/cache prompt rows by exact timestamp plus raw body, and the linked issue provides concrete installed-release duplicate context rows.

Is this the best way to solve the issue?

Yes for the code shape, but not yet for merge readiness. The PR preserves the timestamp guardrail and reuses the delivery-visible directive stripper instead of switching to a broad body-only dedupe key, but it still needs real hidden-context proof.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9302c80ca6b8.

Label changes

Label changes:

  • remove mantis: telegram-visible-proof: Current Telegram visible-proof status is not_needed.
  • remove proof: 🎥 video: Current real behavior proof evidence kind is linked_artifact.

Label justifications:

  • P2: This is a bounded Telegram prompt-context bug-fix PR with limited channel blast radius and no crash, security bypass, or complete channel outage.
  • merge-risk: 🚨 session-state: The diff changes model-visible Telegram session/cache context row retention, which can alter agent context state and is not fully settled by CI without real hidden-context proof.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The linked current-head Mantis artifact reports pass/fixed but explicitly skipped visible proof, and the job log says no Crabbox session or worktree was started, so it does not show the hidden prompt-context behavior after the fix. 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

PR surface:

Source +11, Tests +131. Total +142 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 14 3 +11
Tests 2 133 2 +131
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 147 5 +142

What I checked:

Likely related people:

  • mikasa0818: Authored the merged direct Telegram session-transcript prompt-context work that introduced the session/cache merge and dedupe surface this PR changes. (role: feature introducer; confidence: high; commits: ec7a548062d3; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/session-transcript-context.ts, extensions/telegram/src/bot.test.ts)
  • rabsef-bicrym: Authored the merged outbound prompt-context timestamp-alignment fix that this PR builds on for directive-stripped delivered text. (role: adjacent fix author; confidence: high; commits: c8dba85b5d41; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/message-cache.ts, extensions/telegram/src/outbound-message-context.ts)
  • obviyus: Merged the session-transcript context PR and has recent commits in the Telegram prompt-context and transcript area. (role: recent area contributor and merger; confidence: medium; commits: ec7a548062d3, 3ad465d32b3b; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/session-transcript-context.ts, src/config/sessions/transcript.ts)
  • jalehman: Merged the adjacent timestamp-alignment PR and is a plausible reviewer for the same Telegram session/cache context contract. (role: adjacent merger and reviewer; confidence: medium; commits: c8dba85b5d41; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/message-cache.ts, extensions/telegram/src/outbound-message-context.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.
Review history (2 earlier review cycles)
  • reviewed 2026-07-06T03:21:09.455Z sha 8a3b4c2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-06T06:43:59.459Z sha 5c4cc72 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 6, 2026
@clawsweeper
clawsweeper Bot temporarily deployed to qa-live-shared July 6, 2026 03:24 Inactive
@momothemage

Copy link
Copy Markdown
Contributor Author

@openclaw-mantis telegram desktop proof: verify that a Telegram DM follow-up after an assistant reply using [[reply_to_current]] includes only one prior visible assistant context row.

@openclaw-mantis

openclaw-mantis Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: Mantis did not generate before/after GIFs because the PR changes hidden Telegram conversation context rather than Telegram-visible chat behavior.

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-desktop/pr-100573/run-28773461514-1/index.json

@momothemage

Copy link
Copy Markdown
Contributor Author

@openclaw-mantis telegram desktop proof: verify that a Telegram DM follow-up after an assistant reply using [[reply_to_current]] includes only one prior visible assistant context row.

@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 6, 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.

@clawsweeper clawsweeper Bot added the proof: 🎥 video Contributor real behavior proof includes video or recording evidence. label Jul 6, 2026
@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🦞✅
Maintainer-approved ClawSweeper automerge is complete.

Approver: momothemage
Head: 5c4cc7245ef0
Merge status: merged by ClawSweeper automerge
Merged at: 2026-07-06T08:11:09Z
Merge commit: e0d23cfc5a26

What merged:

  • Merged fix(telegram): dedupe visible assistant prompt context after ClawSweeper review.

Automerge notes:

  • PR branch already contained follow-up commit before automerge: fix(telegram): align directive reply prompt timestamps

The automerge loop is complete.

Automerge progress:

  • 2026-07-06 07:41:55 UTC review queued 5c4cc7245ef0 (queued)
  • 2026-07-06 08:11:11 UTC merged 5c4cc7245ef0 (merged by ClawSweeper automerge)

@clawsweeper clawsweeper Bot added clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge clawsweeper:human-review Needs maintainer review before ClawSweeper can continue and removed proof: 🎥 video Contributor real behavior proof includes video or recording evidence. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jul 6, 2026
@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🦞✅
ClawSweeper is pausing this repair loop for human review.

Source: clawsweeper[bot]
Reason: - [P1] Manual review remains because the external PR needs real hidden-context proof and has a protected maintainer label; I did not find a narrow code defect for an automated repair lane.; Cleared: No concrete security or supply-chain concern found; the diff is limited to Telegram runtime/tests and does not change dependencies, workflows, permissions, credentials, downloads, or lockfiles. (sha=5c4cc7245ef0ea1bee514d41b48bc1aa0f44bf6a)

Why human review is needed:
This item touches a maintainer-protected decision point. ClawSweeper is keeping the item open so a maintainer can own the final validation choice.

What the maintainer can do as a next step:
If the maintainer accepts the current risk and wants ClawSweeper to continue merge gates, comment @clawsweeper approve. If the flagged decision needs more evidence first, add the missing proof or resolve the maintainer-owned blocker, then comment @clawsweeper automerge. If the maintainer wants to own landing outside automation, merge manually after repository gates pass.

I added clawsweeper:human-review and left the final call with a maintainer.

@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper approve

@clawsweeper clawsweeper Bot removed the clawsweeper:human-review Needs maintainer review before ClawSweeper can continue label Jul 6, 2026
@clawsweeper
clawsweeper Bot merged commit e0d23cf into main Jul 6, 2026
139 of 143 checks passed
@clawsweeper
clawsweeper Bot deleted the feature/issue-99117-telegram-context-dedupe branch July 6, 2026 08:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 6, 2026
Summary:
- Merged fix(telegram): dedupe visible assistant prompt context after ClawSweeper review.

Automerge notes:
- PR branch already contained follow-up commit before automerge: fix(telegram): align directive reply prompt timestamps

Validation:
- ClawSweeper review passed for head 5c4cc72.
- Required merge gates passed before the squash merge.

Prepared head SHA: 5c4cc72
Review: openclaw#100573 (comment)

Co-authored-by: momothemage <[email protected]>
Approved-by: momothemage
consoleaf added a commit to consoleaf/openclaw that referenced this pull request Jul 8, 2026
…p [AI]

PR openclaw#100573 added stripInlineDirectiveTagsForDelivery to both
resolvePromptContextTextDedupeKey and normalizePromptContextTimestampText,
but directive-tag stripping alone does not normalise Markdown emphasis
characters (* _ ` ~). When the session transcript stores the assistant
reply with Markdown formatting (e.g. **bold**) but the Telegram
message cache stores the rendered text without it (e.g. bold), the
dedup key and timestamp-alignment comparison still mismatch, producing
duplicate messages in the conversation context.

Add stripMarkdownFormatting to both surfaces so the formatting
divergence is eliminated before the key/comparison is computed.
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
Summary:
- Merged fix(telegram): dedupe visible assistant prompt context after ClawSweeper review.

Automerge notes:
- PR branch already contained follow-up commit before automerge: fix(telegram): align directive reply prompt timestamps

Validation:
- ClawSweeper review passed for head 5c4cc72.
- Required merge gates passed before the squash merge.

Prepared head SHA: 5c4cc72
Review: openclaw#100573 (comment)

Co-authored-by: momothemage <[email protected]>
Approved-by: momothemage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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.

[Bug]: Telegram prompt context includes duplicate assistant entries from session transcript + channel cache

1 participant