Add turn_end hook#2592
Merged
dgageot merged 3 commits intodocker:mainfrom Apr 29, 2026
Merged
Conversation
Symmetric counterpart of turn_start. Fires once per turn no matter how the turn ended: normal stop, error, hook-blocked, loop-detected, max-iterations, or context cancellation. Reason is reported via hooks.Input.Reason. The runtime extracts the per-iteration body into runTurn() so a deferred dispatch fires turn_end on every exit path. Uses context.WithoutCancel so handlers run to completion on Ctrl+C. Assisted-By: docker-agent
- drop unused turnEndReasonMaxIterations (max-iterations exits before turn_start, so turn_end never fires for that path) and update doc comments accordingly - rework blockingProvider/blockingStream to capture ctx.Done()/ctx.Err() at construction time instead of stashing context.Context in a struct field (containedctx) - gci/gofumpt fixups Assisted-By: docker-agent
45e23a7 to
0df5837
Compare
dgageot
previously approved these changes
Apr 29, 2026
Member
|
@rumpl docs update is missing, though |
Assisted-By: docker-agent
Member
Author
|
Done in 41f29c9 \u2014 added |
dgageot
approved these changes
Apr 29, 2026
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.
Symmetric counterpart of
turn_start. Fires once per turn no matter how the turn ended: normal stop, error, hook-blocked, loop-detected, max-iterations, or context cancellation. Exit reason is reported viahooks.Input.Reason(normal,continue,steered,error,canceled,hook_blocked,loop_detected,max_iterations).Implementation: extract the per-iteration body into
runTurn()so a single deferred dispatch firesturn_endon every exit path. Usescontext.WithoutCancelfor the dispatch so handlers run to completion on Ctrl+C.Testing:
pkg/runtime/turn_end_test.gopins the four exit paths (normal, hook-blocked, stream error, context cancellation) plus the per-iteration count when a tool call provokes a follow-on iteration.