From c656fc8a10cf4a94b90a136588cfe81ee9d5415b Mon Sep 17 00:00:00 2001 From: pmorgan Date: Sun, 22 Feb 2026 11:58:03 -0700 Subject: [PATCH] Fix URL blocking in shell tool and orphaned tool result pairing Strip URLs before path detection in shell guard so schemes like https://... aren't incorrectly treated as file paths. Also fix consecutive tool results from parallel calls being dropped as orphans. Co-Authored-By: Claude Opus 4.6 --- pkg/agent/context.go | 6 +++++- pkg/tools/shell.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/agent/context.go b/pkg/agent/context.go index a9db5afdd..560162cd3 100644 --- a/pkg/agent/context.go +++ b/pkg/agent/context.go @@ -230,7 +230,11 @@ func sanitizeHistoryForProvider(history []providers.Message) []providers.Message continue } last := sanitized[len(sanitized)-1] - if last.Role != "assistant" || len(last.ToolCalls) == 0 { + // A tool result is valid if it follows either an assistant with + // tool calls, or another tool result (multiple consecutive results + // from parallel tool calls). + validPredecessor := (last.Role == "assistant" && len(last.ToolCalls) > 0) || last.Role == "tool" + if !validPredecessor { logger.DebugCF("agent", "Dropping orphaned tool message", map[string]any{}) continue } diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index a1ee0b6e1..f6d916195 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -290,8 +290,12 @@ func (t *ExecTool) guardCommand(command, cwd string) string { return "" } + // Strip URLs before path detection so schemes like https://... aren't + // treated as file paths. + cmdNoURLs := regexp.MustCompile(`[a-zA-Z][a-zA-Z0-9+.-]*://[^\s\"']+`).ReplaceAllString(cmd, "") + pathPattern := regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`) - matches := pathPattern.FindAllString(cmd, -1) + matches := pathPattern.FindAllString(cmdNoURLs, -1) for _, raw := range matches { p, err := filepath.Abs(raw)