Repository navigation
fix: keep balanced trailing brackets in URLs extracted from task text - #5576
Merged
sauravpanda merged 3 commits intoAug 29, 2026
Merged
sauravpanda merged 3 commits into
sauravpanda merged 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
sanitize_url_candidate() strips trailing prose punctuation so that "Go to https://example.com/docs." does not navigate with the sentence's period attached. It also stripped every trailing ) and ], including the ones the URL opened itself, so a task like Summarize https://en.wikipedia.org/wiki/Python_(programming_language) auto-navigated to .../Python_(programming_language and landed on the wrong page. Wikipedia disambiguation links are the common case. Whether the bracket belongs to the URL is decided by balance: a closing bracket with a matching opener inside the candidate is part of the path, while one the prose opened, as in "(see https://example.com/guide)", is not. Strip trailing punctuation as before, and only drop a closing bracket when the candidate has more of them than openers. Fixes browser-use#5575
The trimming loop counted brackets across the whole candidate on every iteration, so a candidate ending in many unmatched brackets rescanned it once per bracket. 50,000 trailing ')' took 0.9s, where the regex this replaced was linear. Count the four bracket characters once and decrement as characters are trimmed, tracking the end index instead of reslicing. Same results, and 200,000 trailing ')' now takes 0.011s.
aniketwaghh
force-pushed
the
fix_url_trailing_bracket_truncation
branch
from
August 28, 2026 04:20
3290a65 to
3c565af
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.
Fixes #5575
What was wrong
sanitize_url_candidate()drops trailing prose punctuation so that "Go to https://example.com/docs." does not navigate with the sentence's period attached. It did that with a single character class:which also strips closing brackets the URL opened itself.
Agent._extract_start_url()runs every URL it finds in the task through this before auto-navigating, so:navigated to
https://en.wikipedia.org/wiki/Python_(programming_languageand landed on the wrong page. Wikipedia disambiguation links are the common shape.The fix
Whether a trailing bracket belongs to the URL is a question of balance.
.../Python_(programming_language)closes a bracket the URL opened, so it is part of the path. In "See the docs (https://example.com/guide)" the prose opened it, so dropping it stays correct. The loop strips trailing punctuation as before and only drops a closing bracket when the candidate has more closers than openers.Before and after
Summarize https://en.wikipedia.org/wiki/Python_(programming_language)...Python_(programming_language...Python_(programming_language)Check https://example.com/a[1] pleasehttps://example.com/a[1https://example.com/a[1]Go to https://example.com/docs. Then stop.https://example.com/docshttps://example.com/docsSee the docs (https://example.com/guide) for details.https://example.com/guidehttps://example.com/guideThe last two rows are the behaviour that had to be preserved: a sentence period is still dropped, and a bracket the prose opened is still dropped.
Bracket totals are counted once and decremented while trimming, with an end index instead of reslicing, so a candidate ending in a long run of brackets stays linear like the regex it replaces. 200,000 trailing
)takes 0.011s.Testing
Added assertions to
test_beta_agent_exposes_task_helper_methods, next to the existing_extract_start_urlcases, covering both directions: the bracket the URL opened is kept, the one the prose opened is not. They fail onmainand pass here.Full
tests/ci, before and after, on the same machine:The two failures are pre-existing and unrelated, both in
test_beta_agent.py(test_beta_agent_constructor_type_hints_match_browser_use_core_paramsandtest_beta_agent_initializes_tools_and_action_models,Toolsclass-identity assertions). They fail identically on a clean tree. I also diffed the skipped-test lists between the two runs and they are identical, so nothing changed state.No new warnings.