-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Issue#186 #1121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Issue#186 #1121
Conversation
…ible Expose executed Playwright commands in act results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
Exposes executed Playwright command details in ActResult
to help developers understand what actions Stagehand generated.
Key changes:
- Added
PlaywrightCommandResult
interface withmethod
,selector
, andarguments
fields - Added optional
playwrightCommand
field toActResult
interface - Implemented
buildPlaywrightCommand()
andnormalizeSelector()
helper methods - Updated all
ActResult
returns to includeplaywrightCommand
metadata - Updated documentation with example response
Issues found:
- Critical logic error in self-heal fallback path (lines 204-215): uses original failed method/args instead of newly observed element's method/args, causing self-heal to potentially retry with the same failing command
Confidence Score: 1/5
- This PR contains a critical bug in the self-heal logic that will cause failures
- The self-heal fallback incorrectly uses the original failed
observe.method
andobserve.arguments
instead of the newly discoveredelement.method
andelement.arguments
, defeating the purpose of the self-heal retry. This will cause the retry to fail with the same error. The PR also lacks a changeset as required by custom instructions. lib/handlers/actHandler.ts
lines 204-215 must be fixed before merge
Important Files Changed
File Analysis
Filename | Score | Overview |
---|---|---|
types/stagehand.ts | 5/5 | Added new PlaywrightCommandResult interface and playwrightCommand field to ActResult |
docs/references/act.mdx | 5/5 | Updated documentation to include playwrightCommand field with example |
lib/handlers/actHandler.ts | 1/5 | Added playwrightCommand tracking throughout act handler, but self-heal logic uses wrong method/args |
Sequence Diagram
sequenceDiagram
participant User
participant StagehandPage
participant ActHandler
participant ObserveHandler
participant PlaywrightPage
User->>StagehandPage: page.act(action)
StagehandPage->>ActHandler: observeAct(action)
ActHandler->>ObserveHandler: observe(instruction)
ObserveHandler-->>ActHandler: ObserveResult[]
ActHandler->>ActHandler: actFromObserveResult(element)
ActHandler->>ActHandler: buildPlaywrightCommand(method, args, selector)
Note over ActHandler: Creates PlaywrightCommandResult
ActHandler->>PlaywrightPage: _performPlaywrightMethod(method, args, selector)
alt Success
PlaywrightPage-->>ActHandler: success
ActHandler-->>User: ActResult with playwrightCommand
else Failure (selfHeal enabled)
PlaywrightPage-->>ActHandler: error
ActHandler->>ObserveHandler: observe(instruction) [retry]
ObserveHandler-->>ActHandler: ObserveResult[] [new element]
ActHandler->>ActHandler: buildPlaywrightCommand(method, args, fallbackSelector)
Note over ActHandler: Updates playwrightCommand with fallback selector
ActHandler->>PlaywrightPage: _performPlaywrightMethod(method, args, fallbackSelector)
PlaywrightPage-->>ActHandler: success/failure
ActHandler-->>User: ActResult with playwrightCommand
end
Additional Comments (1)
3 files reviewed, 3 comments
attemptedPlaywrightCommand = this.buildPlaywrightCommand( | ||
observe.method, | ||
observe.arguments, | ||
fallbackSelector, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: self-heal fallback uses wrong method/args
uses observe.method
and observe.arguments
(from original failed attempt) instead of element.method
and element.arguments
from the newly observed element
attemptedPlaywrightCommand = this.buildPlaywrightCommand( | |
observe.method, | |
observe.arguments, | |
fallbackSelector, | |
); | |
attemptedPlaywrightCommand = this.buildPlaywrightCommand( | |
element.method, | |
element.arguments, | |
fallbackSelector, | |
); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/handlers/actHandler.ts
Line: 204:208
Comment:
**logic:** self-heal fallback uses wrong method/args
uses `observe.method` and `observe.arguments` (from original failed attempt) instead of `element.method` and `element.arguments` from the newly observed element
```suggestion
attemptedPlaywrightCommand = this.buildPlaywrightCommand(
element.method,
element.arguments,
fallbackSelector,
);
```
How can I resolve this? If you propose a fix, please make it concise.
await this._performPlaywrightMethod( | ||
// override previously provided method and arguments | ||
observe.method, | ||
observe.arguments, | ||
// only update selector | ||
element.selector, | ||
fallbackSelector, | ||
domSettleTimeoutMs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: self-heal uses original method/args instead of new element's
the comment says "override previously provided method and arguments" but the code does the opposite - it uses the original observe.method
and observe.arguments
instead of using the new element.method
and element.arguments
from the fresh observation
await this._performPlaywrightMethod( | |
// override previously provided method and arguments | |
observe.method, | |
observe.arguments, | |
// only update selector | |
element.selector, | |
fallbackSelector, | |
domSettleTimeoutMs, | |
await this._performPlaywrightMethod( | |
element.method, | |
element.arguments, | |
fallbackSelector, | |
domSettleTimeoutMs, | |
); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/handlers/actHandler.ts
Line: 209:215
Comment:
**logic:** self-heal uses original method/args instead of new element's
the comment says "override previously provided method and arguments" but the code does the opposite - it uses the original `observe.method` and `observe.arguments` instead of using the new `element.method` and `element.arguments` from the fresh observation
```suggestion
await this._performPlaywrightMethod(
element.method,
element.arguments,
fallbackSelector,
domSettleTimeoutMs,
);
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
ActResult
so callers can inspect what Stagehand executedpage.act
Testing
fixes issue #186