Skip to content

[fix] ensure selfHeal respects arguments #897

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

Merged

Conversation

miguelg719
Copy link
Collaborator

@miguelg719 miguelg719 commented Jul 19, 2025

why

On self healing we were finding the selector, but nor remembering the arguments previously passed; so either they were empty or the LLM was hallucinating them. This PR fixes this

what changed

Updated the logic from selfHealing to reuse the previously passed arguments and method

test plan

  • Added evals to act and regression (evals/tasks/heal_*.ts)

@miguelg719 miguelg719 added the bug Something isn't working label Jul 19, 2025
Copy link

changeset-bot bot commented Jul 19, 2025

🦋 Changeset detected

Latest commit: 31e36c4

The changes in this PR will be included in the next version bump.

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

@miguelg719 miguelg719 marked this pull request as ready for review July 20, 2025 01:09
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR addresses a critical bug in Stagehand's self-healing functionality where action arguments were not being preserved during the healing process. The fix maintains the original method and arguments when retrying failed actions, only updating the selector through observation.

Key changes:

  1. Modified actHandler.ts to preserve original method and arguments during self-healing
  2. Added selfHeal: true to default StagehandConfig
  3. Added three new test cases to validate argument preservation:
    • heal_scroll_50: Tests scroll position preservation
    • heal_simple_google_search: Tests search text preservation
    • heal_custom_dropdown: Tests click handling on custom dropdowns

PR Description Notes:

  • The PR description template is completely empty. Please fill in the 'why', 'what changed', and 'test plan' sections.

Confidence score: 4/5

  1. This PR is safe to merge with proper testing as it fixes a bug rather than introducing new functionality.
  2. The changes are well-contained and include comprehensive test coverage for various interaction types.
  3. Special attention needed for:
    • evals/tasks/heal_*.ts files to ensure test coverage is comprehensive
    • lib/handlers/actHandler.ts to verify self-healing logic is correct

6 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

@@ -48,6 +48,7 @@ const StagehandConfig = {
},
},
},
selfHeal: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanmcguire12 👀, 👍 / 👎 ?

Comment on lines 13 to 18
await stagehand.page.act({
description: "Scroll 50% down the page",
selector: "/html/body/div/div/button",
arguments: ["50"],
method: "scrollTo",
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this make sense to self heal at all?

@seanmcguire12 seanmcguire12 force-pushed the miguel/stg-562-fix-bug-with-self-heal-forgetting-arguments branch from b3f01bc to 048c119 Compare July 25, 2025 18:12
@seanmcguire12 seanmcguire12 added act These changes pertain to the act function targeted-extract These changes pertain to targeted extract labels Jul 25, 2025
const element: ObserveResult = observeResults[0];
await this._performPlaywrightMethod(
// override previously provided method and arguments
observe.method,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will also be overriden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
act These changes pertain to the act function bug Something isn't working targeted-extract These changes pertain to targeted extract
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants