Skip to content

Fix: keep the conversation when an agent changes project folder - #64

Merged
DevMando merged 1 commit into
mainfrom
fix/folder-change-keeps-conversation
Sep 10, 2026
Merged

Fix: keep the conversation when an agent changes project folder#64
DevMando merged 1 commit into
mainfrom
fix/folder-change-keeps-conversation

Conversation

@DevMando

Copy link
Copy Markdown
Owner

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

  • The conversation survives a folder change. The agent now takes the rebuild path that keeps chat history instead of the one that clears it. It still refreshes everything that has to follow the move — its instructions, its tool set, and its connected MCP servers.
  • The new folder's project skills are picked up. Skills defined in the new project are rescanned before the agent's instructions are rebuilt, so they are available immediately rather than after a restart.
  • The agent is told the folder moved. A note is added to the conversation recording the change and instructing the agent to re-read any file it needs rather than reuse paths or file contents from before the switch. Without this the history would survive but quietly go stale, with the agent reasoning about a folder that is no longer there.
  • The status message is honest about what happens. "Rebuilding the AI session for the new project" now reads "Switching to the new project — this conversation is kept."

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:

  • Cross-folder context is now a deliberate feature, not an accident. After a switch the model can still see the earlier folder's file contents in its history. The added note tells it to treat those as stale, but on a weaker model that instruction carries less weight than it would on a stronger one. The previous behavior avoided this by discarding everything, at the cost the PR is fixing.
  • Longer conversations. Keeping history across folder changes means a heavy multi-folder session accumulates context that used to be dropped. Existing compaction still applies.

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.

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.
@DevMando
DevMando merged commit 789e4fd into main Sep 10, 2026
1 check passed
@DevMando
DevMando deleted the fix/folder-change-keeps-conversation branch September 10, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant