fix: treat screenshot failure as non-critical in browser tool#150
Open
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
Open
fix: treat screenshot failure as non-critical in browser tool#150mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where the browser tool would discard successfully-fetched page content when screenshot capture fails. The fix treats screenshot failures as non-critical warnings rather than fatal errors, ensuring the AI agent receives valid content even when screenshots are unavailable.
Changes:
- Modified
ContentMD(),ContentHTML(), andLinks()to continue with empty screenshot name when screenshot capture fails, logging a warning instead of returning an error - Fixed
getHTML()to useminHtmlContentSize(300 bytes) instead ofminMdContentSize(50 bytes) for size validation - Replaced stdlib
log.Printlncalls with structuredlogrus.WithField()logging
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| backend/pkg/tools/browser.go | Implements graceful screenshot failure handling in three methods, fixes HTML size check constant, and standardizes logging to use logrus |
| backend/pkg/tools/browser_test.go | Adds comprehensive test coverage including helper function newTestScraper and 6 test cases covering screenshot failure scenarios and size validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Three fixes in browser.go: 1. ContentMD(), ContentHTML(), Links(): Screenshot failure no longer discards successfully-fetched page content. The screenshot is a non-critical side-effect (wrapCommandResult already ignores the PutScreenshot return value). When getScreenshot fails, the error is logged as a warning and the content is returned with an empty screenshot name. 2. getHTML(): Fix wrong minimum content size constant. The function was comparing against minMdContentSize (50 bytes) instead of minHtmlContentSize (300 bytes), accepting HTML responses that are too small to be useful. 3. Replace stdlib log.Println calls with logrus structured logging to match the project convention used everywhere else. Closes vxcontrol#149 Signed-off-by: mason5052 <ehehwnwjs5052@gmail.com>
d091a03 to
c68f933
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.