[Bug Report]: BrowserSearch count can exceed the documented result limit

Author: dajiaohuangCreated Aug 22, 2026Updated Aug 22, 2026

Version

@agent-infra/browser-search 0.0.5; upstream main at c2ad42e3eb9b27830db41a3e6f51ca7179d9b168

Issue Type

  • Select a issue type
  • Agent TARS Web UI (@agent-tars/web-ui)
  • Agent TARS CLI (@agent-tars/server)
  • Agent TARS Server (@agent-tars/server)
  • Agent TARS (@agent-tars/core)
  • MCP Agent (@tarko/mcp-agent)
  • Agent Kernel (@tarko/agent)
  • Other (@agent-infra/browser-search)

Model Provider

  • Select a model provider
  • Volcengine
  • Anthropic
  • OpenAI
  • Azure OpenAI
  • Other (not model-dependent)

Problem Description

BrowserSearchOptions.count is documented as the maximum result length, but BrowserSearch.perform() can return more entries than requested. The implementation requests at least three results per query with Math.max(3, ...) and returns the flattened engine results without applying the public limit.

A network-free reproduction with a mock browser whose search page returns three links:

typescript
const search = new BrowserSearch({ browser: mockBrowserReturningThreeLinks });
const results = await search.perform({
  query: 'query',
  count: 1,
  needVisitedUrls: false,
});

console.log(results.length); // 3

Expected: at most one result.

Actual: all three extracted results are returned. With multiple queries, the flattened combined results can likewise exceed the requested global maximum.

This affects callers that use count to bound downstream context and work. A minimal fix would preserve the existing per-query request behavior while capping the final flattened result array, with regression coverage for single- and multi-query searches.

Environment used for reproduction: Windows, Node.js 24.14.1. The behavior also follows directly from packages/agent-infra/search/browser-search/src/browser-search.ts on the current default branch.

Error Logs

{"requested":1,"returned":3,"urls":["https://example.com/0","https://example.com/1","https://example.com/2"]}

Source: bytedance/UI-TARS-desktop