Repository navigation
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Confidence Score: 4/5
[Medium impact] The effect stays within restart’s wait for an existing run. Fix the skipped stop for live legacy runs before merging. Findings
SummaryRestart now checks local run liveness while waiting for a stop. Worker runs still use their saved status.
|
| if local { | ||
| return cli.IsRunning(ctx, dag, dagRunID), nil |
There was a problem hiding this comment.
If a run started by an older binary still answers on its legacy socket but its heartbeat has gone stale, GetCurrentStatus reports Running while IsRunning returns false. The former checks legacy socket addresses; the latter checks only the current address unless the process record is fresh. Heartbeat write failures can leave this state while the old run continues.
This makes the loop exit before calling Stop. Restart then launches another copy without even writing the old run's abort flag. Preserve the legacy-aware check, or distinguish an uncertain liveness result from a confirmed stop.
353dca7 to
b0f8e53
Compare
Restart stopped a run by reading its status file until the status was no longer running. A local run saves its final status and leaves its socket before it closes the status file, and the close replaces the file. On Windows a read at that moment finds no status, so restart failed with "no status data" right after the run aborted. For a local run, the stop loop now asks Manager.IsRunning, which counts the run as running only while its socket answers or its process record is fresh with a running status. A run on a worker is still followed through its status.
Following only Manager.IsRunning missed a live run that reads as running through its process identity alone, with no socket and a stale process record: restart skipped the stop and started the new run next to it. The stop loop reads the run's status again, and only a local run whose status cannot be read counts as stopped once IsRunning says so. The loop also sends the stop before its first check, so a run that read as running always gets one.
IsRunning counted a local run as stopped when its status could not be read, even while its process record was fresh. A running run that compacts its status file on Windows can then look stopped, and restart started the new run beside it. A stop sent while the status file was missing also failed restart outright. While a local run's status cannot be read, restart now asks whether its process record is fresh. The run releases the record only after it closes its status file. A stop that fails because the status is missing no longer ends restart; the next check decides.
A retry's missing status file made the run read as its earlier, finished attempt, which restart took as stopped while the retry still held its process record. A run known only by its PID was also taken as stopped once its status file went missing. Restart now follows the attempt it stopped: a status counts only when it is that attempt's. Otherwise the attempt runs while its process record is fresh or its process still lives, as the stale-run repair decides. The stop's error check is also written the way lint asks.
A stop goes by run ID and acts on the run's latest status. While a retry's status file was missing, restart kept sending stops, and one could find the earlier attempt failed with retries left and abort it. Restart now sends a stop only after the attempt it stopped read as running, and otherwise only waits. The process record check is behind a small interface so a test can count the checks.
50db333 to
bb9b017
Compare
Each stop restart sent looked up the run's latest attempt again, so a status file that went missing between a read and a stop could let the stop abort an earlier failed attempt. The process record check also accepted any attempt of the run, so a retry started after the stopped attempt ended kept restart waiting on a run it never stopped. Restart now sends the stop once, and again only when it did not reach the run, and checks the process record of the stopped attempt alone.
Summary
On Windows,
dagu restartcan fail right after it stops the run withfailed to stop running DAG: failed to get current status: failed to find status by dag-run ID: no status data. The stop loop re-reads the run's status file until the status is no longer running. A run replaces that file when it compacts it, and it always compacts it on close. A read during the replace on Windows finds no file, so the run's newest attempt looks empty. If the run has no earlier attempt, the read fails. If it has one, the read returns that attempt's old status. CI run 47035121113 hit this inTestProjectSettingsSkipWorkspaceLabel/ProjectsOff.Changes
no status dataafter the run aborted. After: restart waits until the attempt releases its process record, then starts the new run.Core change
A run releases its process record only after it closes its status file:
withPreparedLocalExecutionstops the proc handle afteragent.Runreturns. So while the stopped attempt's status cannot be read, a fresh record for that attempt means it is alive, and a released record means the file is closed. The saved PID covers a live run whose heartbeat went stale, asrepairStaleLocalRunIfDeaddoes.internal/cmd/restart.go:348,internal/cmd/restart.go:395Testing
TestStopDAGIfRunningUnreadableStatusfails onmainwith the same error as CI. The run answers Running on its socket until the stop arrives. Then it leaves the socket and releases its process record while its attempt has no status file.TestStopDAGIfRunningHeldRecordremoves the status file of a running attempt that holds a fresh process record. It runs once with no earlier attempt and once with an earlier attempt that failed with retries left. Restart must keep waiting until the record is released, and the earlier attempt must stayfailed.TestStopDAGIfRunningStaleHeartbeatcovers a live run with no socket and a stale record, known only by its PID. Restart must ask it to stop, keep waiting while its status file is missing, and return once it reads as aborted.TestStopDAGIfRunningNewerRetrystarts a retry after the stopped attempt ends. Restart must return once the stopped attempt releases its record.go test ./internal/cmd/passes.-race -count=3on the restart tests passes.Performance
Low risk. The loop keeps its 100 ms interval and runs only while one restart waits for one run to stop. Only while the stopped attempt's own status cannot be read does each check list the process records of the DAG's process group, one directory read. That lasts for the length of a status file replace, or until the attempt releases its record.
Out of scope
runtime.Manager.Stopby run ID. If the attempt's status file goes missing in the moment between restart's read and its one stop, the stop can still act on an earlier attempt.mainhas the same window. Closing it needs an attempt-scoped stop on the exportedManagerAPI.