Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(browser): 保留输入预检修复额度及有效配方状态
Dasha7976a999c12
diff --git a/packages/browser-control-runtime/src/_generated/extension/src/browser/pw-session.ts b/packages/browser-control-runtime/src/_generated/extension/src/browser/pw-session.tsindex e92550fb6d..6f7441497b 100644--- a/packages/browser-control-runtime/src/_generated/extension/src/browser/pw-session.ts+++ b/packages/browser-control-runtime/src/_generated/extension/src/browser/pw-session.ts@@ -9,6 +9,7 @@*/import crypto from "node:crypto";import path from "node:path";+import { getBrowserControlState } from "../browser-control-state.js";import { isManagedLocalCdpConnection } from "../../../../shim/cdp-locality.js";import {isFutureDateTimestampMs,@@ -946,7 +947,6 @@ async function connectBrowser(cdpUrl: string, ssrfPolicy?: SsrFPolicy): Promise<const endpoint = wsUrl ?? normalized;const connectEndpoint = async (target: string) => {const headers = getHeadersWithAuth(target);- const { getBrowserControlState } = await import("../browser-control-state.js");const isLocal = isManagedLocalCdpConnection(normalized, target, getBrowserControlState()?.profiles.values() ?? [],);diff --git a/packages/browser-control-runtime/upstream/browser-runtime.lock.json b/packages/browser-control-runtime/upstream/browser-runtime.lock.jsonindex 84679f55b9..6f233db946 100644--- a/packages/browser-control-runtime/upstream/browser-runtime.lock.json+++ b/packages/browser-control-runtime/upstream/browser-runtime.lock.json@@ -120,7 +120,7 @@}],"fileCount": 335,- "contentHash": "0e6dedbbe3e2c850ccd4867e21b8fda3b25837b0d8145c6f0a4a6c47603447c7",+ "contentHash": "0e13e4827f1eea59d796bb5727e1775aac55b5066f98fe204458801fba1f6171","fsSafe": {"package": "@openclaw/fs-safe","version": "0.4.0"diff --git a/packages/lizi-mcps/src/browser/browserMcpServer.test.ts b/packages/lizi-mcps/src/browser/browserMcpServer.test.tsindex 19c0e98cd1..157dc5da38 100644--- a/packages/lizi-mcps/src/browser/browserMcpServer.test.ts+++ b/packages/lizi-mcps/src/browser/browserMcpServer.test.ts@@ -1202,6 +1202,49 @@ describe('recipe on-use maintenance', () => {expect((await invoke(h, { action: 'recipe', recipeId: stored.id, inputs: { query: 'test' } })).ok).toBe(true);} finally { await h.cleanup(); }});+ // Review #6822: saved-use coverage above did not exercise repair preflight.+ // MCP entry/unit: all three preflight paths must leave the page and budget untouched.+ it.each(['missing', 'non-scalar', 'interpolation'] as const)('preserves the repair trial after %s input preflight failure', async (failure) => {+ const candidate = { ...draft, inputs: { query: { required: true } }, steps: [{ ...draft.steps[0],+ guard: { url: 'https://example.com/', ...(failure === 'interpolation' ? { selector: '#{{missing}}' } : {}) } }] };+ const stored = { ...candidate, validation: { site: 'example.com', state: 'suspended' as const } };+ const saved: unknown[] = [];+ const h = await makeHarness({+ getUserRecipes: async () => ({ version: `repair-preflight-${failure}`, recipes: new Map([[stored.id, stored]]), siteGuides: new Map() }),+ saveUserRecipe: async (x) => { saved.push(x); return { ok: true }; },+ }, (_req, i) => ({ result: i === 0 ? true : { title: 'found' } }));+ const run = { action: 'recipe', site: 'example.com', recipeDraft: candidate };+ try {+ const inputs = failure === 'missing' ? undefined : { query: failure === 'non-scalar' ? {} : 'test' };+ expect((await invoke(h, { ...run, inputs })).ok).toBe(false);+ expect(h.calls).toHaveLength(0);+ expect(saved).toHaveLength(0);+ expect((await invoke(h, { ...run, inputs: { query: 'test', missing: 'account' } })).verified).toBe(true);+ const calls = h.calls.length;+ expect((await invoke(h, { ...run, inputs: { query: 'test', missing: 'account' } })).message).toContain('次数已用完');+ expect(h.calls).toHaveLength(calls);+ } finally { await h.cleanup(); }+ });+ // Review #6822: a draft failure differs from failure of the saved definition.+ // MCP entry/unit: guard/expect failures must not disable the old working recipe.+ it.each(['guard', 'expect'] as const)('keeps an active recipe usable after a candidate %s failure', async (failure) => {+ const stored = { ...draft, validation: { site: 'example.com', state: 'active' as const } };+ const saved: unknown[] = [];+ let trial = true;+ const h = await makeHarness({+ getUserRecipes: async () => ({ version: `active-draft-${failure}`, recipes: new Map([[stored.id, stored]]), siteGuides: new Map() }),+ saveUserRecipe: async (x) => { saved.push(x); return { ok: true }; },+ }, (req) => ({ result: (req.request as { fn?: string })?.fn?.includes('const g =')+ ? !(trial && failure === 'guard') : { title: trial ? '' : 'found' } }));+ try {+ expect((await invoke(h, { action: 'recipe', site: 'example.com', recipeDraft: draft })).failureKind).toBe(failure);+ expect(saved).toHaveLength(0);+ trial = false;+ expect((await invoke(h, { action: 'recipe', recipeId: stored.id })).ok).toBe(true);+ expect((await invoke(h, { action: 'recipe', site: 'example.com', recipeDraft: draft })).verified).toBe(true);+ expect(saved).toHaveLength(0);+ } finally { await h.cleanup(); }+ });it('rejects moving an existing recipe id to a different site', async () => {const stored = { ...draft, validation: { site: 'example.com', state: 'active' as const } };const h = await makeHarness({diff --git a/packages/lizi-mcps/src/browser/tools.ts b/packages/lizi-mcps/src/browser/tools.tsindex 80292aff3c..18576f9361 100644--- a/packages/lizi-mcps/src/browser/tools.ts+++ b/packages/lizi-mcps/src/browser/tools.ts@@ -750,10 +750,7 @@ export function registerBrowserTools(registry: BrowserToolRegistry, deps: Browse}const suspended = failedRecipes.has(id) || persisted?.validation?.state === 'suspended';if (!candidate && suspended) return errorResult('recipe', `配方已暂停复用。${recovery}`);- if (candidate && (suspended || repairUsed.has(id))) {- if (repairUsed.has(id)) return errorResult('recipe', `本任务的修复验证次数已用完。${recovery}`);- repairUsed.add(id);- }+ if (candidate && repairUsed.has(id)) return errorResult('recipe', `本任务的修复验证次数已用完。${recovery}`);verifiedDrafts.delete(id);// Thread the caller's tab/profile routing into every recipe step:// step requests from stepToRequest carry no profile/targetId, so@@ -772,6 +769,9 @@ export function registerBrowserTools(registry: BrowserToolRegistry, deps: BrowserunningRecipes.add(id);const runResult = await runRecipe(entry.recipe, args.inputs as Record<string, unknown> | undefined, {call: async (req) => {+ // Input/request preflight can fail before touching the page. Only+ // an actual browser attempt consumes the single repair trial.+ if (candidate && suspended) repairUsed.add(id);const res = await runtime.call({...req,...(args.profile ? { profile: args.profile } : {}),@@ -787,10 +787,11 @@ export function registerBrowserTools(registry: BrowserToolRegistry, deps: Browseif (runResult.ok && candidate) {verifiedDrafts.set(id, { site: args.site!, content: JSON.stringify(entry.recipe) });} else if (!runResult.ok && runResult.failureKind !== 'input' && runResult.failedStep !== undefined) {- failedRecipes.add(id);- // Keep the last known definition, not a failed candidate. A normal- // use failure persists across tasks; missing input does not age a recipe.- if (persisted && deps.saveUserRecipe) {+ // A failed draft is not evidence that the saved active version is+ // stale. Keep its state, while limiting new/previously failed drafts.+ if (!candidate || !persisted || suspended) failedRecipes.add(id);+ // Only failure while using the saved definition can suspend it on disk.+ if (!candidate && persisted && deps.saveUserRecipe) {try {// Bundled recipes predate validation metadata; their guide// supplies the owning site. Never guess from a host substring.diff --git a/scripts/browser-runtime/sync.mjs b/scripts/browser-runtime/sync.mjsindex 615966f1e7..5010905f89 100644--- a/scripts/browser-runtime/sync.mjs+++ b/scripts/browser-runtime/sync.mjs@@ -1518,13 +1518,13 @@ const UNTORN_DOWN_BROWSER_MESSAGE =[`import path from "node:path";`,`import path from "node:path";+import { getBrowserControlState } from "../browser-control-state.js";import { isManagedLocalCdpConnection } from "openclaw/plugin-sdk/cdp-locality";`,],[` const headers = getHeadersWithAuth(target);// Bypass proxy for loopback CDP connections (#31219)`,` const headers = getHeadersWithAuth(target);- const { getBrowserControlState } = await import("../browser-control-state.js");const isLocal = isManagedLocalCdpConnection(normalized, target, getBrowserControlState()?.profiles.values() ?? [],);