Skip to content

Telegram plugin-state cache writes rows with expires_at = NULL, hits 1000-row hard cap, migrations fail #87332

Closed

Description

@adamamzalag

Summary

Doctor in 2026.5.26 reports:

PluginStateStoreError: Plugin state for telegram exceeds the 1000 live row limit.
Failed migrating Telegram forum topic-name cache entry -1003734409696:1230

Root cause: telegram.message-cache namespace writes rows with expires_at = NULL,
so the expiry sweep (idx_plugin_state_expiry WHERE expires_at IS NOT NULL) never
evicts them. They accumulate until the per-plugin 1000-row cap, then any new write
(including the doctor's topic-name-cache migration) fails.

Evidence

~/.openclaw/plugin-state/state.sqlite, current live state:

namespace row count rows with expires_at = NULL
telegram.message-cache 700 700 (100%)
telegram.bot-info-cache 1 0
telegram.topic-name-cache.<hash> 1 1

Within hours of a manual prune this morning the cache refilled to 998/1000.

Sample row:

namespace=telegram.message-cache
entry_key=eafd015eb3f678ca29b14de8:default:-1003734409696:17179
value_json={"sourceMessage":{"message_id":17179, ...}}
created_at=1779886069586
expires_at=NULL

Environment

  • openclaw 2026.5.26 (10ad3aa)
  • node 26.0.0 (homebrew)
  • macOS 25.5.0

Impact

  • Doctor migrations on upgrade silently lose data (topic-name-cache entries
    dropped when cap is hit during the rewrite).
  • Per-plugin 1000-row ceiling reached forever for any Telegram instance with
    more than ~1000 cached inbound messages.
  • Manual SQLite prune is the only mitigation, and it refills within hours.
  • topic-name-cache.<hash> namespace appears partially populated after the
    failed migration — only 1 row where the migration source had more.

Suggested fix direction

Either:

  • Set a TTL on telegram.message-cache writes (e.g. 24h / 7d, matching how
    long inbound message context is realistically useful), and let
    pruneExpiredPluginState evict them, OR
  • Cap telegram.message-cache namespace size explicitly with LRU eviction
    on insert, decoupled from the global 1000-row plugin cap, OR
  • Raise the 1000-row cap (less ideal — same growth pattern will hit any new
    ceiling).

Side note

Filed alongside #87331 (Native hook relay unavailable regression). Both
surfaced on the same upgrade; this one looks design-level rather than a
regression.

Activity

  1. WarrenJones commented on May 27, 2026

    @WarrenJones
  2. clawsweeper commented on May 27, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 27, 2026, 11:32 AM ET / 15:32 UTC.

    Summary
    Keep open. Current main still matches the reported shipped behavior: Telegram opens telegram.message-cache with a 1000-entry namespace budget but no TTL, persists rows without per-write TTL, and the core plugin-state store treats expires_at = NULL as live rows that count toward the global 1000-row plugin cap. No merged fix or canonical duplicate was found in the provided related context; the only current discussion is a contributor offering to investigate.

    Reproducibility: yes. Source inspection gives a high-confidence path: fill telegram.message-cache with NULL-expiry rows near the plugin-wide cap, add any sibling Telegram namespace row, then a message-cache write or doctor plugin-state import can hit PLUGIN_STATE_LIMIT_EXCEEDED; I did not execute it because this review is read-only.

    Next step
    This is a narrow, source-backed Telegram/plugin-state repair candidate with clear affected files and regression-test paths, but it should be manually promoted because the failure was source-proven rather than executed in this read-only review.

    Review details

    Best possible solution:

    Keep this open and land a focused Telegram/plugin-state fix that gives message-cache durable rows a bounded lifetime or smaller namespace budget with global-cap headroom, handles existing NULL-expiry rows, and protects doctor topic-name imports with regression coverage.

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

    Yes. Source inspection gives a high-confidence path: fill telegram.message-cache with NULL-expiry rows near the plugin-wide cap, add any sibling Telegram namespace row, then a message-cache write or doctor plugin-state import can hit PLUGIN_STATE_LIMIT_EXCEEDED; I did not execute it because this review is read-only.

    Is this the best way to solve the issue?

    Yes, the maintainable direction is a narrow Telegram-owned fix using the existing plugin-state TTL and max-entry contracts, plus migration coverage. Raising the global 1000-row cap alone would only move the failure point.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A fix that only adds TTL for new writes may leave existing expires_at = NULL message-cache rows blocking doctor imports until a write path or doctor path prunes them.
    • bestSolution:@
    • triagePriority:@
    • impactLabels:@
    • mergeRiskLabels:@
    • mergeRiskOptions:@
    • reviewMetrics:@
    • labelJustifications:@
    • itemCategory:@
    • reproductionStatus:@
    • reproductionConfidence:@
    • requiresNewFeature@

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

    Label changes

    Label changes:

    • add P2: This is a normal-priority Telegram/plugin-state stability bug with real upgrade impact but a limited affected surface.
    • add impact:data-loss: The reported failure can leave Telegram cache migration entries unwritten or partially imported when plugin-state cap enforcement trips.
    • add impact:session-state: The affected rows are persisted Telegram prompt/reply context state, so failed writes can make local conversation context stale or incomplete.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P2: This is a normal-priority Telegram/plugin-state stability bug with real upgrade impact but a limited affected surface.
    • impact:data-loss: The reported failure can leave Telegram cache migration entries unwritten or partially imported when plugin-state cap enforcement trips.
    • impact:session-state: The affected rows are persisted Telegram prompt/reply context state, so failed writes can make local conversation context stale or incomplete.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs extensions/telegram/src/message-cache.test.ts extensions/telegram/src/state-migrations.test.ts
    • node scripts/run-vitest.mjs src/plugin-state/plugin-state-store.test.ts src/commands/doctor-state-migrations.test.ts

    What I checked:

    • Telegram message cache has no TTL on current main: resolveDefaultPersistentStore() opens telegram.message-cache with maxEntries only, and persistCachedNode() calls persistentStore.register(...) without ttl options, so new plugin-state rows default to no expiry. (extensions/telegram/src/message-cache.ts:556, 8e41c118fa80)
    • Plugin-state rows without ttl are stored as NULL expiry: pluginStateRegister() computes expiresAt = null when no ttl is provided, then writes that value to expires_at. (src/plugin-state/plugin-state-store.sqlite.ts:445, 8e41c118fa80)
    • NULL expiry rows are live and not swept: The SQLite store prunes only rows where expires_at IS NOT NULL, while live counts include rows where expires_at IS NULL; those rows therefore remain live for cap enforcement. (src/plugin-state/plugin-state-store.sqlite.ts:244, 8e41c118fa80)
    • Global plugin cap can block sibling Telegram namespaces: After namespace eviction, enforcePostRegisterLimits() counts all live rows for the plugin and throws PLUGIN_STATE_LIMIT_EXCEEDED once the plugin exceeds the 1000 live-row cap. (src/plugin-state/plugin-state-store.sqlite.ts:419, 8e41c118fa80)
    • Doctor plugin-state imports use the same no-TTL store path: Legacy migration plans open a keyed store with only namespace and maxEntries, then call store.register(...) without ttl, so imports can hit the same live-row accounting behavior. (src/infra/state-migrations.ts:159, 8e41c118fa80)
    • Telegram migration imports message cache before topic-name cache: Telegram doctor plans import bot-info, message-cache, then topic-name cache; the message-cache plan uses TELEGRAM_MESSAGE_CACHE_PERSISTENT_MAX_MESSAGES as its max entries, matching the reported starvation path for later topic-name imports. (extensions/telegram/src/state-migrations.ts:200, 8e41c118fa80)

    Likely related people:

    • SYU8384: Available blame/log history attributes the current message-cache and plugin-state lines to the recent current-main grafted commit by Syu, with a noreply handle of SYU8384. (role: recent area contributor; confidence: medium; commits: 0503853c294b; files: extensions/telegram/src/message-cache.ts, src/plugin-state/plugin-state-store.ts, src/plugin-state/plugin-state-store.sqlite.ts)
    • steipete: The v2026.5.26 release commit that shipped this behavior is by Peter Steinberger, and the available history shows repeated adjacent state-migration refactors by the same author. (role: release and adjacent state-migration contributor; confidence: medium; commits: 10ad3aa16068, 493e1c246eec, 62793e602785; files: extensions/telegram/src/message-cache.ts, src/infra/state-migrations.ts)
    • vincentkoc: Recent history for src/infra/state-migrations.ts includes migration performance and leaf-type work, making this a plausible routing candidate for doctor migration behavior. (role: recent migration-path contributor; confidence: medium; commits: 97ee0c6fd339, 74e7b8d47b18, 9c3d9c5c18f0; files: src/infra/state-migrations.ts)
    • gumadeiras: Recent history shows focused work on legacy state migration discovery tests, which are likely affected by a regression test for this issue. (role: adjacent migration test contributor; confidence: low; commits: 5ae059db16c6; files: src/infra/state-migrations.ts, extensions/telegram/src/state-migrations.test.ts)
    How this review workflow works
    • 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.
  3. added
    P2Normal backlog priority with limited blast radius.
    impact:data-lossCan lose, corrupt, or silently drop user/session/config data.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on May 27, 2026
  4. Udjin79 commented on May 27, 2026

    @Udjin79
    Contributor

    I filed #87357 shortly after this one, before noticing it. They describe the same end-state from two different angles and are worth keeping side-by-side rather than dedupe'd, because the proposed fix directions don't fully overlap.

    The angle in #87357: even if telegram.message-cache rows had a sensible TTL, the enforcePostRegisterLimits eviction primitive cannot engage on the current code path. The reason is in plugin-state-store:

    if (namespaceCount > params.maxEntries) {
      params.store.statements.deleteOldestNamespace.run(...);
    }
    if (countLivePlugin > MAX_ENTRIES_PER_PLUGIN) {
      throw ...;
    }

    With TELEGRAM_MESSAGE_CACHE_PERSISTENT_MAX_MESSAGES === MAX_ENTRIES_PER_PLUGIN === 1000 and any co-tenant namespace (telegram.bot-info-cache has 1 live row by design), the path is:

    1. upsertEntry lifts telegram.message-cache to exactly 1000.
    2. Namespace check: 1000 > 1000 → false, no eviction.
    3. Per-plugin check: 1001 > 1000 → throw, transaction rolls back.

    The eviction primitive never runs because the strict > gate keeps it dormant until the per-plugin throw has already fired. Even with TTL on writes, the same trap reappears for any plugin that owns more than one namespace.

    So a few observations on the fix-direction options here, with respect — none are wrong, but each carries trade-offs that the structural patch in #87357 avoids:

    • TTL on telegram.message-cache writes (24h / 7d) — changes the semantic of cached reply context: anything older than the TTL stops being available for inbound reply_to_message resolution, even when the row would still be useful. Drops the cache from a bounded LRU to a time-bounded buffer. Workable, but a semantic change rather than a bug fix.
    • Decoupled namespace LRU on insert — equivalent in effect to fixing the gate, but reimplements the eviction logic in the plugin instead of using what plugin-state-store already provides.
    • Raise the 1000 cap — postpones the same trap. Any value where sum(namespace.maxEntries) ≥ plugin.maxEntries keeps the bug intact for plugins with multiple namespaces.

    The narrower fix in #87357: change the namespace eviction gate from strict > to >= (or reserve namespace headroom such that Σ(namespace.maxEntries) < MAX_ENTRIES_PER_PLUGIN). That makes the existing primitive engage on the right transition without altering data lifetime semantics, and unblocks any future plugin with co-tenant namespaces, not just telegram.

    (Field workaround for anyone hitting this before a fix lands: prune the oldest telegram.message-cache rows directly in SQLite to give the plugin some headroom, then patch TELEGRAM_MESSAGE_CACHE_PERSISTENT_MAX_MESSAGES down to 998 in the installed bundle as a temporary measure. Reapply on every reinstall.)

  5. steipete commented on May 27, 2026

    @steipete
    Contributor

    Fixed on main by e339586 and backported to release/2026.5.27 by 9cc1a83.

    Those commits raise the plugin-wide live-row cap, keep Telegram's persistent message-cache namespace bounded, evict only within the namespace currently being written, and add regression coverage for Telegram-shaped plugin-state namespaces plus migration rollback.

    Closing as fixed. Please reopen or file a fresh issue if this reproduces on a build containing 9cc1a83 or newer.

  6. locked as resolved and limited conversation to collaborators on May 30, 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

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions