[runner] Make the executor lifecycle explicit - #4286
Merged
Merged
Conversation
`GetJobInfo` was not a getter. It configured runner logging and resolved the job user and working dir, and `Run` called the same `preRun` again, guarded by an "already called once" check. That guard returned nil when the first call had failed -- the log file field was already set by then -- so a second call reported success with `jobUser` and `jobWorkingDir` left unset. Only `Run`'s `jobStateHistory` gate, which called this "already running or finished", kept the job from starting with those fields empty. The pair is now `Setup` and `Finalize`, with `JobInfo` as a plain accessor. `Setup` has a single caller, so the guard goes with it. `Setup` finalizes itself when it fails and `Run` finalizes when it returns, so neither the handler nor a later caller has to remember to; the `Finalize` the handler defers is a safeguard and nothing more. `Finalize` also takes over setting `WaitLogsFinished`. That used to run in a defer registered before `postRun`, and so ran before it. The stripper holds the last incomplete line until it is closed, which left the state that tells `/api/pull` its data is final published one flush early. A failed `preRun` was worse: it returned before `postRun` was deferred at all, so the buffered runner logs were never flushed and the state never became final. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetJobInfowas not a getter. It configured runner logging and resolved the job user and working dir, andRuncalled the samepreRunagain, guarded by an "already called once" check. That guard returned nil when the first call had failed -- the log file field was already set by then -- so a second call reported success withjobUserandjobWorkingDirleft unset. OnlyRun'sjobStateHistorygate, which called this "already running or finished", kept the job from starting with those fields empty.The pair is now
SetupandFinalize, withJobInfoas a plain accessor.Setuphas a single caller, so the guard goes with it.Setupfinalizes itself when it fails andRunfinalizes when it returns, so neither the handler nor a later caller has to remember to; theFinalizethe handler defers is a safeguard and nothing more.Finalizealso takes over settingWaitLogsFinished. That used to run in a defer registered beforepostRun, and so ran before it. The stripper holds the last incomplete line until it is closed, which left the state that tells/api/pullits data is final published one flush early. A failedpreRunwas worse: it returned beforepostRunwas deferred at all, so the buffered runner logs were never flushed and the state never became final.