Skip to content

Stale session agent:main:main survives dmScope change to per-channel-peer, causing duplicate message delivery #31010

Description

@Skrblik

Bug Description

When session.dmScope is changed from default to per-channel-peer, the old session agent:main:main persists in the session store and is not cleaned up. This causes duplicate message delivery to the same Telegram chat, because both sessions have active deliveryContext pointing to the same target.

Environment

  • OS: Windows 11 25H2 (x64)
  • OpenClaw: v2026.2.26
  • Node: v22.16.0
  • Channel: Telegram (single bot, single chat)

Steps to Reproduce

  1. Start with default dmScope (no explicit setting).
  2. Session agent:main:main is created and actively used.
  3. Change config to session.dmScope: "per-channel-peer".
  4. Restart gateway.
  5. New session agent:main:telegram:direct:<chatId> is created.
  6. Old session agent:main:main survives in the session store with its deliveryContext still pointing to the same Telegram chat.

Actual Behavior

Both sessions are active simultaneously:

  • agent:main:telegram:direct:6101296751 (per-channel-peer, correct)
  • agent:main:main (legacy, should have been removed or deactivated)

When a subagent completes (auto-announce) or a cron job delivers results, both sessions receive and forward the message, resulting in the user getting every notification twice.

Evidence from openclaw sessions --all-agents --json:

{
  "key": "agent:main:telegram:direct:6101296751",
  "updatedAt": 1772402601476,
  "model": "claude-opus-4-6-thinking"
},
{
  "key": "agent:main:main",
  "updatedAt": 1772402601461,
  "model": "gemini-3-flash"
}

Both updated at the exact same second, both delivering to the same telegram:6101296751 target.

Expected Behavior

When dmScope changes to per-channel-peer, the gateway should either:

  1. Migrate the old agent:<id>:main session to the new agent:<id>:telegram:direct:<chatId> key, OR
  2. Deactivate/remove the old session so it no longer receives or delivers messages.

Workaround

Manually delete the agent:main:main entry from agents/main/sessions/sessions.json and restart the gateway.

Additional Context

This issue is particularly disruptive because:

  • Users may not realize they have duplicate sessions until they notice repeated messages.
  • The old session continues to consume tokens (it had 111k tokens accumulated).
  • openclaw sessions cleanup does not remove the stale session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions