Skip to content

test(session-hygiene): include user_id on the synthetic MessageEvent - #10907

Closed
luigileap wants to merge 1 commit into
NousResearch:mainfrom
luigileap:fix/session-hygiene-user-id-guard
Closed

test(session-hygiene): include user_id on the synthetic MessageEvent#10907
luigileap wants to merge 1 commit into
NousResearch:mainfrom
luigileap:fix/session-hygiene-user-id-guard

Conversation

@luigileap

Copy link
Copy Markdown

Problem

$ python -m pytest tests/gateway/test_session_hygiene.py::test_session_hygiene_messages_stay_in_originating_topic
...
>       assert result == "ok"
E       AssertionError: assert None == 'ok'

Root cause

PR #8280 (commit cac6178, "fix(gateway): propagate user identity
through process watcher pipeline") added an early-return guard at the
top of GatewayRunner._handle_message:

elif source.user_id is None:
    logger.debug("Ignoring message with no user_id from %s", ...)
    return None

Real-world motivation: Telegram service messages, channel forwards, and
anonymous admin actions arrive without a from_user and were
triggering spurious pairing flows with user_id=None. The guard drops
them before any auth or agent work happens.

test_session_hygiene_messages_stay_in_originating_topic builds a
synthetic MessageEvent whose SessionSource has chat_id="-1001",
thread_id="17585", and no user_id. After the guard landed, the
handler returns None before reaching the mocked _run_agent (which
returns "ok"), so the assertion fails.

Fix

Set user_id="795544298" on the synthetic SessionSource — the same
numeric user the test already uses as TELEGRAM_HOME_CHANNEL. With a
valid user_id the handler clears the guard and reaches the agent path
the test is meant to exercise (session-hygiene message stays in its
originating topic).

Verification

$ python -m pytest --override-ini="addopts=" -q \
    tests/gateway/test_session_hygiene.py::test_session_hygiene_messages_stay_in_originating_topic
.                                                                        [100%]
1 passed in 0.25s

PR NousResearch#8280 (commit cac6178, "fix(gateway): propagate user identity
through process watcher pipeline") added an early-return guard in
`GatewayRunner._handle_message`:

    elif source.user_id is None:
        logger.debug("Ignoring message with no user_id from %s", ...)
        return None

This catches Telegram service messages, channel forwards, and
anonymous admin actions that previously triggered spurious pairing
flows.

`test_session_hygiene_messages_stay_in_originating_topic` built a
`SessionSource` without `user_id`, so after the guard landed the
handler returned `None` before reaching `_run_agent`, and the
assertion `assert result == "ok"` failed.

Set `user_id="795544298"` on the synthetic source — matching the
same numeric user already used as `TELEGRAM_HOME_CHANNEL` elsewhere
in the test — so the event looks like a normal authorised message
and the handler runs the agent path the test is meant to cover.
@teknium1

Copy link
Copy Markdown
Contributor

Thanks @luigileap! A user_id was added to this test's MessageEvent by another contributor before this PR could be reviewed (currently at tests/gateway/test_session_hygiene.py line 382, value "12345"). Closing as redundant — appreciate you catching the validation gap!

@teknium1 teknium1 closed this Apr 23, 2026
@alt-glitch alt-glitch added type/test Test coverage or test infrastructure P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants