{"record":{"id":"528a4436384d49d6","repo":"chenhg5/cc-connect","slug":"start-existing-task-w","errorCode":null,"errorMessage":"start existing task: %w","messagePattern":"start existing task: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/windows.go","lineNumber":70,"sourceCode":"\t// We still write 0600 so the file's POSIX bits do not advertise read\n\t// access, and rely on the user's own profile ACLs for primary defense\n\t// (the script lives under %USERPROFILE%\\.cc-connect by default).\n\t// WriteFile only applies perm on create, so Chmod the existing file\n\t// after writing to harden reinstalls of pre-existing 0644 scripts.\n\tif err := os.WriteFile(scriptPath, []byte(buildWindowsTaskScript(cfg)), 0600); err != nil {\n\t\treturn fmt.Errorf(\"write task script: %w\", err)\n\t}\n\tif err := os.Chmod(scriptPath, 0600); err != nil {\n\t\treturn fmt.Errorf(\"chmod task script: %w\", err)\n\t}\n\n\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 {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/windows.go#L52-L88","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)."],"exampleFix":"// before: reusing a half-broken existing task\nif err := m.Start(); err != nil {\n\treturn fmt.Errorf(\"start existing task: %w\", err)\n}\n// after: uninstall stale task and reinstall cleanly\nif err := m.Uninstall(); err != nil {\n\treturn fmt.Errorf(\"clean stale task: %w\", err)\n}\nif err := createWindowsTask(scriptPath); err != nil {\n\treturn err\n}\nif err := m.Start(); err != nil {\n\treturn fmt.Errorf(\"start task: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if daemon.Installed() {\n\tif err := daemon.Uninstall(); err != nil {\n\t\t// resolve stale task before reinstalling\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := daemon.Install(scriptPath); err != nil {\n\tif strings.Contains(err.Error(), \"start existing task\") {\n\t\t_ = daemon.Uninstall()\n\t\terr = daemon.Install(scriptPath)\n\t}\n\tif err != nil { slog.Error(\"daemon install failed\", \"error\", err) }\n}","preventionTips":["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."],"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-14T05:17:10.506Z"}