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
5 changes: 3 additions & 2 deletions .agents/skills/verify/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ exit 0
| `new-session-send` | Sender: `send` with `to` set to the full new session id | As `talk-send`, for the new instance id. |
| `new-session-old-instance-not-live` | Sender: `send` with `instance` set to the old instance id, which the same sender process listed before | The result reads `talk: the send failed: not-live`. After 0.5 s, a sentinel `send` to the new instance is delivered, the answer continues the `new-session-send` answer, the peer is still in the new session, and no entry of that answer holds the message id or the payload text of that send. |
| `fork-list`, `fork-send`, `fork-old-instance-not-live` | RPC `fork` with `entryId` set to the last assistant message of the new session. Then the same actions as for `new_session`, with the instance id of `new-session-list` as the old instance id. | As the `new-session-` lines. Also, the answer that confirmed `fork-send`, which is the kept answer, holds the talk entry of `new-session-send`, which the fork inherited. The sentinel answer of `fork-old-instance-not-live` continues the kept answer, so it holds that entry again with the same `id`, `parentId`, `details.messageId`, and `content`. |
| `closed-peer-not-live` | The peer stdin ends and the peer exits. Sender: `send` with `instance` set to the instance id of `fork-list`. | The result reads `talk: the send failed: not-live`. |
| `closed-peer-not-live` | After the driver confirms the peer exited, the sender calls `send` with the instance id from `fork-list`. | The result reads `talk: the send failed: not-live`. Without a confirmed exit, the check fails without sending. |
| `extensions-loaded`, `isolated`, `real-state` | The whole run; the warnings include the standard error of the peer | As in the `hooks` mode |
| `sessions` | Both omp processes | The sender exits 0 after its last turn. The peer exits 0 after its stdin ends. |
| `registry` | The peer from its start and the sender from its start; the script reads the result after `talk-offered`, while both wait. The peer again from the new session id of each `new_session` and `fork`, apart from the list step. The final scan of the peer before its stdin ends, and of the sender before its last turn. | As in the `hooks` mode, for each of the two processes, with the work folder of the run as `cwd`. After a session change, the valid private entry also has the new session id, and its instance id is the instance id of the list. Each final scan finds no entry of the registrations of its process in the default folder. When a check before it fails and no final scan found a problem, this line reads `not run`. |
| `registry` | The peer from its start and the sender from its start; the script reads the result after `talk-offered`, while both wait. The peer again from the new session id of each `new_session` and `fork`, apart from the list step. The final scan of the peer before its stdin ends, and of the sender before its last turn. | As in the `hooks` mode, for each of the two processes, with the work folder of the run as `cwd`. After a session change, the valid private entry also has the new session id, and its instance id is the instance id of the list. Each final scan finds no entry of the registrations of its process in the default folder. An earlier failure can leave this check `not run`. A later failure does not reset a completed check. |
| `registry-removed` | After the cleanup | The registry folder does not exist. |

A failed scenario check stops the scenario. Each scenario line after it prints `FAIL <name>: not run, because an earlier check failed`. The lines from `extensions-loaded` on run in each case, except `registry`, which needs `talk-offered`.
Expand Down Expand Up @@ -286,6 +286,7 @@ The other lines are as above. talk is off on this omp and registers no session,
| `FAIL talk-offered: the first fixture turn of the <peer or sender> took more than 30 s` | The responder did not identify an opening prompt before the deadline. It did not inspect that turn's tool list. | Check whether omp sent the prompt. If it did, compare its message format with `latestEvent` in `smokeTalkTurns.ts`. |
| `FAIL talk-offered: the first fixture turn of the <peer or sender> does not offer the talk tool` | The named process sent its opening turn without `talk` in the tool list. | Check `extensions-loaded`. If the extension loaded, check tool registration and whether omp offers `talk` as a provider tool instead of a Bash command. |
| V6 `talk` prints `the <action> call talk-sender-<n> took more than 30 s` | The driver did not receive a matching completion before the deadline. The message alone does not say whether a tool result arrived. | Check whether the tool ran and returned. If it did, check the call ID and the latest event. Run `bun run test:unit cli/test/unit/verifySmokeTalkTurns.test.ts`. |
| `talk` or `talk-ui` reports `the peer omp exit was not confirmed after SIGKILL` | The final 10 s wait ended without an exit event. A closed socket does not prove exit. | Repeat V6 with `bun --preload ./cli/test/fixtures/talk/unconfirmed-peer.ts` in place of `bun`. Require exit 1 and `FAIL sessions: fixture: peer exit was not confirmed after SIGKILL` followed by the stderr excerpt. For `talk`, also require `FAIL closed-peer-not-live: fixture: peer exit was not confirmed after SIGKILL`. All other checks must pass. Reject any `fixture: attempted post-close send` on stderr. |
| V6 `talk` reports another failure in `talk-`, `new-session-`, `fork-`, or `closed-peer-` | The step name identifies where the driver stopped, not which operation failed. | Read the reason after the step name. Check the named RPC command, tool result, or fixture operation. |
| V6 `talk` prints `FAIL handover-refused` | A print session did not refuse the `handover` action before its side turn: the result has no refusal, the fake model got a side-turn request with the handover template, the peer holds the note or a handover entry, or the call took more than 30 s because a flow opened in a session without a terminal | Check the refusals of `handoverFlow` in `cli/talk/extension.ts` and `runHandover` in `cli/talk/tool/tool.ts` (#260 H3) |
| V6 `talk-ui` prints `FAIL ui-ready` or `FAIL old-omp` with `footer with the model name` | The TUI omp did not start in the pseudo-terminal, for example because it shows the setup wizard | Read the screen text in the reason. Check `startup.setupWizard` in the isolated `config.yml` and the omp version (V2) |
Expand Down
157 changes: 62 additions & 95 deletions .agents/skills/verify/scripts/omp-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ import {
TalkPosixSystem,
TalkTrustError,
} from "../../../../cli/talk/transport/trustPosix.ts";
import {
PEER_CLOSE_MS,
peerSessionFailure,
peerShutdown,
type PeerResult,
} from "./smokePeerShutdown.ts";
import {
type Attribution,
decodeAttribution,
Expand Down Expand Up @@ -357,11 +363,14 @@ function isolatedEnv(isolation: Isolation): Record<string, string> {
return env;
}

interface OmpResult {
interface OmpDiagnostics {
readonly stderr: string;
}

interface OmpResult extends OmpDiagnostics {
readonly argv: readonly string[];
readonly code: number | "timeout" | null;
readonly stdout: string;
readonly stderr: string;
}

/**
Expand Down Expand Up @@ -1261,7 +1270,7 @@ function pluginMarkers(plugin: LinkedPlugin | null): string[] {
*/
function countWarnings(
skillWarnings: readonly Json[],
results: readonly OmpResult[],
results: readonly OmpDiagnostics[],
stateDir: string,
markers: readonly string[],
): string[] {
Expand Down Expand Up @@ -1304,7 +1313,7 @@ interface Run {
readonly workDir: string;
readonly requests: JsonObject[];
readonly script: Script;
readonly results: OmpResult[];
readonly results: OmpDiagnostics[];
readonly omp: (argv: readonly string[], options?: OmpOptions) => Promise<OmpResult>;
readonly plugin: LinkedPlugin | null;
/** The modification time of the fresh sweep stamp in the scratch home. */
Expand Down Expand Up @@ -1383,7 +1392,7 @@ async function install(failures: string[], setup: InstallSetup = DEFAULT_SETUP):
if (setup.configYaml !== null)
writeFileSync(join(isolation.stateDir, "agent", "config.yml"), setup.configYaml);

const results: OmpResult[] = [];
const results: OmpDiagnostics[] = [];
const omp = async (argv: readonly string[], options: OmpOptions = {}): Promise<OmpResult> => {
const result = await runOmp(
argv,
Expand Down Expand Up @@ -2030,9 +2039,6 @@ const LIST_ATTEMPTS = 20;
const LIST_RETRY_MS = 250;
/** The wait before a check that expects no entry, so that a late append would show. */
const SETTLE_MS = 500;
const PEER_CLOSE_MS = 10_000;
/** Allow buffered RPC output to drain after exit, but not an inherited pipe to keep the fixture open. */
const RPC_OUTPUT_DRAIN_MS = 250;
/** The number of session id characters that a `list` line shows. */
const SHORT_ID_LENGTH = 8;

Expand Down Expand Up @@ -2079,9 +2085,9 @@ interface RpcPeer {
readonly send: (command: JsonObject) => Promise<Json>;
/**
* Ends stdin and waits for the exit; SIGTERM, then SIGKILL, when omp does not exit in time. A process that
* already exited, or never started, gives its result at once. Repeated calls share the first result.
* already exited still receives its bounded output drain. Repeated calls share the first result.
*/
readonly close: () => Promise<OmpResult>;
readonly close: () => Promise<PeerResult>;
}

/** A spawned RPC omp: its handle, and its ready line, which fails when the process ends first or takes too long. */
Expand All @@ -2091,9 +2097,7 @@ interface RpcStart {
}

/**
* Starts omp in RPC mode. The handle comes at spawn, apart from the ready line, so a mode records the process
* before it waits: a peer that exits or stalls before its ready line still gets its final scan, its close, and
* its exit result.
* Returns the peer handle before readiness so both modes can scan and close it even if startup stalls.
*/
function startRpcOmp(
argv: readonly string[],
Expand All @@ -2107,32 +2111,32 @@ function startRpcOmp(
let ended = false;
const waiting = new Map<string, Deferred<Json>>();
const ready = Promise.withResolvers<void>();
let drainTimer: NodeJS.Timeout | undefined;
const exited = Promise.withResolvers<number | null>();
const output = createInterface({ input: child.stdout });
/** Settle once, after the peer exits and its output drains or the drain deadline expires. */
const end = (code: number | null, problem: string): void => {
if (ended) return;
ended = true;
clearTimeout(drainTimer);
children.delete(child);
output.close();
child.stdin.destroy();
child.stdout.destroy();
child.stderr.destroy();
const gone = new Error(`${problem}: ${short(stderr)}`);
for (const reply of waiting.values()) reply.reject(gone);
waiting.clear();
ready.reject(gone);
exited.resolve(code);
};
const shutdown = peerShutdown(child, {
endInput: () => child.stdin.end(),
signal: (signal) => child.kill(signal),
unref: () => child.unref(),
release: (problem) => {
ended = true;
children.delete(child);
output.close();
child.stdin.destroy();
child.stdout.destroy();
child.stderr.destroy();
const gone = new Error(`${problem}: ${short(stderr)}`);
for (const reply of waiting.values()) reply.reject(gone);
waiting.clear();
ready.reject(gone);
return stderr;
},
});
child.stdin.on("error", () => undefined);
child.stderr.on("data", (chunk: Buffer) => {
stderr += chunk.toString("utf8");
});
child.on("error", (error) => {
stderr += String(error);
if (child.pid === undefined) end(null, "the peer omp did not start");
if (child.pid === undefined) shutdown.failedToStart();
});
output.on("line", (line) => {
const message = parseJsonText(line);
Expand All @@ -2151,14 +2155,6 @@ function startRpcOmp(
);
else reply.resolve(message["data"] ?? null);
});
child.once("exit", (code) => {
// A descendant can hold stdout or stderr after the peer exits. Keep its
// buffered replies until `close`, but never wait indefinitely for EOF.
drainTimer = setTimeout(() => end(code, `the peer omp exited ${code}`), RPC_OUTPUT_DRAIN_MS);
});
child.on("close", (code) => {
end(code, `the peer omp exited ${code}`);
});

const send = (rpcCommand: JsonObject): Promise<Json> => {
if (ended) return Promise.reject(new Error("the peer omp has ended"));
Expand All @@ -2169,30 +2165,8 @@ function startRpcOmp(
child.stdin.write(`${JSON.stringify({ id, ...rpcCommand })}\n`);
return withTimeout(reply.promise, STEP_TIMEOUT_MS, `RPC ${String(rpcCommand["type"])}`);
};
const exitWithin = (ms: number): Promise<number | null | undefined> =>
withTimeout(exited.promise, ms, "the exit").catch(() => undefined);
const stop = async (): Promise<OmpResult> => {
if (!ended) child.stdin.end();
let code = await exitWithin(PEER_CLOSE_MS);
if (code === undefined) {
child.kill("SIGTERM");
code = await exitWithin(PEER_CLOSE_MS);
}
if (code === undefined) {
child.kill("SIGKILL");
code = await exitWithin(PEER_CLOSE_MS);
if (code === undefined) {
child.unref();
end(null, "the peer omp did not exit after SIGKILL");
return { argv, code: "timeout", stdout: "", stderr };
}
}
return { argv, code, stdout: "", stderr };
};
let closing: Promise<OmpResult> | undefined;
const close = (): Promise<OmpResult> => (closing ??= stop());
return {
peer: { pid: child.pid, send, close },
peer: { pid: child.pid, send, close: shutdown.close },
ready: withTimeout(ready.promise, STEP_TIMEOUT_MS, "the ready line of the peer omp"),
};
}
Expand Down Expand Up @@ -2412,7 +2386,7 @@ async function talkMode(): Promise<{ lines: string[]; registry: string | null }>
const pass = (): void => {
results.set(step, "");
};
let peer: FixtureProcess<RpcPeer> = { kind: "absent" };
let peer: FixtureProcess<RpcPeer, PeerResult> = { kind: "absent" };
let senderRun: Promise<OmpResult> | null = null;
// The registrations that the mode attributed for each omp process, and the problems of the `registry` line.
const peerAttributed: Attributed[] = [];
Expand All @@ -2430,8 +2404,7 @@ async function talkMode(): Promise<{ lines: string[]; registry: string | null }>
reportRegistry();
};
try {
// The peer: omp in RPC mode. Its first provider turn answers the driver's prompt. The mode holds its handle
// before the ready line, so a peer that ends or stalls first still gets its final scan and its exit result.
// The peer's first provider turn answers the driver's prompt.
const started = startRpcOmp(
["--mode", "rpc", "--model", `${MODEL_PROVIDER}/${PEER_MODEL_ID}`, "--no-title"],
run.workDir,
Expand Down Expand Up @@ -2763,6 +2736,7 @@ async function talkMode(): Promise<{ lines: string[]; registry: string | null }>
// The smoke ends the peer here; the sender stays live until the end of the mode.
await finalScan(peerAttributed);
peer = { kind: "closed", result: await rpc.close() };
if (peer.result.kind === "unconfirmed") failStep(peer.result.reason);
const closed = await sender.call(TALK_TOOL, {
action: "send",
instance: afterFork.instance,
Expand All @@ -2775,9 +2749,7 @@ async function talkMode(): Promise<{ lines: string[]; registry: string | null }>
results.set(step, error instanceof Error ? error.message : String(error));
}

// The sender ends after its next turn, and a slow peer turn that still waits ends; a sender that still
// waits in a tool call is stopped. After a failed step, the peer ends here too; a peer that exited or stalled
// before its ready line is still open here, so it gets its final scan and its exit result as well.
// Finish any pending turns. After a failed step, scan the peer before closing its handle.
await finalScan(senderAttributed);
sender.finish();
peerModel.release();
Expand All @@ -2794,16 +2766,13 @@ async function talkMode(): Promise<{ lines: string[]; registry: string | null }>
return senderRun;
});
const sessionFailures: string[] = [];
for (const [name, result] of [
["sender", senderResult],
["peer", peerResult],
] as const) {
if (result === null) sessionFailures.push(`the ${name} omp did not run`);
else if (result.code !== 0)
sessionFailures.push(
`the ${name} omp exited ${result.code}: ${short(result.stderr || result.stdout)}`,
);
}
if (senderResult === null) sessionFailures.push("the sender omp did not run");
else if (senderResult.code !== 0)
sessionFailures.push(
`the sender omp exited ${senderResult.code}: ${short(senderResult.stderr || senderResult.stdout)}`,
);
const peerFailure = peerSessionFailure(peerResult, short);
if (peerFailure) sessionFailures.push(peerFailure);
if (peerResult !== null) run.results.push(peerResult);
const warnings = countWarnings(
[],
Expand Down Expand Up @@ -3221,13 +3190,12 @@ class TerminalOmp {
}

/**
* One omp process of a talk mode: not started, open while the driver holds a handle to close (whether or not the
* process passed its readiness check), or closed with its exit result.
* An open handle needs cleanup even before readiness. A closed handle has a shutdown result, not proof of exit.
*/
type FixtureProcess<Handle> =
type FixtureProcess<Handle, Completion> =
| { readonly kind: "absent" }
| { readonly kind: "open"; readonly handle: Handle }
| { readonly kind: "closed"; readonly result: OmpResult };
| { readonly kind: "closed"; readonly result: Completion };

/** One `talk` call of the RPC peer that the driver waits for. */
interface MarkedCall {
Expand Down Expand Up @@ -3377,8 +3345,8 @@ async function talkUiMode(): Promise<{ lines: string[]; registry: string | null
const pass = (): void => {
results.set(step, "");
};
let terminal: FixtureProcess<TerminalOmp> = { kind: "absent" };
let peer: FixtureProcess<RpcPeer> = { kind: "absent" };
let terminal: FixtureProcess<TerminalOmp, OmpResult> = { kind: "absent" };
let peer: FixtureProcess<RpcPeer, PeerResult> = { kind: "absent" };

/**
* omp before 19.2.0: one capability notice, no load error, no `/talk` command, and no `talk` tool. The first
Expand Down Expand Up @@ -3881,8 +3849,6 @@ async function talkUiMode(): Promise<{ lines: string[]; registry: string | null
await screen.waitFor(UI_READY_TEXT, 0, "footer with the model name");
if (checks === OLD_OMP_CHECKS) await oldOmpFlow(screen);
else {
// The mode holds the peer handle before the ready line, so a peer that ends or stalls first still gets its
// final scan and its exit result.
const started = startRpcOmp(
["--mode", "rpc", "--model", `${MODEL_PROVIDER}/${PEER_MODEL_ID}`, "--no-title"],
run.workDir,
Expand Down Expand Up @@ -3921,14 +3887,15 @@ async function talkUiMode(): Promise<{ lines: string[]; registry: string | null
if (peer.kind === "open") peer = { kind: "closed", result: await peer.handle.close() };
const peerResult = peer.kind === "closed" ? peer.result : null;
const sessionFailures: string[] = [];
const sessions: Array<readonly [string, OmpResult | null]> = [["TUI", terminalResult]];
if (checks === UI_CHECKS) sessions.push(["peer", peerResult]);
for (const [name, result] of sessions) {
if (result === null) sessionFailures.push(`the ${name} omp did not run`);
else if (result.code !== 0)
sessionFailures.push(
`the ${name} omp exited ${result.code}: ${short(result.stderr.slice(-600))}`,
);
const excerpt = (stderr: string): string => short(stderr.slice(-600));
if (terminalResult === null) sessionFailures.push("the TUI omp did not run");
else if (terminalResult.code !== 0)
sessionFailures.push(
`the TUI omp exited ${terminalResult.code}: ${excerpt(terminalResult.stderr)}`,
);
if (checks === UI_CHECKS) {
const peerFailure = peerSessionFailure(peerResult, excerpt);
if (peerFailure) sessionFailures.push(peerFailure);
}
for (const result of [terminalResult, peerResult]) if (result !== null) run.results.push(result);
const warnings = countWarnings(
Expand Down
Loading
Loading