Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
405 lines
13 KiB
TypeScript
405 lines
13 KiB
TypeScript
import { compareToolCallShape, stableHash } from "./parity-shared.js";
|
|
// Qa Lab plugin module implements harness parity behavior.
|
|
import type {
|
|
RuntimeId,
|
|
RuntimeParityCell,
|
|
RuntimeParityDrift,
|
|
RuntimeParityToolCall,
|
|
RuntimeParityUsage,
|
|
} from "./runtime-parity.js";
|
|
import type { RuntimeParityComparisonMode } from "./runtime-tool-metadata.js";
|
|
|
|
export type HarnessVariant = {
|
|
id: string;
|
|
label: string;
|
|
runtime?: RuntimeId;
|
|
model?: string;
|
|
configPatch?: Record<string, unknown>;
|
|
systemPromptOverlay?: string;
|
|
toolDescriptionOverlay?: Record<string, string>;
|
|
};
|
|
|
|
export type HarnessParityDrift =
|
|
| RuntimeParityDrift
|
|
| "system-prompt"
|
|
| "tool-description"
|
|
| "tool-schema";
|
|
|
|
export type HarnessParityPromptStats = {
|
|
systemPromptChars: number;
|
|
projectContextChars: number;
|
|
nonProjectContextChars: number;
|
|
skillPromptChars: number;
|
|
toolSummaryChars: number;
|
|
toolSchemaChars: number;
|
|
toolCount: number;
|
|
};
|
|
|
|
export type RuntimeParitySystemPromptReport = {
|
|
systemPrompt?: {
|
|
chars?: number;
|
|
projectContextChars?: number;
|
|
nonProjectContextChars?: number;
|
|
text?: string;
|
|
hash?: string;
|
|
contentHash?: string;
|
|
};
|
|
skills?: {
|
|
promptChars?: number;
|
|
prompt?: string;
|
|
hash?: string;
|
|
contentHash?: string;
|
|
};
|
|
tools?: {
|
|
listChars?: number;
|
|
schemaChars?: number;
|
|
entries?: Array<{
|
|
name?: string;
|
|
summary?: string;
|
|
summaryHash?: string;
|
|
summaryChars?: number;
|
|
schema?: unknown;
|
|
schemaHash?: string;
|
|
schemaChars?: number;
|
|
propertiesCount?: number;
|
|
}>;
|
|
};
|
|
};
|
|
|
|
export type HarnessRuntimeParityCell = RuntimeParityCell & {
|
|
systemPromptReport?: RuntimeParitySystemPromptReport;
|
|
};
|
|
|
|
export type HarnessParityCell = HarnessRuntimeParityCell & {
|
|
variant: HarnessVariant;
|
|
promptStats: HarnessParityPromptStats;
|
|
systemPromptHash: string;
|
|
toolDescriptionHash: string;
|
|
toolSchemaHash: string;
|
|
tokenUsage: RuntimeParityUsage;
|
|
tokenUsageSource: "live-usage" | "mock-estimate";
|
|
};
|
|
|
|
export type HarnessParityResult = {
|
|
scenarioId: string;
|
|
left: HarnessParityCell;
|
|
right: HarnessParityCell;
|
|
drift: HarnessParityDrift;
|
|
driftDetails?: string;
|
|
promptDelta: {
|
|
systemPromptChars: number;
|
|
projectContextChars: number;
|
|
skillPromptChars: number;
|
|
toolSummaryChars: number;
|
|
toolSchemaChars: number;
|
|
toolCount: number;
|
|
};
|
|
tokenDeltaPercent: number;
|
|
firstDriftTurn?: number;
|
|
};
|
|
|
|
function countComparableTranscriptRecords(transcriptBytes: string) {
|
|
let count = 0;
|
|
for (const line of transcriptBytes.split(/\r?\n/u)) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed) {
|
|
continue;
|
|
}
|
|
try {
|
|
const parsed = JSON.parse(trimmed) as {
|
|
message?: { role?: unknown };
|
|
role?: unknown;
|
|
};
|
|
if (
|
|
(parsed.message && typeof parsed.message.role === "string") ||
|
|
typeof parsed.role === "string"
|
|
) {
|
|
count += 1;
|
|
}
|
|
} catch {
|
|
// Ignore malformed QA transcript rows and keep parity classification deterministic.
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
function readPositiveNumber(value: unknown) {
|
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
}
|
|
|
|
function buildPromptStats(report: RuntimeParitySystemPromptReport | undefined) {
|
|
const toolEntries = Array.isArray(report?.tools?.entries) ? report.tools.entries : [];
|
|
return {
|
|
systemPromptChars: readPositiveNumber(report?.systemPrompt?.chars),
|
|
projectContextChars: readPositiveNumber(report?.systemPrompt?.projectContextChars),
|
|
nonProjectContextChars: readPositiveNumber(report?.systemPrompt?.nonProjectContextChars),
|
|
skillPromptChars: readPositiveNumber(report?.skills?.promptChars),
|
|
toolSummaryChars: toolEntries.reduce(
|
|
(sum, entry) => sum + readPositiveNumber(entry.summaryChars),
|
|
0,
|
|
),
|
|
toolSchemaChars: readPositiveNumber(report?.tools?.schemaChars),
|
|
toolCount: toolEntries.length,
|
|
};
|
|
}
|
|
|
|
function estimateUsage(
|
|
cell: RuntimeParityCell,
|
|
stats: HarnessParityPromptStats,
|
|
): RuntimeParityUsage {
|
|
const inputChars =
|
|
stats.systemPromptChars +
|
|
stats.skillPromptChars +
|
|
stats.toolSummaryChars +
|
|
stats.toolSchemaChars +
|
|
cell.transcriptBytes.length;
|
|
const outputChars = cell.finalText.length + cell.toolCalls.length * 80;
|
|
const inputTokens = Math.ceil(inputChars / 4);
|
|
const outputTokens = Math.ceil(outputChars / 4);
|
|
return {
|
|
inputTokens,
|
|
outputTokens,
|
|
totalTokens: inputTokens + outputTokens,
|
|
};
|
|
}
|
|
|
|
function normalizeTextForParity(text: string) {
|
|
return text.replace(/\s+/gu, " ").trim();
|
|
}
|
|
|
|
function compareToolResultShape(left: RuntimeParityToolCall[], right: RuntimeParityToolCall[]) {
|
|
const total = Math.min(left.length, right.length);
|
|
for (let index = 0; index < total; index += 1) {
|
|
const leftCall = left[index];
|
|
const rightCall = right[index];
|
|
if (!leftCall || !rightCall) {
|
|
continue;
|
|
}
|
|
if (
|
|
leftCall.resultHash !== rightCall.resultHash ||
|
|
(leftCall.errorClass ?? "") !== (rightCall.errorClass ?? "")
|
|
) {
|
|
return `tool result ${index + 1} differs (${leftCall.tool})`;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function firstDriftTurn(leftTranscript: string, rightTranscript: string): number | undefined {
|
|
const leftLines = leftTranscript.trim().length ? leftTranscript.trim().split(/\r?\n/u) : [];
|
|
const rightLines = rightTranscript.trim().length ? rightTranscript.trim().split(/\r?\n/u) : [];
|
|
const total = Math.max(leftLines.length, rightLines.length);
|
|
for (let index = 0; index < total; index += 1) {
|
|
if ((leftLines[index] ?? "") !== (rightLines[index] ?? "")) {
|
|
return index + 1;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function buildHarnessParityCell(params: {
|
|
variant: HarnessVariant;
|
|
cell: HarnessRuntimeParityCell;
|
|
tokenUsageSource: HarnessParityCell["tokenUsageSource"];
|
|
}): HarnessParityCell {
|
|
const report = params.cell.systemPromptReport;
|
|
const promptStats = buildPromptStats(report);
|
|
const toolEntries = report?.tools?.entries ?? [];
|
|
const tokenUsage =
|
|
params.tokenUsageSource === "live-usage"
|
|
? params.cell.usage
|
|
: estimateUsage(params.cell, promptStats);
|
|
return {
|
|
...params.cell,
|
|
variant: params.variant,
|
|
...(report ? { systemPromptReport: report } : {}),
|
|
promptStats,
|
|
systemPromptHash: stableHash({
|
|
systemPrompt: report?.systemPrompt ?? null,
|
|
skills: report?.skills ?? null,
|
|
}),
|
|
toolDescriptionHash: stableHash(
|
|
toolEntries.map((entry) => {
|
|
return {
|
|
name: entry.name,
|
|
summary: entry.summary,
|
|
summaryHash: entry.summaryHash,
|
|
summaryChars: entry.summaryChars,
|
|
};
|
|
}),
|
|
),
|
|
toolSchemaHash: stableHash({
|
|
listChars: report?.tools?.listChars,
|
|
schemaChars: report?.tools?.schemaChars,
|
|
entries: toolEntries.map((entry) => {
|
|
return {
|
|
name: entry.name,
|
|
schema: entry.schema,
|
|
schemaHash: entry.schemaHash,
|
|
schemaChars: entry.schemaChars,
|
|
propertiesCount: entry.propertiesCount,
|
|
};
|
|
}),
|
|
}),
|
|
tokenUsage,
|
|
tokenUsageSource: params.tokenUsageSource,
|
|
};
|
|
}
|
|
|
|
export function buildHarnessParityResult(params: {
|
|
scenarioId: string;
|
|
left: HarnessParityCell;
|
|
right: HarnessParityCell;
|
|
comparisonMode?: RuntimeParityComparisonMode;
|
|
}): HarnessParityResult {
|
|
const promptDelta = {
|
|
systemPromptChars:
|
|
params.right.promptStats.systemPromptChars - params.left.promptStats.systemPromptChars,
|
|
projectContextChars:
|
|
params.right.promptStats.projectContextChars - params.left.promptStats.projectContextChars,
|
|
skillPromptChars:
|
|
params.right.promptStats.skillPromptChars - params.left.promptStats.skillPromptChars,
|
|
toolSummaryChars:
|
|
params.right.promptStats.toolSummaryChars - params.left.promptStats.toolSummaryChars,
|
|
toolSchemaChars:
|
|
params.right.promptStats.toolSchemaChars - params.left.promptStats.toolSchemaChars,
|
|
toolCount: params.right.promptStats.toolCount - params.left.promptStats.toolCount,
|
|
};
|
|
const tokenDeltaPercent =
|
|
params.left.tokenUsage.totalTokens === 0
|
|
? params.right.tokenUsage.totalTokens === 0
|
|
? 0
|
|
: 100
|
|
: ((params.right.tokenUsage.totalTokens - params.left.tokenUsage.totalTokens) /
|
|
params.left.tokenUsage.totalTokens) *
|
|
100;
|
|
const failDetails =
|
|
params.left.transportErrorClass || params.right.transportErrorClass
|
|
? "at least one harness variant hit a transport failure"
|
|
: params.left.runtimeErrorClass || params.right.runtimeErrorClass
|
|
? "at least one harness variant hit a runtime failure"
|
|
: undefined;
|
|
if (failDetails) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "failure-mode",
|
|
driftDetails: failDetails,
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
if (params.left.systemPromptHash !== params.right.systemPromptHash) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "system-prompt",
|
|
driftDetails: "system prompt report differs",
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
if (params.left.toolDescriptionHash !== params.right.toolDescriptionHash) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "tool-description",
|
|
driftDetails: "tool description summary shape differs",
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
if (params.left.toolSchemaHash !== params.right.toolSchemaHash) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "tool-schema",
|
|
driftDetails: "tool schema shape differs",
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
const compareToolShapes =
|
|
params.comparisonMode !== "codex-native-workspace" && params.comparisonMode !== "outcome-only";
|
|
const compareTranscriptStructure =
|
|
params.comparisonMode !== "codex-native-workspace" && params.comparisonMode !== "outcome-only";
|
|
|
|
if (compareToolShapes) {
|
|
const toolCallDrift = compareToolCallShape(params.left.toolCalls, params.right.toolCalls);
|
|
if (toolCallDrift) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "tool-call-shape",
|
|
driftDetails: toolCallDrift,
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
const toolResultDrift = compareToolResultShape(params.left.toolCalls, params.right.toolCalls);
|
|
if (toolResultDrift) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "tool-result-shape",
|
|
driftDetails: toolResultDrift,
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
}
|
|
const leftTranscriptRecords = countComparableTranscriptRecords(params.left.transcriptBytes);
|
|
const rightTranscriptRecords = countComparableTranscriptRecords(params.right.transcriptBytes);
|
|
if (
|
|
compareTranscriptStructure &&
|
|
(leftTranscriptRecords !== rightTranscriptRecords ||
|
|
(!params.left.finalText && Boolean(params.right.finalText)) ||
|
|
(Boolean(params.left.finalText) && !params.right.finalText))
|
|
) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "structural",
|
|
driftDetails: `transcript/final-text structure differs (${leftTranscriptRecords} message records vs ${rightTranscriptRecords} message records)`,
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
if (
|
|
normalizeTextForParity(params.left.finalText) !== normalizeTextForParity(params.right.finalText)
|
|
) {
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "text-only",
|
|
driftDetails: "final text differs after whitespace normalization",
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
firstDriftTurn: firstDriftTurn(params.left.transcriptBytes, params.right.transcriptBytes),
|
|
};
|
|
}
|
|
return {
|
|
scenarioId: params.scenarioId,
|
|
left: params.left,
|
|
right: params.right,
|
|
drift: "none",
|
|
promptDelta,
|
|
tokenDeltaPercent,
|
|
};
|
|
}
|