Skip to content

fix: file explorer not switching workdir on session change - #37

Merged
saucam merged 1 commit into
mainfrom
fix/file-explorer-session-switch
Jun 26, 2026
Merged

fix: file explorer not switching workdir on session change#37
saucam merged 1 commit into
mainfrom
fix/file-explorer-session-switch

Conversation

@saucam

@saucam saucam commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Three bugs in the file-tree state when switching sessions in the web UI:

1. resetFileTreeForSession was a no-op (SolidJS merge bug)
setState("bySession", id, {}) uses SolidJS's path-setter with a plain-object argument, which performs a merge (not a replace). Since the merged object is empty, the old session's entries were never cleared — memory wasn't reclaimed and the old session's tree state persisted indefinitely.

Fixed by using produce() (immer-style assignment) to do an actual replacement.

2. Stale entries shown without a loading indicator on session switch
loadDirectory sets loading: true but does not clear existing entries. The loading indicator condition is loading && entries === null, so if stale entries existed (from a previous visit), no spinner appeared. The user saw the old session's file listing while the new fetch was in-flight.

Fixed by adding a clearFirst?: boolean option to loadDirectory. When clearFirst: true, entries are cleared before the request so the loading… spinner always appears. Used in the FileTree effect on every session switch.

3. No workdir path shown in the FileTree header
The header displayed "Files" without indicating which session's working directory was shown. Users couldn't confirm the tree had switched sessions.

Fixed by adding the current session's workdir below the header (truncated with full path on hover).

Test plan

  • web/src/state/files.test.ts (9 new tests): loadDirectory with/without clearFirst, resetFileTreeForSession clears state
  • Full web test suite: 104 tests pass
  • Daemon test suite: 504 tests pass
  • TypeScript type check: no errors
  • ESLint: no errors

Closes #36

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • The file tree now shows the current working directory in the sidebar when a session is selected.
    • Switching sessions now refreshes the root folder with a clearer loading state.
  • Bug Fixes

    • File tree contents no longer linger briefly from a previous session while new data is loading.
    • Session changes now reset file tree state more reliably, improving consistency across views.

Three bugs in the file-tree state on session switch:

1. resetFileTreeForSession used `setState("bySession", id, {})` which is
   a SolidJS merge (no-op) — the old session's entries were never cleared,
   so stale data persisted and memory wasn't reclaimed.
   Fixed by using produce() to perform a real replacement.

2. loadDirectory on session switch kept stale entries visible while the
   new fetch was in-flight (loading indicator only fires when entries===null).
   Added clearFirst option that wipes entries before the request, ensuring
   the "loading…" indicator always appears on session switch.

3. FileTree header showed "Files" with no workdir path, so after switching
   sessions the user couldn't tell which session's directory was shown.
   Added a workdir label under the header that updates with focusedSession.

Closes #36

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 782ab61c-8a4e-4139-a006-5b9f0bff3bb3

📥 Commits

Reviewing files that changed from the base of the PR and between 5bc05ec and f83f0b5.

📒 Files selected for processing (3)
  • web/src/components/files/FileTree.tsx
  • web/src/state/files.test.ts
  • web/src/state/files.ts

📝 Walkthrough

Walkthrough

The file tree now reloads the focused session root with explicit clearing, shows the active workdir in the header, and the file-tree store and tests support the new clear-first loading and reset behavior.

Changes

File tree session refresh

Layer / File(s) Summary
Store loading and reset behavior
web/src/state/files.ts
loadDirectory now accepts clearFirst, clears entries and expanded before reload, and session reset replaces the per-session node map.
Session switch UI
web/src/components/files/FileTree.tsx
The focused-session effect reloads the root directory with clearFirst: true, and the header renders workdir in a truncated monospace line.
State tests
web/src/state/files.test.ts
Vitest coverage exercises stale-entry clearing, successful reloads, session isolation, and session reset behavior.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the session-switch/workdir bug fixed by the PR.
Linked Issues check ✅ Passed The changes implement the linked session-switch fix: clear-first loading, workdir header, and state reset cleanup.
Out of Scope Changes check ✅ Passed The edits stay within the file-explorer/session-switch fix and its tests, with no unrelated feature work.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/file-explorer-session-switch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.69%. Comparing base (5bc05ec) to head (f83f0b5).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #37   +/-   ##
=======================================
  Coverage   59.69%   59.69%           
=======================================
  Files          47       47           
  Lines        7255     7255           
=======================================
  Hits         4331     4331           
  Misses       2924     2924           
Flag Coverage Δ
daemon 59.69% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@saucam
saucam merged commit 6a082a4 into main Jun 26, 2026
5 checks passed
@saucam saucam mentioned this pull request Jun 28, 2026
saucam added a commit that referenced this pull request Jun 28, 2026
Patch release rolling up six fixes/doc changes since v0.1.1:

- file explorer switches workdir on session change (#37)
- interrupted tool calls marked cancelled, not failed (#35)
- writeBatch guarded against in-flight streams; no TUI double-print (#33)
- TUI reconnects + re-mints token on JWT expiry (#34)
- Telegram /attach disconnects old session before switching (#29)
- richer README badges (#27)

Bumps package.json to 0.1.2 so the release.yml tag check passes, and
backfills the previously-undocumented 0.1.1 entry in the CHANGELOG.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

fix: file explorer doesn't update on session switch

1 participant