Fix close_session final save being a guaranteed no-op#52030
Merged
Conversation
bennetbo
approved these changes
Mar 23, 2026
bennetbo
reviewed
Mar 23, 2026
close_session removed the session from the map before calling save_thread, which immediately tried to look it up via get_mut. The lookup always failed, making the final save a no-op. Fix by calling save_thread before removing the session, then returning the pending_save task so the caller awaits the DB write. Also changes pending_save from Task<()> to Task<Result<()>> to avoid an unnecessary cx.spawn wrapper in close_session.
7bf9442 to
8f9202e
Compare
AmaanBilwar
pushed a commit
to AmaanBilwar/zed
that referenced
this pull request
Mar 23, 2026
…#52030) `close_session` removed the session from `self.sessions` before calling `save_thread`, but `save_thread` immediately looks up the session in `self.sessions` and returns early if it's not found. This meant the explicit final save was always a no-op. Additionally, when the local `session` variable was dropped at the end of the closure, it cancelled any in-flight save from a prior observe callback by dropping `session.pending_save`. So on session close: - The explicit final save was a guaranteed no-op - Any in-flight save from an earlier observation was cancelled **Fix:** Call `save_thread` while the session is still in the map, then extract the `pending_save` task and return it so the caller can actually await the save completing. **Test:** Added `test_close_session_saves_thread` which sets a draft prompt without a `run_until_parked()` before `close_session`, so the only way the data gets persisted is if `close_session` itself performs the save. Also strengthened the existing `test_save_load_thread` similarly. Closes AI-95 Release Notes: - Fixed a bug where closing an agent thread could lose unsaved changes (e.g. draft prompts) made in the same frame.
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.
close_sessionremoved the session fromself.sessionsbefore callingsave_thread, butsave_threadimmediately looks up the session inself.sessionsand returns early if it's not found. This meant the explicit final save was always a no-op.Additionally, when the local
sessionvariable was dropped at the end of the closure, it cancelled any in-flight save from a prior observe callback by droppingsession.pending_save.So on session close:
Fix: Call
save_threadwhile the session is still in the map, then extract thepending_savetask and return it so the caller can actually await the save completing.Test: Added
test_close_session_saves_threadwhich sets a draft prompt without arun_until_parked()beforeclose_session, so the only way the data gets persisted is ifclose_sessionitself performs the save. Also strengthened the existingtest_save_load_threadsimilarly.Closes AI-95
Release Notes: