Skip to content

fix: Telegram inline-button taps are timestamped with the card's send date instead of the tap time - #170957

Closed
Irish-Joseph wants to merge 2 commits into
openclaw:mainfrom
Irish-Joseph:fix/telegram-callback-tap-timestamp
Closed

Irish-Joseph wants to merge 2 commits into
openclaw:mainfrom
Irish-Joseph:fix/telegram-callback-tap-timestamp

Conversation

@Irish-Joseph

@Irish-Joseph Irish-Joseph commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #169881

What Problem This Solves

Fixes: inline-button taps (callback_query) being recorded with the timestamp of the message that carries the button, so a tap made long after a confirmation card was sent appears to predate the card it answers.

User Impact

Any consumer that reasons about a tap by timestamp — freshness checks ("is this tap newer than the message it answers?"), dedupe/supersede logic, audit ordering — now sees the actual tap time. In the reported flow, a Send tap on a 22-minute-old card no longer looked older than that card.

Why This Change Was Made

A Telegram callback_query carries no timestamp of its own. The model-callback path synthesized the inbound message from the card and passed no date, so the canonical inbound builder derived ProviderMessageTimestamp from the card's date. The fix passes the tap time (Math.floor(Date.now() / 1000)) into buildSyntheticTextMessage, which already honors a supplied date — the same pattern the poll-response path already uses. All other callback behavior is untouched (the interactive/plugin callback path is intentionally out of scope; see #133267 for plugin-handler date exposure).

Evidence

  • New test bot-handlers.callback-router.tap-timestamp.test.ts drives the live callback router through the model-command path with a card dated ~20 minutes before the (fake-timer) tap and asserts the inbound message carries the tap time, not the card date.
  • Red/green proof: with the source change reverted, the new test fails with expected 1786404800 to be 1786406000 (card date vs tap time); with the fix it passes.
  • model-callback.loopback.integration.test.ts, telegram-ingress-callback.integration.test.ts, and bot-handlers.callback-questions.runtime.test.ts all pass.
  • oxfmt --check and oxlint clean on the touched files.

Review response (2026-10-15)

Addressed the receipt-time defect in commit c6e31d3ca38:

  • Queued/replayed callbacks now keep the spool receipt time, not the dispatch time. The ingress spool already persists receivedAt per claim (telegram-ingress-drain.ts serialize); deserialize now stamps the in-memory update with it (withTelegramUpdateReceivedAt, an in-memory marker that is never persisted), and the model-callback path reads that receipt time first, falling back to Date.now() for live (unspooled) callbacks. A tap admitted at 15:31 and drained at 15:40 after a blocked handler or restart is now recorded as 15:31.
  • Regression added (bot-handlers.callback-router.tap-timestamp.test.ts, second case): the update is stamped with an admission time 30 minutes before the faked processing time; the inbound message keeps the receipt time and not the processing time. Red/green: reverting only the router change fails it with the processing time.
  • Suites: tap-timestamp (2/2), ingress spool ordering, ingress-callback integration (3/3; two earlier failures reproduced on the clean base commit as machine-load flakiness and are green when the machine is idle). oxfmt + oxlint clean.

Real-behavior proof (2026-10-15, rebased on current main)

A real grammY bot talking to a real HTTP Bot API loopback (same harness style as model-callback.loopback.integration.test.ts) driving the production callback router. The card is sent through the production send path; answerCallbackQuery and editMessageReplyMarkup (routed-button clear) went over real HTTP. The only instrumented point is the processMessageWithReplyChain boundary, which records the actual inbound message the real router builds:

--- live tap (real Bot API loopback) ---
card date sent over the wire:   1786404800     (2026-08-11, the card's date)
inbound msg.date recorded:      1791920865     (the tap's processing second)
processing second window:       [1791920865, 1791920865]
=> the inbound message is stamped with the tap time, not the card date.

--- queued tap (spool receipt stamp, 5 min old) ---
spool receipt second:           1791920565     (admission time, applied via
                                                withTelegramUpdateReceivedAt,
                                                exactly as deserialize does)
inbound msg.date recorded:      1791920565
=> a callback admitted 5 minutes before dispatch keeps the receipt time
   instead of the (later) dispatch time — the review's 15:31/15:40 case.

Branch rebased on main (no conflicts; tap-timestamp, spool, ingress-callback, and model-callback loopback suites re-run green on the new base). The Telegram servers themselves are not involved; this is a loopback Bot API.

@clawsweeper

clawsweeper Bot commented Oct 13, 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.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S labels Oct 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 13, 2026
@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR timestamps generic callback-generated messages from recorded update receipt time instead of the attached card’s send time.

Example: A card sent at 15:09 is tapped at 15:31, and the queued callback is dispatched at 15:40.

  • Before: The callback-generated message is timestamped 15:09.
  • After: The callback-generated message is timestamped 15:31.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The useful timestamp correction remains blocked by two concrete defects; supplied loopback evidence does not meet the scoped live Telegram proof requirement.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: An agent sees a newly tapped button as an interaction that occurred when its older card was sent.
Reason: The generic callback correction has clear value, but plugin submitText and managed select/multiselect submissions retain the same timestamp defect; this bounded PR should use Related rather than close the broader report.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR addresses a current-main Telegram timestamp bug and merits continued review, but both previously reported defects remain.

Priority: P2
Reviewed head: 572b9be2da7226b36e591f415be540f303464e88

Before merge

  • Add real behavior proof - The supplied HTTP Bot API loopback trace exercises the production callback router and records synthetic message.date, but replaces inbound processing and manually attaches queued receipt metadata; provide Telegram Test Server logs or a recording showing an old-card callback reaching final agent context with its original receipt timestamp after actual delayed or restart replay, redacting IPs, API keys, phone numbers, and non-public endpoints. 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.
  • Keep receipt metadata outside the enumerable Telegram update (P2) - Deserializing any spooled update adds an enumerable __openclawReceivedAtMs property. Exact-head CI confirms that this changes the dispatched update shape and breaks existing ingress restart-replay, webhook retry/control replay, and monitor identity assertions. Raw-update logging also serializes the property despite the helper’s stated contract. Store receipt time in an update-keyed WeakMap, following prepared poll-answer metadata. This previously reported finding remains unresolved.
  • Give the processing mock its actual parameter type (P2) - Both tests construct processMessageWithReplyChain with a zero-argument implementation, so Vitest infers mock.calls entries as empty tuples. Reading argument zero here and in the second case fails TypeScript checking; casting the surrounding runtime does not change the mock variable’s inferred signature. Type the mock with the production processing signature and return a valid processing result. This previously reported finding remains unresolved.

Findings

  • [P2] Keep receipt metadata outside the enumerable Telegram update — extensions/telegram/src/telegram-ingress-spool.payload.ts:24-25
  • [P2] Give the processing mock its actual parameter type — extensions/telegram/src/bot-handlers.callback-router.tap-timestamp.test.ts:75

Tests

  • Missing end-to-end proof: Missing live Telegram evidence connecting an old-card tap to final agent-context timestamps through actual delayed or restart replay; supplied red/green claims cover the router, while queued evidence manually attaches metadata.
Agent review details

How this fits together

Telegram polling and webhooks persist updates with receipt timestamps; the ingress drain delivers them to the callback router, whose synthetic messages supply agent-context timestamps.

flowchart LR
A[Telegram callback update] --> B[Durable ingress queue]
B --> C[Ingress drain]
C --> D[Callback router]
D --> E[Synthetic inbound message]
E --> F[Agent context]
Loading

Technical review

Best possible solution:

Carry receipt time in an update-keyed WeakMap and use it consistently for callback-generated agent messages.

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

Current-main source establishes card-date inheritance into agent timestamps, and the canonical report identifies an affected official release; no target code was executed.

Is this the best way to solve the issue?

Reusing the existing durable receipt timestamp handles delayed dispatch correctly, but enumerable metadata changes raw updates and sibling interactive submissions still inherit the card date.

Full review comments:

  • [P2] Keep receipt metadata outside the enumerable Telegram update — extensions/telegram/src/telegram-ingress-spool.payload.ts:24-25
    Deserializing any spooled update adds an enumerable __openclawReceivedAtMs property. Exact-head CI confirms that this changes the dispatched update shape and breaks existing ingress restart-replay, webhook retry/control replay, and monitor identity assertions. Raw-update logging also serializes the property despite the helper’s stated contract. Store receipt time in an update-keyed WeakMap, following prepared poll-answer metadata. This previously reported finding remains unresolved.
    Confidence: 0.99
  • [P2] Give the processing mock its actual parameter type — extensions/telegram/src/bot-handlers.callback-router.tap-timestamp.test.ts:75
    Both tests construct processMessageWithReplyChain with a zero-argument implementation, so Vitest infers mock.calls entries as empty tuples. Reading argument zero here and in the second case fails TypeScript checking; casting the surrounding runtime does not change the mock variable’s inferred signature. Type the mock with the production processing signature and return a valid processing result. This previously reported finding remains unresolved.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7840eae2df25.

Provenance checked

  • Generic callback timestamp inheritance changes intended behavior with a stated reason (unknown: The recorded split and consolidation PRs preserved behavior; history through callback.runtime.ts establishes carry-forward, not the original reason for inheriting the card date.)
  • Durable ingress receipt-time propagation keeps the original intent (ee0e3a4: The shared ingress monitor preserves Telegram-owned admission and transport contracts while recording receivedAt; this PR consumes that existing fact.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test extensions/telegram/src/bot-handlers.callback-router.tap-timestamp.test.ts extensions/telegram/src/telegram-ingress-drain.test.ts extensions/telegram/src/webhook.test.ts extensions/telegram/src/monitor.webhook-identity.test.ts --maxWorkers=1
  • pnpm tsgo:extensions:test
  • pnpm check:changed
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ee0e3a4 adds extensions/telegram/src/telegram-ingress-drain.ts:111 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ee0e3a4d478e; files: extensions/telegram/src/telegram-ingress-drain.ts)

PR surface

Source +37, Tests +139. Total +176 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 38 1 +37
Tests 1 139 0 +139
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 177 1 +176

Root-cause cluster

Relationship: same_root_cause
Canonical: #169881
Summary: The canonical issue and both open fixes concern inherited card timestamps; plugin metadata exposure is adjacent work.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Incorrect callback timestamps affect Telegram interaction ordering and agent context with a channel-specific blast radius.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. An old-card button tap and its resulting agent context and Telegram reply can demonstrate the corrected interaction timestamp through Telegram’s Test Server.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-13T10:45:15.179Z sha f89bee64495c06e0856bcbbff5d122ead62dd95d :: needs real behavior proof before merge. :: [P2] Preserve the callback’s original receipt time during queued dispatch
  • reviewed 2026-10-13T17:00:06.431Z sha c6e31d3ca38b6658e572c07488eff783dc66e8b7 :: needs real behavior proof before merge. :: [P2] Keep receipt metadata outside the enumerable Telegram update
  • reviewed 2026-10-13T17:40:47.004Z sha c6e31d3ca38b6658e572c07488eff783dc66e8b7 :: needs real behavior proof before merge. :: [P2] Keep receipt metadata outside the enumerable Telegram update | [P2] Give the processing mock its actual parameter type
  • reviewed 2026-10-13T18:09:21.540Z sha 572b9be :: needs real behavior proof before merge. :: [P2] Keep receipt metadata outside the enumerable Telegram update | [P2] Give the processing mock its actual parameter type

Reviewed October 13, 2026, 3:56 PM ET / 19:56 UTC (Revision 5).

…rd date

A callback_query carries no timestamp of its own; the model-callback
path synthesized its inbound message from the card that carries the
button and passed no date, so the tap was recorded with the card's
send time. A tap made long after the card was sent then appeared to
predate the card it answers, breaking freshness and ordering reasoning
over taps.

Pass the tap time into the synthetic message, the same way the poll
path already does; buildSyntheticTextMessage already honors a supplied
date, so no other callback behavior changes.

Proof: new callback-router test drives the model-command path through
the live router with a card dated ~20 minutes before the (faked) tap
and asserts the inbound message carries the tap time. Without the fix
the same test fails with the card date (1786404800 vs 1786406000).
model-callback loopback, ingress-callback, and callback-question
suites pass. oxfmt --check and oxlint are clean on the touched files.

Fixes openclaw#169881.
…penclaw#169881)

Date.now() at dispatch time mis-stamps callbacks that were durably queued
before processing: a tap received at 15:31 but drained after a blocked
handler or restart at 15:40 was recorded as 15:40, keeping false event
times in freshness and ordering consumers.

The ingress spool already persists receivedAt per claim; deserialize now
stamps the in-memory update with it (in-memory marker, never persisted),
and the model-callback path prefers that receipt time over the processing
time, falling back to Date.now() for live (unspooled) callbacks.

Proof: new regression stamps the update with an admission time 30 minutes
before the (faked) processing time and asserts the inbound message keeps
the receipt time; reverting only the router change fails it with the
processing time. The card-date regression, spool ordering suite, and
ingress-callback integration suite pass. oxfmt and oxlint clean.
@Irish-Joseph
Irish-Joseph force-pushed the fix/telegram-callback-tap-timestamp branch from c6e31d3 to 572b9be Compare October 13, 2026 18:02
obviyus added a commit that referenced this pull request Oct 13, 2026
…d time instead of the tap (#170210)

fix(telegram): stamp callback turns with the button-press time

A Telegram inline-button click produced a turn timestamped with the original card message's time, not the time the user pressed the button. Callback updates now carry their receipt time, keyed by update, so generic, single-select and multiselect callbacks report when the press happened. Raw updates and ordinary message timestamps are unchanged.

Proof: Telegram Test Server with a real TDLib user clicking generic, single-select and multiselect buttons on a built Gateway. On main, generic and multiselect callbacks kept the card's old time; with this change the provider timestamp matches the click receipt time.

Thanks @maliv2, and @Irish-Joseph for the parallel fix in #170957.

Co-authored-by: Muhammet Ali Aydın <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Irish-Joseph. This fixes the same callback timestamp bug as #170210, which landed in d2261ea with a smaller update-keyed change, so I'm closing this as a duplicate. Your PR is credited in the merge commit.

@obviyus obviyus closed this Oct 13, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…d time instead of the tap (openclaw#170210)

fix(telegram): stamp callback turns with the button-press time

A Telegram inline-button click produced a turn timestamped with the original card message's time, not the time the user pressed the button. Callback updates now carry their receipt time, keyed by update, so generic, single-select and multiselect callbacks report when the press happened. Raw updates and ordinary message timestamps are unchanged.

Proof: Telegram Test Server with a real TDLib user clicking generic, single-select and multiselect buttons on a built Gateway. On main, generic and multiselect callbacks kept the card's old time; with this change the provider timestamp matches the click receipt time.

Thanks @maliv2, and @Irish-Joseph for the parallel fix in openclaw#170957.

Co-authored-by: Muhammet Ali Aydın <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram P2 Normal backlog priority with limited blast radius. 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.

Telegram inline-button taps are timestamped with the source message's date, not the tap time

2 participants