Skip to content

Gateway replays stale queued messages after restart #55564

Closed as not planned
Closed as not planned

Description

@JamesTsetsekas

Description

After a gateway restart (e.g. VPS reboot, openclaw gateway restart, or service crash), the gateway delivers all queued/pending outbound messages at once. This creates a flood of stale messages that are no longer relevant.

Steps to Reproduce

  1. Have an active conversation with the agent via Telegram (or any channel)
  2. Reboot the VPS or restart the gateway service
  3. After the gateway comes back online, all pending messages from before the restart are delivered to the channel simultaneously

Observed Behavior

  • ~20+ stale messages delivered all at once, all with the same timestamp
  • Messages reference work that was already completed hours ago
  • Users see a confusing flood of old context that looks like the agent "went nuts"
  • Had to use /stop to cut it off

Expected Behavior

Messages queued before a restart should either:

  • Be dropped if they exceed a configurable TTL (e.g. 60 seconds)
  • Be silently discarded on restart
  • At minimum, have a config option like gateway.delivery.maxAgeMs to control this

Environment

  • OpenClaw 2026.3.24
  • Ubuntu 22.04 (ARM64)
  • Channel: Telegram (forum/topic mode)
  • Gateway runs as systemd user service

Workaround

None currently. Users must manually /stop to halt the flood.

Suggestion

Add a gateway.delivery.staleTTLMs config option (default ~60000ms) that drops queued messages older than the threshold on gateway startup. This would prevent stale message replay while still allowing brief network interruptions to recover gracefully.

Activity

  1. clawsweeper commented on Apr 30, 2026

    @clawsweeper
    Contributor

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

    Close as duplicate/superseded: the stale outbound replay behavior is still present, but the remaining TTL/config policy is already tracked by the open canonical issue and the focused implementation candidate remains open for review.

    Canonical path: Keep the remaining TTL/default/expire-action decision in #16555, then land or replace #54900 with a backward-compatible outbound expiry policy.

    So I’m closing this here and keeping the remaining discussion on #16555 and #54900.

    Review details

    Best possible solution:

    Keep the remaining TTL/default/expire-action decision in #16555, then land or replace #54900 with a backward-compatible outbound expiry policy.

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

    Yes, at source level. Seed an old pending delivery entry with retryCount 0 and no lastAttemptAt, then run recoverPendingDeliveries; current main treats it as eligible and gateway startup calls that path.

    Is this the best way to solve the issue?

    Yes for cleanup routing. The code fix should be resolved through the canonical TTL policy issue and focused PR candidate rather than keeping this duplicate report open.

    Security review:

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

    What I checked:

    • current_issue_state: Live GitHub state shows this issue is open, externally authored, unassigned, has no protected labels, and has no merged closing pull request.
    • startup_recovery_has_no_age_gate: Current main loads pending delivery entries, sorts by enqueuedAt, then applies recovery budget, max retries, retry backoff, and delivery replay; there is no queued-age or expiry action before delivery. (src/infra/outbound/delivery-queue-recovery.ts:588, bb5010b89a5a)
    • first_attempt_entries_remain_replayable: isEntryEligibleForRecoveryRetry returns eligible for retryCount 0 entries with no lastAttemptAt and does not compare Date.now() with enqueuedAt, so an old never-attempted queue entry remains replayable. (src/infra/outbound/delivery-queue-recovery.ts:330, bb5010b89a5a)
    • queue_entry_shape_matches_report: enqueueDelivery writes enqueuedAt and retryCount: 0 before send, matching the stale first-attempt state described in the report. (src/infra/outbound/delivery-queue-storage.ts:145, bb5010b89a5a)
    • gateway_startup_invokes_recovery: Gateway scheduled-service activation calls recoverPendingDeliveries during startup with config, logger, and deliver function only; no age or TTL policy is passed. (src/gateway/server-runtime-services.ts:156, bb5010b89a5a)
    • strict_config_lacks_delivery_ttl_surface: MessagesConfig and the strict MessagesSchema include messages.queue but no messages.delivery, maxAgeMs, staleTTLMs, or expireAction surface for the requested operator policy. (src/config/types.messages.ts:101, bb5010b89a5a)

    Likely related people:

    • steipete: Current blame and history point to Peter Steinberger for the split recovery/storage files, active delivery claim changes, and maintainer-facing direction on the canonical TTL issue. (role: recent area contributor and reviewer; confidence: high; commits: 562e4a1791fb, aa27a9474fa3, 5e97045345a6; files: src/infra/outbound/delivery-queue-recovery.ts, src/infra/outbound/delivery-queue-storage.ts, src/infra/outbound/delivery-queue.policy.test.ts)
    • nabbilkhan: Commit 207e2c5 added the original outbound delivery crash recovery and durable queue startup replay path that this issue extends. (role: introduced behavior; confidence: high; commits: 207e2c5affa9; files: src/infra/outbound/delivery-queue.ts, src/infra/outbound/deliver.ts, src/gateway/server.impl.ts)
    • Marcus Castro: Recent reconnect-drain work changed the shared pending-delivery drain path that any stale expiry policy needs to preserve consistently. (role: adjacent reconnect-drain contributor; confidence: medium; commits: 95d467398e46; files: src/infra/outbound/delivery-queue-recovery.ts, src/infra/outbound/delivery-queue-storage.ts, src/infra/outbound/delivery-queue.reconnect-drain.test.ts)
    • Stephen Schoettler: Recovery-budget work changed retry accounting for deadline-deferred entries, which affects stale-entry predicates and expiry policy design. (role: adjacent recovery-budget contributor; confidence: medium; commits: b07312c55b5d; files: src/infra/outbound/delivery-queue.ts, src/infra/outbound/outbound.test.ts)

    Codex review notes: model gpt-5.5, reasoning high; reviewed against bb5010b89a5a.

  2. added
    P2
    impact:message-loss
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-product-decision
    on May 19, 2026
  3. locked as resolved and limited conversation to collaborators on May 25, 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

    P2clawsweeper:needs-product-decisionclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:message-lossissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions