𝗧𝗵𝗲 𝗗𝗮𝗻𝗴𝗲𝗿 𝗼𝗳 𝗦𝗶𝗹𝗲𝗻𝘁 𝗙𝗮𝗶𝗹𝘂𝗿𝗲𝘀 You use tools to get work done. But what if a tool returns the wrong answer without an error? This is more dangerous than a tool that crashes. A crash is a signpost. A silent failure is a forgery.

I found a bug in my browser tool. It returned "[object Promise]" as a webpage. I searched for similar issues and found 10 more tools with the same bug. The problem was not a typo, but a shape. This shape was copied across the codebase.

The bug happened because AppleScript's do JavaScript is synchronous. It returns immediately, without waiting for async work to finish. This means that if you pass an async function to do JavaScript, it will return a Promise object, not the result of the function.

To fix this, I moved the async loop to the Node side. I use a helper function to poll the page's state until it settles, then read the result. This way, the await lives in Node, and the call into the page is a single synchronous expression.

The lesson is to keep the async loop on the side that can await, and poll observable state across the boundary instead of awaiting across it. Don't ask the bridge to wait. Ask it, repeatedly, "are you done yet?" — and do the waiting yourself.

If you're building agent tooling, watch out for silent failures. Grep your codebase for tools that return "[object Promise]" or act on stale state. If you find one, don't just fix it. Find its siblings and fix the shape that was copied.

Source: https://dev.to/achiya-automation/my-browser-tool-returned-object-promise-as-a-webpage-one-grep-later-10-more-tools-had-the-37p8