Skip to content

fix(telegram): history claims rejected voice attachments were delivered - #130399

Merged
steipete merged 1 commit into
mainfrom
codex/qa-telegram-accepted-media-20260826
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-telegram-accepted-media-20260826

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #130398

What Problem This Solves

Fixes an issue where users receiving a text alternative after Telegram rejects an automatically generated final voice message would see the rejected audio filename in the conversation history instead of the text that was delivered. The affected final-reply mirror also incorrectly includes rejected attachments in mixed-media payloads.

Why This Change Was Made

Record accepted media at the Telegram delivery boundary and pass that fact to the existing transcript mirror. Keep the existing media-first history representation, partial-failure handling, storage, and durable-send behavior unchanged. Remove redundant first-item and pending-follow-up bookkeeping within the same media owner.

Production LOC: +18/-14 (net +4). The added state distinguishes media actually accepted by Telegram from a successful text alternative; tests are +40/-4.

User Impact

When a voice message cannot be delivered but its text alternative succeeds, the conversation history now retains that text. Mixed replies retain accepted attachments without claiming rejected ones were sent. Ordinary media and captionless-media recovery keep their existing behavior.

Evidence

  • Three focused regression cases failed against unchanged production: rejected voice alone and an accepted image before/after the rejected voice. Each failure showed the rejected voice URL in the mirror payload.
  • Owner verification: 407 passing tests across Telegram delivery, durable sends, caption editing, and dispatch transcript behavior.
  • Independent verification: 414 passing tests, including seven real grammY serialized HTTP request/response cases through the actual transcript formatter. Cases cover text recovery, both mixed-media orders, accepted voice, caption-too-long recovery, photo-to-document recovery, and complete fallback failure.
  • Fresh authenticated Codex review of the complete patch and owner/caller/sibling context returned no actionable findings through priority P2.
  • Provider-wire evidence used an intercepted HTTP endpoint and a stub database append. It is not live Telegram or running-Gateway evidence.
  • An isolated running Gateway used documented automatic final-answer speech, native quoted Telegram ingress, a synthetic Bot API and speech endpoint, and a scripted provider. It synthesized real OGG/Opus, received VOICE_MESSAGES_FORBIDDEN, and delivered the text alternative. The actual Gateway chat.history response contains a channel-final delivery-mirror entry with the delivered text and no rejected audio filename. Independent source-blind validation passed all five cases below. This is mock-provider Gateway proof, not live Telegram.
  • Scope clarification from runtime investigation: ordinary model MEDIA: directives are delivered as blocks and do not activate this final-reply mirror. Mixed-media combinations are covered at the delivery-owner boundary, not claimed as the automatic-speech Gateway flow.
  • Local changed gates passed the first 17 stages, including formatting, boundary guards, doctor tests, and dead-export scans. Global plugin typechecking is locally blocked by missing unrelated IMAP dependencies; hosted exact-head CI remains required.

Hosted CI run 33012032715 passed on 803821394a15270d157c40bf97fb94012264cf64, including the required CI gate.

Independent source-blind operator evidence (fresh synthetic chats, real Gateway API; sequential completion observed in Gateway diagnostics):

Case Observed Telegram requests Observed delivery history
900101: voice forbidden Voice rejected, text accepted Exact accepted text; no audio filename
900102: changed fallback text Voice rejected, new text accepted Exact changed text; no stale or audio entry
900103: ordinary voice Voice accepted; no text fallback Accepted voice filename retained
900104: caption recovery Caption-bearing voice rejected; captionless voice and separate text accepted Accepted voice filename retained
900105: total failure Voice and both text attempts rejected No successful-delivery mirror

The validator inspected all 11 Telegram send attempts and exactly four matching channel-final history entries. Total failure produced the explicit diagnostic final reply failed: GrammyError: Call to 'sendMessage' failed! (400: Bad Request: text must be non-empty); the synthetic endpoint deliberately rejected nonempty text, so this proves failure handling, not Telegram's real validation rules. Final refreshed history still contained no success record for that failed case.

{"kind":"mock-provider-gateway","verdict":"pass","head":"803821394a15270d157c40bf97fb94012264cf64","flow":"automatic final-only TTS with native quote","cases":5,"telegramSendAttempts":11,"channelFinalMirrors":4,"falseSuccessMirrors":0,"sourceBlind":true,"liveTelegram":false}

AI-assisted. No configuration, public SDK, authentication, protocol, schema, or migration changes.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 20:45
@steipete
steipete merged commit 549360b into main Aug 26, 2026
194 checks passed
@steipete
steipete deleted the codex/qa-telegram-accepted-media-20260826 branch August 26, 2026 21:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 4:53 PM ET / 20:53 UTC.

ClawSweeper review

What this changes

The PR records only Telegram attachments accepted by the platform so mirrored conversation history reflects delivered fallback text and accepted mixed media.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer-authored PR open: the patch fixes the current-main transcript defect at the delivery owner, with no blocking correctness finding. Exact-head CI is still running and a live mirror assertion would further reduce risk.

