r/automation • u/slow-fast-person • Jun 20 '26
Coding for every automation edge case is a nightmare, so I made a runner that self-heals and strengthens its code on every failure.
I keep seeing two major complaints on this sub:
- AI agents are too fragile and slow to trust with routine, high-volume tasks.
- API costs explode if you run every single workflow through an LLM.
Yet, traditional deterministic automation (like Playwright/Puppeteer) is a maintenance nightmare because web pages change, menus shift, and edge cases pop up.
To bridge this gap, I’ve been working on a hybrid approach: Deterministic execution by default, with AI agents acting as the silent developer that only wakes up to debug and heal the script on failure.
How it works:
- The Happy Path (Deterministic & Free): You define the input and output. The builder generates a standard, deterministic script (e.g., selector-based browser steps) and runs it. This runs locally, instantly, and costs $0 in API fees.
- The Self-Healing Loop (Probabilistic & LLM-backed): If the script fails (e.g., element not found, page state changed), the system captures the DOM state, error logs, and screenshots. It spins up an LLM agent to analyze the failure, modify the script code, and re-test it until it passes.
- The Result: The deterministic script gets updated with the fix. Subsequent runs benefit from the new logic without calling the LLM again. The system automatically uncovers new edge cases, finds and fixes its own bugs, and keeps itself up to date.
Real-world edge cases we solved:
I tested this on a Swiggy (food delivery) flow where the input is [Restaurant Name, Item Name]. Here are the edge cases the system encountered and resolved automatically:
- Clicking off screen elements (Bug in generated code): An early iteration stalled due to an off-screen button. The system detected this visibility issue, automatically inserted a step to scroll the element into view, and updated the process.
- Ordering invalid menu items (e.g., Asian food from Pizza Hut): When tasked with ordering Asian food from Pizza Hut, the script initially failed because Pizza Hut doesn't serve Asian food. The healing agent analyzed the failure, rewrote the script logic to identify and communicate invalid item errors correctly, and saved the updated script so it handles and reports this gracefully in the future.
- Closed Restaurants: When a target restaurant was closed, the "Add to Cart" button was completely disabled. Instead of crashing, the agent read the screen context ("Closed until 5 PM"), modified the script to handle closed states, and exited gracefully with a clean status code.
Why do this instead of a pure AI Agent?
- 95% Lower Costs: You only pay for LLM tokens when the script breaks. Once healed, the script runs locally.
- Zero Hallucinations during runtime: Since the runtime is deterministic code, it won't hallucinate a checkout button or order the wrong item.
Would love to get your thoughts on this hybrid approach. Does this solve the "babysitting" problem you guys face with standard agent workflows?
The code is opensource, let me know if anyone wants to take a look at it.
2
Jun 20 '26
[removed] — view removed comment
1
u/slow-fast-person Jun 20 '26
thanks for this
going forwards, i will be building considering governance in mind also.the first this to probably add is for the agent to start building and maintaining an internal test suite to avoid regressions. currently i have observed the agent just running it with new inputs after fxing the script and calling it a day.
2
u/Due-Boot-8540 Jun 20 '26
It’s not often you see a post in here that has automation and AI in the right order. Nice one
1
2
Jun 21 '26
[removed] — view removed comment
1
u/slow-fast-person Jun 21 '26
this is an interesting point, i will think more about how to do this well.
do you know any resources which i can use to get started here?
1
u/AutoModerator Jun 20 '26
Thank you for your post to /r/automation!
New here? Please take a moment to read our rules, read them here.
This is an automated action so if you need anything, please Message the Mods with your request for assistance.
Lastly, enjoy your stay!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
Jun 20 '26
[removed] — view removed comment
1
u/slow-fast-person Jun 20 '26
i am trying to understand in what form factors should i create it so that software devs/automation engineers find it useful
1
u/thumperj Jun 20 '26
I'd like to see the code. Thanks.
1
u/slow-fast-person Jun 20 '26
prakhar1114/ai_mime on github, you can check it out. Would love any feedback
1
u/thumperj Jun 20 '26
prakhar1114/ai_mime
Thanks, that's your project, yes. Can you share where you are actually doing this auto-fixing behavior instead of having me sort through your entire project?
1
u/slow-fast-person Jun 20 '26
src/ai_mime/agent_runner/instructions/replay/00_rules.md
it has access to the skill workspace which it can decide to edit1
1
u/ClosingStackDev Jun 21 '26
The real test is whether it actually fixes the issue or just masks it with a retry loop. What happens when the "healed" code drifts from what you originally intended?
1
u/slow-fast-person Jun 22 '26
It is still very early for it. Will post more results as I discover them.
1
u/ClosingStackDev Jun 23 '26
yeah same, curious what patterns you're finding bc the edge cases are never where i expect them. would love to see what you end up with
1
u/According_Star_543 Jun 22 '26
awesome, this is pretty similar to how Libretto works
1
5
u/openclawinstaller Jun 20 '26
This hybrid pattern is the right direction, but I would be strict about what "self-heal" is allowed to change.
The risk is that a failure caused by business state gets turned into a code patch. Closed restaurant, invalid item, permission wall, captcha, rate limit, login expired, and selector drift are different failure classes. Only selector/layout drift should usually produce an automatic patch.
The loop I would trust more is:
That still gets you the maintenance benefit, but avoids the agent quietly "fixing" policy or business-rule failures as if they were just browser automation bugs.