Skip to content

Plugin: detect threads whose worktree path was removed #27

@huntharo

Description

@huntharo

Summary

Detect threads whose recorded worktree path has been removed before we resume them or start turns in that workspace.

Today a thread can still be resumed and rebound even if its cwd no longer exists on disk. The failure only shows up later when Codex tries to execute commands in that missing directory.

Related: #10

Repro

  1. Resume a thread whose cwd points at a Codex-managed worktree.
  2. Remove that worktree directory on disk.
  3. Run /codex_resume <thread> or continue using an existing binding for that thread.
  4. Ask Codex to do something that requires shell execution in the missing workspace.

Observed

  • Resume/bind appears to succeed.
  • Status/bound summary still shows the stale worktree path.
  • Shell or git operations later fail because the directory no longer exists.

Expected

  • The plugin should detect that the thread's recorded worktree path no longer exists before resuming or starting a turn in it.
  • The user should get a clear recovery message instead of discovering the problem only after tool failures.

Findings

  • /codex_resume binds the selected thread using selection.thread.projectKey / workspaceDir with no filesystem existence check first. See src/controller.ts:1048.
  • startTurn accepts workspaceDir and passes it directly into the App Server client without validating that the directory exists. See src/controller.ts:1641.
  • The App Server client uses that workspace path as cwd when starting a new thread, and otherwise resumes the thread and starts the turn without any plugin-side cwd verification. See src/client.ts:3334.
  • The existing worktree badge helper already touches the filesystem indirectly via git -C <cwd> status, but it swallows failures and returns undefined, so a missing worktree is not surfaced as a distinct stale state. See src/controller.ts:3113.

Proposed Scope

  • Detect missing cwd paths before binding/resuming a thread or starting a turn.
  • Treat missing worktree directories as a first-class stale-thread condition, not as a generic later tool failure.
  • Surface the condition in at least one of:
    • resume picker UI
    • /codex_status
    • bound conversation summary / error reply
  • Offer a clear recovery path, likely one of:
    • detach and choose another thread
    • rebind to a valid workspace
    • create a fresh worktree later under the broader worktree lifecycle work

Acceptance

  • Resuming a thread whose recorded worktree directory has been deleted does not silently proceed into later shell failures.
  • The user gets a clear explanation that the stored worktree path is gone.
  • Tests cover the stale-worktree detection path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Inbox

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions