-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(resume): preserve checkpoints after Ctrl-C #902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lizhengfeng101
merged 2 commits into
alibaba:main
from
Gongyl01:fix/resume-after-interrupt
Aug 14, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -606,6 +606,7 @@ func (a *Agent) dispatchSubtasks(ctx context.Context) ([]model.LlmComment, error | |||||||||||||||||||||||||||||||||||||
| timeout := time.Duration(a.args.ConcurrentTaskTimeout) * time.Minute | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| var dispatched int64 | ||||||||||||||||||||||||||||||||||||||
| dispatchLoop: | ||||||||||||||||||||||||||||||||||||||
| for i := range toDispatch { | ||||||||||||||||||||||||||||||||||||||
| if toDispatch[i].IsDeleted { | ||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -655,9 +656,17 @@ func (a *Agent) dispatchSubtasks(ctx context.Context) ([]model.LlmComment, error | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| select { | ||||||||||||||||||||||||||||||||||||||
| case sem <- struct{}{}: // acquire semaphore | ||||||||||||||||||||||||||||||||||||||
| case <-ctx.Done(): | ||||||||||||||||||||||||||||||||||||||
| break dispatchLoop | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if ctx.Err() != nil { | ||||||||||||||||||||||||||||||||||||||
| <-sem // release the slot acquired concurrently with cancellation | ||||||||||||||||||||||||||||||||||||||
| break dispatchLoop | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| dispatched++ | ||||||||||||||||||||||||||||||||||||||
| wg.Add(1) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+659
to
669
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| sem <- struct{}{} // acquire semaphore | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| go func(d model.Diff) { | ||||||||||||||||||||||||||||||||||||||
| fingerprint := reviewItemFingerprint(a.reviewMode(), d) | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -731,15 +740,18 @@ func (a *Agent) dispatchSubtasks(ctx context.Context) ([]model.LlmComment, error | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| wg.Wait() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if dispatched == 0 { | ||||||||||||||||||||||||||||||||||||||
| return a.args.CommentCollector.Comments(), nil | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // All subtasks finished — collect comments from the global collector once. | ||||||||||||||||||||||||||||||||||||||
| if a.args.CommentWorkerPool != nil { | ||||||||||||||||||||||||||||||||||||||
| a.args.CommentWorkerPool.Await() | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if ctxErr := ctx.Err(); ctxErr != nil { | ||||||||||||||||||||||||||||||||||||||
| a.recordContextFailure(ctxErr) | ||||||||||||||||||||||||||||||||||||||
| return a.args.CommentCollector.Comments(), ctxErr | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if dispatched == 0 { | ||||||||||||||||||||||||||||||||||||||
| return a.args.CommentCollector.Comments(), nil | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| failed := atomic.LoadInt64(&a.subtaskFailed) | ||||||||||||||||||||||||||||||||||||||
| reused := int64(0) | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -756,6 +768,22 @@ func (a *Agent) dispatchSubtasks(ctx context.Context) ([]model.LlmComment, error | |||||||||||||||||||||||||||||||||||||
| return a.args.CommentCollector.Comments(), nil | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| func (a *Agent) recordContextFailure(err error) { | ||||||||||||||||||||||||||||||||||||||
| if b := a.session.Manifest(); b != nil { | ||||||||||||||||||||||||||||||||||||||
| var setErr error | ||||||||||||||||||||||||||||||||||||||
| if errors.Is(err, context.DeadlineExceeded) { | ||||||||||||||||||||||||||||||||||||||
| // A deadline truncates pending coverage without overriding completed items. | ||||||||||||||||||||||||||||||||||||||
| setErr = b.SetPendingFailureCause(session.FailureTimeout, "review deadline exceeded") | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| // Explicit cancellation stops the run itself, not just its pending items. | ||||||||||||||||||||||||||||||||||||||
| setErr = b.SetRunFailure(session.RunFailureCancelled, "review was cancelled") | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if setErr != nil { | ||||||||||||||||||||||||||||||||||||||
| a.recordWarning("manifest_error", "", setErr.Error()) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| func (a *Agent) applyResume(diffs []model.Diff) []model.Diff { | ||||||||||||||||||||||||||||||||||||||
| resume := a.args.Resume | ||||||||||||||||||||||||||||||||||||||
| if resume == nil { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I’d prefer not to restore default SIGINT handling before graceful cancellation has written session_end and the manifest, because a second Ctrl-C could otherwise leave the session non-resumable. Forced termination would be better handled separately with an explicit warning.