Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(agents): a durable OpenCode call that asks permission twice is approved, not refused as a repeat (#6235)
ddupont2b7bd1b9046b
diff --git a/docs/content/docs/spaces/guides/keep-an-agent-running.mdx b/docs/content/docs/spaces/guides/keep-an-agent-running.mdxindex 571a6f6ec8..a83cd541ce 100644--- a/docs/content/docs/spaces/guides/keep-an-agent-running.mdx+++ b/docs/content/docs/spaces/guides/keep-an-agent-running.mdx@@ -91,9 +91,7 @@ the conversation or the working folder of the old one. Plan for it:within about a minute, with the same name and an empty disk; the old recordstays listed as offline until you delete it.-Known problems today: OpenCode refuses a-command that touches a folder outside its workspace (the same call is asked-twice, and the second ask is refused as a repeat); `cua agent logs+Known problems today: `cua agent logssession:NAME` shows only the driver's heartbeat lines, not what the agent did.## What happens when it crashesdiff --git a/libs/cua/crates/cua-agents/runner/acp-runner.mjs b/libs/cua/crates/cua-agents/runner/acp-runner.mjsindex f9e4d87c07..1adf525f18 100644--- a/libs/cua/crates/cua-agents/runner/acp-runner.mjs+++ b/libs/cua/crates/cua-agents/runner/acp-runner.mjs@@ -846,7 +846,13 @@ async function answerPermission(params) {const e = byId.get(id);let action = "approve";let why = "";- if (e && e.decision === "approve" && !e.outcome) {+ if (e && e.decision === "approve" && !e.outcome && e.approvedGen === gen) {+ // The same agent process asks again for a call it has not finished: one+ // call, a second permission (OpenCode asks for an external directory, then+ // for the command, both under one call id). Nothing ran between the two+ // requests and nothing restarted, so it is the same approval, not a repeat.+ action = "again";+ } else if (e && e.decision === "approve" && !e.outcome) {// The tool may be running, or may have half-run before a restart: never// approve it blindly a second time.if (durable.policy === "rerun-safe" && READ_ONLY_KINDS.has(info.toolKind)) {@@ -862,9 +868,11 @@ async function answerPermission(params) {why = "repeat request for a tool call that already completed";ledger("duplicate", id, { name: info.name, action: "deny" });}- if (action === "approve" || action === "rerun") {+ if (action === "approve" || action === "rerun" || action === "again") {if (action === "rerun") ledger("rerun", id, { name: info.name, policy: "rerun-safe" });- else {+ else if (action === "again") {+ // Already journaled (the intent of its first request): nothing to add.+ } else {const { end } = ledger("intent", id, {name: info.name,toolKind: info.toolKind,@@ -872,6 +880,8 @@ async function answerPermission(params) {input: clip(JSON.stringify(info.input ?? null) ?? "null", 400),decision: "approve",});+ // Only this agent process may be asked again for it (see above).+ byId.get(id).approvedGen = gen;if (durable.ship && !(await waitShipped(end))) {why = "the journal did not reach the Cua Volume in time; the call was not run";ledger("outcome", id, { name: info.name, status: "failed", summary: why, denied: true });diff --git a/libs/cua/crates/cua-agents/runner/test/durable.test.mjs b/libs/cua/crates/cua-agents/runner/test/durable.test.mjsindex e7b6c9816d..e143648686 100644--- a/libs/cua/crates/cua-agents/runner/test/durable.test.mjs+++ b/libs/cua/crates/cua-agents/runner/test/durable.test.mjs@@ -118,6 +118,24 @@ t("the intent is on disk before the approval is answered; one approval per callassert.equal(outcome.unguarded, undefined);});+t("a second permission request for one call from the same agent process is approved, not refused as a repeat (CUA-2958)", async (box) => {+ // OpenCode asks for an external directory and then for the command, both under one call id.+ box.script({ prompts: [{ match: ".", steps: [tool("call-1", { askTwice: true }), { say: "done" }] }] });+ box.config();+ const r = await box.go({ epoch: 1, resume: false });+ assert.equal(r.code, 0, r.stderr);+ const log = box.agentLog();+ assert.equal(log.filter((l) => l.ev === "permission_first").length, 1);+ assert.equal(log.find((l) => l.ev === "permission_first").outcome.outcome, "selected");+ assert.equal(log.filter((l) => l.ev === "permission").length, 1);+ assert.equal(log.find((l) => l.ev === "permission").outcome.outcome, "selected", "the second request was approved");+ assert.deepEqual(box.effects(), ["call-1"], "the command ran once");+ // One intent, one outcome: the second request added nothing to the journal.+ assert.deepEqual(box.tools().map((x) => x.kind), ["intent", "outcome"]);+ const perms = box.events().filter((e) => e.type === "permission");+ assert.deepEqual(perms.map((e) => e.action), ["approve", "again"]);+});+t("guard: the harness is not switched to full access and is approved with allow-once, so it keeps asking", async (box) => {box.script({ prompts: [{ match: ".", steps: [tool("call-1")] }] });box.config({ modeKinds: ["full_access"] });diff --git a/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjs b/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjsindex ba029d461d..615ca00f9f 100644--- a/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjs+++ b/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjs@@ -62,6 +62,20 @@ async function runSteps(steps, sid, cx) {const t = st.tool;const base = { toolCallId: t.id, title: t.title ?? t.id, kind: t.kind ?? "execute", rawInput: t.input ?? { id: t.id } };await note({ sessionUpdate: "tool_call", ...base, status: "pending" });+ if (t.permission !== false && t.askTwice) {+ // OpenCode: a command that touches a folder outside the workspace is asked for twice under one call id,+ // first as an "external directory" request (kind other), then for the command.+ const first = await cx.request("session/request_permission", {+ sessionId: sid,+ toolCall: { ...base, kind: "other", title: "external_directory: /outside", status: "pending" },+ options: [+ { kind: "allow_once", name: "Allow", optionId: "allow" },+ { kind: "reject_once", name: "Reject", optionId: "reject" },+ ],+ });+ log({ ev: "permission_first", id: t.id, outcome: first.outcome });+ if (first.outcome.outcome !== "selected" || first.outcome.optionId === "reject") continue;+ }if (t.permission !== false) {const res = await cx.request("session/request_permission", {sessionId: sid,