fix(core): make JobResult.Finish idempotent - #491
Merged
Merged
Conversation
A job can be finished from more than one code path: an early finish inside a tool decision, followed by the regular completion. The second Finish closed the already-closed ready channel and panicked with "close of closed channel", taking the whole agent down. Finish now checks whether the ready channel is already closed (under the job lock) and returns early. The first call wins: its error is stored and its finalizers run exactly once; later calls are no-ops. Adds a regression test that finishes a job twice. Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
|
Merged into main in f2a2af4, together with the other PRs in this batch (branch |
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.
Problem
JobResult.Finishunconditionally closes thereadychannel. A job can legitimately be finished from more than one code path — an early finish inside a tool decision, followed by the regular completion of the job. The second call hitsclose(j.ready)on an already closed channel and panics withclose of closed channel, which brings the whole agent down.Reproduction
The new test
TestJobResultFinishIsIdempotentincore/types/result_finish_test.goreproduces this; it panics onmainand passes with this change.Fix
Finishis now idempotent. Under the job lock it checks whetherreadyis already closed and returns early if so. The first call wins: its error is stored, the channel is closed once, and the finalizers run exactly once. Later calls are no-ops.WaitResultand all other callers are unaffected.Testing
go test ./core/types/...— fails (panic) without the fix, passes with itgo vet ./core/types/— clean🤖 Generated with Claude Code
https://claude.ai/code/session_01PHcZ8CTpZEoK3qgroNnkB4