Skip to content

Add turn_end hook#2592

Merged
dgageot merged 3 commits intodocker:mainfrom
rumpl:feat/turn-end-hook
Apr 29, 2026
Merged

Add turn_end hook#2592
dgageot merged 3 commits intodocker:mainfrom
rumpl:feat/turn-end-hook

Conversation

@rumpl
Copy link
Copy Markdown
Member

@rumpl rumpl commented Apr 29, 2026

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 via hooks.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 fires turn_end on every exit path. Uses context.WithoutCancel for the dispatch so handlers run to completion on Ctrl+C.

Testing: pkg/runtime/turn_end_test.go pins 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.

@rumpl rumpl requested a review from a team as a code owner April 29, 2026 10:39
rumpl added 2 commits April 29, 2026 12:41
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
@rumpl rumpl force-pushed the feat/turn-end-hook branch from 45e23a7 to 0df5837 Compare April 29, 2026 12:42
dgageot
dgageot previously approved these changes Apr 29, 2026
@dgageot
Copy link
Copy Markdown
Member

dgageot commented Apr 29, 2026

@rumpl docs update is missing, though

Assisted-By: docker-agent
@rumpl
Copy link
Copy Markdown
Member Author

rumpl commented Apr 29, 2026

Done in 41f29c9 \u2014 added turn_end to the hook types table, the per-event fields table (with the full reason taxonomy), and a new "Turn-End: per-turn finalizer" section right after Turn-Start.

@dgageot dgageot merged commit d9c5b53 into docker:main Apr 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants