← Back to PRs

#19504: fix(gateway): avoid stale running status from Windows Scheduled Task

by Fologan open 2026-02-17 21:57 View on GitHub →
gateway size: S
Fix stale 'running' reports from schtasks by validating Last Run Result (0x41301/267009) before treating runtime as active. Includes unit tests. <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR fixes a real-world bug where Windows Scheduled Tasks can report a stale `Running` status in `schtasks /Query` output even after the process has already exited. The fix validates the `Last Run Result` field against the well-known "task currently running" code (`0x41301` / `267009`) before trusting the `Running` status, and downgrades to `stopped` with a descriptive detail message when the codes don't match. Key changes: - Adds `normalizeTaskResultCode` to canonicalize both hex (`0x41301`) and decimal (`267009`) representations of result codes for reliable comparison - Adds `deriveScheduledTaskRuntimeStatus` (exported and unit-tested) to encapsulate the stale-state logic, replacing the previous one-liner in `readScheduledTaskRuntime` - `readScheduledTaskRuntime` now spreads `derived.detail` into its return value when the stale condition is detected, giving callers visibility into why status was overridden - Three new unit tests cover the hex, decimal, and stale-detection paths <h3>Confidence Score: 5/5</h3> - This PR is safe to merge; it tightens a runtime status check without altering any installation, scheduling, or process-management logic. - The change is narrowly scoped: it adds a new exported pure function and reroutes a single-line status derivation through it. The normalization logic correctly handles both hex and decimal input, and the fallback when `lastRunResult` is absent (trusting "Running") is sound. The only gap is a missing test for the `Running` + no-`lastRunResult` case, which is a minor coverage concern rather than a correctness risk. - No files require special attention; `src/daemon/schtasks.test.ts` could benefit from one additional edge-case test. <sub>Last reviewed commit: 77f901a</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs