Skip to content

An open-source, faster Devin alternative

TypeScript

Add VM-DO exec-path diagnostics (socket census + fallback logging)

Brian Reardon5b71eaf3f3e4
diff --git a/cloudflare-workers/api-edge/src/index.ts b/cloudflare-workers/api-edge/src/index.ts
index 4dd0227b..dbc67de1 100644
--- a/cloudflare-workers/api-edge/src/index.ts
+++ b/cloudflare-workers/api-edge/src/index.ts
@@ -1239,7 +1239,9 @@ async function tryVmDoExec(req: Request, env: Env, caller: Caller, id: string):
// fallback when the DO reports the channel isn't connected.
const body = await req.clone().text();
const stub = env.VM_SESSIONS.get(env.VM_SESSIONS.idFromName(id));
- const doResp = await stub.fetch("https://do/exec", {
+ // sid rides as a query param purely for DO-side diagnostics (idFromName is
+ // one-way; the DO can't recover its own name).
+ const doResp = await stub.fetch("https://do/exec?sid=" + id, {
method: "POST",
headers: { "content-type": "application/json" },
body,
@@ -1248,6 +1250,7 @@ async function tryVmDoExec(req: Request, env: Env, caller: Caller, id: string):
if (doResp.status === 200) {
return new Response(doResp.body, { status: 200, headers: { "content-type": "application/json" } });
}
+ console.log(`vmdo-exec ${id}: DO ${doResp.status} — tunnel fallback`);
} catch {
// DO unreachable — fall through to the tunnel.
}
diff --git a/cloudflare-workers/vm-do/src/vm_session.ts b/cloudflare-workers/vm-do/src/vm_session.ts
index 42872592..11b96fb6 100644
--- a/cloudflare-workers/vm-do/src/vm_session.ts
+++ b/cloudflare-workers/vm-do/src/vm_session.ts
@@ -75,6 +75,12 @@ export class VmSession {
} catch {
return json({ error: "invalid body" }, { status: 400 });
}
+ // Diagnostic: socket census at exec time — sid comes from the edge as a
+ // query param (idFromName is one-way, the DO doesn't know its own name).
+ const socks = this.state.getWebSockets("vm");
+ console.log(
+ `exec sid=${url.searchParams.get("sid") ?? "?"} sockets=${socks.length} states=[${socks.map((s) => s.readyState).join(",")}]`,
+ );
// connected:false lets the edge fall back to the tunnel path (no flag).
if (!this.connectedSocket()) return json({ connected: false, error: "vm not connected" }, { status: 409 });
try {
@@ -95,6 +101,7 @@ export class VmSession {
}
private acceptHostConnection(): Response {
+ console.log(`connect: replacing ${this.state.getWebSockets("vm").length} existing socket(s)`);
// Only one host socket per box; a redial replaces the old one.
for (const socket of this.state.getWebSockets("vm")) socket.close(1012, "replaced");
const pair = new WebSocketPair();