Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions packages/ae-devtools-cli/conformance/mcp-real-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

import { arg } from "../devtools-cli/argv.mjs";
import { spawnMcpStdio, withTimeout } from "../devtools-cli/real-run-kit.mjs";
import { spawnMcpStdio, withTimeout, isCleanServerShutdown } from "../devtools-cli/real-run-kit.mjs";

const HERE = dirname(fileURLToPath(import.meta.url));
const CLI = join(HERE, "..");
Expand Down Expand Up @@ -204,14 +204,30 @@ try {
await new Promise((r) => setTimeout(r, 3000));
shutdownConfirmed = child.exitCode !== null || child.signalCode !== null;
}
// A child that only exits because SIGKILL destroyed it did NOT shut
// down cleanly — session.close() (unsavedChanges:"refuse") never ran
// to completion. That is a failed run, not a confirmed cleanup.
const cleanShutdown = shutdownConfirmed && !forcedKill && child.signalCode !== "SIGKILL";
rec({ step: "server.stopped", fixturePath, shutdownConfirmed, cleanShutdown, forcedKill, results });
// Clean shutdown means the server's OWN shutdown path completed:
// SIGTERM → shutdown(143) → session.close() → process.exit(143).
// Merely stopping is not proof — an exit code of 1 (e.g. an
// unhandled rejection during close) or death by signal means
// session.close() never confirmed the owned AE session closed
// (Issue #384). exitCode/signalCode are recorded either way.
const exitCode = child.exitCode;
const signalCode = child.signalCode;
const cleanShutdown = isCleanServerShutdown({
shutdownConfirmed, forcedKill, exitCode, signalCode,
});
rec({
step: "server.stopped", fixturePath, shutdownConfirmed, cleanShutdown,
forcedKill, exitCode, signalCode, results,
});
if (!cleanShutdown) {
fatal = true;
rec({ fatal: shutdownConfirmed ? "MCP server child required SIGKILL — unclean shutdown" : "MCP server child did not exit after SIGTERM+SIGKILL" });
rec({
fatal: !shutdownConfirmed
? "MCP server child did not exit after SIGTERM+SIGKILL"
: forcedKill
? "MCP server child required SIGKILL — unclean shutdown"
: `MCP server shutdown exit was not the clean SIGTERM path (exitCode=${exitCode} signalCode=${signalCode})`,
});
}

// Verdict: a recorded isError or a non-COMPLETED outcome is a failed
Expand Down
18 changes: 15 additions & 3 deletions packages/ae-devtools-cli/conformance/real-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
aeProcessSnapshot,
createEvalDispatch,
gitHeadAndDirty,
isCleanTimeoutProbe,
} from "../devtools-cli/real-run-kit.mjs";

const HERE = dirname(new URL(import.meta.url).pathname);
Expand Down Expand Up @@ -478,20 +479,31 @@ export async function main() {
});
const t0 = Date.now();
const timeoutRequestId = `conf-timeout-${Date.now().toString(36)}`;
// Exactly-one-send check (Issue #384): an UNKNOWN outcome alone does
// not prove the runner did not resend. No other probe dispatches in
// this window, so the transport send-count delta across the probe +
// late-completion wait must be exactly 1.
const sendsBeforeTimeout = session.transport.sendCount();
const timeoutResult = await timeoutDispatch('$.sleep(2000); "slept"', timeoutRequestId);
// Let the sleeping host script finish before close.
await new Promise((r) => setTimeout(r, 2500));
const sendsAfterTimeout = session.transport.sendCount();
const timeoutSendDelta = sendsAfterTimeout - sendsBeforeTimeout;

evidence.timeoutProbe = {
outcome: timeoutResult.outcome,
contractOutcome: timeoutResult.contractOutcome ?? null,
retry: timeoutResult.retry ?? null,
elapsedMs: Date.now() - t0,
quarantined: shortRunner.isQuarantined(timeoutRequestId),
sendsBefore: sendsBeforeTimeout,
sendsAfter: sendsAfterTimeout,
sendDelta: timeoutSendDelta,
};
step("timeout.probe", {
ok: timeoutResult.outcome === "UNKNOWN",
ok: isCleanTimeoutProbe({ outcome: timeoutResult.outcome, sendDelta: timeoutSendDelta }),
...evidence.timeoutProbe,
});
// Let the sleeping host script finish before close.
await new Promise((r) => setTimeout(r, 2500));

