Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

fix: recover when a scope has no computer (#1557)

Joshua France76e312f1faaf
diff --git a/src/harness/agent-tools.ts b/src/harness/agent-tools.ts
index b88e85e1d..8f22f2eae 100644
--- a/src/harness/agent-tools.ts
+++ b/src/harness/agent-tools.ts
@@ -889,7 +889,7 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
name: "sandbox",
label: "sandbox",
description:
- "Manage sandbox resources. list returns providers, supported actions, inventory, and this scope's optional default. create provisions a blank sandbox without changing the default or copying files. set_default changes routing only; pass sandbox_id:null to clear it. status reports health and recovery expiry without provisioning. restart recovers working state where supported and stops running processes. retire deletes the named sandbox after its default and jobs are cleared. Durable outputs belong in Files or git. Select an exact sandbox_id for status/restart or omit it to use the stored default.",
+ "Manage sandbox resources. list returns providers, supported actions, inventory, and this scope's optional default. If work needs a computer and this scope has no default, do not report blocked: list providers, create a sandbox, set_default to it, and retry. Only report blocked if creation fails. create provisions a blank sandbox without changing the default or copying files. set_default changes routing only; pass sandbox_id:null to clear it. status reports health and recovery expiry without provisioning. restart recovers working state where supported and stops running processes. retire deletes the named sandbox after its default and jobs are cleared. Durable outputs belong in Files or git. Select an exact sandbox_id for status/restart or omit it to use the stored default.",
parameters: Type.Object({
action: Type.String({ enum: sandboxActions }),
sandbox_id: Type.Optional(
diff --git a/src/sandbox/sandbox-routing.ts b/src/sandbox/sandbox-routing.ts
index 0f23279b9..0eff8d173 100644
--- a/src/sandbox/sandbox-routing.ts
+++ b/src/sandbox/sandbox-routing.ts
@@ -21,6 +21,9 @@ export type SandboxBackendName =
export type SandboxScopeDefaults = Partial<Record<ScopeKind, SandboxBackendName>>;
+const NO_DEFAULT_SANDBOX =
+ "this scope has no default sandbox; use sandbox list, create, set_default, then retry before reporting blocked";
+
export function sandboxDefaultForScope(
scope: string | undefined,
fallback: SandboxBackendName,
@@ -93,7 +96,7 @@ export function createSandboxRouter(opts: RoutingSandboxOptions): Sandbox {
async function computerTarget(scopeId: string): Promise<{ sandbox: Sandbox; scopeId: string; resourceId?: string }> {
const resource = await opts.resources?.resolve(scopeId);
- if (resource === null) throw new Error("this scope has no default sandbox");
+ if (resource === null) throw new Error(NO_DEFAULT_SANDBOX);
if (resource) {
const sandbox = backends[resource.backend];
if (!sandbox) throw new Error(`sandbox backend unavailable: ${resource.backend}`);
@@ -163,7 +166,7 @@ export function createSandboxRouter(opts: RoutingSandboxOptions): Sandbox {
if (provOpts?.sandboxId) resource = await opts.resources?.get(provOpts.sandboxId);
else if (!provOpts?.scratch) resource = await opts.resources?.resolve(scope);
if (provOpts?.sandboxId && !resource) throw new Error("sandbox inventory unavailable");
- if (resource === null) throw new Error("this scope has no default sandbox; create one or specify sandbox_id");
+ if (resource === null) throw new Error(NO_DEFAULT_SANDBOX);
if (resource) {
const sandbox = backends[resource.backend];
if (!sandbox) throw new Error(`sandbox backend unavailable: ${resource.backend}`);
diff --git a/test/agent-tools.test.ts b/test/agent-tools.test.ts
index 8a002fb02..4ab363668 100644
--- a/test/agent-tools.test.ts
+++ b/test/agent-tools.test.ts
@@ -496,6 +496,14 @@ test("sandbox advertises available management actions and retires migrate", asyn
await assert.rejects(() => call(execute, { command: "", computer: "migrate" }), /migrate has been retired/);
});
+test("sandbox tells the agent to provision a missing default before reporting a blocker", () => {
+ const ref: ToolContextRef = { current: fakeToolContext(), emit: () => {}, scopeLabel: "group:C1" };
+ const sandbox = createAgentTools(ref, { sandboxResources: true }).find((t) => t.name === "sandbox")!;
+ assert.match(sandbox.description, /needs a computer and this scope has no default/i);
+ assert.match(sandbox.description, /list.*create.*set_default.*retry/is);
+ assert.match(sandbox.description, /report.*blocked.*creation fails/is);
+});
+
test("sandbox creation and default routing remain independent", async () => {
const calls: unknown[] = [];
const ref: ToolContextRef = {
diff --git a/test/sandbox-resources.test.ts b/test/sandbox-resources.test.ts
index 07ff142ac..619d984c2 100644
--- a/test/sandbox-resources.test.ts
+++ b/test/sandbox-resources.test.ts
@@ -118,7 +118,10 @@ test("unset defaults remain unset durably while explicit execution remains usabl
const record = await resources.create("alice", "personal:alice", "local");
await resources.setDefault("alice", "personal:alice", null);
assert.equal((await defaults.get("personal:alice"))?.sandboxId, null);
- await assert.rejects(router.provision(layers), /no default sandbox/);
+ await assert.rejects(
+ router.provision(layers),
+ /sandbox list, create, set_default, then retry before reporting blocked/,
+ );
const explicit = await router.provision(layers, { sandboxId: record.id });
assert.equal(explicit.resourceId, record.id);
const listed = await resources.list("alice", "personal:alice");