Skip to content

fix(telegram): keep membership audit deadline on the monotonic clock - #185290

Merged
obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/BUG-152-telegram-audit-membership-deadline-wall-clock
Oct 27, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/BUG-152-telegram-audit-membership-deadline-wall-clock

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A Telegram group membership audit that runs while the host clock jumps (NTP resync, manual change) can report a healthy audit as timed out, or stall past its budget. The audit deadline and its remaining budget came from Date.now() (wall clock), while the fetch and response-body timeouts consume that budget through monotonic setTimeout timers, so a clock jump distorts the remaining budget in either direction.

  • Problem: auditTelegramGroupMembershipImpl seeded deadlineMs with Date.now() and recomputed the remaining budget with Date.now() before each fetchWithTimeout / readResponseWithLimit call. A forward jump clamps the budget to zero and fast-paths a healthy audit to "timed out" without making a request; a backward jump inflates it and stalls the audit.
  • Solution: seed the deadline and derive the remaining budget from performance.now(), matching the monotonic timers. The deadline is a process-internal closure, never serialized or read across processes, so no dual-clock handling is needed.
  • Scope: three Date.now() calls in extensions/telegram/src/audit-membership-runtime.ts. The elapsedMs report in audit.ts stays on the wall clock; no API or transport behavior changes.

Why This Change Was Made

The audit runs inside the Gateway and must not hang or fail because of clock adjustments. Since the deadline is produced and consumed locally within one audit call, the monotonic clock is the only correct reference for it.

User Impact

Telegram group audits now finish within their configured timeout regardless of host clock adjustments. Operators no longer see spurious "timed out" results or audits that stall past their budget after a clock resync.

Evidence

Shipped path: the real CLI (openclaw channels status --probe --timeout 70000) → Gateway WebSocket RPC → channels.status → Telegram auditAccount → auditTelegramGroupMembershipImpl → real fetch to a real loopback Bot API HTTP peer. A probe in the Gateway process answers the audit's second Date.now() (the remaining-budget read) as real ± 60000ms, modelling an NTP jump between the deadline seed and that read. Both runs use the checkout's built CLI and Gateway; pre-fix is the origin/main bundle, post-fix is the same bundle with this PR's compiled three-line change (that file is the only source delta).

shipped run pre-fix (Date.now()) post-fix (performance.now())
no skew (control) audit ok audit ok
+60s at budget read, healthy bot audit failed — "timed out after 29993ms", elapsedMs: 2, no getChatMember audit ok — status: "member", elapsedMs: 5, getChatMember sent
-60s at budget read, stalled body telegram status timed out after 30000ms (CLI 35.3s): the inflated budget outlived the status budget bounded by the real budget: "response body stalled for 14991ms" (CLI 19.8s)

Both backward runs report failure because the peer stalls the body; the difference is the bound: 30s status timeout versus a 14.99s audit bound.

Raw terminal output:

$ node openclaw.mjs channels status --probe --timeout 70000      # pre-fix, +60s
- Telegram default: ... works, audit failed
- telegram default: ... Telegram membership audit timed out after 29993ms (matchKey=-1001 matchSource=id)

$ node openclaw.mjs channels status --probe --timeout 70000      # post-fix, +60s
- Telegram default: ... works, audit ok

$ node openclaw.mjs channels status --probe --timeout 70000      # pre-fix, -60s, stalled body
- telegram status timed out after 30000ms
- Telegram default: enabled, configured, error:status timed out after 30000ms, running, ...

$ node openclaw.mjs channels status --probe --timeout 70000      # post-fix, -60s, stalled body
- Telegram default: ... works, audit failed
- telegram default: ... Telegram membership audit response body stalled for 14991ms (matchKey=-1001 matchSource=id)

Gateway clock probe, pre-fix: audit #1 Date.now() #1 (deadline seed) at audit-membership-runtime-DOlhcNn8.mjs:23:27, then #2 (remaining-budget read) answered as real+60000ms at :34:59; the backward run answers real-60000ms at :34:59 and :42:57. Post-fix: no audit Date.now() line is ever emitted; the log only records arm file observed.

Bot API peer: pre-fix +60s run has getMe at 05:21:20.658Z, next poll at 05:21:24.511Z, no getChatMember in between; post-fix +60s run has getMe 05:23:04.497Z → getChatMember ?chat_id=-1001&user_id=700000001 05:23:04.507Z.

Regression test (audit.test.ts, it.each([-60_000, 60_000]), fake timers move only Date.now()): holds group 1's fetch across the jump so the shared deadline is re-read, and holds group 2's response body idle; pre-fix RED in both directions, post-fix GREEN 9/9.

auditTelegramGroupMembershipImpl seeded its fetch/read deadline with
Date.now() and computed remaining budget with Date.now() too, while
fetchWithTimeout and readResponseWithLimit consume that budget through
monotonic setTimeout timers. A wall-clock jump (NTP resync or manual
adjustment) distorted the remaining budget: a forward jump shrank it to
zero, misreporting a healthy audit as timed out; a backward jump inflated
it, amplifying the timeout and stalling the audit past its configured
budget.

Seed the deadline and derive remaining budget from performance.now()
instead so both sides measure elapsed time on the same monotonic clock.
@clawsweeper

clawsweeper Bot commented Oct 27, 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: XS labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR uses monotonic time to calculate Telegram membership-audit deadlines and adds regression coverage for wall-clock jumps.

Example: The host clock advances 60 seconds during a healthy Telegram group membership audit.

  • Before: The audit reports a timeout without sending getChatMember.
  • After: The audit sends getChatMember and reports the bot as a member.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal complete repair with discriminating regression coverage, supplied shipped-entry-point evidence, and passing exact-head validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Contributor terminal output exercises the built channels status CLI through Gateway RPC and the production Telegram audit against a real loopback HTTP peer, showing forward-jump membership success and backward-jump bounded body failure after applying the three-line production change.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Telegram membership checks can falsely time out or exceed their intended budget when the host wall clock changes.
Reason: The change restores the existing bounded-audit contract with three clock substitutions and focused regression coverage.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current Telegram audit deadline bug with a focused change; no actionable findings remain, and the exact-head CI gate passes.

Priority: P2
Reviewed head: 57803a87deb8351a67ea73be4bc7111d2ad27b6b

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Telegram plugin receives configured group IDs and an audit budget from channel status checks, queries the Bot API, and returns membership results and diagnostic errors.

flowchart LR
  A[Channels status CLI] --> B[Gateway channels status]
  B --> C[Telegram account audit]
  C --> D[Membership deadline owner]
  D --> E[Fetch and bounded body reader]
  E --> F[Telegram Bot API]
  E --> G[Membership audit result]
Loading

Technical review

Best possible solution:

Merge the focused monotonic-clock repair while retaining the existing shared timeout budget and transport lifecycle.

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

Current-main source directly exposes the clock mismatch, and the contributor supplies before/after CLI and Gateway output for both jump directions; this read-only review did not execute target code.

Is this the best way to solve the issue?

Using performance.now() for the local deadline and every remaining-budget read restores the existing timeout invariant without another abstraction or configuration option.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 32d0945d21d2.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still contains the bug: The deadline seed and both remaining-budget calculations use Date.now(), so wall-clock adjustments change the available budget. (extensions/telegram/src/audit-membership-runtime.ts:30, 32d0945d21d2)
  • Smallest complete production fix: The introduced production hunks replace exactly the three deadline clock reads with performance.now(); the deadline remains local to one audit invocation. (extensions/telegram/src/audit-membership-runtime.ts:30, 57803a87deb8)
  • Discriminating regression coverage: The revised test holds the first fetch across each clock jump and leaves the second response body idle, distinguishing premature timeout from an inflated remaining budget; this addresses the earlier review finding. (extensions/telegram/src/audit.test.ts:79, 57803a87deb8)
  • Contributor runtime evidence: The full PR body records built CLI → Gateway → Telegram audit → real loopback HTTP runs: a forward jump changes false timeout to membership success, and a backward jump changes the outer status timeout to a bounded body-stall result. (57803a87deb8)
  • Exact-head validation and merge state: GitHub reports the reviewed head cleanly mergeable, with successful CI, dependency-review, and security-sensitive-review statuses; the changed Node test check also passed. A canceled auto-response job is automation activity, not a product validation failure. (57803a87deb8)
  • Feature history and original intent: History across the current and former src/telegram paths identifies repeated Telegram refactoring by Peter Steinberger and bounded diagnostic-read work by Alix-007 in fix(telegram): bound stalled diagnostic response reads #106035; the patch preserves that bounded-read intent. Extended pickaxe and historical-blob reads encountered unavailable promisor objects, so the original introduction of the wall-clock choice remains unverified. (extensions/telegram/src/audit-membership-runtime.ts:30, 32d0945d21d2)

PR surface

Source 0, Tests +44. Total +44 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 44 0 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 47 3 +44

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Clock adjustments can produce false or delayed Telegram membership-audit results, with limited impact on diagnostics.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (3 earlier review cycles)
  • reviewed 2026-10-27T01:28:53.118Z sha edb2637 :: needs changes before merge. :: [P2] Hold an audit operation across the clock jump
  • reviewed 2026-10-27T03:53:33.918Z sha 57803a8 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T05:15:05.133Z sha 57803a8 :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 1:43 AM ET / 05:43 UTC (Revision 4).

The initial regression test responded immediately, so the audit completed
before the wall-clock jump mattered and passed even with the Date.now()
deadline. Hold group 1's fetch across the jump so the shared deadline is
re-read afterward, and hold group 2's response body idle so the audit is
bounded only by the recomputed remaining budget.

Verified both directions: green on performance.now() (head), red on
Date.now() (base) - a forward jump clamps the budget to ~1ms (request
never completes) and a backward jump inflates it (never settles within
the window).
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Runtime proof on head 57803a8 against main 9b7db69: built CLI and Gateway in a secretless Node 24.22.1 container, running the shipped openclaw channels status --probe through the real Gateway and Telegram adapter to a local Bot API fixture (fake token). The first getChatMember answered slowly and the second stalled. Date.now was shifted back 60 seconds inside the Gateway process only, during the first request (the system clock was not touched).

Run CLI time Outcome
Main, step 1 6.757 s Partial status: outer timeout, audit detail lost
Main, step 2 7.379 s Gateway RPC timeout, config-only fallback
Main, no step 4.187 s Full status with the stalled-group audit
Candidate, step 1 4.283 s Full status with the stalled-group audit
Candidate, step 2 4.357 s Full status with the stalled-group audit
Candidate, no step 4.310 s Full status with the stalled-group audit

Limits: main's existing monotonic outer budget caps it near 6 seconds, so this doesn't show a full 60-second stall. The reported audit.elapsedMs is still derived from the wall clock and reads negative after the step; that display value is not fixed here.

@obviyus
obviyus merged commit 25fc14d into openclaw:main Oct 27, 2026
173 of 174 checks passed
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Landed in 25fc14d. Thanks @SunnyShu0925. The Telegram membership audit now ignores wall-clock jumps.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…penclaw#185290)

fix(telegram): keep the membership audit deadline on the monotonic clock

The Telegram membership audit measured its deadline with the wall clock, so a backward clock step let it overrun its budget, and `channels status --probe` lost the audit detail to the outer status timeout. The deadline now uses monotonic time.

Evidence: shipped `openclaw channels status --probe` through the real Gateway and Telegram adapter to a local Bot API fixture, with Date.now shifted back 60 seconds inside the Gateway process only. On main the status came back partial or config-only after 6.8s and 7.4s (twice); with this change it returned the full audit in 4.3s and 4.4s (twice), matching the no-step runs. The reported audit.elapsedMs still uses the wall clock and is not fixed here. Production 6 lines.

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 28, 2026
…185290)

fix(telegram): keep the membership audit deadline on the monotonic clock

The Telegram membership audit measured its deadline with the wall clock, so a backward clock step let it overrun its budget, and `channels status --probe` lost the audit detail to the outer status timeout. The deadline now uses monotonic time.

Evidence: shipped `openclaw channels status --probe` through the real Gateway and Telegram adapter to a local Bot API fixture, with Date.now shifted back 60 seconds inside the Gateway process only. On main the status came back partial or config-only after 6.8s and 7.4s (twice); with this change it returned the full audit in 4.3s and 4.4s (twice), matching the no-step runs. The reported audit.elapsedMs still uses the wall clock and is not fixed here. Production 6 lines.

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 25fc14d)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 58a49bb31d7a50f82398f5c898d761f3ea79bacd)
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: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

2 participants