Skip to content

Agent Mesh

address review comments

Antonio Ojead6b2c7e9ba08
diff --git a/cmd/sam-hub/main.go b/cmd/sam-hub/main.go
index ecbb6cee..7027141a 100644
--- a/cmd/sam-hub/main.go
+++ b/cmd/sam-hub/main.go
@@ -959,7 +959,11 @@ func connectBootstrap(ctx context.Context, h *Hub, peers []string) {
logger.Errorf("[Federation] HTTP Get error for %s: %v", peerStr, err)
continue
}
-
+ if resp.StatusCode != http.StatusOK {
+ logger.Errorf("[Federation] HTTP Get for %s returned status %d", peerStr, resp.StatusCode)
+ _ = resp.Body.Close()
+ continue
+ }
bodyBytes, err := io.ReadAll(resp.Body)
_ = resp.Body.Close()
if err != nil {
diff --git a/cmd/sam-node/mcp.go b/cmd/sam-node/mcp.go
index d2dbaeee..862b4b34 100644
--- a/cmd/sam-node/mcp.go
+++ b/cmd/sam-node/mcp.go
@@ -154,8 +154,8 @@ func (n *SamNode) CallMCPTool(ctx context.Context, targetPeer peer.ID, toolName
if err == nil {
return res, nil
}
- if errors.Is(err, context.DeadlineExceeded) || strings.Contains(err.Error(), "context deadline exceeded") {
- logger.Warnf("[MCP] Tool call failed with timeout, not retrying: %v", err)
+ if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) || strings.Contains(err.Error(), "context deadline exceeded") {
+ logger.Warnf("[MCP] Tool call failed with timeout or cancellation, not retrying: %v", err)
return nil, err
}
logger.Warnf("[MCP] Tool call failed, retrying in %v: %v", backoff, err)
diff --git a/cmd/sam-node/mcp_test.go b/cmd/sam-node/mcp_test.go
index 575f9da4..311ac3ff 100644
--- a/cmd/sam-node/mcp_test.go
+++ b/cmd/sam-node/mcp_test.go
@@ -136,7 +136,7 @@ func TestResolveRelayAddresses(t *testing.T) {
// Verify that the direct IP circuit address was added to the target's peerstore
addrs := localHost.Peerstore().Addrs(targetID)
foundDirect := false
- expectedDirectAddrStr := fmt.Sprintf("/ip4/10.0.0.1/tcp/4501/p2p/%s/p2p-circuit", relayID.String())
+ expectedDirectAddrStr := fmt.Sprintf("/p2p/%s/p2p-circuit", relayID.String())
for _, addr := range addrs {
if addr.String() == expectedDirectAddrStr {
@@ -146,6 +146,6 @@ func TestResolveRelayAddresses(t *testing.T) {
}
if !foundDirect {
- t.Errorf("Expected address %s not found in peerstore. Got: %v", expectedDirectAddrStr, addrs)
+ t.Errorf("Expected generic circuit address %s not found in peerstore. Got: %v", expectedDirectAddrStr, addrs)
}
}
diff --git a/cmd/sam-node/node.go b/cmd/sam-node/node.go
index 0e3eeda3..f940e982 100644
--- a/cmd/sam-node/node.go
+++ b/cmd/sam-node/node.go
@@ -1270,7 +1270,10 @@ func (n *SamNode) StartIngressServer(ctx context.Context) error {
logger.Infof("[Ingress] Forwarding to service %s, upstreamPath: %q", serviceName, upstreamPath)
if upstreamPath == "" {
- r.URL.Path = ""
+ r.URL.Path = "/"
+ if len(parts) == 2 {
+ r.Header.Set("X-Sam-No-Trailing-Slash", "true")
+ }
} else {
r.URL.Path = "/" + upstreamPath
}
diff --git a/cmd/sam-node/service.go b/cmd/sam-node/service.go
index fca3265d..09bc56b9 100644
--- a/cmd/sam-node/service.go
+++ b/cmd/sam-node/service.go
@@ -58,13 +58,11 @@ func newReverseProxyHandler(targetURL string) (http.Handler, error) {
proxy := httputil.NewSingleHostReverseProxy(u)
originalDirector := proxy.Director
proxy.Director = func(req *http.Request) {
- originalPath := req.URL.Path
+ noTrailingSlash := req.Header.Get("X-Sam-No-Trailing-Slash") == "true"
+ req.Header.Del("X-Sam-No-Trailing-Slash")
originalDirector(req)
- // httputil.NewSingleHostReverseProxy automatically appends a trailing slash
- // when joining an empty request path with a target URL. If the client requested
- // the exact base path (empty) and the target doesn't natively end in a slash, strip it.
- if originalPath == "" && !strings.HasSuffix(u.Path, "/") && strings.HasSuffix(req.URL.Path, "/") {
+ if noTrailingSlash && !strings.HasSuffix(u.Path, "/") && strings.HasSuffix(req.URL.Path, "/") {
req.URL.Path = strings.TrimSuffix(req.URL.Path, "/")
}
logger.Debugf("[ReverseProxy] Forwarding to: %q", req.URL.String())
diff --git a/cmd/sam-node/sidecar.go b/cmd/sam-node/sidecar.go
index 2092e931..02945bc4 100644
--- a/cmd/sam-node/sidecar.go
+++ b/cmd/sam-node/sidecar.go
@@ -353,7 +353,7 @@ func createEgressProxy(node *SamNode) http.Handler {
req.URL.Scheme = "libp2p"
req.URL.Host = peerID
req.Host = peerID
- if upstreamPath == "" {
+ if len(parts) == 5 {
req.URL.Path = fmt.Sprintf("/%s/%s", serviceType, serviceName)
} else {
req.URL.Path = fmt.Sprintf("/%s/%s/%s", serviceType, serviceName, upstreamPath)