Skip to content
Draft
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
26 changes: 11 additions & 15 deletions docs/guides/pr-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,17 @@ personality instead.

A scenario with `transcriptReplay` plays a fixed recording into the target
and scores what its transcriber heard (see
[simulations learnings](../learnings/simulations.md#recording-replays)). The
simulations API runs a replay only from a **saved** scenario, so a check
sends a replay scenario by its UUID in the org, not from the branch. The
target is still built from the branch, which is what a replay tests. So:

- The check needs `transport: voice`, and runs only in its own org (no
`runOrg`).
- Apply the scenario before the check can run it. The build fails for a
replay scenario that has never been deployed.
- Before a live run, the check reads each saved replay scenario. If the
file's `transcriptReplay`, `evaluations`, `latencyExpectations` or
`toolMocks` differ from the saved copy, the check stops with an error and
sends nothing: apply the scenario, then rerun.
- Replays are in a platform rollout. An org outside it gets a 400 from the
run.
[simulations learnings](../learnings/simulations.md#recording-replays)). Like
every other scenario, a check sends it inline from the branch, so a PR that
edits the recording URL, the answer key or the WER threshold is tested with
those edits, and the scenario needn't be deployed first. The build refuses
what the platform would:

- The check needs `transport: voice` and an assistant target, not a squad.
- A replay scenario takes no `hooks` and no `latencyExpectations`.
- Replays are in a platform rollout. A run org outside it gets a 400 from
the run. An org or target assistant with HIPAA, PCI or zero data
retention must use `answerKeyUrl` instead of an inline `answerKey`.

## 3. Dry run locally (no key, nothing sent)

Expand Down
21 changes: 11 additions & 10 deletions docs/learnings/simulations.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,12 @@ behaviours worth knowing when a check surprises you.
default error mocks whether or not a tool was called; read tool results
from `metadata.call.messages` (`tool_calls` carry the ids and names,
`tool_call_result` the answers by `toolCallId`).
- **Replays go by saved UUID.** The run API rejects an inline
`transcriptReplay` ("An inline scenario cannot use transcriptReplay"), on
purpose: a replay must pass the checks that run when a scenario is saved,
and an answer key sent in a run request is never stored. So the check sends
`{type: "simulation", scenarioId, personality}` for a replay scenario, and
first compares the saved copy with the branch's file (see
[Recording replays](#recording-replays)). Replays mock every tool on the
platform by default, so the fail-closed tool rule still holds.
- **Replays go inline too.** The run API accepts an inline
`transcriptReplay` and applies the checks that run when a scenario is
saved, so the 400s match save's (see
[Recording replays](#recording-replays)). Before that change it refused
one ("An inline scenario cannot use transcriptReplay"), and a check had to
run the saved copy instead of the branch's.
- **Runs are named by their entries.** The run API has no run-level name.
The dashboard's runs table (and the runs list's `summary.source.name`)
shows the entries' shared `name` when every entry has the same one (2 or
Expand Down Expand Up @@ -319,8 +317,11 @@ transcriptReplay:
required only when it says `required: true`. For HIPAA, PCI and
zero-data-retention orgs, `value` is absent and only an `answerKeyUrl` can
be saved.
- **Replays run only from a saved scenario**, by `scenarioId` or
`simulationId`, and the org must be in the replay rollout.
- **Replays run inline or saved**, and the org must be in the replay
rollout. Inline or saved, a replay needs the voice transport and a single
assistant target, takes only `wer` metric evaluations, and takes no
`hooks` or `latencyExpectations`. Omitted `instructions` and
`evaluations` are stored as `''` and `[]`.
- **Host the recording at a fixed public URL**, and keep it fetchable for
every future run. Presigned call-recording links expire after 30 minutes,
and Vapi's file store rejects audio. A URL pinned to a commit SHA works.
Expand Down
20 changes: 11 additions & 9 deletions improvements.md
Original file line number Diff line number Diff line change
Expand Up @@ -2401,18 +2401,20 @@ failing one, or a run failing only on a latency budget, showed no detail.

### Current behavior and mitigation

A check sends a replay scenario by its saved UUID, with the target still
built from the branch. It needs voice, its own org, and a deployed scenario.
Before a live run it reads each saved replay scenario and stops with an error
if the file's replay settings differ, so a branch edit isn't judged on the
old copy. The verdict reads `results.transcriptEvaluation` and
`results.latencyEvaluations`.
The platform now accepts an inline `transcriptReplay`, with save's checks,
so a check sends a replay scenario inline from the branch like any other.
The build refuses a replay over chat, against a squad, or with `hooks` or
`latencyExpectations`, as the platform does. The verdict reads
`results.transcriptEvaluation` and `results.latencyEvaluations`.

Before inline replays shipped, a check ran the saved copy by UUID and
compared it with the branch's file first, so a PR that edited a replay was
never what ran.

### Risk

The exception to "what's in the files is what runs" is permanent unless the
platform starts accepting inline replays. The stale-copy comparison accepts
extra keys the platform adds, so a key removed from the file goes unnoticed.
A run org outside the replay rollout, or one where the inline-replay change
hasn't deployed, gets a 400 for the whole run.

### Status

Expand Down
33 changes: 13 additions & 20 deletions src/check-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,7 @@ export function checkMocksApply(args: CheckMocksArgs): void {
walkObject(w, body.target, base);
body.simulations.forEach((entry, index) => {
const label = `simulations[${index}] (${entry.name})`;
// Only a transcript replay goes by scenarioId (see replayEntryBuild). Its
// saved copy can't take default mocks; the platform answers a replay's
// tool calls with a mock of its own, and the dead servers still apply.
if (entry.scenario === undefined && entry.scenarioId === undefined)
w.errors.push(`${label}: needs an inline scenario or a scenarioId`);
if (entry.scenario !== undefined && entry.scenarioId !== undefined)
if ("scenarioId" in entry)
w.errors.push(`${label}: scenarios must be inline, not by scenarioId`);
if (
entry.personalityId !== undefined &&
Expand All @@ -450,12 +445,11 @@ export function checkMocksApply(args: CheckMocksArgs): void {
w.errors.push(
`${label}: personalities must be inline or stock, not ${entry.personalityId}`,
);
if (entry.scenario)
walkObject(w, entry.scenario, {
...base,
path: `${label}.scenario`,
where: "scenario",
});
walkObject(w, entry.scenario, {
...base,
path: `${label}.scenario`,
where: "scenario",
});
if (entry.personality)
walkObject(w, entry.personality, {
...base,
Expand All @@ -464,12 +458,11 @@ export function checkMocksApply(args: CheckMocksArgs): void {
});
});
if (!w.strict) return;
body.simulations.forEach((entry, index) => {
if (entry.scenario)
defaultMocksAdd(
w,
entry.scenario,
`simulations[${index}] (${entry.name}).scenario`,
);
});
body.simulations.forEach((entry, index) =>
defaultMocksAdd(
w,
entry.scenario,
`simulations[${index}] (${entry.name}).scenario`,
),
);
}
168 changes: 28 additions & 140 deletions src/check-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// from the PR branch's files: the target assistant or squad with its tools,
// handoffs and structured outputs, plus every scenario, judge and
// personality the check's suites and simulations name. Nothing is looked up
// on the platform — what's in the files is what runs — with one exception:
// the API runs a transcript replay only from a saved scenario, so a replay
// scenario is sent by its deployed UUID (replayEntryBuild).
// on the platform — what's in the files is what runs.
//
// Pure: inputs come from orgResourcesRead and promotionStateParse. Every
// problem is collected, so one dry run reports them all.

import type { CheckDefinition, CheckTarget } from "./check-config.ts";
import { checkMocksApply } from "./check-mocks.ts";
import {
assistantInline,
assistantSelfRefs,
Expand All @@ -29,7 +28,6 @@ import {
refResolve,
serverFieldsStrip,
} from "./check-payload-refs.ts";
import { checkMocksApply } from "./check-mocks.ts";
import { credentialForwardMap, replaceCredentialRefs } from "./credentials.ts";
import type { PromotionBindingsResolved } from "./promotion.ts";
import { promotionBindingsApply } from "./promotion.ts";
Expand All @@ -53,9 +51,7 @@ export interface CheckPayloadInput {
export interface CheckSimulationEntry {
type: "simulation";
name: string;
// Inline, except for a transcript replay, which goes by scenarioId.
scenario?: Record<string, unknown>;
scenarioId?: string;
scenario: Record<string, unknown>;
personality?: Record<string, unknown>;
personalityId?: string;
}
Expand All @@ -69,21 +65,11 @@ export interface CheckRunBody {
iterations: number;
}

// A replay scenario the body runs by its saved UUID, with the branch file's
// replay settings, so a live run can first check the saved copy matches.
export interface CheckReplay {
// simulations/scenarios/<id>
scenario: string;
scenarioId: string;
expected: Record<string, unknown>;
}

export interface CheckPayloadResult {
body?: CheckRunBody;
errors: string[];
warnings: string[];
bytes: number;
replays?: CheckReplay[];
}

export const MAX_PAYLOAD_BYTES = 4.5 * 1024 * 1024;
Expand Down Expand Up @@ -377,7 +363,6 @@ function personalityBuild(
function entriesBuild(
ctx: CheckPayloadContext,
check: CheckDefinition,
replays: CheckReplay[],
): CheckSimulationEntry[] {
const entries: CheckSimulationEntry[] = [];
const used = new Set<string>();
Expand All @@ -400,24 +385,9 @@ function entriesBuild(
continue;
}
const scenarioLabel = `simulations/scenarios/${scenarioFile.id}`;
if (isObject(scenarioFile.data.transcriptReplay)) {
const entry = replayEntryBuild(ctx, {
check,
scenarioFile,
simulation,
label,
});
if (!entry) continue;
entries.push({ ...entry, name: entryName(entry.name, used) });
if (!replays.some((replay) => replay.scenarioId === entry.scenarioId))
replays.push({
scenario: scenarioLabel,
scenarioId: entry.scenarioId!,
expected: replayComparedPick(scenarioFile.data),
});
continue;
}
const scenario = serverFieldsStrip(scenarioFile.data);
if (isObject(scenario.transcriptReplay))
replayRulesCheck(ctx, check, scenario, scenarioLabel);
judgesInline(ctx, scenario, scenarioLabel);
if (isObject(scenario.targetOverrides))
overridesProcess(
Expand Down Expand Up @@ -448,110 +418,35 @@ function entriesBuild(
return entries;
}

interface ReplayEntryArgs {
check: CheckDefinition;
scenarioFile: OrgResource;
simulation: OrgResource;
label: string;
}

// POST /eval/simulation/run rejects an inline transcriptReplay ("Save the
// scenario, then run it by simulationId or scenarioId"), so a replay runs the
// copy saved in the org. The target is still built from the branch, which is
// what a replay tests: the branch's transcriber against a fixed recording.
function replayEntryBuild(
// The platform runs a transcript replay only over voice against a single
// assistant, and refuses a replay scenario with a tester's settings. Checked
// here so a dry run reports what a live run's 400 would.
function replayRulesCheck(
ctx: CheckPayloadContext,
{ check, scenarioFile, simulation, label }: ReplayEntryArgs,
): CheckSimulationEntry | undefined {
const scenarioLabel = `simulations/scenarios/${scenarioFile.id}`;
if (check.transport !== "voice") {
ctx.errors.push(
`${scenarioLabel}: a transcriptReplay scenario needs transport: voice`,
);
return undefined;
}
if (check.runOrg !== check.org) {
check: CheckDefinition,
scenario: Record<string, unknown>,
label: string,
): void {
if (check.transport !== "voice")
ctx.errors.push(
`${scenarioLabel}: a transcriptReplay scenario runs only in its own org (${check.org}), not runOrg ${check.runOrg}`,
`${label}: a transcriptReplay scenario needs transport: voice`,
);
return undefined;
}
const uuid = ctx.sourceState.scenarios[scenarioFile.id]?.uuid;
if (!uuid) {
if (ctx.targetMembers)
ctx.errors.push(
`${scenarioLabel}: a transcriptReplay scenario runs from its saved copy; apply it to ${check.org} first`,
`${label}: a transcriptReplay scenario runs only against an assistant, not a squad`,
);
return undefined;
}
ctx.warnings.push(
`${scenarioLabel}: transcriptReplay runs the copy saved in ${check.org}; a live check fails if this file's replay settings differ from it, until you apply`,
);
const personality = personalityBuild(
ctx,
simulation.data.personalityId,
`${label}.personalityId`,
);
if (!personality) return undefined;
const name =
typeof simulation.data.name === "string"
? simulation.data.name
: simulation.id;
return { type: "simulation", name, scenarioId: uuid, ...personality };
}

// The scenario settings that decide a replay's result. None hold a
// reference: a replay takes only metric evaluations.
const REPLAY_COMPARED_KEYS = [
"transcriptReplay",
"evaluations",
"latencyExpectations",
"toolMocks",
] as const;

function replayComparedPick(
data: Record<string, unknown>,
): Record<string, unknown> {
const picked: Record<string, unknown> = {};
for (const key of REPLAY_COMPARED_KEYS)
if (data[key] !== undefined) picked[key] = clone(data[key]);
return picked;
for (const key of ["hooks", "latencyExpectations"])
if (!isEmpty(scenario[key]))
ctx.errors.push(
`${label}.${key}: a transcriptReplay scenario takes none`,
);
}

function isEmpty(value: unknown): boolean {
if (value === undefined || value === null) return true;
if (Array.isArray(value)) return value.length === 0;
return isObject(value) && Object.keys(value).length === 0;
}

// Whether the saved value holds everything the file says. The platform can
// add defaults the file leaves out, so extra saved keys don't count; arrays
// must match item for item.
function savedCovers(local: unknown, saved: unknown): boolean {
if (isEmpty(local) && isEmpty(saved)) return true;
if (Array.isArray(local))
return (
Array.isArray(saved) &&
saved.length === local.length &&
local.every((item, index) => savedCovers(item, saved[index]))
);
if (isObject(local))
return (
isObject(saved) &&
Object.entries(local).every(
([key, value]) => value === undefined || savedCovers(value, saved[key]),
)
);
return local === saved;
}

// The replay settings where the branch's file and the saved scenario
// differ, for checkRunAll to refuse a run that would test a stale copy.
export function replayDifferences(
replay: CheckReplay,
saved: Record<string, unknown>,
): string[] {
return REPLAY_COMPARED_KEYS.filter(
(key) => !savedCovers(replay.expected[key], saved[key]),
return (
value === undefined ||
value === null ||
(Array.isArray(value) && value.length === 0)
);
}

Expand Down Expand Up @@ -658,8 +553,7 @@ export function checkPayloadBuild(
warnings: [],
};
const target = targetBuild(ctx, input.target);
const replays: CheckReplay[] = [];
const simulations = entriesBuild(ctx, input.check, replays);
const simulations = entriesBuild(ctx, input.check);
const label = runLabelBuild(input);
// The dashboard labels a run with its entries' name only when they all
// share it; each item still shows its own scenario and personality.
Expand Down Expand Up @@ -696,11 +590,5 @@ export function checkPayloadBuild(
);
if (ctx.errors.length > 0)
return { errors: ctx.errors, warnings: ctx.warnings, bytes };
return {
body,
errors: [],
warnings: ctx.warnings,
bytes,
...(replays.length > 0 ? { replays } : {}),
};
return { body, errors: [], warnings: ctx.warnings, bytes };
}
Loading
Loading