Priority: P2
Reviewed head: 803821394a15270d157c40bf97fb94012264cf64

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with behavior-level regression coverage and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Maintainer-authored PRs are exempt from the contributor proof gate; its synthetic evidence is useful, but a redacted persisted-mirror assertion would still strengthen review confidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Maintainer-authored PRs are exempt from the contributor proof gate; its synthetic evidence is useful, but a redacted persisted-mirror assertion would still strengthen review confidence.
Evidence reviewed 7 items Current-main defect: Current main records requested mediaList in the transcript payload after any reply delivery; a rejected voice plus accepted text therefore still reaches the media-first formatter.
Formatter contract: The transcript formatter intentionally prefers attachment filenames whenever mediaUrls is nonempty, so filtering belongs at the delivery producer rather than in the formatter.
Owner-boundary repair: The PR appends a media URL only after the send helper returns successfully, then supplies that accepted list to mirror aggregation.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/telegram/src/bot/delivery.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.extension-telegram.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130399-Z5pSw0/target

[vitest] still running with no output for 30000ms.
 ✓  extension-telegram  extensions/telegram/src/bot/delivery.test.ts (131 tests) 1812ms
     ✓ maps an exhausted request-not-started marker to streaming no-dispatch custody  1250ms

 Test Files  1 passed (1)
      Tests  131 passed (131)
   Start at  20:54:43
   Duration  30.88s (transform 23.64s, setup 1.24s, import 27.65s, tests 1.81s, environment 0ms)

[test] passed 1 Vitest shard in 37.06s
[test] starting test/vitest/vitest.extension-telegram.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130399-Z5pSw0/target

 ✓  extension-telegram  extensions/telegram/src/bot/delivery.test.ts (131 tests) 1804ms
     ✓ maps an exhausted request-not-started marker to streaming no-dispatch custody  1268ms

 Test Files  1 passed (1)
      Tests  131 passed (131)
   Start at  20:55:21
   Duration  14.28s (transform 7.47s, setup 540ms, import 11.77s, tests 1.80s, environment 0ms)

[test] passed 1 Vitest shard in 20.49s

Assertions:

  • NOT OBSERVED expect_output: mirrors accepted media — command exited successfully; expected output was not observed in the captured pane

How this fits together

Telegram reply delivery sends media and fallback text through the Bot API, then mirrors the result into OpenClaw conversation history. The mirror should represent what recipients actually received, not requested media that Telegram rejected.

flowchart LR
  A[Agent reply] --> B[Telegram delivery]
  B --> C{Media accepted?}
  C -->|Yes| D[Accepted media list]
  C -->|No| E[Fallback text]
  D --> F[Transcript mirror]
  E --> F
  F --> G[Conversation history]
Loading

Before merge

  • Resolve merge risk (P1) - Production code is net +4 lines; the accepted-media list is necessary owner-boundary state because the existing flow otherwise discards the distinction between requested and accepted attachments.
  • Resolve merge risk (P1) - Exact-head CI is still in progress, and the PR’s synthetic Gateway smoke does not yet show the persisted mirror entry.
  • Complete next step (P2) - No mechanical repair is identified; await exact-head CI and normal maintainer merge handling.
Agent review details

Security

None.

PR surface

Source +4, Tests +36. Total +40 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 18 14 +4
Tests 1 40 4 +36
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 58 18 +40

Review metrics

Metric Value Why it matters
Production vs test LOC production +4 (18 added, 14 removed); tests +36 (40 added, 4 removed) The small production increase records an otherwise-lost acceptance fact at the delivery boundary; the tests cover voice-only and mixed-media ordering.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #130398
Summary: This PR is the focused candidate fix for the linked rejected-voice transcript bug.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the delivery-boundary accepted-media record once exact-head CI is green; retain the media-first formatter unchanged because it correctly formats the accepted attachment set.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the delivery-boundary accepted-media record once exact-head CI is green; retain the media-first formatter unchanged because it correctly formats the accepted attachment set.

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

Yes, from source: make sendVoice reject with VOICE_MESSAGES_FORBIDDEN while sendMessage succeeds, then inspect the transcript-mirror payload; current main includes the rejected URL and the candidate’s focused tests cover that path.

Is this the best way to solve the issue?

Yes: the formatter correctly prefers delivered media, so recording the accepted-media fact where Telegram delivery succeeds is the narrowest maintainable repair.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs misleading Telegram conversation history for a bounded but user-visible fallback path.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Maintainer-authored PRs are exempt from the contributor proof gate; its synthetic evidence is useful, but a redacted persisted-mirror assertion would still strengthen review confidence.

Label justifications:

  • P2: This repairs misleading Telegram conversation history for a bounded but user-visible fallback path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Maintainer-authored PRs are exempt from the contributor proof gate; its synthetic evidence is useful, but a redacted persisted-mirror assertion would still strengthen review confidence.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current repair, the blamed requested-media line, and the Telegram dispatch refactor that owns transcript formatting. (role: feature owner and recent area contributor; confidence: high; commits: 803821394a15, 99a02bf115cf, bb3fae834810; files: extensions/telegram/src/bot/delivery.replies.ts, extensions/telegram/src/bot-message-dispatch-session.ts)
  • Ayaan Zaidi: Local file-history shortlog shows repeated contributions to the Telegram delivery and transcript area, though the available partial history cannot resolve individual commits. (role: recent area contributor; confidence: medium; files: extensions/telegram/src/bot/delivery.replies.ts, extensions/telegram/src/bot-message-dispatch-session.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let exact-head CI complete successfully.
  • Optionally capture a redacted Gateway transcript/mirror result for a rejected-voice text fallback.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

[Bug]: Telegram history includes rejected voice attachments after text fallback

1 participant