refactor(session): streamline tenant context handling for async operations
- Updated session title generation and message completion to utilize the session's tenant ID directly, ensuring correct context is used in background operations. - Removed unnecessary context value extraction and background context creation, simplifying the code and improving clarity. - Enhanced the handling of stop events and message updates to consistently apply the session's tenant ID, improving the accuracy of operations in shared agent scenarios. This update improves the reliability of async operations by ensuring the correct tenant context is consistently applied.
This commit is contained in:
@@ -160,6 +160,7 @@ func (h *Handler) setupStreamHandler(
|
||||
func (h *Handler) setupStopEventHandler(
|
||||
eventBus *event.EventBus,
|
||||
sessionID string,
|
||||
sessionTenantID uint64,
|
||||
assistantMessage *types.Message,
|
||||
cancel context.CancelFunc,
|
||||
) {
|
||||
@@ -167,7 +168,9 @@ func (h *Handler) setupStopEventHandler(
|
||||
logger.Infof(ctx, "Received stop event, cancelling async operations for session: %s", sessionID)
|
||||
cancel()
|
||||
assistantMessage.Content = "用户停止了本次对话"
|
||||
h.completeAssistantMessage(ctx, assistantMessage)
|
||||
// Use session's tenant for message update (ctx may have effectiveTenantID when using shared agent)
|
||||
updateCtx := context.WithValue(ctx, types.TenantIDContextKey, sessionTenantID)
|
||||
h.completeAssistantMessage(updateCtx, assistantMessage)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user