{"record":{"id":"43b7029b7bbe95a1","repo":"chenhg5/cc-connect","slug":"start-task-w","errorCode":null,"errorMessage":"start task: %w","messagePattern":"start task: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/windows.go","lineNumber":82,"sourceCode":"\tif err := stopWindowsTask(); err != nil {\n\t\tslog.Warn(\"schtasks: stop existing task failed\", \"error\", err)\n\t}\n\tif err := deleteWindowsTask(); err != nil {\n\t\tif windowsTaskMatchesAction(scriptPath) {\n\t\t\tif err := m.Start(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"start existing task: %w\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t\treturn err\n\t}\n\n\tif err := createWindowsTask(scriptPath); err != nil {\n\t\treturn err\n\t}\n\n\tif err := m.Start(); err != nil {\n\t\treturn fmt.Errorf(\"start task: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (*schtasksManager) Uninstall() error {\n\tif err := stopWindowsTask(); err != nil {\n\t\tslog.Warn(\"schtasks: stop task failed\", \"error\", err)\n\t}\n\tif err := deleteWindowsTask(); err != nil {\n\t\treturn err\n\t}\n\tif err := os.Remove(windowsTaskScriptPath()); err != nil && !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"remove task script: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (*schtasksManager) Start() error {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/windows.go#L64-L100","documentation":"Install() on Windows wraps a failure of m.Start() after successfully creating a fresh scheduled task (createWindowsTask succeeded). It means the task was registered but Start-ScheduledTask (via startWindowsTask/runPowerShell) failed. The PowerShell error and its output are wrapped via %w.","triggerScenarios":"Calling daemon.Install on Windows when createWindowsTask succeeds but startWindowsTask fails: task immediately not found, Get-ScheduledTask returns an error state, Start-ScheduledTask rejects the request, or the PowerShell script exits non-zero.","commonSituations":"Fresh install on a machine where the task is registered but cannot be started (restricted RunLevel Limited principal conflicts, Task Scheduler service stopped, group policy blocks starting tasks, antivirus interference).","solutions":["Read the wrapped PowerShell output in the error for the exact Start-ScheduledTask failure reason.","Check the Task Scheduler service is running: `Get-Service Schedule`.","Confirm the task exists and inspect its state: `Get-ScheduledTask -TaskName <name>`.","Try starting it manually: `Start-ScheduledTask -TaskName <name>` and check `$?`/state to reproduce outside the daemon.","Uninstall and reinstall to recreate the task with a fresh principal."],"exampleFix":"// before\nif err := m.Start(); err != nil {\n\treturn fmt.Errorf(\"start task: %w\", err)\n}\n// after: log wrapped output and surface remediation hint\nif err := m.Start(); err != nil {\n\tslog.Error(\"schtasks: failed to start newly created task; try uninstall+install\", \"error\", err)\n\treturn fmt.Errorf(\"start task: %w\", err)\n}","handlingStrategy":"retry","validationCode":"out, _ := exec.Command(\"powershell\", \"-NoProfile\", \"-Command\",\n\t\"Get-ScheduledTask -TaskName '<name>' -ErrorAction SilentlyContinue\").Output()\n// task should exist after Install; verify the Schedule service is running","typeGuard":null,"tryCatchPattern":"if err := daemon.Install(scriptPath); err != nil {\n\tif strings.Contains(err.Error(), \"start task\") {\n\t\ttime.Sleep(2 * time.Second)\n\t\tif err2 := daemon.Start(); err2 != nil {\n\t\t\tslog.Error(\"task start failed\", \"error\", err2)\n\t\t}\n\t}\n}","preventionTips":["Ensure the Task Scheduler service (Schedule) is running before install.","Install from an interactive user session, not a service context.","Retry Start after a short delay; task registration can lag."],"tags":["windows","scheduled-task","daemon","process-start"],"backgroundTag":"command-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}