Copilot commented on code in PR #1536:
URL: https://github.com/apache/dubbo-admin/pull/1536#discussion_r3834631640


##########
ai/component/hooks/component.go:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package hooks
+
+import (
+       "context"
+       "errors"
+       "fmt"
+       "log/slog"
+       "time"
+
+       "dubbo-admin-ai/runtime"
+
+       "go.opentelemetry.io/otel"
+       "go.opentelemetry.io/otel/attribute"
+       "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
+       "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
+       "go.opentelemetry.io/otel/propagation"
+       "go.opentelemetry.io/otel/sdk/resource"
+       sdktrace "go.opentelemetry.io/otel/sdk/trace"
+)
+
+type LoggingSpec struct {
+       Enabled bool `yaml:"enabled"`

Review Comment:
   The logging configuration exposes only `enabled`, and the registration never 
requests or emits `State.Input`/`State.Output`. As a result, the 
`logging.capture_content` capability described by this PR is rejected by the 
schema and cannot be enabled; only tracing supports the advertised opt-in 
content policy. Add the same `none`/`truncated`/`full` setting to the logging 
spec/schema and apply it when registering and formatting the logging hook.



##########
ai/component/server/engine/handlers.go:
##########
@@ -74,7 +77,18 @@ func (h *AgentHandler) StreamChat(c *gin.Context) {
                }
        }()
 
-       channels = h.agent.Interact(&schema.UserInput{Content: req.Message, 
Context: pageContext}, sessionID)
+       // The interaction can outlive the SSE request. Preserve request-scoped
+       // values (including an extracted trace context) while detaching 
cancellation
+       // and deadlines from the client connection.
+       extractedCtx := otel.GetTextMapPropagator().Extract(
+               c.Request.Context(),
+               propagation.HeaderCarrier(c.Request.Header),
+       )
+       interactionCtx := context.WithoutCancel(extractedCtx)
+       channels = h.agent.Interact(interactionCtx, &schema.UserInput{Content: 
req.Message, Context: pageContext}, sessionID)

Review Comment:
   Once cancellation is detached here, the existing panic-recovery path can no 
longer rely on request cancellation to stop the interaction. If any code after 
`Interact` panics, the handler recovers and returns without consuming these 
bounded channels; the agent can then block forever on its next send, preventing 
its end hook and shutdown drain from completing. Start the same discard drain 
from the recovery defer whenever `channels` has been created.



-- 
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]

Reply via email to