Skip to content

fix(cron): mark session as ended after job completes#2998

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-2cdc8d39
Mar 25, 2026
Merged

fix(cron): mark session as ended after job completes#2998
teknium1 merged 1 commit intomainfrom
hermes/hermes-2cdc8d39

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Salvage of PR #2979 by @ygd58. Fixes #2972.

Cron was the only execution path that never called end_session(), leaving ended_at = NULL permanently. This made cron sessions invisible to hermes prune --older-than and indistinguishable from active sessions.

Bug in original PR

The original PR called _session_db.end_session() with zero arguments, but the method requires (session_id, end_reason). This would have been a silent TypeError at runtime (swallowed by the except Exception wrapper), so sessions still wouldn't get marked.

Fix

  • Captured session_id in _cron_session_id before agent construction so it's available in the finally block even if AIAgent() fails
  • Calls end_session(_cron_session_id, 'cron_complete') with proper arguments
  • Updated existing test to verify end_session is called with correct args

Test plan

All 34 cron scheduler tests pass. Live-tested with a real cron job — verified ended_at is set after completion.

Cron was the only execution path that never called end_session(),
leaving ended_at = NULL permanently. This made cron sessions invisible
to hermes prune --older-than and indistinguishable from active sessions.

Captures session_id in a local variable before agent construction so
it's available in the finally block even if AIAgent() fails, then calls
end_session(session_id, 'cron_complete') before close().

Cherry-picked from PR #2979 by ygd58. Fixed bug: original PR called
end_session() with zero arguments (TypeError — method requires
session_id and end_reason).

Fixes #2972.
@teknium1 teknium1 merged commit 650b400 into main Mar 25, 2026
1 of 2 checks passed
InB4DevOps pushed a commit to InB4DevOps/hermes-agent that referenced this pull request Mar 25, 2026
Cron was the only execution path that never called end_session(),
leaving ended_at = NULL permanently. This made cron sessions invisible
to hermes prune --older-than and indistinguishable from active sessions.

Captures session_id in a local variable before agent construction so
it's available in the finally block even if AIAgent() fails, then calls
end_session(session_id, 'cron_complete') before close().

Cherry-picked from PR NousResearch#2979 by ygd58. Fixed bug: original PR called
end_session() with zero arguments (TypeError — method requires
session_id and end_reason).

Fixes NousResearch#2972.

Co-authored-by: ygd58 <ygd58@users.noreply.github.com>
outsourc-e pushed a commit to outsourc-e/hermes-agent that referenced this pull request Mar 26, 2026
Cron was the only execution path that never called end_session(),
leaving ended_at = NULL permanently. This made cron sessions invisible
to hermes prune --older-than and indistinguishable from active sessions.

Captures session_id in a local variable before agent construction so
it's available in the finally block even if AIAgent() fails, then calls
end_session(session_id, 'cron_complete') before close().

Cherry-picked from PR NousResearch#2979 by ygd58. Fixed bug: original PR called
end_session() with zero arguments (TypeError — method requires
session_id and end_reason).

Fixes NousResearch#2972.

Co-authored-by: ygd58 <ygd58@users.noreply.github.com>
StreamOfRon pushed a commit to StreamOfRon/hermes-agent that referenced this pull request Mar 29, 2026
Cron was the only execution path that never called end_session(),
leaving ended_at = NULL permanently. This made cron sessions invisible
to hermes prune --older-than and indistinguishable from active sessions.

Captures session_id in a local variable before agent construction so
it's available in the finally block even if AIAgent() fails, then calls
end_session(session_id, 'cron_complete') before close().

Cherry-picked from PR NousResearch#2979 by ygd58. Fixed bug: original PR called
end_session() with zero arguments (TypeError — method requires
session_id and end_reason).

Fixes NousResearch#2972.

Co-authored-by: ygd58 <ygd58@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants