Skip to content

fix(gateway): tz-aware datetime compare in suspend_recent_sessions - #10397

Closed
shagarwal wants to merge 2 commits into
NousResearch:mainfrom
shagarwal:fix/session-suspension-datetime-compare
Closed

fix(gateway): tz-aware datetime compare in suspend_recent_sessions#10397
shagarwal wants to merge 2 commits into
NousResearch:mainfrom
shagarwal:fix/session-suspension-datetime-compare

Conversation

@shagarwal

Copy link
Copy Markdown

Problem

SessionStore.suspend_recent_sessions() (the startup session-suspension safety net from #7536) compared entry.updated_at (a datetime) to a float cutoff derived from time.time():

cutoff = _time.time() - max_age_seconds
...
if not entry.suspended and entry.updated_at >= cutoff:

This raised TypeError: >= not supported between instances of datetime.datetime and float on gateway startup, silently disabling the whole loop-recovery mechanism.

Impact

When a gateway restart happened mid-conversation (e.g. to stop an ignored-chat loop), in-flight sessions were blindly resumed instead of reset, resulting in apparent multi-hour hangs where the agent appeared stuck and never responded to the user.

Observed in the wild: gateway restart at 06:25, user session sat suspended-but-resumed until ~08:02, never processing queued messages.

Fix

  • Compute cutoff as a tz-aware datetime using _now() - timedelta(...)
  • Normalize entry.updated_at tzinfo to match the cutoff before comparing
  • Guard entry.updated_at is None

No behavior change when timestamps are well-formed; just stops the routine from crashing.

Extract key frames (4 evenly-spaced) and audio from user-sent videos,
run vision analysis on frames and STT on audio, then inject descriptions
into the message text before the agent processes it.

- Add _enrich_message_with_video() to gateway/run.py
- Add video cache utilities to gateway/platforms/base.py
- Add HTTP video URL caching to WhatsApp adapter
The startup session-suspension routine compared datetime.updated_at to
a float cutoff (time.time()-based), throwing TypeError and silently
disabling the loop-recovery safety net introduced in NousResearch#7536.

When a gateway restart occurred mid-session, in-flight sessions were
blindly resumed instead of reset, leading to apparent multi-hour hangs
where the agent never responded.

Fix: compute cutoff as tz-aware datetime, normalize entry.updated_at
tzinfo to match, and guard None.
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery labels Apr 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #8026 and #8129 — all fix the same TypeError comparing float vs datetime in suspend_recent_sessions(). See also #7995 and #7973.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the detailed write-up and the real-world reproduction timeline, @shagarwal! This is a valid bug report.

After reviewing main, the fix is already in place — automated hermes-sweeper review found that suspend_recently_active() on current main already uses a datetime-based cutoff:

Closing as implemented on main. The resume_pending skip guard added in cb4addaca also covers the broader stuck-resume scenario described in the impact section.

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 P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants