Fix: keep the conversation when an agent changes project folder - #64
Merged
Conversation
Changing a tab's project root called AIService.ReinitializeAsync, which ends in ClearHistoryAsync. That wipe is meant for model switches, where a different model mid-history really is a different conversation. A folder change is not: it is a navigation step inside one piece of work, so everything said up to that point still applies. Take the history-preserving path instead. RefreshSettingsAsync rebuilds the system prompt, the agent, and the MCP tool set exactly as Reinitialize does, and swaps the system message in place, but leaves the conversation alone — the same trade ChatController.RefreshFromConfigAsync already makes. The tools need no rebuild to follow the move: they hold the live ProjectRootAccessor that is mutated above them, not a copied path. Reload skills before refreshing, since the new folder brings its own project skills and the skill index is baked into the system prompt. Append a note to history recording the move. Without it the model keeps resolving remembered paths against a root that shifted under it — history survives but silently goes stale. The progress line is reworded to say the conversation is kept, and moves into a shared constant: the replay filter matches it verbatim, so rewording one side alone would make a stale notice reappear on every session restore.
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.
Summary
Changing an agent's project folder wiped its conversation. Everything said before the switch was gone, with no warning and no way back. The conversation is now kept across a folder change, while the agent still repoints all of its tooling at the new folder.
What was happening
Using "open folder" to point an agent at a different project rebuilt that agent's AI session from scratch, and rebuilding included clearing the chat history. In the app it looked like three status lines — project root changed, rebuilding the session, ready — after which the agent had no memory of anything discussed beforehand.
This mattered most in exactly the situation the button exists for: working across two folders in one task. A user comparing two repositories, or moving from a prototype to the real project, lost the entire conversation at the moment they switched, including any instructions or decisions established up to that point. The loss was silent and irreversible.
The clear was not a bug in isolation. It is the correct behavior when a user switches models, because a different model part-way through a history really is a different conversation. A folder change was reusing that same path and inheriting a consequence it did not need.
What changed
Scope and risk
Medium. It changes what an agent carries with it across a folder change, which affects what the model sees on its next message. Only the folder-change path is touched — switching models, matching global defaults, and starting a new agent all keep their current behavior.
Two things a reviewer should weigh:
Also worth noting: the reworded status line is matched exactly by the code that decides which messages to replay when a session is restored. Both sides now read from one shared constant so the two cannot drift, but it is the kind of coupling worth a second pair of eyes.
Verification
Desktop builds clean (0 warnings, 0 errors) and the full Desktop test suite passes — 330 of 330.
Not covered: no automated test exercises the folder-change path itself. It runs through WinUI and a live AI service, and the test project deliberately links only host-testable files, so this was not reachable from a unit test. A reviewer should manually confirm by holding a short conversation, switching the agent's folder, and asking a follow-up question that depends on what was said before the switch — then confirming file operations afterward land in the new folder.
This only helps folder changes from here on. Conversations already cleared by the old behavior are not recoverable.