Skip to content

Recover deleted session working directories - #375

Merged
yottadynamics merged 3 commits into
mainfrom
worktree-lively-running-yak
Oct 3, 2026
Merged

yottadynamics merged 3 commits into
mainfrom
worktree-lively-running-yak

Conversation

@yottadynamics

@yottadynamics yottadynamics commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

Recover gracefully when the session's working directory is deleted or removed, such as when an active worktree is cleaned up externally.

Cwd recovery is centralized at tool dispatch and remains session-local. It updates the shared CwdRef, emits one CwdChanged event with recovery details, and prevents mutating tools from silently executing in the fallback directory. Read-only tools continue using explicit session cwd paths. Recovery does not call process-global os.Chdir, avoiding cross-session cwd races.

Related issue

Not linked.

How was this tested?

  • go test -race ./internal/agent ./internal/tui
  • go test ./...
  • go vet ./...
  • LSP diagnostics for changed source files

All passed.

Checklist

  • go test ./... passes
  • go vet ./... is clean
  • govulncheck ./... reports no reachable vulnerabilities
  • Tests added or updated — deleted-cwd recovery, event deduplication, read-only continuation, and mutation refusal
  • Docs updated in the same change if behavior or surface changed — no user-facing documentation changes required
  • PR is focused on one logical change

Drafted with yottacode


Drafted with yottacode

yottacode contributor and others added 2 commits October 2, 2026 23:35
Co-authored-by: yottacode <325888353+yottacode-agent@users.noreply.github.com>
Co-authored-by: yottacode <325888353+yottacode-agent@users.noreply.github.com>
@yottadynamics

Copy link
Copy Markdown
Owner Author

Follow-up fixes applied:

  • Removed global os.Chdir from cwd recovery to avoid cross-session/process cwd races.
  • Recovery now distinguishes missing directories from other stat failures.
  • Stable fallback state remains synchronized.
  • Recovery now occurs after ToolStart and emits CwdChanged after ToolResult, preserving the tool lifecycle contract.
  • Mutating tools remain blocked after recovery; read-only tools continue from the recovered session cwd.

Verification: go test -race ./internal/agent ./internal/tui, go test ./..., and go vet ./... all pass.

Co-authored-by: yottacode <325888353+yottacode-agent@users.noreply.github.com>
@yottadynamics

Copy link
Copy Markdown
Owner Author

Additional correctness fix pushed in 2300d2b:

  • Recovery no longer changes the process-global cwd; it only updates the session-local CwdRef.
  • Set no longer destroys the stable fallback after a temporary/failed target transition.
  • The fallback recovery behavior remains covered by the existing tests.

Verification passed: go test ./internal/agent ./internal/tui, go test -race ./internal/agent ./internal/tui, go test ./..., go vet ./..., and clean LSP diagnostics for internal/agent/cwd.go.

@yottadynamics
yottadynamics merged commit 25fcd86 into main Oct 3, 2026
7 checks passed
@yottadynamics
yottadynamics deleted the worktree-lively-running-yak branch October 3, 2026 15:47
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