Refactor CLI Detached Spawn Helper

Review target: GitHub pull request 1724.
Gather this target's diff with (instead of any local git diff):
gh pr view 1724 --json title,body,author,baseRefName,headRefName,state,additions,deletions,changedFiles,labelsfor contextgh pr diff 1724for the unified diff
The PR's diff is the only review scope — local working-tree changes are out of scope. When you need surrounding code, Read the files in this checkout if it matches the PR's branch, otherwise fetch file contents via gh.
Analyze the changes and provide a thorough code review that includes:
- An overview of what the PR does
- Analysis of code quality and style
- Specific suggestions for improvements
- Any potential issues or risks
Keep your review concise but thorough. Focus on:
- Code correctness
- Following project conventions
- Performance implications
- Test coverage
- Security considerations
Format your review with clear sections and bullet points.
Done. Summary:
PR feedback applied (commit 4975ded86, pushed):
- Six platform files (
telemetry/detached_{unix,windows,other}.go+trail_refresh_detached_{unix,windows,other}.go) collapsed into one portableexecx.SpawnDetached(dir, args...). Reuses existingdetachFromTTY, so no third copy ofSysProcAttrlogic. - Includes
testing.Testing()no-op guard — in-process unit tests can never fork the test binary. This closed a real pre-existing hazard: any test hittingTrackCommandDetachedwith a visible command would have re-exec'd the whole test suite detached. - Net: -238/+87 lines.
Issue refs stripped: all #450 mentions gone from code comments, test comments, failure messages, and PR body (rewrote prose to describe symptom instead). Two caveats:
- Dropped
Fixes #450from PR body per "anywhere" — issue will NOT auto-close on merge. Re-add if you want closure linkage. - Older commit messages on branch still say
#450(3aa23f49b,95dd5a550). Rewriting means force-push mid-review; squash-merge erases them anyway. Left alone.
Test duplication check: no overlap with existing suite. TestTrailEnablementCache_ReadsClonePreference covers cache read/scope/TTL; TurnStart injection tests cover consumption. The 7 new tests each assert distinct behavior (spawn seam, refresh timeout bound, exit-0, file logging, no stray logs, throttle semantics, throttle wiring). Only soft overlap: ThrottlesWithinWindow's first two assertions are implied by CollapsesBurst, but the window-boundary re-record cases are unique — keep both.
Behavior changes from the refactor (deliberate, flagging):
- Unix detach:
Setpgid→Setsid(full session detach, matchesNonInteractivesemantics — strictly stronger). - Telemetry child cwd:
/(unix) /os.TempDir()(windows) →os.TempDir()everywhere.
Verification: mise run fmt clean, golangci-lint 2.11.3 (mise binary direct, per stale-shadow note) 0 issues, go build ./... + GOOS=windows cross-build clean, full ./cmd/entire/cli/... test tree green.
Review verdict on rest of PR: solid. Detached-spawn pattern matches telemetry precedent, throttle flock keyed to git-common-dir is correct for multi-worktree, child re-checks cache before dialing, mutation-verified tests are load-bearing. One minor known quirk: throttle marker is written before the spawn attempt, so a failed os.Executable()/Start() suppresses retry for one 3s window — self-heals, not worth code.