Skip to content

Move AI chat sessions to ~/.studio/sessions#4128

Merged
bcotrim merged 10 commits into
trunkfrom
move-ai-sessions-to-studio-dir
Jul 13, 2026
Merged

Move AI chat sessions to ~/.studio/sessions#4128
bcotrim merged 10 commits into
trunkfrom
move-ai-sessions-to-studio-dir

Conversation

@bcotrim

@bcotrim bcotrim commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Implemented with Claude Code from a detailed plan (target location, migration hook point, race handling). Code, migration tests, and verification steps reviewed by me.

Proposed Changes

AI chat sessions were the last piece of Studio state still living in the Electron userData dir (~/Library/Application Support/Studio/sessions, %APPDATA%\Studio\sessions) — a historical accident: sessions shipped (#2767) just before the ~/.studio config split (#2793), and only the config JSONs moved. This PR consolidates sessions under ~/.studio/sessions, resolved via a new getSessionsDirectory() helper in well-known-paths.ts next to the other config paths.

Existing sessions are migrated by a shared Migration registered in both existing migration pipelines — the CLI's (runs as yargs middleware on every invocation) and the desktop's (runs at boot, before the main window exists) — so it covers CLI-only and desktop-only users alike. A lockfile serializes concurrent desktop + CLI first runs.

After moving the files, the migration leaves a symlink at the legacy location (a junction on Windows — no privileges needed) pointing at ~/.studio/sessions. That makes the move transparent to everything that still resolves the old path: older Studio/CLI versions running next to a newer one keep reading and writing the same store, and absolute paths persisted inside session entries (e.g. screenshot artifacts from take_screenshot) keep resolving — no session data rewriting needed. If linking fails (e.g. network-redirected %APPDATA%), the migration degrades to a self-healing merge that sweeps straggler files into the new root on every run — destination wins on collisions, cross-volume moves fall back to copy+remove. Failures are logged with home-dir-sanitized paths; success is silent like the other CLI migrations.

User impact: none visible — sessions and their screenshots keep working in both the desktop app and the CLI, from the new location, across version skew between surfaces. The E2E path overrides (E2E_APP_DATA_PATH) keep their previous semantics, and the migration is skipped under E2E/dev sandboxes so test runs can't touch real sessions. The experimental hosted backend's session path was updated to match so it keeps reading the same sessions desktop/CLI write.

Testing Instructions

  1. With existing sessions under the old location (~/Library/Application Support/Studio/sessions), run npm run cli:build && node apps/cli/dist/cli/main.mjs code sessions list — all sessions listed, files now under ~/.studio/sessions, old path is now a symlink to it (ls -l).
  2. Run it again — idempotent no-op, same list.
  3. Old-version compatibility: with the link in place, sessions written to the old path (simulating an outdated surface) land in ~/.studio/sessions, and old screenshot artifacts render in the desktop conversation view (their persisted absolute paths resolve through the link).
  4. Start the desktop app, open Studio Code — session history intact, new sessions land under ~/.studio/sessions/YYYY/MM/DD/.
  5. Fresh setup (no old dir): sessions are created directly under ~/.studio/sessions.

To revert the migration between scenarios (removes the link, then moves the sessions back so the migration runs again — bare rm refuses to delete a real directory, so it only ever removes the link):

# macOS
rm ~/Library/Application\ Support/Studio/sessions && mv ~/.studio/sessions ~/Library/Application\ Support/Studio/sessions
# Windows (PowerShell)
(Get-Item $env:APPDATA\Studio\sessions).Delete(); Move-Item ~\.studio\sessions $env:APPDATA\Studio\sessions

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@bcotrim
bcotrim marked this pull request as ready for review July 9, 2026 18:53
@bcotrim
bcotrim requested review from a team, katinthehatsite and youknowriad July 9, 2026 18:53
@wpmobilebot

wpmobilebot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 7d64694 vs trunk

app-size

Metric trunk 7d64694 Diff Change
App Size (Mac) 1350.13 MB 1419.50 MB +69.36 MB 🔴 5.1%

site-editor

Metric trunk 7d64694 Diff Change
load 1075 ms 1046 ms 29 ms ⚪ 0.0%

site-startup

Metric trunk 7d64694 Diff Change
siteCreation 7030 ms 7022 ms 8 ms ⚪ 0.0%
siteStartup 2361 ms 2375 ms +14 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@youknowriad

Copy link
Copy Markdown
Contributor

That makes sense but I didn't test. Feel free to ship after testing.

@katinthehatsite katinthehatsite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these chanegs are good to go, I reviewed the code and did not find anything concerning 👍 Claude reviewed as well and it looked good 👍

@bcotrim
bcotrim enabled auto-merge (squash) July 13, 2026 16:02
@bcotrim
bcotrim merged commit b1fda35 into trunk Jul 13, 2026
12 checks passed
@bcotrim
bcotrim deleted the move-ai-sessions-to-studio-dir branch July 13, 2026 16:38
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.

4 participants