chenhg5/cc-connect · error
start existing task: %w
Error message
start existing task: %w
What it means
Install() on Windows wraps a failure from m.Start() when an existing scheduled task could not be deleted (deleteWindowsTask returned an error, but its action matched the script, so the code tried to reuse it). It means the schtasks task exists and matches this installation, but Start-ScheduledTask failed. The underlying PowerShell error and output are wrapped via %w.
Source
Thrown at daemon/windows.go:70
// We still write 0600 so the file's POSIX bits do not advertise read
// access, and rely on the user's own profile ACLs for primary defense
// (the script lives under %USERPROFILE%\.cc-connect by default).
// WriteFile only applies perm on create, so Chmod the existing file
// after writing to harden reinstalls of pre-existing 0644 scripts.
if err := os.WriteFile(scriptPath, []byte(buildWindowsTaskScript(cfg)), 0600); err != nil {
return fmt.Errorf("write task script: %w", err)
}
if err := os.Chmod(scriptPath, 0600); err != nil {
return fmt.Errorf("chmod task script: %w", err)
}
if err := stopWindowsTask(); err != nil {
slog.Warn("schtasks: stop existing task failed", "error", err)
}
if err := deleteWindowsTask(); err != nil {
if windowsTaskMatchesAction(scriptPath) {
if err := m.Start(); err != nil {
return fmt.Errorf("start existing task: %w", err)
}
return nil
}
return err
}
if err := createWindowsTask(scriptPath); err != nil {
return err
}
if err := m.Start(); err != nil {
return fmt.Errorf("start task: %w", err)
}
return nil
}
func (*schtasksManager) Uninstall() error {
if err := stopWindowsTask(); err != nil {View on GitHub (pinned to 4000b2338a)
Solutions
- Uninstall first (`cc-connect daemon uninstall` or delete the task in Task Scheduler) and then run Install again to create a fresh task.
- Inspect the wrapped error output (schtasks/PowerShell message) for the concrete cause (not found, access denied, policy block).
- Run the terminal as the same (or elevated) user that owns the task; check Task Scheduler for a disabled or broken task entry.
- Verify PowerShell script execution policy allows the generated command (Get-ExecutionPolicy).
Example fix
// before: reusing a half-broken existing task
if err := m.Start(); err != nil {
return fmt.Errorf("start existing task: %w", err)
}
// after: uninstall stale task and reinstall cleanly
if err := m.Uninstall(); err != nil {
return fmt.Errorf("clean stale task: %w", err)
}
if err := createWindowsTask(scriptPath); err != nil {
return err
}
if err := m.Start(); err != nil {
return fmt.Errorf("start task: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if daemon.Installed() {
if err := daemon.Uninstall(); err != nil {
// resolve stale task before reinstalling
}
} Try / catch
if err := daemon.Install(scriptPath); err != nil {
if strings.Contains(err.Error(), "start existing task") {
_ = daemon.Uninstall()
err = daemon.Install(scriptPath)
}
if err != nil { slog.Error("daemon install failed", "error", err) }
} Prevention
- Always run uninstall before reinstall to avoid the stale-task reuse path.
- Check task state in Task Scheduler before installing.
- Keep installs/uninstalls under the same Windows user account.
When it happens
Trigger: Calling daemon.Install on Windows when: (1) Unregister-ScheduledTask fails (task in use, permissions), and (2) windowsTaskMatchesAction confirms the task already points at this scriptPath, and (3) Start() -> startWindowsTask -> runPowerShell returns an error (task not found, Start-ScheduledTask failure, timeout exit).
Common situations: Reinstalling/re-running `cc-connect daemon install` while the task exists but is in a bad state; task registered under a different user; PowerShell execution blocked by policy; the task is disabled or corrupt in Task Scheduler.
Related errors
- start task: %w
- start scheduled task: %s (%w)
- systemd user session not available in WSL2. Add the follow
- powershell.exe not found: Windows Task Scheduler management
- create data dir: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/528a4436384d49d6.
Report an issue: GitHub.