Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Phone batch: a cancel notice during the first claim check keeps the batch from starting

Xiaolei Shi510a33810b3b
diff --git a/server/drivers/phone-proxy.test.ts b/server/drivers/phone-proxy.test.ts
index 480d00a6f7..a8109b22f3 100644
--- a/server/drivers/phone-proxy.test.ts
+++ b/server/drivers/phone-proxy.test.ts
@@ -481,6 +481,27 @@ esac
expect(adbLog()).toEqual(["devices -l", ...adb]);
});
+ it.each([
+ { name: "batch", args: { steps: [{ action: "tap", x: 540, y: 1200 }] }, result: { content: [{ type: "text", text: "The client cancelled this call." }], isError: true }, adb: [] },
+ { name: "tap", args: { x: 540, y: 1200 }, result: { content: [{ type: "text", text: "Tapped 540,1200" }] }, adb: ["devices -l", "-s FAKE123 shell input tap 540 1200"] },
+ ])("a cancel notice during the phone claim stops a batch from starting, not a single tool: $name", async ({ name, args, result, adb }) => {
+ const harness = createServer((request, response) => {
+ request.resume();
+ setTimeout(() => response.writeHead(200).end("{}"), 300);
+ });
+ await new Promise<void>((resolve) => harness.listen(0, "127.0.0.1", resolve));
+ try {
+ const { port } = harness.address() as AddressInfo;
+ const claimed = startProxy({ OMB_HARNESS_URL: `http://127.0.0.1:${port}`, OMB_PHONE_TOKEN: "tok" });
+ rmSync(join(home, "adb.log"), { force: true });
+ const response = await claimed(name, args, "this call");
+ expect(response.result).toEqual(result);
+ expect(adbLog()).toEqual(adb);
+ } finally {
+ harness.close();
+ }
+ });
+
it("stops a batch at the next step once the harness refuses the claim", async () => {
const answers = [200, 409];
const harness = createServer((request, response) => {
diff --git a/server/drivers/phone-proxy.ts b/server/drivers/phone-proxy.ts
index 2fb129d1cc..3c04f9b7f7 100644
--- a/server/drivers/phone-proxy.ts
+++ b/server/drivers/phone-proxy.ts
@@ -612,14 +612,14 @@ async function handle(message: Json, ensureClaim: () => Promise<ClaimOutcome>) {
if (method === "tools/call") {
const name = String(params.name ?? "");
if (!TOOLS.some((tool) => tool.name === name)) return rpcError(id, -32602, `Unknown tool: ${name}`);
- const claim = await ensureClaim();
- if (!claim.ok) return ok(id, textResult(claim.message, true));
- callsCancelled.set(id, false);
+ if (name === "batch") callsCancelled.set(id, false);
const stillWanted = async (): Promise<ClaimOutcome> => {
const stillClaimed = await ensureClaim();
return callsCancelled.get(id) ? { ok: false, message: "The client cancelled this call." } : stillClaimed;
};
try {
+ const claim = await stillWanted();
+ if (!claim.ok) return ok(id, textResult(claim.message, true));
return ok(id, await callTool(name, (params.arguments ?? {}) as Json, stillWanted));
} catch (error) {
return ok(id, textResult(error instanceof Error ? error.message : String(error), true));