Files
kandev/apps/backend/internal/worktree
José Almeida 7e938f6bdb fix(worktree): bound git ref-inspection with context timeout (#685)
* fix(worktree): bound git ref-inspection with context timeout

branchExists and currentBranch spawned raw exec.Command with no context
and no timeout, and both were called while Manager.Create held the
per-repo mutex. A hung git subprocess (credential helper, stuck filter,
filesystem stall) kept the lock in Manager.repoLocks forever, blocking
every subsequent task on the same repository until the backend was
restarted.

Route both helpers through newNonInteractiveGitCmd with a new
defaultGitInspectTimeout (10s) so ctx cancellation and bounded
deadlines propagate to the subprocess. Also log lock-hold duration on
release for future diagnosis.

* fix(worktree): address review feedback on inspect-timeout change

- branchExists/currentBranch now log the ctx error when the bound fires,
  so a hung git surfaces in logs instead of only as a misleading "branch
  not found" (CodeRabbit).
- inspectTimeout is a Manager field (defaults to defaultGitInspectTimeout)
  so tests can shrink it; added an isolation test that verifies the
  internal bound fires even when the caller ctx has no deadline (Claude).
- Route setUpstreamIfExists through newNonInteractiveGitCmd so it also
  gets non-interactive env + WaitDelay while repoLock is held (Claude).
- Simplify TestCreate_HangingRevParseReleasesRepoLock: drop redundant
  sync.WaitGroup and extract hangOnRevParseScript constant shared by all
  four tests (CodeRabbit).
2026-04-24 00:41:49 +01:00
..