evidence.transportSends = session.transport.sendCount();
evidence.opResultSummary = Object.fromEntries(
Expand Down
22 changes: 22 additions & 0 deletions packages/ae-devtools-cli/devtools-cli/real-run-kit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,25 @@ export function withTimeout(promise, ms, tag) {
new Promise((_, rej) => setTimeout(() => rej(new Error("TIMEOUT " + tag)), ms)),
]);
}

/**
* Conformance timeout-probe verdict (Issue #384): UNKNOWN alone does
* not prove the runner did not resend. The probe passes only when the
* outcome is UNKNOWN AND the transport send-count delta across the
* probe window is exactly one.
*/
export function isCleanTimeoutProbe({ outcome, sendDelta }) {
return outcome === "UNKNOWN" && sendDelta === 1;
}

/**
* Conformance MCP-shutdown verdict (Issue #384): clean shutdown is the
* server's OWN SIGTERM path completing — exit code 143 (128+SIGTERM)
* after session.close(), with no signal and no forced kill. Mere
* termination (any other exit code, death by signal, SIGKILL rescue)
* is not proof the owned AE session closed.
*/
export function isCleanServerShutdown({ shutdownConfirmed, forcedKill, exitCode, signalCode }) {
return shutdownConfirmed === true && forcedKill !== true &&
exitCode === 143 && signalCode === null;
}
26 changes: 26 additions & 0 deletions packages/ae-devtools-cli/devtools-cli/tests/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
aeProcessSnapshot,
createEvalDispatch,
gitHeadAndDirty,
isCleanServerShutdown,
isCleanTimeoutProbe,
spawnMcpStdio,
withTimeout,
} from "../real-run-kit.mjs";
Expand Down Expand Up @@ -830,6 +832,30 @@ t("kit: aeProcessSnapshot and gitHeadAndDirty degrade honestly", async () => {
assert.ok(git.head === null || typeof git.head === "string");
});

// ---- Issue #384: conformance verdict helpers (fake-level) ----

t("kit: isCleanTimeoutProbe requires UNKNOWN AND exactly one send", () => {
assert.equal(isCleanTimeoutProbe({ outcome: "UNKNOWN", sendDelta: 1 }), true);
// A resend still lands UNKNOWN — the delta is what catches it.
assert.equal(isCleanTimeoutProbe({ outcome: "UNKNOWN", sendDelta: 2 }), false);
assert.equal(isCleanTimeoutProbe({ outcome: "UNKNOWN", sendDelta: 0 }), false);
assert.equal(isCleanTimeoutProbe({ outcome: "COMPLETED", sendDelta: 1 }), false);
});

t("kit: isCleanServerShutdown requires the server's own exit-143 path", () => {
const clean = { shutdownConfirmed: true, forcedKill: false, exitCode: 143, signalCode: null };
assert.equal(isCleanServerShutdown(clean), true);
// Exit 1 during shutdown (e.g. unhandled rejection in close) is NOT clean.
assert.equal(isCleanServerShutdown({ ...clean, exitCode: 1 }), false);
assert.equal(isCleanServerShutdown({ ...clean, exitCode: 0 }), false);
// Death by signal means session.close() never confirmed the AE close.
assert.equal(isCleanServerShutdown({ ...clean, exitCode: null, signalCode: "SIGTERM" }), false);
assert.equal(isCleanServerShutdown({ ...clean, exitCode: null, signalCode: "SIGKILL" }), false);
// SIGKILL rescue or unconfirmed exit is never clean.
assert.equal(isCleanServerShutdown({ ...clean, forcedKill: true }), false);
assert.equal(isCleanServerShutdown({ ...clean, shutdownConfirmed: false, exitCode: null, signalCode: null }), false);
});


// ---- Issue #227: runId path-traversal + AppleScript injection guards ----

Expand Down
Loading