picoclaw/pkg
Tong Niu 44a52c0cf6
fix(tools): close resp.Body on retry cancel and cache http.Client instances (#940)
* fix(tools): close resp.Body on retry cancel and cache http.Client instances

Fix resp.Body leak in DoRequestWithRetry where req.Body (request) was
incorrectly closed instead of resp.Body (response) on context cancel.
Cache http.Client on web search/fetch provider structs and channel
adapters (WeCom, LINE) to avoid per-call allocation overhead.

* fix(channels): preserve original http client timeouts for LINE and WeCom

Split LINE single 60s client into infoClient (10s) for bot info lookups
and apiClient (30s) for messaging API calls. Lower WeCom cached client
base timeout from 60s to 30s (matching uploadMedia), and ensure it is
always >= the configured ReplyTimeout so the per-request context
deadline remains the effective limit.

* refactor(tools): extract timeout consts and deduplicate WebFetchTool constructors

Address PR review feedback from xiaket:
- Define searchTimeout, perplexityTimeout, fetchTimeout, defaultMaxChars,
  and maxRedirects as package-level consts instead of magic numbers.
- Remove misleading "No proxy" comment in NewWebFetchTool.
- Deduplicate NewWebFetchTool by delegating to NewWebFetchToolWithProxy.

* test(utils): add context cancellation test for DoRequestWithRetry

Verify that resp.Body is properly closed when the context is canceled
during retry sleep, covering the C8 resp.Body leak fix.

* fix(utils): close resp in test to satisfy bodyclose linter

* fix(utils): eliminate flakiness in context cancellation retry test

Synchronize cancellation using an onRoundTrip callback from the
transport wrapper instead of a timing-based context timeout. This
ensures the first client.Do completes before cancel fires, so
cancellation always hits during sleepWithCtx.
2026-03-01 16:55:46 +11:00
..
agent fix(tools): close resp.Body on retry cancel and cache http.Client instances (#940) 2026-03-01 16:55:46 +11:00
auth feat: add picoclaw-launcher with web UI for configuration and gateway management (#904) 2026-02-28 18:38:38 +08:00
bus feat: Add reasoning_channel_id to communication platform configurations and improve message bus context cancellation handling. 2026-02-27 16:58:42 +08:00
channels fix(tools): close resp.Body on retry cancel and cache http.Client instances (#940) 2026-03-01 16:55:46 +11:00
config fix(config): keep empty agents.defaults.model in saved config 2026-02-28 00:18:10 +08:00
constants refactor: replace bool map with set-style map for internal channels (#472) 2026-02-19 11:48:17 +01:00
cron style: fix gci import grouping in config, cron, and skills installer 2026-02-26 20:38:11 +08:00
devices refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
fileutil refactor(pkg): move atomic file write to dedicated fileutil package 2026-02-24 23:57:13 +08:00
health refactor(channels): consolidate HTTP servers into shared server managed by Manager 2026-02-23 02:39:09 +08:00
heartbeat Merge branch 'sipeed:main' into reasoning-chnl 2026-02-27 14:50:14 +05:30
identity feat(identity): add unified user identity with canonical platform:id format 2026-02-23 06:56:48 +08:00
logger enable prealloc 2026-02-25 21:31:07 +11:00
media fix(media): separate import groups for gci linter 2026-02-26 22:45:59 +09:00
migrate Feat/update migrate (#910) 2026-02-28 19:59:17 +08:00
providers Merge pull request #824 from 0xYiliu/fix/issue-783-fallback-alias-resolution 2026-02-28 00:25:18 +08:00
routing feat(identity): add unified user identity with canonical platform:id format 2026-02-23 06:56:48 +08:00
session feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
skills fix(skills): use registry-backed search for skills discovery (#929) 2026-03-01 15:20:20 +11:00
state refactor(pkg): move atomic file write to dedicated fileutil package 2026-02-24 23:57:13 +08:00
tools fix(tools): close resp.Body on retry cancel and cache http.Client instances (#940) 2026-03-01 16:55:46 +11:00
utils fix(tools): close resp.Body on retry cancel and cache http.Client instances (#940) 2026-03-01 16:55:46 +11:00
voice feat(linter): Fix govet linter 2026-02-20 22:35:16 +02:00