larry-zy commented on code in PR #1540:
URL: https://github.com/apache/dubbo-admin/pull/1540#discussion_r3912325897
##########
ai/component/agent/react/react.go:
##########
@@ -77,18 +85,30 @@ func NewReActAgent(g *genkit.Genkit, promptBasePath string,
defaultModel string,
// Interact runs one interaction asynchronously and returns immediately with
the
// Channels the caller streams from. The loop, final answer emission, and
channel
// close all happen on a background goroutine; the caller owns draining
Channels.
-func (ra *ReActAgent) Interact(input *schema.UserInput, sessionID string)
*agent.Channels {
+func (ra *ReActAgent) Interact(parent context.Context, input
*schema.UserInput, sessionID string) *agent.Channels {
chans := agent.NewChannels(ra.bufferSize)
go func() {
- ctx, s, history, err := ra.newInteraction(input, sessionID)
+ if parent == nil {
+ parent = context.Background()
+ }
+ ctx, s, err := ra.newInteraction(parent, input, sessionID)
if err != nil {
chans.ErrorChan <- err
chans.Close()
return
}
+ defer s.cancelPersistence()
if err := runLoop(ctx, s, ra.maxIterations,
ra.buildSteps(chans)...); err != nil {
Review Comment:
This cancellation path leaves a persisted active Turn behind.
`newInteraction` has already called `BeginTurn` and stored the user message,
but `runLoop` still uses the request-derived context. When the client
disconnects, a stage can return `context.Canceled`, this branch returns, and
the `NextTurnForTurn` call below is skipped. Because active Turns count toward
`max_turns`, repeated disconnected requests can exhaust the session
permanently. The detached persistence context only protects writes/finalization
reached on the success path. Please finalize or explicitly abort/delete this
Turn on every cancellation/error path (or run the interaction with a bounded
detached work context).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]