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.
Summary
/newfires the pluginon_session_finalizehook even when there is no existing session. In that first-session path, the hook is invoked withsession_id=Nonebefore the new session is created.Affected code
gateway/run.py:3989-3995gateway/run.py:4018-4030tests/gateway/test_session_boundary_hooks.pyWhy this is a bug
_handle_reset_command()always emitson_session_finalize, but it computes the payload asold_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_finalizealways carries a real, already-existing session ID.Minimal reproduction
Expected behavior
/newshould skipon_session_finalizeand only emiton_session_resetfor the newly created session.Actual behavior
session_id=None.Suggested investigation
if old_entry is not None.tests/gateway/test_session_boundary_hooks.pywith a no-existing-session case to prevent regressions.