Skip to content

fix(projects): preserve sessions when replacing a moved folder - #2473

Merged
vastsa merged 5 commits into
vastsa:mainfrom
Linuxdazhao:fix/project-folder-relocation-20261120
Nov 21, 2026
Merged

vastsa merged 5 commits into
vastsa:mainfrom
Linuxdazhao:fix/project-folder-relocation-20261120

Conversation

@Linuxdazhao

Copy link
Copy Markdown
Contributor

Fixes #2469.

Summary

  • Treat replacement of the only root in a legacy or stored single-root group as an explicit relocation through the existing Edit project flow.
  • Preserve the original project id, sessions, path-scoped memory, scheduled-task ownership, and bound workspacePath, including supported non-canonical path spellings.
  • Absorb only an empty shadow project at the replacement path. Reject a target with chats, tasks, or memory, and roll back the group and project changes together on failure.
  • Refresh the live workspace immediately when the active single-root project moves.

Multi-root detachment is unchanged: removed roots with chats remain standalone projects. No automatic move detection or non-empty project merge is introduced.

Documentation

Updated the project-group RPC contract, data-storage semantics, project-editor behavior, and E2E-PROJECT-relocate-single-root-with-existing-sessions. No schema, RPC-shape, or UI changes.

Validation

  • Baseline: all three initial relocation regressions failed before the fix.
  • cargo test -p host-core --locked db:: — 70 passed.
  • cargo test -p host-core --locked project_group_update_rpc — 3 passed.
  • node scripts/e2e-project-edit.mjs — passed.
  • pnpm build:js — passed.
  • pnpm docs:check — passed.
  • cargo fmt --all -- --check — passed.
  • pnpm check:pr-base — passed against current origin/main.
  • Independent data-safety review found no remaining issues after the scheduled-task, orphan-memory, current-project, alias-path, and live-workspace cases were addressed.

A full Host run passed 1341 tests with 1 skipped and 2 unrelated local-environment failures: the plugin snapshot sees the installed AIE application plugins, and the login-PATH probe rejects this shell's relative entry. The affected suites above pass on the latest upstream base.

The full native UI journey in the new E2E scenario remains Draft; the existing project-edit Electron probe passed.

@vastsa

vastsa commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks — the bug in #2469 is real and the transaction/rollback handling looks correct, but two gaps block landing:

  1. Sessions move off a folder that still exists. In crates/host-core/src/db/project_groups.rs, relocating_single_root is current.roots.len() == 1 && ordered.len() == 1 && primary != current_primary; it never checks that the old folder is gone. Swapping an existing folder A for an unrelated folder B in Edit project now moves A's sessions, project memory and scheduled tasks (including workspacePath, so the tasks run in B). Before this PR they stayed with A. The spec text in this PR says this applies when the project was moved externally, so please also require that the old primary no longer exists on disk (main already does a similar is_dir() check nearby), and add a test for the "old folder still exists" case.
  2. The two-step repair from [Bug] 项目所属工作区的文件夹名在外部重命名后,使用项目编辑无法切换工作区到重命名后的文件夹 #1869 still orphans sessions. Saving once with both the new and stale folders, then saving again without the stale one, goes through the roots.len() == 2 path, which skips the new relocation and detaches the old project as before. Either cover that sequence or state why it is out of scope.

Minor: the relocation switches the live workspace with st.workspace.set in rpc/mod.rs but skips the st.hashline.drop_all() that the workspace.set handler runs.

Relocation moved sessions, memory and scheduled tasks even when the
replaced folder still existed, so swapping an existing folder for an
unrelated one silently rebound its data. It now requires the old
primary to be gone from disk; otherwise the edit keeps the existing
detach semantics.

The two-step repair from vastsa#1869 (save the replacement next to the stale
root, then drop the stale root) went through the multi-root path and
still orphaned sessions. When exactly one removed root is missing and
owns data and the remaining root's project is empty, it is relocated
in the same transaction. The live workspace switch now mirrors
workspace.set, including dropping hashline state.

fixes vastsa#2469
@vastsa

vastsa commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Addressed the review in cbd0e0c (on top of your work, no force-push):

  1. Relocation now requires the old primary to be missing on disk; replacing a folder that still exists keeps the previous detach behavior (new tests for legacy and stored groups).
  2. The two-step repair ([Bug] 项目所属工作区的文件夹名在外部重命名后,使用项目编辑无法切换工作区到重命名后的文件夹 #1869) is covered: when exactly one removed root is missing and owns data, and the remaining root's project is empty, it is relocated in the same transaction. If the remaining project already has data, it falls back to the existing detach instead of rejecting, so an ordinary multi-root cleanup does not start failing.
  3. The live workspace switch now mirrors workspace.set, including hashline.drop_all(), and is keyed on the current project id.

Also merged latest origin/main.

@vastsa
vastsa merged commit 8a96c9b into vastsa:main Nov 21, 2026
6 checks passed
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.

[Bug] Replacing a moved project folder leaves sessions bound to the missing path

2 participants