Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Unblock tracked Fly deployments (#1692)

Joshua France1b251b1cde43
diff --git a/cli/src/backends/fly.ts b/cli/src/backends/fly.ts
index 753133190..ae1bc5fbd 100644
--- a/cli/src/backends/fly.ts
+++ b/cli/src/backends/fly.ts
@@ -71,6 +71,7 @@ const FLY_RESPONSE = "QM_LAYER_RESPONSE=";
const FLY_REMOTE_ERROR = "QM_LAYER_ERROR=";
const FLY_REQUEST_TIMEOUT_MS = 120_000;
const FLY_EXEC_TIMEOUT_SEC = 120;
+const FLY_EXEC_ARG_BYTES = 64 * 1024;
const FLY_APP_NOT_FOUND = /could not find app|app not found/i;
const FLY_MACHINES_API = "https://api.machines.dev/v1";
@@ -120,7 +121,11 @@ async function flyRequest(
body: string,
): Promise<{ status: number; body: string }> {
const app = `${appPrefixOf(config)}-core`;
- const script = `const fs=require("node:fs"),{createHmac}=require("node:crypto");const fail=error=>{const code=error&&(error.cause&&error.cause.code||error.code);console.log(${JSON.stringify(FLY_REMOTE_ERROR)}+JSON.stringify({message:error&&error.message?error.message:String(error),...(typeof code==="string"?{code}:{})}))};try{const method=${JSON.stringify(method)},path="/v1/deployment-layer",body=fs.readFileSync(0,"utf8"),timestamp=Math.floor(Date.now()/1000),canonical=method+"\\n"+path+"\\n"+body,secret=process.env.CORE_SIGNING_SECRET;if(!secret)throw new Error("CORE_SIGNING_SECRET is not set on core");const signature=createHmac("sha256",secret).update("v0:"+timestamp+":"+canonical).digest("hex");fetch("http://127.0.0.1:"+(process.env.PORT||8080)+path,{method,headers:{"content-type":"application/json","x-timestamp":String(timestamp),"x-signature":"v0="+signature},...(method==="PUT"?{body}: {})}).then(async response=>console.log(${JSON.stringify(FLY_RESPONSE)}+JSON.stringify({status:response.status,body:await response.text()}))).catch(fail)}catch(error){fail(error)}`;
+ const script = `const{createHmac}=require("node:crypto");const fail=error=>{const code=error&&(error.cause&&error.cause.code||error.code);console.log(${JSON.stringify(FLY_REMOTE_ERROR)}+JSON.stringify({message:error&&error.message?error.message:String(error),...(typeof code==="string"?{code}:{})}))};try{const method=${JSON.stringify(method)},path="/v1/deployment-layer",body=Buffer.from(process.argv.slice(1).join(""),"base64").toString("utf8"),timestamp=Math.floor(Date.now()/1000),canonical=method+"\\n"+path+"\\n"+body,secret=process.env.CORE_SIGNING_SECRET;if(!secret)throw new Error("CORE_SIGNING_SECRET is not set on core");const signature=createHmac("sha256",secret).update("v0:"+timestamp+":"+canonical).digest("hex");fetch("http://127.0.0.1:"+(process.env.PORT||8080)+path,{method,headers:{"content-type":"application/json","x-timestamp":String(timestamp),"x-signature":"v0="+signature},...(method==="PUT"?{body}: {})}).then(async response=>console.log(${JSON.stringify(FLY_RESPONSE)}+JSON.stringify({status:response.status,body:await response.text()}))).catch(fail)}catch(error){fail(error)}`;
+ const encodedBody = Buffer.from(body).toString("base64");
+ const bodyArgs = Array.from({ length: Math.ceil(encodedBody.length / FLY_EXEC_ARG_BYTES) }, (_, index) =>
+ encodedBody.slice(index * FLY_EXEC_ARG_BYTES, (index + 1) * FLY_EXEC_ARG_BYTES),
+ );
const machineId = flyCoreMachineId(app);
let response: Response;
let text: string;
@@ -134,8 +139,7 @@ async function flyRequest(
"content-type": "application/json",
},
body: JSON.stringify({
- command: ["node", "-e", script],
- stdin: body,
+ command: ["node", "-e", script, ...bodyArgs],
timeout: FLY_EXEC_TIMEOUT_SEC,
}),
signal: AbortSignal.timeout(FLY_REQUEST_TIMEOUT_MS),
diff --git a/cli/src/util.ts b/cli/src/util.ts
index 0d4b3f97b..1ab08c8cf 100644
--- a/cli/src/util.ts
+++ b/cli/src/util.ts
@@ -38,6 +38,7 @@ export function capture(
try {
return execFileSync(cmd, args, {
encoding: "utf8",
+ maxBuffer: 16 * 1024 * 1024,
stdio: ["ignore", "pipe", "pipe"],
...procOpts(opts),
});
diff --git a/cli/test/deployment-layer.test.ts b/cli/test/deployment-layer.test.ts
index 7a3c8d811..eaff4bcc2 100644
--- a/cli/test/deployment-layer.test.ts
+++ b/cli/test/deployment-layer.test.ts
@@ -672,10 +672,11 @@ function flySyncOpts(dir: string, allowUnavailable?: boolean): Parameters<typeof
};
}
-test("fly sync succeeds on the response marker, piping the exact bundle over stdin", async () => {
+test("fly sync carries the exact bundle in bounded exec arguments", async () => {
const dir = mkdtempSync(join(tmpdir(), "qm-layer-fly-"));
try {
writeLayer(dir);
+ writeFileSync(join(dir, "sandbox", "skills", "a", "SKILL.md"), "x".repeat(100_000));
const argsLog = join(dir, "args.log");
const bin = fakeFlyStatus(
dir,
@@ -690,12 +691,19 @@ test("fly sync succeeds on the response marker, piping the exact bundle over std
const request = captured[0]!;
assert.equal(request.url, "https://api.machines.dev/v1/apps/acme-core/machines/machine-core/exec");
assert.equal(request.authorization, "Bearer test-token");
- assert.equal(request.body.stdin, bundle, "the full bundle reaches the remote script's stdin");
+ assert.equal(request.body.stdin, undefined, "the transport does not rely on Machines exec stdin");
assert.equal(request.body.timeout, 120);
assert.ok(Array.isArray(request.body.command));
assert.deepEqual((request.body.command as string[]).slice(0, 2), ["node", "-e"]);
const remoteScript = (request.body.command as string[])[2] ?? "";
assert.match(remoteScript, /createHmac\("sha256"/, "the signing script is passed to node -e directly");
+ assert.equal(
+ Buffer.from((request.body.command as string[]).slice(3).join(""), "base64").toString("utf8"),
+ bundle,
+ "the full bundle reaches the remote script",
+ );
+ assert.ok((request.body.command as string[]).slice(3).every((arg) => Buffer.byteLength(arg) <= 64 * 1024));
+ assert.ok((request.body.command as string[]).length > 4, "large bundles are split across arguments");
assert.doesNotMatch(remoteScript, /eval\(/, "no eval indirection");
assert.deepEqual(JSON.parse(readFileSync(argsLog, "utf8")) as string[], [
"status",
diff --git a/cli/test/util.test.ts b/cli/test/util.test.ts
index 05847120b..e69b87337 100644
--- a/cli/test/util.test.ts
+++ b/cli/test/util.test.ts
@@ -3,7 +3,20 @@ import assert from "node:assert/strict";
import { chmodSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
-import { canonicalJson, runInheritAsync, flyBin, isInvalidSecret, readEnvFile, writeEnvValue } from "../src/util.ts";
+import {
+ canonicalJson,
+ capture,
+ runInheritAsync,
+ flyBin,
+ isInvalidSecret,
+ readEnvFile,
+ writeEnvValue,
+} from "../src/util.ts";
+
+test("capture accepts CLI output larger than Node's one-megabyte default", () => {
+ const output = capture(process.execPath, ["-e", 'process.stdout.write("x".repeat(2 * 1024 * 1024))']);
+ assert.equal(output.length, 2 * 1024 * 1024);
+});
test("managed credential encryption keys require strong material", () => {
assert.equal(isInvalidSecret("CONNECTOR_SECRET_KEY", "short"), true);
diff --git a/package-lock.json b/package-lock.json
index 44659e142..173092116 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -19,7 +19,7 @@
"@aws-sdk/credential-provider-node": "^3.972.70",
"@aws-sdk/s3-request-presigner": "^3.1061.0",
"@earendil-works/pi-ai": "0.82.0",
- "@earendil-works/pi-coding-agent": "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.3/earendil-works-pi-coding-agent-0.82.0-qm-security.3.tgz",
+ "@earendil-works/pi-coding-agent": "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.4/earendil-works-pi-coding-agent-0.82.0-qm-security.4.tgz",
"@fly/sprites": "0.2.3",
"@openai/codex": "0.155.1",
"@opencode-ai/plugin": "1.18.31",
@@ -1008,8 +1008,8 @@
},
"node_modules/@earendil-works/pi-coding-agent": {
"version": "0.82.0",
- "resolved": "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.3/earendil-works-pi-coding-agent-0.82.0-qm-security.3.tgz",
- "integrity": "sha512-kuQ98isehj6j3QwtC2pCWdHmNxKOgqwjUCvmaFwdlN2frRv6brHMWtn8v/fUkxBFPtzHf99APhoidpmAiUX61Q==",
+ "resolved": "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.4/earendil-works-pi-coding-agent-0.82.0-qm-security.4.tgz",
+ "integrity": "sha512-MqE18XzGgcnzNUnqa0jbXdOq1wfsRv0eyoCk7UMC5MMU0maGH8KfXNocvC9T+WDXvMLuu98dM9DSR4F8PvVPDQ==",
"hasShrinkwrap": true,
"license": "MIT",
"dependencies": {
@@ -1029,7 +1029,7 @@
"proper-lockfile": "4.1.2",
"semver": "7.8.0",
"typebox": "1.1.38",
- "undici": "8.9.0",
+ "undici": "8.10.2",
"yaml": "2.9.0"
},
"bin": {
@@ -2718,9 +2718,9 @@
"license": "MIT"
},
"node_modules/@earendil-works/pi-coding-agent/node_modules/undici": {
- "version": "8.9.0",
- "resolved": "https://registry.npmjs.org/undici/-/undici-8.9.0.tgz",
- "integrity": "sha512-aWZpUj7XoGonMClx4gdDRfgBjqeA+F473aDmROQQbM9n6PRfK/u1q/a0X4wMTgcHfT8H6fpbt98PFuDUwFg2YA==",
+ "version": "8.10.2",
+ "resolved": "https://registry.npmjs.org/undici/-/undici-8.10.2.tgz",
+ "integrity": "sha512-/y4/bH9YNU5hi9NIrpOuvGXFcxrj3CMrV+/AYpowAYTpHn8gX/XPFjNy766FPoYY0miQhdW977JFWKGNhBdwyQ==",
"license": "MIT",
"engines": {
"node": ">=22.19.0"
@@ -8509,9 +8509,9 @@
}
},
"node_modules/ip-address": {
- "version": "10.3.1",
- "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.3.1.tgz",
- "integrity": "sha512-1e9d3kb97NHJTIJDZW9rKqW2h6+dFa50Dy0fpPSMQp2ADje5gvKsXmdiK6dwY5t76TaTt5+P5N1Y/LoToIxP6g==",
+ "version": "10.7.2",
+ "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.2.tgz",
+ "integrity": "sha512-7H/2gFSIitxc0hG3nOI1glS8QLo/EHBFFLk8vEUjXY/xu0AdL8jZ9U1IzO2PUm0d2D/ofQcAifb0g6OBkt8U7w==",
"license": "MIT",
"engines": {
"node": ">= 12"
@@ -11323,9 +11323,9 @@
}
},
"node_modules/undici": {
- "version": "8.9.0",
- "resolved": "https://registry.npmjs.org/undici/-/undici-8.9.0.tgz",
- "integrity": "sha512-aWZpUj7XoGonMClx4gdDRfgBjqeA+F473aDmROQQbM9n6PRfK/u1q/a0X4wMTgcHfT8H6fpbt98PFuDUwFg2YA==",
+ "version": "8.10.2",
+ "resolved": "https://registry.npmjs.org/undici/-/undici-8.10.2.tgz",
+ "integrity": "sha512-/y4/bH9YNU5hi9NIrpOuvGXFcxrj3CMrV+/AYpowAYTpHn8gX/XPFjNy766FPoYY0miQhdW977JFWKGNhBdwyQ==",
"license": "MIT",
"engines": {
"node": ">=22.19.0"
diff --git a/package.json b/package.json
index 17329937d..f61acc5d1 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,7 @@
"@aws-sdk/credential-provider-node": "^3.972.70",
"@aws-sdk/s3-request-presigner": "^3.1061.0",
"@earendil-works/pi-ai": "0.82.0",
- "@earendil-works/pi-coding-agent": "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.3/earendil-works-pi-coding-agent-0.82.0-qm-security.3.tgz",
+ "@earendil-works/pi-coding-agent": "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.4/earendil-works-pi-coding-agent-0.82.0-qm-security.4.tgz",
"@fly/sprites": "0.2.3",
"@openai/codex": "0.155.1",
"@opencode-ai/plugin": "1.18.31",
@@ -115,7 +115,8 @@
"fast-json-stringify": {
"fast-uri": "4.1.4"
},
- "undici": "8.9.0",
+ "undici": "8.10.2",
+ "ip-address": "10.7.2",
"protobufjs": "7.6.5"
},
"devDependencies": {
diff --git a/test/pi-dependency-security.test.ts b/test/pi-dependency-security.test.ts
index 00a181b07..2c16cb6ca 100644
--- a/test/pi-dependency-security.test.ts
+++ b/test/pi-dependency-security.test.ts
@@ -6,7 +6,7 @@ import test from "node:test";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
const piCodingAgentTarball =
- "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.3/earendil-works-pi-coding-agent-0.82.0-qm-security.3.tgz";
+ "https://github.com/yc-software/pi/releases/download/qm-pi-coding-agent-0.82.0-security.4/earendil-works-pi-coding-agent-0.82.0-qm-security.4.tgz";
function installedVersion(path: string): string {
const manifestUrl = new URL(`../node_modules/${path}/package.json`, import.meta.url);
@@ -49,10 +49,10 @@ test("Pi and MCP security overrides are materialized by the root lockfile", () =
assert.deepEqual(lockedVersions(packages, "fast-uri").sort(), ["3.1.7", "4.1.4"]);
assert.deepEqual(lockedVersions(packages, "hono"), ["4.13.5"]);
assert.deepEqual(lockedVersions(packages, "protobufjs"), ["7.6.5"]);
- assert.deepEqual(lockedVersions(packages, "undici"), ["8.9.0"]);
+ assert.deepEqual(lockedVersions(packages, "undici"), ["8.10.2"]);
assert.deepEqual(lockedVersions(packages, "@hono/node-server"), ["2.0.10"]);
assert.equal(dependencyVersion(minimatchManifest, "brace-expansion"), "5.0.9");
- assert.equal(dependencyVersion(piManifest, "undici"), "8.9.0");
+ assert.equal(dependencyVersion(piManifest, "undici"), "8.10.2");
assert.equal(dependencyVersion(piManifest, "protobufjs"), "7.6.5");
assert.equal(installedVersion("@hono/node-server"), "2.0.10");
assert.match(