Repository navigation
feat: keep assistant conversations per user in sessionStorage - #556
Merged
Merged
Conversation
|
Automatic reviews are disabled for this repository. |
|
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.



Problem
A conversation with the assistant lives only in the hook's memory, so a reload or a closed panel loses it, and a shared browser could leak one user's thread to the next.
Change
useAssistantChatloads its thread fromsessionStorageunderassistant-chat:<userId>:<projectId|general>and writes it back when a turn is appended, settles or is cleared, never on mount and never per token. Invalid entries are dropped on load, a pending answer becomescut, empty or not, so a lost answer stays visible, and the loaded copy is capped at 40 messages. A stored message whoseerror,sources,toolsUsed,checksortiminghas the wrong shape is dropped like any other invalid entry.clearAssistantHistory()removes every stored thread and bumps a module-level epoch; a hook instance whose thread was loaded under an older epoch no longer writes, so a sign-out that runs before React unmounts the panel cannot write the in-flight thread back. The unmount cleanup only aborts the request in flight.AssistantRootclears the history in its existing sign-out listener, before it closes the panel. Storage failures (QuotaExceededError, blocked storage) are caught.Verification
useAssistantChat.test.tsgains 27 newitandit.eachdeclarations (37 test cases once the tables run) andAssistantRoot.test.tsxgains 2 (2 cases); the hook file now runs 86 cases against 49 before. They cover: load and save round trip, cap, invalid entries and the shape check on the optional parts, user and project swaps while mounted, mount writes nothing, an idle conversation cleared removes its key, a clear with a token render still on its way, sign-out then unmount with a turn in flight leaves storage empty, sign-out then settle leaves it empty,QuotaExceededErrordoes not throw, blocked storage, a stored empty pending answer loads ascut, and the sign-out listener clearing before it closes. Two existing tests and twobeforeEachblocks changed: inuseAssistantChat.test.ts, thebeforeEachalso clearssessionStorage, "empties the conversation and aborts the request in flight" now also asserts the stored copy is dropped, and "aborts the request when the hook unmounts" now asserts the partial is not stored; inAssistantRoot.test.tsxthebeforeEachalso clearssessionStorage.npm run lint,npm run typecheck,npm run test:coverage(thresholds hold) and./scripts/ci/ci-local.sh fastare green.Migrations
None.
Screenshots
None, no UI change.