From 5cfa7ccc8f4082db111bc0186c5fa3d44b767ad3 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 00:01:32 +0530 Subject: refactor(tools): declare concurrency in the tool definition serialized: true was applied in registry.ts, away from the tools it describes. Now a required concurrency field on each definition, with a test pinning the serialized set so the classes cannot drift. The lock check defaults to taking the mutex for any class that is not explicitly "parallel", so a definition that bypasses defineBrowserTool at runtime fails safe rather than racing on shared CDP state. The test script gains --conditions=import: pi-coding-agent publishes no "require" condition, so importing any tool definition from a CJS-loaded test could not resolve it. Co-Authored-By: Claude Opus 5 (1M context) --- src/domains/page.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/domains/page.ts') diff --git a/src/domains/page.ts b/src/domains/page.ts index 8e674cb..0d7aa8b 100644 --- a/src/domains/page.ts +++ b/src/domains/page.ts @@ -17,6 +17,7 @@ export const pageInfoTool = defineBrowserTool({ "browser_page_info auto-detects alert, confirm, prompt, and beforeunload dialogs.", ], parameters: Type.Object({}), + concurrency: "parallel", async handler(_args, { client }): Promise> { const r = await client.pageInfo(); if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); @@ -46,6 +47,7 @@ export const waitTool = defineBrowserTool({ promptSnippet: "Wait N seconds", promptGuidelines: ["Use sparingly — prefer browser_wait_for_load when waiting for a page load."], parameters: WaitArgs, + concurrency: "parallel", async handler(args, { signal }): Promise> { try { await sleep(Math.round(args.seconds * 1000), signal); @@ -71,6 +73,7 @@ export const waitForLoadTool = defineBrowserTool({ "Returns when readyState becomes 'complete' OR the timeout elapses.", ], parameters: WaitForLoadArgs, + concurrency: "serialized", async handler(args, { client, signal }): Promise> { const timeoutMs = (args.timeout ?? 15) * 1000; const start = Date.now(); @@ -106,6 +109,7 @@ export const waitForTool = defineBrowserTool({ "Returns a typed timeout error if the condition isn't met within the timeout.", ], parameters: WaitForArgs, + concurrency: "parallel", async handler(args, { client, signal }): Promise> { if (args.selector === undefined && args.text === undefined) { return err({ kind: "invalid_state", message: "Provide a selector or text to wait for." }); -- cgit v1.2.3