Skip to content

Stuck "claimed" rows in channel_ingress_events block all inbound delivery after restart (no stale-claim recovery) #96374

Closed as not planned

Description

@love1106

OpenClaw version: 2026.6.10
Channel: Telegram (long-polling / isolated ingress mode)
Storage: channel_ingress_events table in state/openclaw.sqlite

Summary

Inbound messages stop being delivered to the agent after the gateway is restarted while a worker has an in-flight claimed row in channel_ingress_events. The claim is never released, so the stuck rows block all subsequent pending events on the same queue indefinitely. The agent keeps polling and reports healthy, but never processes or replies to any incoming message.

This is a classic stale-claim / orphaned-lease bug: the queue has no visibility-timeout or reaper to recover claims owned by a dead worker.

Impact

  • Agent appears fully healthy: /ready and /health return OK, Telegram polling logs show isolated polling ingress started, no errors.
  • Telegram side shows pending_update_count: 0 (updates are fetched), but the agent never emits an Inbound message log and never replies.
  • Every message sent after the stuck claim is silently queued as pending and never dispatched.
  • Symptom is indistinguishable from "channel broken" at the surface; openclaw doctor --lint does not detect it (config is valid; the failure is purely at the runtime queue layer).

Root cause

channel_ingress_events lifecycle: pending → claimed (worker takes it) → completed (purged) / failed.

When a worker claims an event (status='claimed', sets claim_token/claim_owner/claimed_at) and the gateway process is then killed mid-flight (SIGKILL, container restart, resource resize), the row stays claimed forever. On restart, a new worker does not reclaim these orphaned rows, and they sit ahead of newer pending rows in the queue ordering, blocking delivery.

The table schema already carries everything needed to detect this (claimed_at, attempts, last_attempt_at) — there is simply no logic that releases claims older than a timeout.

Reproduction (observed in production)

  1. Agent (Telegram, isolated polling ingress) is actively processing.
  2. Container is restarted abruptly (in our case: an orchestrator stop → resize → start sequence, plus a few manual restarts during debugging) while several events were claimed.
  3. After restart: polling resumes cleanly, no conflict, healthy — but agent never processes any inbound message.

Observed DB state (40 stuck rows for one telegram queue):

status='claimed'  count=31   (all claim_owner='7:239da3b5-...', claimed_at≈resize time, attempts=0, last_error=NULL)
status='pending'  count=9    (every message the user sent afterwards, never dispatched)

All 31 claimed rows were owned by a single dead worker id; none ever advanced to completed. Telegram offset on the API side had advanced past them (updates fetched), but the agent never saw them because they were stuck in the local DB queue.

Workaround used

DELETE FROM channel_ingress_events
WHERE channel_id = 'telegram'
  AND status IN ('claimed', 'pending');

After clearing the stuck rows and restarting, the new worker claimed → dispatched → completed normally (Inbound message logged, outbound send ok, queue back to empty).

Suggested fix

Add stale-claim recovery to the channel_ingress_events consumer, e.g. any of:

  1. Visibility timeout / claim TTL — on claim acquisition, reset rows where status='claimed' AND claimed_at < now() - CLAIM_TTL_MS back to pending (clear claim_token/claim_owner), bump attempts.
  2. Startup reaper — on gateway boot, release all claimed rows whose claim_owner doesn't match a live worker (workers are short-lived per-process, so any pre-restart claim is by definition orphaned).
  3. Worker heartbeat / lease renewal — require periodic claim renewal; expired leases auto-release.

Option (2) alone (release-on-boot) would have fully prevented this case, since a restart guarantees the previous claim owner is dead.

Optionally: have openclaw doctor surface a warning when channel_ingress_events has claimed rows with claimed_at older than N minutes — this would have made diagnosis immediate.

Activity

  1. clawsweeper commented on Jun 24, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

    Close as a duplicate: the report is the same SQLite channel_ingress_events stale-claim deadlock already tracked by the older open canonical issue, with an open candidate PR for the shared startup recovery fix.

    Root-cause cluster
    Relationship: duplicate
    Canonical: #90945
    Summary: This issue is a duplicate of the canonical open SQLite channel_ingress_events stale-claim recovery report; the same durable claimed rows block later Telegram delivery after restart.

    Members:

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

    Canonical path: Keep #90945 as the canonical tracker and review, land, or close #90989 after maintainer validation.

    So I’m closing this here and keeping the remaining discussion on #90945 and #90989.

    Review details

    Best possible solution:

    Keep #90945 as the canonical tracker and review, land, or close #90989 after maintainer validation.

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

    Yes at source level: current main keeps claimed rows out of pending replay and has only queue-local recovery hooks, while the report and canonical issue provide matching production DB states. I did not run a live crash/restart reproduction in this read-only review.

    Is this the best way to solve the issue?

    Yes: duplicate close is the best triage path because the fix belongs in shared channel/gateway SQLite ingress recovery and is already represented by the canonical issue and open candidate PR.

    Security review:

    Security review: No patch is under review, and the report is not itself a security disclosure.

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • steipete: GitHub path history maps the SQLite-backed channel ingress queue and schema to refactor(channels): store inbound queues in SQLite, the durable storage path involved in this report. (role: introduced shared queue storage; confidence: high; commits: b0679d1f13da; files: src/channels/message/ingress-queue.ts, src/state/openclaw-state-schema.sql, extensions/telegram/src/telegram-ingress-spool.ts)
    • vincentkoc: Recent commits touch the shared ingress queue and Telegram claim-preservation behavior near this recovery surface. (role: recent area contributor; confidence: medium; commits: 62456d65eb8b, b4cdd9211957, 49572863d3c1; files: src/channels/message/ingress-queue.ts, extensions/telegram/src/telegram-ingress-spool.ts)
    • 849261680: The open candidate PR implements the startup stale SQLite ingress claim sweep for the canonical issue and includes focused gateway/queue proof. (role: candidate fix contributor; confidence: high; commits: c6628275564c, a624eb35ccb3, 6044bb712b5c; files: src/channels/message/ingress-queue.ts, src/gateway/server-startup-ingress-sweep.ts, src/gateway/server-startup-plugins.ts)
    • obviyus: Recent Telegram history includes PID-reused ingress claim recovery work adjacent to the liveness and stale-claim evidence in the canonical cluster. (role: adjacent Telegram recovery contributor; confidence: medium; commits: d1b33a6040a4, 89a3b9a07edc; files: extensions/telegram/src/telegram-ingress-spool.ts, extensions/telegram/src/polling-session.ts)

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

  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    on Jun 24, 2026
  3. locked as resolved and limited conversation to collaborators on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions