mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-20 23:57:11 -04:00
[PR #151] [MERGED] fix: prevent http.DefaultClient mutation in search tools #194
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/151
Author: @mason5052
Created: 2/26/2026
Status: ✅ Merged
Merged: 3/2/2026
Merged by: @asdek
Base:
feature/next_release← Head:fix/http-client-global-mutation📝 Commits (2)
e36f47ffix: prevent http.DefaultClient mutation in search toolsc716ec6test: remove unused test server and dead imports in search tool tests📊 Changes
4 files changed (+298 additions, -6 deletions)
View changed files
📝
backend/pkg/tools/tavily.go(+5 -3)➕
backend/pkg/tools/tavily_test.go(+148 -0)📝
backend/pkg/tools/traversaal.go(+5 -3)➕
backend/pkg/tools/traversaal_test.go(+140 -0)📄 Description
Description
Problem
Both
tavily.goandtraversaal.goassignhttp.DefaultClientto a local variable and then mutate itsTransportfield when configuring a proxy URL:Since
http.DefaultClientis a process-wide singleton, this creates a data race: concurrent requests from different tool instances overwrite each other's proxy configuration, and all other HTTP callers in the process inherit the mutated transport.Solution
Create a new
http.Clientinstance when proxy is configured instead of mutating the global. When no proxy is set,DefaultClientis used read-only (no mutation). This matches the correct pattern already used inbrowser.go:callScraper().Type of Change
Areas Affected
Testing
Configuration
Steps to Reproduce the Bug
http.DefaultClient.Transportis overwritten by whichever goroutine runs lastTest Results
tavily_test.go: Tests thathttp.DefaultClient.Transportis NOT mutated aftersearch()with proxy configured. Also coversIsAvailable()andparseHTTPResponse()error paths.traversaal_test.go: Same mutation guard test, plusIsAvailable()andparseHTTPResponse()success/error paths.Security Considerations
Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.