Keep progress writes outside model deadlines

This commit is contained in:
2026-11-17 04:17:24 +00:00
parent 1bc54a405c
commit 9192239bfd
6 changed files with 75 additions and 13 deletions

View File

@@ -22,6 +22,9 @@ type CallHooks struct {
OnCall func(structuredoutput.CallRecord)
OnEvent pk.ExecutionObserver
OnEventWithCall func(uint64, structuredoutput.DiagnosticContext, pk.ExecutionEvent)
// OnProgress runs before and after the engine's timed operation. A nil
// count marks the start. A completion may have unknown execution counts.
OnProgress func(structuredoutput.DiagnosticContext, *outcomes.ExecutionCounts, error)
}
type RoleClient struct {
@@ -66,6 +69,11 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
var prepared *structuredoutput.PreparedSnapshot
var prompt structuredoutput.PromptMetadata
var record structuredoutput.CallRecord
progressContext := req.Context
progressContext.Role = c.role
if progress := c.hooks.OnProgress; progress != nil {
progress(progressContext, nil, nil)
}
if c.hooks.OnCall != nil || c.hooks.OnEventWithCall != nil {
record.CallID = c.runtime.nextCallID.Add(1)
record.RequestedPromptID = req.PromptID
@@ -115,6 +123,9 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
}
onCall(record)
}
if progress := c.hooks.OnProgress; progress != nil {
progress(progressContext, &response.Execution, err)
}
return response, err
}}
fail := func(err error) (*pendingCall, error) {