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 <noreply@anthropic.com>
This commit is contained in:
pmorgan 2026-02-22 11:58:03 -07:00
parent 65cc670df6
commit c656fc8a10
2 changed files with 10 additions and 2 deletions

View file

@ -230,7 +230,11 @@ func sanitizeHistoryForProvider(history []providers.Message) []providers.Message
continue continue
} }
last := sanitized[len(sanitized)-1] 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{}) logger.DebugCF("agent", "Dropping orphaned tool message", map[string]any{})
continue continue
} }

View file

@ -290,8 +290,12 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
return "" 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\"']+`) pathPattern := regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`)
matches := pathPattern.FindAllString(cmd, -1) matches := pathPattern.FindAllString(cmdNoURLs, -1)
for _, raw := range matches { for _, raw := range matches {
p, err := filepath.Abs(raw) p, err := filepath.Abs(raw)