Merge pull request #41 from dj-oyu/fix/heartbeat-worktree-path

fix: heartbeat worktree uses stale plan dir and blocks workspace reads
This commit is contained in:
dj-oyu 2026-03-15 17:17:42 +09:00 committed by GitHub
commit 2062fe566e
2 changed files with 13 additions and 2 deletions

View file

@ -2511,10 +2511,11 @@ func (al *AgentLoop) executeToolCalls(
}) })
// Heartbeat lazy worktree: create worktree on first write-tool call // Heartbeat lazy worktree: create worktree on first write-tool call
// Always use ai.Workspace (not GetPlanWorkDir) to avoid creating worktrees
// against stale project paths from previous plans.
if opts.Background && isWriteTool(tc.Name) && !agent.IsInWorktree(opts.SessionKey) { if opts.Background && isWriteTool(tc.Name) && !agent.IsInWorktree(opts.SessionKey) {
taskName := "heartbeat-" + time.Now().Format("20060102") taskName := "heartbeat-" + time.Now().Format("20060102")
hbDir := agent.ContextBuilder.GetPlanWorkDir() if wt, wtErr := agent.ActivateWorktree(opts.SessionKey, taskName, agent.Workspace); wtErr == nil {
if wt, wtErr := agent.ActivateWorktree(opts.SessionKey, taskName, hbDir); wtErr == nil {
logger.InfoCF("agent", "Heartbeat worktree created", map[string]any{"branch": wt.Branch}) logger.InfoCF("agent", "Heartbeat worktree created", map[string]any{"branch": wt.Branch})
} }
} }

View file

@ -61,6 +61,16 @@ func resolveFS(ctx context.Context, fs fileSystem, path string) fileSystem {
return fs return fs
} }
// Absolute paths under the original workspace use original fs
// (e.g. heartbeat reading workspace files while in a worktree)
if filepath.IsAbs(path) {
if sfs, ok := fs.(*sandboxFs); ok {
if strings.HasPrefix(path, sfs.workspace+"/") || path == sfs.workspace {
return fs
}
}
}
// Only sandboxFs supports workspace override // Only sandboxFs supports workspace override
if sfs, ok := fs.(*sandboxFs); ok { if sfs, ok := fs.(*sandboxFs); ok {