Skip to content

Pi thread cannot resume after its original worktree is removed following an environment switch #3634

Closed as not planned

Description

@IlyaM

Summary

A Pi-backed BB thread can retain its original worktree in the saved Pi session after update_environment_directory moves the thread to another worktree. Once the original worktree is removed, a later turn cannot start, although BB has a valid current environment.

The thread must resume in the new environment, or fail before the environment switch is committed. It must not retain a hidden dependency on the old worktree.

Versions and environment

  • bb 0.43.0; remote Linux host, x86_64
  • Pi provider; pi 0.85.1 in RPC mode
  • BB-managed Git worktree moved to another existing Git worktree on the same host
  • Observed and retried in an existing thread. A clean, from-scratch reproduction against public main was not run.

Steps to reproduce

  1. Start a Pi-backed BB thread in a managed Git worktree, A.
  2. Create or select a second existing worktree, B, for the same repository.
  3. During a thread turn, call update_environment_directory with B. The tool reports that the change applies to future turns and stops the current turn.
  4. Remove A (or allow its managed-worktree cleanup to remove it).
  5. Send another message to the thread.

Expected vs actual

Expected: The resumed provider process and all agent tools run from B, the thread's current BB environment.

Actual: Pi opens the saved session, reads A from its session header, and rejects the turn because A no longer exists. In the affected run, BB had already recorded the alternate worktree as the thread environment before the failure.

Sanitized relevant output:

pi exited (code 1, signal null): Stored session working directory does not exist: <original worktree A>
Session file: <Pi session file>
Current working directory: <thread environment>

Before A was removed, later tool calls resolved relative paths against A, not B. This means the defect can silently operate in the wrong checkout before becoming a hard failure.

Evidence

The public BB 0.43.0 Pi-provider source both starts the child process in the supplied environment cwd and resumes the saved Pi session with --session:

Pi then reads the session header cwd and, in non-interactive mode, exits if that directory is missing rather than using the process cwd:

BB has a partial missing-cwd fallback for its own provider-session construction, but that does not update the Pi session header before the child is launched with --session:

Related issue

This is related to #3187, which reports a Pi environment-directory update that strands a tool call and then leaves later turns in the old directory. It does not report the distinct post-cleanup resume failure above. Its automated triage identifies the same stale session-cwd mechanism.

What was ruled out

  • The original session did not issue a shell command to remove its original worktree.
  • The destination worktree existed and was a valid Git worktree when BB accepted the environment change.
  • Source inspection indicates that the current Claude Code and Codex providers supply the current BB cwd separately from their resume identity. This is not an end-to-end comparison.
  • The ACP provider was not assessed.

Suggested priority and effort

High — a thread can edit the wrong checkout without an immediate error and later becomes impossible to resume after normal cleanup. Workaround: create a new provider session in the intended worktree. Likely medium effort: define and implement a durable Pi session-relocation path.

Checks

AGENT GENERATED — investigation performed in a private BB thread; no public-safe thread or report link is available.

Activity

  1. added theissue type on Sep 14, 2026
  2. added
    providers
    provider-pi
    confirmed-repro
    on Sep 14, 2026
  3. bb-slop-cop commented on Sep 14, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Bug · High priority · Medium effort. Applied providers, provider-pi, and confirmed-repro.

    Reproduction and root-cause report — REPRODUCED, high confidence. A focused regression test using the real repository-pinned Pi executable fails in two clean checkouts: BB accepts the replacement cwd but passes an unchanged session whose header points to the deleted directory. The 12 existing related tests pass, including the fake-Pi fallback test.

    No PR: durable session relocation requires a persisted-state or environment-switch policy decision outside this rule’s simple-fix limits. The full environment-switch UI journey was not exercised.

  4. SawyerHood commented on Sep 14, 2026

    @SawyerHood
    Collaborator

    Consolidated into #3187 at the owner’s request. The canonical tracker now preserves this report’s additional evidence and acceptance requirements. Closing as duplicate/covered scope, not as fixed.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproprovider-piproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions