mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #150] [MERGED] fix: treat screenshot failure as non-critical in browser tool #192
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/150
Author: @mason5052
Created: 2/26/2026
Status: ✅ Merged
Merged: 3/2/2026
Merged by: @asdek
Base:
feature/next_release← Head:fix/browser-graceful-screenshot-failure📝 Commits (1)
c68f933fix: treat screenshot failure as non-critical in browser tool📊 Changes
2 files changed (+205 additions, -10 deletions)
View changed files
📝
backend/pkg/tools/browser.go(+14 -10)📝
backend/pkg/tools/browser_test.go(+191 -0)📄 Description
Description of the Change
Problem
The browser tool's
ContentMD(),ContentHTML(), andLinks()methods run content fetch and screenshot capture concurrently. When the screenshot request fails for any reason (scraper unavailable, timeout, image too small), the entire operation returns an error -- discarding valid, successfully-fetched page content.The AI agent then receives an error like:
...and interprets the URL as unreachable, wasting tool calls on retries or fallback approaches, even though the content was sitting in memory.
Additionally,
getHTML()was using the wrong minimum content size constant (minMdContentSize= 50 bytes instead ofminHtmlContentSize= 300 bytes), accepting HTML responses that are too small to be useful.The file also mixed Go's stdlib
log.Printlnwithlogrusstructured logging used everywhere else in the codebase.Solution
Three fixes in
backend/pkg/tools/browser.go:Graceful screenshot degradation: In
ContentMD(),ContentHTML(), andLinks(), screenshot failure is now logged as a warning and the content is returned with an empty screenshot name. This is consistent withwrapCommandResult()which already ignores thePutScreenshotreturn value (_, _ = b.scp.PutScreenshot(...)).Fix getHTML() size check: Changed from
minMdContentSize(50) tominHtmlContentSize(300).Consistent logging: Replaced 3
log.Printlncalls withlogrus.WithField("url", url).Info(...)and removed the unused"log"import.Closes #149
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
newTestScraper()helper that creates anhttptest.Serversimulating the scraper service with configurable screenshot behavior ("ok", "fail", "small")TestContentMD_ScreenshotFailure_ReturnsContent-- scraper returns 500 on /screenshot, content is still returnedTestContentHTML_ScreenshotFailure_ReturnsContent-- same for HTMLTestLinks_ScreenshotFailure_ReturnsContent-- same for linksTestContentMD_ScreenshotSmall_ReturnsContent-- screenshot belowminImgContentSize, content still returnedTestContentMD_BothSucceed_ReturnsContentAndScreenshot-- happy path, both content and screenshot file verifiedTestGetHTML_UsesCorrectMinContentSize-- content of 60 bytes (> 50, < 300) is correctly rejected withminHtmlContentSizeTest Results
ContentMD/ContentHTML/Linksreturn error when screenshot fails, discarding valid contentgetHTML()accepts 60-byte HTML (passesminMdContentSizecheck)getHTML()correctly rejects content belowminHtmlContentSize(300 bytes)Security Considerations
No security impact. This change improves reliability by not discarding valid data on non-critical side-effect failure. No new dependencies or permission changes.
Performance Impact
Negligible. The only change in the success path is the addition of a warning log on screenshot failure, which is a fast operation. Content fetch performance is unchanged.
Documentation Updates
No documentation changes required. The fix is internal behavior -- the browser tool API surface remains the same.
Deployment Notes
Backward-compatible. No new environment variables or configuration changes. The only observable difference is that the browser tool now returns content even when screenshots fail, which is the expected behavior described in #149.
Checklist
Code Quality
go fmtandgo vet(for Go code)Security
Compatibility
Documentation
Additional Notes
This PR continues the browser tool hardening work from PR #120 (resource leak prevention). The
wrapCommandResult()method already treats screenshot storage as optional (_, _ = b.scp.PutScreenshot(...)), so returning content without a screenshot is consistent with the existing design intent.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.