Repository navigation
fix(telegram): avoid duplicate history replies for queued messages - #169019
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR correlates Telegram delivery mirrors with their producing run so queued answers appear once in Gateway history. Example: “The train leaves at noon.” is committed before a second answer, and its delivery mirror settles afterward.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a queued-history defect still present on main, and both prior review findings are resolved; no new actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherTelegram dispatch supplies run provenance to the existing transcript writer, and Gateway history consumes the writer-owned correlation for presentation. flowchart LR
A[Telegram input] --> B[Agent run]
B --> C[Assistant transcript]
B --> D[Telegram delivery]
C --> E[Transcript mirror writer]
D --> E
E --> F[Gateway history projection]
F --> G[Control UI history]
Technical reviewBest possible solution: Keep run correlation in the existing transcript writer and consume explicit source identities in the shared history projection. Do we have a high-confidence way to reproduce the issue? Current-main source shows that intervening queued rows defeat latest-message correlation and adjacent-row suppression; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch repairs correlation at its producer and presentation at the shared owner, preserving keyed replay, distinct repeated answers, media guards, and provider exclusion. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 48a348028fb0. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +139, Tests +92, Docs +13, Other -1. Total +243 across 20 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed October 11, 2026, 5:53 AM ET / 09:53 UTC (Revision 4). |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Final head de8079b: build-artifacts, all typechecks, architecture and baseline ratchets pass. CI remains red only in checks-node-changed-extensions-bundle-2 (Codex steering/steering-settlement timeouts, missing receipt assertion, and database-resources-closing teardown cascade), plus aggregate ci-gate; cancelled jobs: 0. The same cases fail independently in https://github.com/openclaw/openclaw/actions/runs/38126796377/job/114432980545. This patch does not change those Codex tests or their steering lifecycle. Pausing for maintainer disposition; no rerun requested. Exact-head ClawSweeper reports zero findings. Final real Telegram capture has three history rows for three delivered answers, unchanged provider replay, and all run-owned messages deleted/read back absent. |
|
Maintainer override: the only red job is checks-node-changed-extensions-bundle-2 (Codex run-attempt.steering-settlement / run-attempt.steering: missing receipt, hook timeouts, then database-resources-closing). The same 6 tests fail identically on pure origin/main ac8a432 in 3 of 3 matched secretless Linux runs, and also 3 of 3 on this head; this PR does not change Codex steering. ci-gate is red only through that shard. ClawSweeper on this exact head reports zero findings. |
|
Landed in 8e2a683. Queued Telegram turns no longer duplicate answers in chat history. |
…penclaw#169019) When a Telegram user sent a second message while the first answer was still streaming, chat.history showed both answers twice, although the user and the model each saw them once. Delivery mirrors were correlated only against the latest transcript message, so the queued order (answer A, queued user turn, answer B, mirror A, mirror B) broke correlation, and the history projection hid a mirror only when its source row was adjacent. Telegram now passes the producing run id with each mirror; the SDK mirror append matches the unused equivalent assistant occurrence within that run (falling back to the previous behavior without a run id), and the history projection resolves explicit source ids across intervening rows. Real Telegram Test Server proof: before, five assistant rows for three delivered answers; after, three rows, one per answer; provider replay unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
Since #169019, the transcript mirror lookup by run id scanned and decoded events across the whole session history, because the JSON-extracted run id inside an OR kept SQLite off its index. Telegram delivery mirroring therefore got slower as a persistent session grew. The lookup now combines the indexed idempotency-key probe and a bounded run lookup with UNION ALL, filters by role in SQL before decoding bodies, and needs no schema change. The count of direct SQLite call sites stays at 605. Measured at 50k events: median 178.00 ms down to 4.39 ms, and run-metadata evaluations from 50,003 to 2,049, with the same row selected. Telegram Test Server proof with 50k historical events: the queued-turn scenario still stores one history row per delivered answer. Fixes #169643. Co-authored-by: Ayaan Zaidi <[email protected]>
…w#169663) Since openclaw#169019, the transcript mirror lookup by run id scanned and decoded events across the whole session history, because the JSON-extracted run id inside an OR kept SQLite off its index. Telegram delivery mirroring therefore got slower as a persistent session grew. The lookup now combines the indexed idempotency-key probe and a bounded run lookup with UNION ALL, filters by role in SQL before decoding bodies, and needs no schema change. The count of direct SQLite call sites stays at 605. Measured at 50k events: median 178.00 ms down to 4.39 ms, and run-metadata evaluations from 50,003 to 2,049, with the same row selected. Telegram Test Server proof with 50k historical events: the queued-turn scenario still stores one history row per delivered answer. Fixes openclaw#169643. Co-authored-by: Ayaan Zaidi <[email protected]>
First-parent upstream 069a5b8..75df19c (17 commits, including openclaw#169043 entry lifecycle queries, openclaw#169034, openclaw#169058 memory index facts, openclaw#168950, openclaw#169019 telegram queued history replies, openclaw#168790/openclaw#168756/ openclaw#168759/openclaw#168739 Solid UI ports, openclaw#168813 codex metadata/startup lifecycles, openclaw#168981, openclaw#168992 agent preparation SQLite work). Only conflict: worker-access inventory, regenerated (631 files, 2436 calls). Auto-merged files carrying our overlay, reviewed: snapshot.ts (upstream's block-reply reconcile reads through index-1; our per-part continuation-marker strip in extractAssistantStreamSnapshot unchanged), codex side-question.ts (upstream's request-scoped client lease; our disableContinuationTools and the extracted dynamic-tool-call helper unaffected), subagent-registry-restore.ts, session-sharing-store.native.ts. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Fixes duplicate assistant replies in
chat.historywhen a second Telegram message arrives during a streamed answer.User Impact
Each delivered answer appears once in history, including queued answers. Telegram delivery and the next model request are unchanged. No configuration or storage migration is required.
Why This Change Was Made
Delivery can settle after multiple answers have already been committed. Bind Telegram mirrors to their producing run rather than only the latest transcript message, and let history resolve an explicit source identity across intervening rows. Keep existing text, media, and source-isolation checks, idempotent delivery replay, and the legacy fallback for callers without a run identity.
Run-scoped lookups select only active-path events for the producing run before decoding message payloads, rather than materializing the whole transcript.
Discord and Slack use the shared dispatch ownership guard rather than Telegram's preview mirror path; their existing delivery behavior is unchanged.
Evidence
pnpm buildpass.80707,80709,80712; history contains exactly three assistant rows. All six run-owned raw input/output IDs were deleted and read back absent. Follow-up provider assistant messages exactly equal the pre-fix capture.Merge danger: two-way door. Reverting restores the old correlation/projection behavior without a schema or config change. Blast radius: Telegram queued-answer history and Gateway presentation of explicitly correlated channel-final mirrors; the provider transcript and transport sends are unchanged.