fix(agent): inject user-provided value into fillForm observe results#1791
fix(agent): inject user-provided value into fillForm observe results#1791tiwalayo wants to merge 1 commit intobrowserbase:mainfrom
Conversation
The fillForm tool receives a `value` parameter but previously only used the `action` field when calling observe(). This caused the LLM to hallucinate placeholder values (e.g., "test@example.com") instead of using the actual user-provided value. This fix injects the user-provided `value` into the observe result's `arguments` array for fill operations before calling act(), ensuring the correct value is typed into form fields. Fixes browserbase#1789 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Greptile SummaryThis PR fixes a real and impactful bug where Confidence Score: 4/5
Last reviewed commit: 0e73368 |
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 3/5
- There is a concrete user-facing risk in
packages/core/lib/v3/agent/tools/fillform.ts: mapping form values by observe-result index can bind values to the wrong fill action when observe output order or count changes. - Given the reported severity (7/10) and strong confidence (8/10), this is more than a minor edge case and could cause incorrect form submissions, so the merge risk is moderate.
- Pay close attention to
packages/core/lib/v3/agent/tools/fillform.ts- index-based binding logic may misassign values when observation results are not aligned with input fields.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/core/lib/v3/agent/tools/fillform.ts">
<violation number="1" location="packages/core/lib/v3/agent/tools/fillform.ts:62">
P1: Form values are injected by observe-result index, which can misbind values to the wrong fill action when observe output ordering/count differs from input fields.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| for (let i = 0; i < observeResults.length; i++) { | ||
| const res = observeResults[i]; | ||
|
|
||
| if (res.method === "fill" && fields[i] !== undefined) { |
There was a problem hiding this comment.
P1: Form values are injected by observe-result index, which can misbind values to the wrong fill action when observe output ordering/count differs from input fields.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/lib/v3/agent/tools/fillform.ts, line 62:
<comment>Form values are injected by observe-result index, which can misbind values to the wrong fill action when observe output ordering/count differs from input fields.</comment>
<file context>
@@ -56,7 +56,13 @@ export const fillFormTool = (
+ for (let i = 0; i < observeResults.length; i++) {
+ const res = observeResults[i];
+
+ if (res.method === "fill" && fields[i] !== undefined) {
+ res.arguments = [fields[i].value];
+ }
</file context>
There was a problem hiding this comment.
This is theoretically valid but not a practical concern. The instruction sent to observe() lists actions in explicit order, and the LLM returns results corresponding to that ordered list.
The original code already had this same implicit assumption—it looped over observeResults and called act() without any correlation mechanism. This fix does not introduce a new ordering assumption.
There is no ID or correlation mechanism between fields and observe results in the existing API, so index-based matching is the only option without a larger architectural refactor, which is out of scope for this bug fix.
Summary
fillFormagent tool dropping thevalueparameter, which caused LLMs to hallucinate placeholder valuesvalueinto observe results before callingact()Problem
The
fillFormtool receives fields with bothactionandvalue:But the execute function only used
actionwhen callingobserve(), causing the LLM to guess what value to fill in. This resulted in hallucinated placeholders liketest@example.cominstead of the actual user-provided value.This bug caused flaky behavior in:
Solution
After receiving observe results, inject the user-provided
valueinto the result'sargumentsarray for fill operations:This ensures the correct value is passed to
act()rather than the LLM-hallucinated placeholder.Fixes #1789
Generated with Claude Code
Summary by cubic
Ensure fillForm uses the user-provided value by injecting it into observe results before act(), preventing hallucinated placeholders. This fixes incorrect inputs in login, search, data entry, and OTP flows.
Written for commit 0e73368. Summary will update on new commits. Review in cubic