Conversation
# why # what changed # test plan <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add level-0 logging when the LLM returns an element ID with no matching xpath and handle these cases gracefully in act and observe. Implements STG-1209 to improve debuggability and prevent invalid element IDs from propagating. - **Bug Fixes** - actHandler: log with category "action" when no xpath exists for the returned elementId; act() now fails gracefully with success: false and a clear message. - observeHandler: log with category "observation" and filter out elements whose IDs are missing from the xpath map. - Tests: added xpath-lookup-failure-logging.test to verify logging, act() failure behavior, and observe() filtering (including multiple missing IDs). <sup>Written for commit 80b6b94. Summary will update on new commits. <a href="https://cubic.dev/pr/browserbase/stagehand/pull/1640">Review in cubic</a></sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Chromie Bot <chromie@browserbase.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 50bd18c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile OverviewGreptile Summary
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
autonumber
actor User
participant ActHandler
participant ObserveHandler
participant Snapshot as captureHybridSnapshot
participant LLM as inference(act/observe)
participant Log as v3Logger
User->>ActHandler: act(instruction, page)
ActHandler->>Snapshot: captureHybridSnapshot(page)
Snapshot-->>ActHandler: combinedTree + combinedXpathMap
ActHandler->>LLM: actInference(domElements, instruction)
LLM-->>ActHandler: element.elementId
ActHandler->>ActHandler: normalizeActInferenceElement(elementId)
alt elementId missing from xpath map
ActHandler->>Log: level 0 "LLM returned ID ... no xpath keyed ..."
ActHandler-->>User: { success:false, message:"Failed to perform act: No action found" }
else xpath found
ActHandler-->>User: performUnderstudyMethod(...)
end
User->>ObserveHandler: observe(instruction, page)
ObserveHandler->>Snapshot: captureHybridSnapshot(page)
Snapshot-->>ObserveHandler: combinedTree + combinedXpathMap
ObserveHandler->>LLM: observeInference(domElements, instruction)
LLM-->>ObserveHandler: elements[] (elementId...)
loop each element
ObserveHandler->>ObserveHandler: lookup elementId in combinedXpathMap
alt elementId missing from xpath map
ObserveHandler->>Log: level 0 "LLM returned ID ... no xpath keyed ..."
ObserveHandler->>ObserveHandler: drop element
else xpath found
ObserveHandler->>ObserveHandler: return Action with selector=xpath=...
end
end
ObserveHandler-->>User: Action[] (filtered)
|
Additional Comments (1)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
There was a problem hiding this comment.
No issues found across 4 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant C as Client
participant H as Act/Observe Handler
participant S as Snapshot (captureHybridSnapshot)
participant LLM as Inference (LLM)
participant L as v3Logger
Note over C, L: Runtime Flow for Act/Observe with XPath Validation
C->>H: act() or observe()
H->>S: captureHybridSnapshot()
S-->>H: { combinedXpathMap, combinedTree }
H->>LLM: Request inference (instruction + tree)
LLM-->>H: Return element(s) with elementId
rect rgb(240, 240, 240)
Note over H, L: NEW: XPath Lookup & Validation Logic
loop For each returned elementId
H->>H: Lookup elementId in combinedXpathMap
alt elementId NOT in map (Failure Path)
H->>L: NEW: v3Logger(level: 0, category: "action/observation")
Note right of L: Logs missing ID for debugging
alt actHandler flow
H-->>C: CHANGED: Return { success: false, message: "No action found" }
else observeHandler flow
H->>H: CHANGED: Filter element out of results
end
else elementId found (Happy Path)
H->>H: Normalize/Trim XPath
opt actHandler flow
H->>H: Perform browser action (click, type, etc.)
H-->>C: Return { success: true }
end
end
end
end
opt observeHandler flow
H-->>C: Return list of validated elements
end
why
To fix silent errors whenever an invalid ID is returned by the LLM (xpath lookup failed)
what changed
Add an error log when the LLM returns an element ID with no matching xpath and handle these cases gracefully in act and observe
actHandler: log with category "action" when no xpath exists for the returned elementId; act() now fails gracefully with success: false and a clear message.observeHandler: log with category "observation" and filter out elements whose IDs are missing from the xpath map.test plan