Skip to content

/new emits on_session_finalize(session_id=None) when no prior session exists #12176

@NewTurn2017

Description

@NewTurn2017

Summary

/new fires the plugin on_session_finalize hook even when there is no existing session. In that first-session path, the hook is invoked with session_id=None before the new session is created.

Affected code

  • gateway/run.py:3989-3995
  • gateway/run.py:4018-4030
  • tests/gateway/test_session_boundary_hooks.py

Why this is a bug

_handle_reset_command() always emits on_session_finalize, but it computes the payload as old_entry.session_id if old_entry else None. When the chat has no prior session entry, plugins still receive a finalize event even though nothing actually ended.

That creates a fake session-boundary event and can break plugins that assume on_session_finalize always carries a real, already-existing session ID.

Minimal reproduction

# session_store has no existing entry for this source
await runner._handle_reset_command(MessageEvent(text="/new", ...))
# observed hook calls:
# call('on_session_finalize', session_id=None, platform='telegram')
# call('on_session_reset', session_id='sess-new', platform='telegram')

Expected behavior

  • If there is no old session, /new should skip on_session_finalize and only emit on_session_reset for the newly created session.

Actual behavior

  • A finalize hook is emitted with session_id=None.

Suggested investigation

  • Guard the finalize hook behind if old_entry is not None.
  • Extend tests/gateway/test_session_boundary_hooks.py with a no-existing-session case to prevent regressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/gatewayGateway runner, session dispatch, deliverycomp/pluginsPlugin system and bundled pluginstype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions