feat(cron): pass origin user_id to delivery mirror (send_message parity)

Multi-participant parity with interactive send_message, which passes
HERMES_SESSION_USER_ID to gateway.mirror.mirror_to_session so the mirror
lands in the exact participant's session.

- cronjob_tools._origin_from_env now captures user_id from the session
  context at job-create time (alongside platform/chat_id/thread_id).
- _maybe_mirror_cron_delivery forwards user_id to mirror_to_session.
- _deliver_result threads origin.user_id through for the origin target.

Effect: in a per-user-isolated group chat (group_sessions_per_user=True,
the default), the mirror resolves to the member who scheduled the job
instead of conservatively no-op'ing on ambiguous candidates. DMs and
shared group/thread sessions are unaffected (single candidate). Default
still OFF.

Tests: helper forwards user_id; E2E _deliver_result forwards origin
user_id. 17/17 in TestCronDeliveryMirror; 527 cron tests pass (4 failures
pre-existing: croniter-not-installed + TZ, identical on baseline).
This commit is contained in:
Victor Kyriazakos 2026-06-22 19:18:39 +03:00 committed by Teknium
parent c06ceb3232
commit 98f3c19282
3 changed files with 61 additions and 5 deletions

View file

@ -294,6 +294,12 @@ def _origin_from_env() -> Optional[Dict[str, str]]:
"chat_id": origin_chat_id,
"chat_name": get_session_env("HERMES_SESSION_CHAT_NAME") or None,
"thread_id": thread_id,
# Captured so an opt-in delivery mirror (cron.mirror_delivery /
# attach_to_session) can resolve the exact participant's session in
# per-user-isolated group chats — parity with interactive
# send_message, which passes HERMES_SESSION_USER_ID to
# gateway.mirror.mirror_to_session. Harmless for DMs/shared sessions.
"user_id": get_session_env("HERMES_SESSION_USER_ID") or None,
}
return None