Skip to content

fix(telegram): requeue aborted ingress claims - #122864

Merged
obviyus merged 3 commits into
openclaw:mainfrom
jchoi-atn:ingress-timeout-recovery
Aug 26, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
jchoi-atn:ingress-timeout-recovery

Conversation

@jchoi-atn

@jchoi-atn jchoi-atn commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When Telegram work is reclaimed after an ingress owner timeout, a late abort from the old owner can be misclassified as delivery failure. Separately, a service-manager restart arrives as plain SIGTERM; draining only its outer transaction can tear down an embedded Codex tool run that is still active, surfacing a misleading tool failure.

Evidence

Focused coverage passes:

corepack pnpm exec vitest run src/cli/gateway-cli/run-loop.test.ts src/daemon/systemd-unit.test.ts extensions/telegram/src/telegram-ingress-drain.test.ts src/channels/message/ingress-drain.test.ts

Summary

  • release abandoned pre-adoption claims without spending retries
  • requeue late-aborted Telegram deferred participants safely
  • preserve dead-lettering when dispatch-dedupe rollback is unsafe
  • drain active embedded agent runs before a managed SIGTERM shutdown
  • give systemd enough stop budget for that cooperative drain

@clawsweeper

clawsweeper Bot commented Aug 12, 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 triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7dc50bd56

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/channels/message/ingress-drain.ts Outdated
Comment on lines +543 to +546
await state.settleOnce(async () => {
// Ownership ended before adoption, so this is not a delivery attempt.
await releaseClaim(state.claim, "turn-abandoned", { recordAttempt: false });
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the non-rejecting abandonment contract

When queue.release rejects, this now propagates from onAbandoned, but completeFollowupRunLifecycle deliberately invokes that callback without observing its promise, and Telegram also discards it with void. The rejection can therefore reach OpenClaw's global unhandled-rejection handler, which exits the gateway for non-transient errors, instead of containing the failed claim release as before. Restore rejection containment while retaining the new recordAttempt: false behavior.

AGENTS.md reference: src/channels/AGENTS.md:L49-L51

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 5:37 AM ET / 09:37 UTC.

ClawSweeper review

What this changes

This PR requeues pre-adoption Telegram claims without consuming retries and increases managed gateway SIGTERM drain time for active embedded runs.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 6 items remain

Keep open. The latest head contains the prior rejection-containment repair, but its manual systemd unit documentation still leaves operators with the old 30-second stop budget, and the PR has only mock/test evidence rather than after-fix behavior proof.

Priority: P1
Reviewed head: d7d980d37a2240e41f84539bd772e62eab5e39b0

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and addresses the prior rejection path, but it needs the manual-service documentation repair and real recovery evidence.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: Only focused Vitest/mock coverage is posted; add redacted after-fix production-boundary traces for abort/reclaim and managed SIGTERM drain recovery before merge, without tokens, endpoints, or identifiers. 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.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Only focused Vitest/mock coverage is posted; add redacted after-fix production-boundary traces for abort/reclaim and managed SIGTERM drain recovery before merge, without tokens, endpoints, or identifiers. 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 6 items Abandonment owner boundary: The shared ingress lifecycle now releases an abandoned pre-adoption claim with recordAttempt false, preserving retry budget while recording turn-abandoned.
Prior rejection finding addressed: The Telegram deferred-settlement chain logs settlement failures, and the core release helper contains release failures, so the previous unobserved onAbandoned rejection path is no longer propagated.
Managed-update convergence: A normal owned service update invokes gateway install --force, which regenerates the managed unit; the remaining mismatch is in supported manual-unit guidance.
Findings 1 actionable finding [P2] Update the manual systemd unit examples
Security None None.

Live Verification

Command: pnpm openclaw gateway --help

Result: PASS (completed)

$ node scripts/run-node.mjs gateway --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 107.05 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 14.3s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4338ms (slowest: built plugin control-plane loads 3594ms)
│
◇

OpenClaw 2026.8.1 (d7d980d) — All your chats, one OpenClaw.

Usage: openclaw gateway [options] [command]

Run, inspect, and query the WebSocket Gateway

Options:
  --allow-unconfigured      Allow gateway start without enforcing gateway.mode=local in config (does not repair config) (default: false)
  --ambient-channels        Allow the gateway to auto-configure channels from ambient environment variables (default: false)
  --auth ‹mode›             Gateway auth mode ("none"|"token"|"password"|"trusted-proxy")
  --bind ‹mode›             Bind mode ("loopback"|"lan"|"tailnet"|"auto"|"custom"). Defaults to
… output truncated …

Assertions:

  • PASS expect_output: gateway

How this fits together

Telegram updates flow through a durable ingress queue whose lifecycle releases, retries, or adopts each claimed update. Gateway shutdown waits for process-wide active work, while the systemd unit determines how long the operating system allows that drain to finish.

flowchart LR
A[Telegram update] --> B[Durable ingress queue]
B --> C[Deferred claim lifecycle]
C --> D{Adopted or abandoned}
D -->|adopted| E[Channel dispatch]
D -->|abandoned| B
F[Managed SIGTERM] --> G[Gateway active-work drain]
G --> H[Systemd stop budget]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Only focused Vitest/mock coverage is posted; add redacted after-fix production-boundary traces for abort/reclaim and managed SIGTERM drain recovery before merge, without tokens, endpoints, or identifiers. 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.
  • Update the manual systemd unit examples (P2) - The generated unit now allows 330 seconds, but the supported manual examples in docs/platforms/linux.md and docs/gateway/index.md still specify TimeoutStopSec=30. Custom-service operators following those guides remain subject to the shutdown interruption this change addresses; update both examples with the generated policy.
  • Resolve merge risk (P2) - The two supported manual systemd examples still direct custom-service operators to use a 30-second stop timeout, so those deployments retain the shutdown interruption this PR is intended to avoid.
  • Resolve merge risk (P1) - Only focused Vitest/mock coverage is posted; no redacted after-fix production-boundary trace demonstrates Telegram reclaim or managed SIGTERM recovery.
  • Resolve merge risk (P1) - Production code grows by net 15 lines; the recovery boundary justifies it only if the documented operator path is kept consistent.
  • Complete next step (P2) - The documentation correction is a narrow mechanical repair; contributor-supplied real behavior proof remains a separate merge gate.

Findings

  • [P2] Update the manual systemd unit examples — src/daemon/systemd-unit.ts:87
Agent review details

Security

None.

PR surface

Source +26, Tests +41. Total +67 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 37 11 +26
Tests 4 57 16 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 94 27 +67

Review metrics

Metric Value Why it matters
Production versus test delta production +26/-11 (net +15); tests +57/-16 (net +41) The positive production growth adds claim-state classification and shutdown coordination; tests cover the changed queue and signal seams.
Managed stop budget 1 generated default changed: 30s → 330s The new budget affects service shutdown availability and must match operator-created systemd units.

Merge-risk options

Maintainer options:

  1. Align operator guidance and prove recovery (recommended)
    Update both manual systemd examples to the new stop budget and add redacted after-fix production-boundary traces before merging.

Technical review

Best possible solution:

Align both manual systemd examples with the generated 330-second stop budget, then attach redacted after-fix traces showing abandoned-claim replay and managed SIGTERM drain recovery.

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

No: the PR supplies focused mock/test coverage, but no current-head production-boundary trace for a reclaimed Telegram claim or managed SIGTERM drain.

Is this the best way to solve the issue?

No: the lifecycle changes are targeted, but leaving the documented manual systemd path at 30 seconds leaves a supported deployment path with the reported shutdown limit.

Full review comments:

  • [P2] Update the manual systemd unit examples — src/daemon/systemd-unit.ts:87
    The generated unit now allows 330 seconds, but the supported manual examples in docs/platforms/linux.md and docs/gateway/index.md still specify TimeoutStopSec=30. Custom-service operators following those guides remain subject to the shutdown interruption this change addresses; update both examples with the generated policy.
    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 high; reviewed against 430de50d6735.

Labels

Label justifications:

  • P1: This fixes channel replay and managed gateway shutdown paths that can interrupt active user work.
  • merge-risk: 🚨 availability: The PR changes process shutdown timing and active-work draining, which can affect gateway availability during service-manager restarts.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only focused Vitest/mock coverage is posted; add redacted after-fix production-boundary traces for abort/reclaim and managed SIGTERM drain recovery before merge, without tokens, endpoints, or identifiers. 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

Acceptance criteria:

  • [P1] pnpm docs:list.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Ayaan Zaidi: Authored the current-head corrective commit that contains the abandonment containment and shutdown-budget changes. (role: latest corrective contributor; confidence: high; commits: d7d980d37a22; files: extensions/telegram/src/telegram-ingress-drain.ts, src/channels/message/ingress-drain.ts, src/cli/gateway-cli/run-loop.ts)
  • jisubi: Authored the two earlier focused commits for Telegram ingress recovery and gateway SIGTERM draining in this PR's supplied commit history. (role: initial branch contributor; confidence: medium; commits: e19485514e13, 85672bdae435; files: extensions/telegram/src/telegram-ingress-drain.ts, src/cli/gateway-cli/run-loop.ts)

Rank-up moves

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

  • Update the two manual systemd examples from 30 to 330 seconds.
  • Attach redacted after-fix traces showing a reclaimed deferred Telegram claim and a managed SIGTERM drain.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-13T00:14:14.295Z sha d7dc50bd567d03db59c6353416ebf9ed3672a66a :: needs real behavior proof before merge. :: [P1] Preserve the non-rejecting abandonment contract
  • reviewed 2026-08-13T00:49:42.807Z sha fda9f2dee671f41d2ddd54a175bb13c6fa655ba1 :: needs real behavior proof before merge. :: [P1] Preserve the non-rejecting abandonment contract
  • reviewed 2026-08-19T11:13:10.870Z sha fda9f2dee671f41d2ddd54a175bb13c6fa655ba1 :: needs real behavior proof before merge. :: [P1] Contain abandonment release failures
  • reviewed August 25, 2026, 6:15 AM ET / 10:15 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Contain abandonment release failures

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes labels Aug 13, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 25, 2026
@obviyus
obviyus force-pushed the ingress-timeout-recovery branch from fda9f2d to d7d980d Compare August 26, 2026 09:31
@obviyus

obviyus commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Land-ready on d7d980d37a2240e41f84539bd772e62eab5e39b0.

  • Main defect: a late Telegram owner abort could become delivery failure after the old owner lost the claim, consuming retry state; generated systemd units also stopped after 30 seconds while the gateway needed a cooperative drain.
  • Contributor e19485514e133db7d3d6c9ede791390b8ed09ecd: requeues pre-adoption aborted claims without spending attempts, while preserving unsafe dispatch-dedupe rollback failures.
  • Contributor 85672bdae435b11eaa8858584f6b97006ab2d177: drains active embedded runs during managed SIGTERM shutdown.
  • Maintainer d7d980d37a2240e41f84539bd772e62eab5e39b0: preserves the current abandonment owner contract, aligns the drain tests, and sets the generated systemd stop budget to 330 seconds.
  • The requeue fix needs the cooperative drain path during real shutdown. The 315-second gateway drain plus 330-second systemd budget is the required new Linux-unit path.

Known limitation: launchd still has its 20-second deadline, and existing systemd units and manual examples still use 30 seconds. A separate follow-up will migrate launchd, installed units, audit coverage, and docs. The maintainer accepted this cross-platform policy and directed this PR to land as-is.

Proof:

  • Gate 2 focused tests passed: Telegram 17/17, core ingress 27/27, gateway loop 60/60, and systemd 18/18.
  • git diff --check and targeted formatting passed; targeted Oxlint passed for all four edited test files.
  • ClawSweeper: 0 actionable findings, 0 security concerns; the supervisor decision is resolved by the maintainer. No rerun was performed on this head.
  • Telegram doctor passed with ok: true.
  • The recorded real-user DM produced one SUT reply (OPENCLAW_E2E_OK), two typing events, and one mock-provider request. The canonical runner cannot express a SIGTERM lifecycle, so focused unit coverage is the behavior evidence for that gap.
  • Exact-head CI: check-lint ended from a runner shutdown signal; changed-extension failures are unrelated MSTeams, Signal, and WhatsApp tests outside this eight-file diff. Local targeted Oxlint passed.

Evidence remains in proof/pr-122864/telegram/.

@obviyus
obviyus merged commit 880a2a6 into openclaw:main Aug 26, 2026
248 of 255 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
Requeue Telegram ingress claims when their owner aborts before adoption, without spending retry attempts or misclassifying late aborts as delivery failures. During managed shutdown, drain active embedded model and tool runs before exit, with a 330-second generated systemd stop budget for the 315-second cooperative gateway drain.

Co-authored-by: jisubi <[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 cli CLI command changes gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. 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.

3 participants