Skip to content

fix(session): use session.directory instead of Instance.directory for path.cwd in messages #379

@randomm

Description

@randomm

Bug Description

Developer agents in taskctl pipelines are seeing the wrong working directory in assistant messages, causing them to correctly stop and refuse to work.

Symptoms:

  • Developer prompt says: "Your working directory: /path/.worktrees/task-name"
  • Agent runs pwd and sees: /path (main project)
  • Agent detects mismatch and stops: "WORKING DIRECTORY MISMATCH DETECTED"

Root Cause:
SessionPrompt.prompt() and compaction logic use Instance.directory for path.cwd in message creation instead of session.directory. This causes all assistant messages to report the main project directory regardless of the session's actual worktree directory.

Files Affected:

  • packages/opencode/src/session/prompt.ts - Lines 388, 613, 1575, 1665
  • packages/opencode/src/session/compaction.ts - Line 123

Fix:
Replace all instances of Instance.directory used for path.cwd with session.directory. The session object is already available in scope at all affected locations.

Quality Gates (Non-Negotiable)

  • TDD: Write tests that reproduce the bug first
  • Coverage: Tests verify worktree directory appears in messages
  • Local Verification: All tests pass locally

Acceptance Criteria

  • Developer agents see correct worktree directory in path.cwd
  • Messages reflect session.directory for all session types
  • All existing tests pass
  • New tests verify the fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions