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.
Summary
This pull request resolves a critical bug that caused sessions to appear lost when the application was launched from a different directory than the one in which the sessions were created. It introduces a global session storage mechanism and a lazy migration strategy to seamlessly transition existing sessions without data loss.
Problem
Previously, session data was stored in a directory scoped to a
project.id, which was derived from the current working directory. This meant that if a user started the application in/project-aand created sessions, those sessions would not be visible when the application was later started in/project-a, as a partial migration had already taken place. This gave the impression that the sessions had been deleted, leading to a confusing and frustrating user experience.The issue was compounded when attempting to interact with a session from a different directory, which would result in an
ENOENT: no such file or directoryerror, as the application would look for the session file in the wrong location.Solution
This PR implements a robust, backwards-compatible solution by refactoring the session storage logic:
Global Session Storage: All new sessions are now created in a centralized
session/global/directory within the application's storage path, removing the dependency on the project's directory.Lazy Migration for Existing Sessions: To handle sessions created before this change, a lazy migration strategy has been implemented in the
get,update, andremovefunctions. When an operation is performed on a session:session/global/directory.session/<project_id>/).Backwards-Compatible Listing: The
listfunction has been updated to read sessions from both the new global directory and any existing project-specific directories, ensuring that all relevant sessions for the current context are displayed, regardless of where they are stored.Load Last Session on Startup: A client-side improvement was also included to automatically load the most recent session on application startup, improving usability.
This approach ensures that all existing data is preserved and migrated seamlessly over time, while all new data adheres to the more robust global storage model.
Testing
This fix has been manually tested by:
ENOENTerror.