ALGOVIGIL
Windows / Task Scheduler

Task Scheduler Said It Was Running. It Wasn't.

netstat showed a healthy connection on the right port. There was just no fresh log file to go with it, because the connection netstat was looking at wasn't tonight's.

Four nights, same bug, same fix — and the fix finally stuck once I understood why it kept coming back.

The setup

A trading system runs several independent strategies, each with its own scheduled Windows task that launches a Python process every evening to connect to a broker and run that night's logic. One night, two of those processes quietly failed to start. Not crashed — never started at all. Task Scheduler's own status said Running. It wasn't.

The red herring

First instinct was to check whether the process was actually connected. netstat showed exactly what I expected: an established connection on the right port, talking to the right account. Looked completely healthy. Except there was no fresh log file for the night, which made no sense if the process really was running and doing its job.

The "established connection" netstat was showing wasn't tonight's process. It was a zombie — a process from four days earlier that had never actually been killed, still sitting there holding the port and the account's API connection slot open, doing absolutely nothing, logging nothing, just quietly squatting.

What was actually happening

Task Scheduler tried to launch the real process for tonight, got refused because the port and connection slot were already taken, and gave up with a genuinely unhelpful Windows error code that has nothing to do with actual permissions.

LastTaskResult : 2147946720 PS> New-Object System.ComponentModel.Win32Exception(4320) Message : The operator or administrator has refused the request. PS> Get-CimInstance Win32_Process -Filter "Name='python.exe'" | Select ProcessId, CreationDate ProcessId CreationDate 16476 2026-10-29 21:30:00 -- 4 days old. Not tonight's process.

Nothing about that error code points at a stale process. It reads like a permissions problem, which is exactly the wrong direction to go looking — the real fault was a four-day-old process nobody had noticed was still alive.

Why it took four tries to actually stick

The fix each time was the same: find and kill the zombie, manually relaunch the real process, confirm it actually connected and started logging. What made this worth writing up is that it happened four separate times before I had a reliable way to even notice it was happening, because the surface-level health check — is something listening on this port — was lying to me every time.

A dead system and a zombie-haunted one look identical from the outside unless you check how old the process actually is, not just whether it's there.

Where the line actually is

This is a different failure than what Gateway Watchdog checks for — that tool watches whether IBKR's Gateway app itself is still accepting connections, and in this case the Gateway was never the problem; it stayed up the entire time. What actually failed was the client process trying to connect into it, blocked by a stale copy of itself nobody had cleaned up. "Is the gateway alive" and "did my own process actually come up tonight" turned out to be two different questions, and I only had tooling for the first one.

Gateway Watchdog

For the adjacent problem — IBKR's Gateway or TWS app itself hanging or going dark with no crash and no error dialog. Free and open-source to run yourself; it watches the API port and logs the moment it stops answering.