Skip to content

fix(gateway): resolve TypeError in suspend_recently_active on startup - #8336

Closed
ystyleb wants to merge 1 commit into
NousResearch:mainfrom
ystyleb:fix/suspend-recently-active-type-error
Closed

fix(gateway): resolve TypeError in suspend_recently_active on startup#8336
ystyleb wants to merge 1 commit into
NousResearch:mainfrom
ystyleb:fix/suspend-recently-active-type-error

Conversation

@ystyleb

@ystyleb ystyleb commented Apr 12, 2026

Copy link
Copy Markdown

Problem

The suspend_recently_active() method in gateway/session.py fails on gateway startup with:

TypeError: '>=' not supported between instances of 'datetime.datetime' and 'float'

This error appears in logs as:

WARNING gateway.run: Session suspension on startup failed: '>=' not supported between instances of 'datetime.datetime' and 'float'

Root Cause

Introduced in commit 2d328d5c (PR #7536). The method calculates cutoff using time.time() which returns a float, then compares it with entry.updated_at which is a datetime object:

cutoff = _time.time() - max_age_seconds  # → float
if not entry.suspended and entry.updated_at >= cutoff:  # datetime >= float → TypeError

Fix

Changed the cutoff calculation to use _now() and timedelta, matching the pattern used elsewhere in the file (e.g., list_sessions()):

cutoff = _now() - timedelta(seconds=max_age_seconds)

Verification

  • The fix ensures type consistency (both are datetime objects)
  • Matches the pattern in list_sessions() method (line 928)
  • Tested locally - no TypeError on gateway restart
  • No other similar issues found in the codebase

The suspend_recently_active() method used time.time() (float) to calculate
the cutoff timestamp, then compared it with entry.updated_at (datetime object),
causing: TypeError: '>=' not supported between instances of 'datetime.datetime' and 'float'

Changed cutoff calculation from:
    cutoff = _time.time() - max_age_seconds
to:
    cutoff = _now() - timedelta(seconds=max_age_seconds)

This matches the pattern used in list_sessions() and other time comparisons
in the same file, ensuring type consistency.

Fixes the error: 'Session suspension on startup failed: ...' seen on gateway restart.
@ystyleb

ystyleb commented Apr 12, 2026

Copy link
Copy Markdown
Author

Closing — this was already fixed in commit 50d86b3 (PR #7981). The fix is identical to what I proposed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant