Restore session during server restart and fix unhandled error in event routes#5707
Open
levxn wants to merge 2 commits intoaden-hive:mainfrom
Open
Restore session during server restart and fix unhandled error in event routes#5707levxn wants to merge 2 commits intoaden-hive:mainfrom
levxn wants to merge 2 commits intoaden-hive:mainfrom
Conversation
Contributor
Author
|
I am making few more edits @RichardTang-Aden , I noticed another bug, getting that fixed now. Though sessions are getting restored now, the setup fails to continue conversation from there, like resuming conversation fails, working on that now, once done I shall submit this PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#5692
Summary
Queen conversation files written to
~/.hive/queen/session/{session_id}/conversations/survive a server restart, but the server had no way to serve them afterwards.GET /api/sessions/{id}returned 404 (in-memory dict wiped),GET /api/sessions/{id}/queen-messagesrequired a live session object, and the frontend silently created a brand-new session — orphaning the on-disk history forever.This PR makes cold (post-restart) sessions first-class: the server recognises them from disk, the messages endpoint works without a live runtime, and the frontend restores history into the new session before the user sees anything.
Changes
core/framework/server/session_manager.pyAdded two static helper methods that inspect
~/.hive/queen/session/on disk without requiring a liveSessionobject in memory:get_cold_session_info(session_id)— checks whether conversation files exist for a given session ID and returns{session_id, cold: True, has_messages, created_at}, orNoneif no data is found.list_cold_sessions()— scans all subdirectories under~/.hive/queen/session/and returns them newest-first. Used by the history endpoint.No SQLite dependency added — the conversation directory itself serves as the index.
core/framework/server/routes_sessions.pyhandle_get_live_session— instead of returning 404 immediately when a session is not in memory, it now callsSessionManager.get_cold_session_info(session_id)first. If disk data exists it returns HTTP 200 with{cold: true, has_messages, created_at}. A genuinely unknown session still returns 404.handle_queen_messages— removed theresolve_session(request)live-session guard. The endpoint now derives the session directory path directly from thesession_idURL parameter and reads from disk. Works for both live and cold sessions with no behaviour change for the live case.handle_session_history(new) —GET /api/sessions/historyscans all on-disk queen session directories and returns them as a list withlive/coldflags. Live sessions (present in the in-memory dict) are markedlive: true, cold: false; everything else islive: false, cold: true. Route registered before{session_id}so it takes priority.core/frontend/src/api/types.tsAdded
cold?: booleantoLiveSessionDetailso TypeScript knows about the new field without a cast.core/frontend/src/api/sessions.tsqueenMessagesreturn type to includesession_idin the response shape.history()method forGET /api/sessions/history.core/frontend/src/pages/workspace.tsxRewrote the reconnect logic in
loadAgentForTypefor the"new-agent"path:Before:
sessionsApi.get(storedId)threw 404 → stale messages cleared → new session created → blank chat.After:
sessionsApi.get(storedId)returns{cold: true}→ server restarted, files are on disk.sessionsApi.queenMessages(oldSessionId)is called against the old cold session ID — the server reads from disk.Before / After
GET /api/sessions/{id}after restartcold: trueGET /api/sessions/{id}/queen-messagesafter restartGET /api/sessions/historyResolves issue #5692