mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(events): keep runtime observers non-blocking
Add a non-blocking runtime publish path and switch hot-path publishers to it. Enforce subscription timeout boundaries, keep ordered subscriber snapshots up to date on subscribe changes, expose all runtime kinds to process hooks, add safe log attrs for non-agent events, and close the gateway message bus on full shutdown.
This commit is contained in:
@@ -310,17 +310,31 @@ func (t *MCPTool) publishRuntimeEvent(
|
||||
severity = runtimeevents.SeverityError
|
||||
}
|
||||
|
||||
publishCtx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
t.runtimeEvents.Publish(publishCtx, runtimeevents.Event{
|
||||
t.runtimeEvents.PublishNonBlocking(runtimeevents.Event{
|
||||
Kind: kind,
|
||||
Source: runtimeevents.Source{Component: "mcp", Name: t.serverName},
|
||||
Scope: scope,
|
||||
Severity: severity,
|
||||
Payload: payload,
|
||||
Attrs: mcpToolCallEventAttrs(payload),
|
||||
})
|
||||
}
|
||||
|
||||
func mcpToolCallEventAttrs(payload MCPToolCallPayload) map[string]any {
|
||||
attrs := map[string]any{
|
||||
"server": payload.Server,
|
||||
"tool": payload.Tool,
|
||||
"duration_ms": payload.DurationMS,
|
||||
}
|
||||
if payload.IsError {
|
||||
attrs["is_error"] = payload.IsError
|
||||
}
|
||||
if payload.Error != "" {
|
||||
attrs["error"] = payload.Error
|
||||
}
|
||||
return attrs
|
||||
}
|
||||
|
||||
// extractContentText extracts text from MCP content array
|
||||
func extractContentText(content []mcp.Content) string {
|
||||
var parts []string
|
||||
|
||||
@@ -350,6 +350,11 @@ func TestMCPTool_Execute_PublishesRuntimeEvents(t *testing.T) {
|
||||
if payload.Server != "github" || payload.Tool != "search_repos" || payload.IsError {
|
||||
t.Fatalf("ended payload = %+v", payload)
|
||||
}
|
||||
if ended.Attrs["server"] != "github" ||
|
||||
ended.Attrs["tool"] != "search_repos" ||
|
||||
ended.Attrs["duration_ms"] == nil {
|
||||
t.Fatalf("ended attrs = %#v", ended.Attrs)
|
||||
}
|
||||
}
|
||||
|
||||
func receiveMCPToolRuntimeEvent(t *testing.T, ch <-chan runtimeevents.Event) runtimeevents.Event {
|
||||
|
||||
Reference in New Issue
Block a user