@cortex-agent/server 2026.8.3-2 → 2026.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/config/thread-templates/agents/benchmark-coder.json +2 -2
- package/defaults/config/thread-templates/agents/benchmark-fixer.json +17 -0
- package/defaults/config/thread-templates/agents/benchmark-reviewer.json +5 -5
- package/defaults/config/thread-templates/templates/benchmark-coder-review-fix.json +21 -0
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +1 -0
- package/defaults/prompts/directives/benchmark-coder.md +1 -0
- package/defaults/prompts/directives/benchmark-fixer.md +1 -0
- package/defaults/prompts/directives/benchmark-reviewer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-coder.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-fixer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-reviewer.md +1 -0
- package/dist/agent-adapter/capabilities.d.ts +32 -1
- package/dist/agent-adapter/capabilities.js +39 -1
- package/dist/agent-adapter/claude/adapter.d.ts +15 -0
- package/dist/agent-adapter/claude/adapter.js +29 -7
- package/dist/agent-adapter/claude/spawn-args.d.ts +5 -2
- package/dist/agent-adapter/claude/spawn-args.js +29 -6
- package/dist/agent-adapter/index.js +11 -1
- package/dist/agent-adapter/normalize/tool-names.d.ts +4 -0
- package/dist/agent-adapter/normalize/tool-names.js +10 -0
- package/dist/agent-adapter/pi/adapter.d.ts +20 -8
- package/dist/agent-adapter/pi/adapter.js +130 -35
- package/dist/agent-adapter/pi/agent-dir.d.ts +20 -53
- package/dist/agent-adapter/pi/agent-dir.js +48 -89
- package/dist/agent-adapter/pi/custom-catalog.d.ts +10 -0
- package/dist/agent-adapter/pi/custom-catalog.js +42 -0
- package/dist/agent-adapter/pi/defaults.d.ts +9 -0
- package/dist/agent-adapter/pi/defaults.js +14 -4
- package/dist/agent-adapter/pi/discovery.d.ts +1 -3
- package/dist/agent-adapter/pi/discovery.js +3 -15
- package/dist/agent-adapter/pi/event-parser.js +8 -0
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +31 -6
- package/dist/agent-adapter/pi/mcp-duration.d.ts +28 -0
- package/dist/agent-adapter/pi/mcp-duration.js +48 -0
- package/dist/agent-adapter/pi/policy-guard.d.ts +40 -0
- package/dist/agent-adapter/pi/policy-guard.js +111 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +62 -0
- package/dist/agent-adapter/pi/providers-config.js +101 -0
- package/dist/agent-adapter/pi/quota-probe.d.ts +11 -0
- package/dist/agent-adapter/pi/quota-probe.js +36 -0
- package/dist/agent-adapter/pi/quota-sink.d.ts +25 -0
- package/dist/agent-adapter/pi/quota-sink.js +31 -0
- package/dist/agent-adapter/pi/session-files.d.ts +2 -0
- package/dist/agent-adapter/pi/session-files.js +19 -0
- package/dist/agent-adapter/pi/session-support.d.ts +14 -3
- package/dist/agent-adapter/pi/session-support.js +8 -0
- package/dist/agent-adapter/pi/spawn-args.d.ts +11 -1
- package/dist/agent-adapter/pi/spawn-args.js +13 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +2 -2
- package/dist/agent-adapter/pi/tool-shims.js +32 -21
- package/dist/agent-adapter/pi/web-search.js +36 -8
- package/dist/agent-adapter/types.d.ts +14 -0
- package/dist/core/locales/en.d.ts +54 -1
- package/dist/core/locales/en.js +2 -0
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/providers.d.ts +45 -0
- package/dist/core/locales/slices/providers.js +95 -0
- package/dist/core/locales/zh.js +2 -0
- package/dist/core/resilient-watch.d.ts +28 -0
- package/dist/core/resilient-watch.js +110 -0
- package/dist/core/settings.js +15 -20
- package/dist/core/types/agent-types.d.ts +6 -0
- package/dist/core/types/thread-types.d.ts +21 -3
- package/dist/domain/agent-run/agent-run-cli.js +3 -1
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +31 -0
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +231 -24
- package/dist/domain/agent-run/benchmark-thread-identity.d.ts +15 -2
- package/dist/domain/agent-run/benchmark-thread-identity.js +123 -34
- package/dist/domain/agent-run/identity.d.ts +5 -0
- package/dist/domain/agent-run/identity.js +4 -1
- package/dist/domain/agent-run/journal.d.ts +3 -2
- package/dist/domain/agent-run/manifest.js +11 -4
- package/dist/domain/agent-run/pinned-node-process.d.ts +4 -0
- package/dist/domain/agent-run/pinned-node-process.js +9 -0
- package/dist/domain/agent-run/role-surface.d.ts +2 -2
- package/dist/domain/agent-run/role-surface.js +7 -3
- package/dist/domain/agent-run/run-config.d.ts +10 -1
- package/dist/domain/agent-run/run-config.js +57 -6
- package/dist/domain/agent-run/runner.js +149 -31
- package/dist/domain/agents/facade.d.ts +37 -122
- package/dist/domain/agents/facade.js +47 -115
- package/dist/domain/agents/spawn-config.d.ts +135 -0
- package/dist/domain/agents/spawn-config.js +121 -0
- package/dist/domain/benchmark/accounting-reconciliation.d.ts +98 -0
- package/dist/domain/benchmark/accounting-reconciliation.js +218 -0
- package/dist/domain/benchmark/arm-schema.d.ts +43 -0
- package/dist/domain/benchmark/arm-schema.js +243 -0
- package/dist/domain/benchmark/capabilities.d.ts +4 -0
- package/dist/domain/benchmark/capabilities.js +54 -0
- package/dist/domain/benchmark/decimal-text.d.ts +27 -0
- package/dist/domain/benchmark/decimal-text.js +67 -0
- package/dist/domain/benchmark/lease-echo.d.ts +43 -0
- package/dist/domain/benchmark/lease-echo.js +56 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.d.ts +14 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.js +47 -0
- package/dist/domain/benchmark/policy-compiler.d.ts +68 -0
- package/dist/domain/benchmark/policy-compiler.js +680 -0
- package/dist/domain/benchmark/resolved-policy.d.ts +110 -0
- package/dist/domain/benchmark/resolved-policy.js +195 -0
- package/dist/domain/benchmark/trial-adapter-factory.d.ts +38 -0
- package/dist/domain/benchmark/trial-adapter-factory.js +165 -0
- package/dist/domain/benchmark/trial-thread-adapter.d.ts +25 -0
- package/dist/domain/benchmark/trial-thread-adapter.js +106 -0
- package/dist/domain/benchmark/variant-proposal.d.ts +45 -0
- package/dist/domain/benchmark/variant-proposal.js +42 -0
- package/dist/domain/benchmark/workspace-lease.d.ts +99 -0
- package/dist/domain/benchmark/workspace-lease.js +272 -0
- package/dist/domain/costs/codex-quota.d.ts +29 -0
- package/dist/domain/costs/codex-quota.js +102 -0
- package/dist/domain/costs/cost-tracker.d.ts +48 -9
- package/dist/domain/costs/cost-tracker.js +74 -18
- package/dist/domain/costs/rate-limit-throttle.d.ts +23 -1
- package/dist/domain/costs/rate-limit-throttle.js +61 -6
- package/dist/domain/costs/resume-registry.d.ts +3 -1
- package/dist/domain/costs/resume-registry.js +10 -1
- package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +26 -2
- package/dist/domain/mcp/tools/benchmark-thread-run.js +63 -20
- package/dist/domain/mcp/tools/cost.js +15 -6
- package/dist/domain/pi-providers/custom-provider-model.d.ts +53 -0
- package/dist/domain/pi-providers/custom-provider-model.js +122 -0
- package/dist/domain/pi-providers/custom-provider-service.d.ts +59 -0
- package/dist/domain/pi-providers/custom-provider-service.js +143 -0
- package/dist/domain/pi-providers/gateway-route-store.d.ts +23 -0
- package/dist/domain/pi-providers/gateway-route-store.js +78 -0
- package/dist/domain/pi-providers/index.d.ts +4 -0
- package/dist/domain/pi-providers/index.js +8 -0
- package/dist/domain/pi-providers/models-json-store.d.ts +6 -0
- package/dist/domain/pi-providers/models-json-store.js +77 -0
- package/dist/domain/scheduling/jobs/_shared.d.ts +4 -1
- package/dist/domain/scheduling/jobs/_shared.js +11 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +1 -0
- package/dist/domain/scheduling/jobs/task-dispatch.js +49 -54
- package/dist/domain/sessions/session-lifecycle.d.ts +22 -0
- package/dist/domain/sessions/session-lifecycle.js +20 -1
- package/dist/domain/system/system-notice.d.ts +4 -1
- package/dist/domain/system/system-notice.js +6 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +0 -4
- package/dist/domain/tasks/dispatch-utils.js +24 -37
- package/dist/domain/threads/runner.d.ts +16 -1
- package/dist/domain/threads/runner.js +62 -8
- package/dist/domain/threads/template-loader.d.ts +5 -0
- package/dist/domain/threads/template-loader.js +120 -36
- package/dist/domain/threads/template-validate.d.ts +244 -0
- package/dist/domain/threads/template-validate.js +574 -0
- package/dist/domain/threads/template-validate.parity.d.ts +1 -0
- package/dist/domain/threads/template-validate.parity.js +47 -0
- package/dist/domain/threads/template-writer.d.ts +55 -0
- package/dist/domain/threads/template-writer.js +131 -0
- package/dist/domain/ui-service/app-router.d.ts +143 -1
- package/dist/domain/ui-service/app-router.js +29 -3
- package/dist/domain/ui-service/input-schemas.d.ts +228 -4
- package/dist/domain/ui-service/input-schemas.js +132 -1
- package/dist/domain/ui-service/mutate/config.d.ts +10 -1
- package/dist/domain/ui-service/mutate/config.js +45 -5
- package/dist/domain/ui-service/mutate/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/mutate/custom-providers.js +37 -0
- package/dist/domain/ui-service/mutate/profiles.d.ts +21 -0
- package/dist/domain/ui-service/mutate/profiles.js +156 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
- package/dist/domain/ui-service/mutate/schedules.js +53 -3
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
- package/dist/domain/ui-service/mutate/sessions.js +25 -1
- package/dist/domain/ui-service/mutate/system.d.ts +2 -1
- package/dist/domain/ui-service/mutate/system.js +17 -3
- package/dist/domain/ui-service/mutate/thread-templates.d.ts +4 -0
- package/dist/domain/ui-service/mutate/thread-templates.js +71 -0
- package/dist/domain/ui-service/query/config.js +30 -0
- package/dist/domain/ui-service/query/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/query/custom-providers.js +13 -0
- package/dist/domain/ui-service/query/machine-detail.d.ts +2 -0
- package/dist/domain/ui-service/query/machine-detail.js +56 -0
- package/dist/domain/ui-service/query/machine-probe.d.ts +18 -0
- package/dist/domain/ui-service/query/machine-probe.js +136 -0
- package/dist/domain/ui-service/query/schedules.js +5 -0
- package/dist/domain/ui-service/query/sessions.js +8 -2
- package/dist/domain/ui-service/query/thread-template-detail.d.ts +8 -0
- package/dist/domain/ui-service/query/thread-template-detail.js +94 -0
- package/dist/domain/ui-service/query/thread-templates.d.ts +5 -3
- package/dist/domain/ui-service/query/thread-templates.js +44 -7
- package/dist/domain/ui-service/types.d.ts +298 -7
- package/dist/domain/ui-service/ui-service.js +27 -3
- package/dist/entry/app.js +24 -3
- package/dist/entry/auth-cli.d.ts +4 -1
- package/dist/entry/auth-cli.js +10 -2
- package/dist/entry/cli-help.js +6 -2
- package/dist/entry/cli.js +2 -1
- package/dist/entry/daemon.d.ts +0 -11
- package/dist/entry/daemon.js +5 -49
- package/dist/entry/provider-cli.d.ts +16 -0
- package/dist/entry/provider-cli.js +203 -0
- package/dist/events/event-types.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +3 -2
- package/dist/orchestration/routing/commands/cost.d.ts +8 -0
- package/dist/orchestration/routing/commands/cost.js +93 -21
- package/dist/orchestration/routing/commands/login-custom.d.ts +26 -0
- package/dist/orchestration/routing/commands/login-custom.js +89 -0
- package/dist/orchestration/routing/commands/login.d.ts +3 -0
- package/dist/orchestration/routing/commands/login.js +7 -0
- package/dist/orchestration/routing/message-router.js +48 -33
- package/dist/orchestration/routing/webhook.js +1 -1
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/thread-callback.js +1 -1
- package/dist/store/conversation-history-repo.d.ts +5 -1
- package/dist/store/conversation-history-repo.js +2 -1
- package/dist/store/cost-repo.d.ts +17 -0
- package/dist/store/cost-repo.js +47 -5
- package/dist/store/profile-repo.d.ts +0 -10
- package/dist/store/profile-repo.js +34 -56
- package/dist/store/session-registry-repo.d.ts +12 -0
- package/dist/store/session-registry-repo.js +16 -0
- package/package.json +1 -1
- package/web/dist/assets/index-DYMfaAi4.css +1 -0
- package/web/dist/assets/index-uOoZjGKa.js +141 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-XqBCYtkw.js +0 -139
- package/web/dist/assets/index-zpf3OSKC.css +0 -1
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { resolveProfileConfig as daemonResolveProfile } from '../agents/profile-manager.js';
|
|
8
|
-
import {
|
|
8
|
+
import { variantProposal, } from '../benchmark/variant-proposal.js';
|
|
9
|
+
import { createWorkspaceLease, createWorkspaceStepBoundary, readActiveLeaseState, resolveWorkspacePlacement, withActiveWorkspaceLease, } from '../benchmark/workspace-lease.js';
|
|
10
|
+
import { createThread as daemonCreateThread, getTemplate as daemonGetTemplate, loadConfig as daemonLoadConfig, resolveTemplateAgents as daemonResolveTemplateAgents, FILE_REF_PREFIX, } from '../threads/index.js';
|
|
9
11
|
import { createLocalThreadRuntimeDeps, getLocalThreadRuntimeDeps, scopedLocalThreadService, withLocalThreadRuntimeDeps, } from '../threads/local-runtime-deps.js';
|
|
10
12
|
import { BenchmarkRateLimitError, runThread as daemonRunThread, } from '../threads/runner.js';
|
|
11
13
|
import { executionRepo as daemonExecutionRepo } from '../../store/execution-repo.js';
|
|
@@ -15,6 +17,8 @@ import { benchmarkInstructionHashes, BenchmarkIdentityProtocolError, freezeBench
|
|
|
15
17
|
import { openJournal, TrajectoryWriteFailedError, } from './journal.js';
|
|
16
18
|
import { resolveLifecyclePaths, validateTrajectoryLifecycle, writeStartedMarker, writeTerminalManifest, } from './manifest.js';
|
|
17
19
|
import { terminalManifestProblem } from './manifest-contract.js';
|
|
20
|
+
import { preparePinnedTrialPaths } from './pinned-node-process.js';
|
|
21
|
+
import { loadAgentRunConfigWithPolicy } from './run-config.js';
|
|
18
22
|
import { attachSupervisor, resolveSupervisorBinary, SupervisorContainmentError, } from './supervisor.js';
|
|
19
23
|
const executionRepo = scopedLocalThreadService(daemonExecutionRepo, deps => deps.executionStore);
|
|
20
24
|
const sessionStore = scopedLocalThreadService(daemonSessionStore, deps => deps.sessionStore);
|
|
@@ -24,7 +28,9 @@ const getTemplate = (...args) => ((getLocalThreadRuntimeDeps()?.getTemplate ?? d
|
|
|
24
28
|
const loadConfig = (...args) => ((getLocalThreadRuntimeDeps()?.loadTemplates ?? daemonLoadConfig)(...args));
|
|
25
29
|
const resolveTemplateAgents = (...args) => ((getLocalThreadRuntimeDeps()?.resolveTemplateAgents ?? daemonResolveTemplateAgents)(...args));
|
|
26
30
|
const createThread = (...args) => ((getLocalThreadRuntimeDeps()?.createThread ?? daemonCreateThread)(...args));
|
|
27
|
-
const BENCHMARK_SLOTS = new Set([
|
|
31
|
+
const BENCHMARK_SLOTS = new Set([
|
|
32
|
+
'benchmark-coder', 'benchmark-reviewer', 'benchmark-fixer',
|
|
33
|
+
]);
|
|
28
34
|
const SUMMARY_LIMIT = 2000;
|
|
29
35
|
const MAX_TIMER_MS = 2_147_483_647;
|
|
30
36
|
const SUPERVISOR_GRACE_MS = 1_000;
|
|
@@ -95,6 +101,52 @@ function validateLimits(request) {
|
|
|
95
101
|
throw new Error('Benchmark deadlineEpochMs must be an absolute positive integer');
|
|
96
102
|
}
|
|
97
103
|
}
|
|
104
|
+
/** The compiled arm is the single authority on which variant a trial runs, exactly as it is on the
|
|
105
|
+
* backend. A request that carries no compiled policy is the shipped path and keeps its own field;
|
|
106
|
+
* a request that contradicts the arm is refused rather than silently overridden. */
|
|
107
|
+
function expectedVariant(request) {
|
|
108
|
+
const policy = request.trialPolicy;
|
|
109
|
+
const armVariant = policy?.arm.orchestration?.coder_review_variant;
|
|
110
|
+
if (armVariant === undefined)
|
|
111
|
+
return request.coderReviewVariant;
|
|
112
|
+
if (request.coderReviewVariant !== undefined && request.coderReviewVariant !== armVariant) {
|
|
113
|
+
throw new Error(`Benchmark request coder-review variant '${request.coderReviewVariant}' `
|
|
114
|
+
+ `disagrees with arm '${policy.arm.name}' variant '${armVariant}'`);
|
|
115
|
+
}
|
|
116
|
+
return armVariant;
|
|
117
|
+
}
|
|
118
|
+
/** The one placement decision of the run: a function of (variant, slot) and of nothing else.
|
|
119
|
+
* A run that declares no variant has a single workspace — the shared writable root. */
|
|
120
|
+
function stepPlacement(request) {
|
|
121
|
+
const variant = expectedVariant(request);
|
|
122
|
+
if (!variant)
|
|
123
|
+
return () => 'shared-writable';
|
|
124
|
+
return slot => resolveWorkspacePlacement(variant, slot);
|
|
125
|
+
}
|
|
126
|
+
/** The pinned trial paths put the trial temp directory at `<trial root>/tmp`. */
|
|
127
|
+
function trialSnapshotPaths(request) {
|
|
128
|
+
if (!request.trialRoot)
|
|
129
|
+
return null;
|
|
130
|
+
const root = path.resolve(request.trialRoot);
|
|
131
|
+
return { root, tempDir: path.join(root, 'tmp') };
|
|
132
|
+
}
|
|
133
|
+
function validateWorkspacePlacement(request) {
|
|
134
|
+
if (!expectedVariant(request) || request.trialRoot)
|
|
135
|
+
return;
|
|
136
|
+
const placement = stepPlacement(request);
|
|
137
|
+
const snapshotRoles = ['parent', 'benchmark-coder', 'benchmark-reviewer', 'benchmark-fixer']
|
|
138
|
+
.filter((slot) => {
|
|
139
|
+
try {
|
|
140
|
+
return placement(slot) === 'disposable-snapshot';
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
if (snapshotRoles.length > 0) {
|
|
147
|
+
throw new Error(`Benchmark trialRoot is required: ${snapshotRoles.join(', ')} runs in a disposable snapshot`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
98
150
|
function validateRequest(request) {
|
|
99
151
|
if (!path.isAbsolute(request.workspaceCwd) || !isDirectory(request.workspaceCwd)) {
|
|
100
152
|
throw new Error('Benchmark workspaceCwd must be an existing absolute directory');
|
|
@@ -102,6 +154,10 @@ function validateRequest(request) {
|
|
|
102
154
|
if (!path.isAbsolute(request.trajectoryRoot)) {
|
|
103
155
|
throw new Error('Benchmark trajectoryRoot must be absolute');
|
|
104
156
|
}
|
|
157
|
+
if (request.trialRoot !== undefined && !path.isAbsolute(request.trialRoot)) {
|
|
158
|
+
throw new Error('Benchmark trialRoot must be absolute');
|
|
159
|
+
}
|
|
160
|
+
validateWorkspacePlacement(request);
|
|
105
161
|
if (!request.template || !request.profileName || !request.rootRunId) {
|
|
106
162
|
throw new Error('Benchmark template, profileName, and rootRunId are required');
|
|
107
163
|
}
|
|
@@ -112,9 +168,25 @@ function initializeRuntime() {
|
|
|
112
168
|
threadStore.load();
|
|
113
169
|
loadConfig();
|
|
114
170
|
}
|
|
115
|
-
|
|
171
|
+
/** The compiled arm is the single authority on which backend a trial runs. A request that carries
|
|
172
|
+
* no compiled policy is the shipped one-backend path and keeps its behaviour. */
|
|
173
|
+
function expectedBackend(request) {
|
|
174
|
+
const policy = request.trialPolicy;
|
|
175
|
+
if (policy === undefined)
|
|
176
|
+
return 'claude';
|
|
177
|
+
const backend = policy.arm.backend;
|
|
178
|
+
if (!backend) {
|
|
179
|
+
throw new Error(`Benchmark arm '${policy.arm.name}' declares no backend`);
|
|
180
|
+
}
|
|
181
|
+
return backend;
|
|
182
|
+
}
|
|
183
|
+
function resolveProfile(name, backend) {
|
|
116
184
|
const profile = resolveProfileConfig(name);
|
|
117
|
-
if (profile.backend !==
|
|
185
|
+
if (profile.backend !== backend) {
|
|
186
|
+
throw new Error(`Benchmark profile must use backend ${backend}`);
|
|
187
|
+
}
|
|
188
|
+
// Meaningless outside Claude, and mandatory inside it: TUI mode has no trial surface.
|
|
189
|
+
if (backend === 'claude' && profile.claudeBackend !== 'print') {
|
|
118
190
|
throw new Error('Benchmark profile must use Claude print mode');
|
|
119
191
|
}
|
|
120
192
|
if (profile.fallback.length > 0) {
|
|
@@ -122,6 +194,19 @@ function resolveProfile(name) {
|
|
|
122
194
|
}
|
|
123
195
|
return profile;
|
|
124
196
|
}
|
|
197
|
+
/** `resolveFileRef` is fail-soft: an unreadable prompt file makes the resolved value the raw
|
|
198
|
+
* `file:<name>.md` string, so a benchmark step would run with that literal as its entire system
|
|
199
|
+
* prompt while phase B hashed the bundle's real bytes. Its fail-soft behaviour is shared with
|
|
200
|
+
* every non-benchmark agent and is left alone; a benchmark run refuses here instead. */
|
|
201
|
+
function assertResolvedPrompts(agents) {
|
|
202
|
+
for (const agent of agents) {
|
|
203
|
+
for (const field of ['directive', 'systemPrompt']) {
|
|
204
|
+
if (agent[field]?.startsWith(FILE_REF_PREFIX)) {
|
|
205
|
+
throw new Error(`Benchmark agent ${agent.slotId} ${field} did not resolve: ${agent[field]}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
125
210
|
function resolveTemplate(name) {
|
|
126
211
|
const template = getTemplate(name);
|
|
127
212
|
if (!template)
|
|
@@ -130,6 +215,7 @@ function resolveTemplate(name) {
|
|
|
130
215
|
if (agents.length === 0 || agents.some(agent => !BENCHMARK_SLOTS.has(agent.slotId))) {
|
|
131
216
|
throw new Error('Benchmark template contains a non-benchmark agent slot');
|
|
132
217
|
}
|
|
218
|
+
assertResolvedPrompts(agents);
|
|
133
219
|
if (!BENCHMARK_SLOTS.has(template.entryAgent)) {
|
|
134
220
|
throw new Error('Benchmark template entry agent is not a benchmark slot');
|
|
135
221
|
}
|
|
@@ -168,11 +254,24 @@ function writeRunStarted(request, thread, journal, startedAt) {
|
|
|
168
254
|
threadId: thread.id, journalPath: journal.path, now: () => new Date(startedAt),
|
|
169
255
|
});
|
|
170
256
|
}
|
|
171
|
-
|
|
257
|
+
/** The thread artifact carries the trial's own evidence and is scanned by the transition engine:
|
|
258
|
+
* it must resolve inside the trial root. Asserted here, before anything spawns; the launch that
|
|
259
|
+
* makes it true is the trial's own. */
|
|
260
|
+
function assertArtifactInsideTrial(request, thread) {
|
|
261
|
+
if (!request.trialRoot)
|
|
262
|
+
return;
|
|
263
|
+
const artifact = path.resolve(thread.artifactPath);
|
|
264
|
+
const root = path.resolve(request.trialRoot);
|
|
265
|
+
if (artifact !== root && !artifact.startsWith(`${root}${path.sep}`)) {
|
|
266
|
+
throw new Error(`Benchmark thread artifact must resolve inside the trial root: ${artifact}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async function createRunArtifacts(request, profile, template, backend) {
|
|
172
270
|
fs.mkdirSync(request.trajectoryRoot, { recursive: true });
|
|
173
|
-
const identities = freezeBenchmarkThreadIdentities(request, profile, template);
|
|
271
|
+
const identities = freezeBenchmarkThreadIdentities(request, profile, template, backend, request.trialPolicy);
|
|
174
272
|
const identity = identities.entry;
|
|
175
273
|
const thread = createBenchmarkRecord(request);
|
|
274
|
+
assertArtifactInsideTrial(request, thread);
|
|
176
275
|
const lifecycle = resolveLifecyclePaths({
|
|
177
276
|
trajectoryRoot: request.trajectoryRoot, rootRunId: request.rootRunId, threadId: thread.id,
|
|
178
277
|
});
|
|
@@ -188,15 +287,18 @@ async function createRunArtifacts(request, profile, template) {
|
|
|
188
287
|
return {
|
|
189
288
|
request, profile, template, thread, journal, lifecycle, identity,
|
|
190
289
|
roleIdentities: identities.roles, modelProtocolProblem: identities.modelProtocolProblem,
|
|
191
|
-
|
|
290
|
+
roleIdentityProblem: identities.roleIdentityProblem,
|
|
291
|
+
parentIdentityProblem: identities.parentIdentityProblem,
|
|
292
|
+
startedAt, terminalAssistantText: new Map(),
|
|
192
293
|
};
|
|
193
294
|
}
|
|
194
295
|
async function prepareRun(request) {
|
|
195
296
|
validateRequest(request);
|
|
196
297
|
initializeRuntime();
|
|
197
|
-
const
|
|
298
|
+
const backend = expectedBackend(request);
|
|
299
|
+
const profile = resolveProfile(request.profileName, backend);
|
|
198
300
|
const template = resolveTemplate(request.template);
|
|
199
|
-
return createRunArtifacts(request, profile, template);
|
|
301
|
+
return createRunArtifacts(request, profile, template, backend);
|
|
200
302
|
}
|
|
201
303
|
function supervisorCancelReason(reason) {
|
|
202
304
|
return reason === 'deadline' ? 'deadline' : 'cancel';
|
|
@@ -234,6 +336,12 @@ function installControl(prepared) {
|
|
|
234
336
|
admissionOpen: true, admitted: 0, reason: null, sessions: [],
|
|
235
337
|
threadId: prepared.thread.id, request: prepared.request,
|
|
236
338
|
timer: null, abortHandler: () => { }, deps, cancellation: null,
|
|
339
|
+
lease: createWorkspaceLease({
|
|
340
|
+
sharedRoot: prepared.request.workspaceCwd,
|
|
341
|
+
threadId: prepared.thread.id,
|
|
342
|
+
trialPaths: trialSnapshotPaths(prepared.request),
|
|
343
|
+
admission: () => ({ admitted: control.admitted, sessions: control.sessions.length }),
|
|
344
|
+
}),
|
|
237
345
|
};
|
|
238
346
|
control.abortHandler = () => closeAdmission(control, 'cancel');
|
|
239
347
|
prepared.request.signal.addEventListener('abort', control.abortHandler, { once: true });
|
|
@@ -280,6 +388,9 @@ function createSpawner(control, supervisorBinary) {
|
|
|
280
388
|
stopForAdmissionProblem(control, problem);
|
|
281
389
|
throw problem;
|
|
282
390
|
}
|
|
391
|
+
// After admission so a step-limit or deadline keeps its own stop reason, and before the
|
|
392
|
+
// supervisor attaches so no model process exists when the single-writer invariant is broken.
|
|
393
|
+
control.lease.assertAdmissible(options.cwd?.toString() ?? '');
|
|
283
394
|
const session = attachSupervisor({
|
|
284
395
|
binary: supervisorBinary,
|
|
285
396
|
args: [command, ...args],
|
|
@@ -294,7 +405,7 @@ function createSpawner(control, supervisorBinary) {
|
|
|
294
405
|
};
|
|
295
406
|
};
|
|
296
407
|
}
|
|
297
|
-
function threadRunOptions(prepared, spawner) {
|
|
408
|
+
function threadRunOptions(prepared, spawner, boundary) {
|
|
298
409
|
const channel = prepared.thread.channel;
|
|
299
410
|
return {
|
|
300
411
|
adapter: createNoopAdapter(), channel,
|
|
@@ -302,8 +413,10 @@ function threadRunOptions(prepared, spawner) {
|
|
|
302
413
|
threadAnchorId: null, statusMsg: null, startTime: Date.now(), onProgress: null,
|
|
303
414
|
benchmark: {
|
|
304
415
|
workspaceCwd: prepared.request.workspaceCwd,
|
|
416
|
+
resolveStepWorkspace: boundary.resolveStepWorkspace,
|
|
417
|
+
settleStepWorkspace: boundary.settleStepWorkspace,
|
|
305
418
|
resolvedProfileName: prepared.request.profileName,
|
|
306
|
-
expectedBackend:
|
|
419
|
+
expectedBackend: expectedBackend(prepared.request),
|
|
307
420
|
expectedModel: prepared.profile.model,
|
|
308
421
|
disableHooks: true,
|
|
309
422
|
disableControlPlane: true,
|
|
@@ -318,20 +431,43 @@ function threadRunOptions(prepared, spawner) {
|
|
|
318
431
|
},
|
|
319
432
|
};
|
|
320
433
|
}
|
|
434
|
+
/** The parent stops writing, then the thread takes the workspace. The precondition is asserted at
|
|
435
|
+
* the instant of the call, never waited for: this entry path builds the spawner and enters the
|
|
436
|
+
* thread with nothing admitted, and a run that has admitted anything fails closed instead. */
|
|
437
|
+
function takeThreadWorkspace(lease) {
|
|
438
|
+
lease.beginDrain();
|
|
439
|
+
try {
|
|
440
|
+
lease.completeDrain();
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
lease.abortDrain(error instanceof Error ? error.message : String(error));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
321
446
|
async function runLocalThread(prepared, control, supervisorBinary) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
447
|
+
// Any identity gate refuses, and all of them refuse here — before the workspace is taken and
|
|
448
|
+
// before any spawner exists, so a divergent identity can never reach a process.
|
|
449
|
+
const problem = prepared.modelProtocolProblem
|
|
450
|
+
?? prepared.roleIdentityProblem
|
|
451
|
+
?? prepared.parentIdentityProblem;
|
|
452
|
+
if (problem) {
|
|
453
|
+
return { result: null, error: new BenchmarkIdentityProtocolError(problem) };
|
|
327
454
|
}
|
|
328
455
|
try {
|
|
329
|
-
|
|
456
|
+
takeThreadWorkspace(control.lease);
|
|
457
|
+
const boundary = createWorkspaceStepBoundary({
|
|
458
|
+
lease: control.lease,
|
|
459
|
+
placement: stepPlacement(prepared.request),
|
|
460
|
+
artifactPath: prepared.thread.artifactPath,
|
|
461
|
+
});
|
|
462
|
+
const result = await control.deps.runThread(prepared.thread.id, threadRunOptions(prepared, createSpawner(control, supervisorBinary), boundary));
|
|
330
463
|
return { result, error: null };
|
|
331
464
|
}
|
|
332
465
|
catch (error) {
|
|
333
466
|
return { result: null, error };
|
|
334
467
|
}
|
|
468
|
+
finally {
|
|
469
|
+
control.lease.release();
|
|
470
|
+
}
|
|
335
471
|
}
|
|
336
472
|
function asAgentSlot(value) {
|
|
337
473
|
if (!BENCHMARK_SLOTS.has(value))
|
|
@@ -345,9 +481,14 @@ function writeNormalizedEvent(prepared, input) {
|
|
|
345
481
|
const identity = prepared.roleIdentities.get(input.agentSlotId);
|
|
346
482
|
if (!identity)
|
|
347
483
|
throw new Error(`Missing benchmark role identity: ${input.agentSlotId}`);
|
|
484
|
+
// The verdict is read from the stream the role actually spoke, so it is captured here rather
|
|
485
|
+
// than recovered later from the artifact file or from a summary one backend never populates.
|
|
486
|
+
if (input.event.type === 'assistant_text') {
|
|
487
|
+
prepared.terminalAssistantText.set(input.step, input.event.text);
|
|
488
|
+
}
|
|
348
489
|
prepared.journal.writeEvent({
|
|
349
490
|
threadId: prepared.thread.id, step: input.step,
|
|
350
|
-
agentSlot: asAgentSlot(input.agentSlotId), backend:
|
|
491
|
+
agentSlot: asAgentSlot(input.agentSlotId), backend: prepared.profile.backend,
|
|
351
492
|
provider: prepared.profile.provider, requestedModel: prepared.profile.model,
|
|
352
493
|
reportedModel: reportedModel(input.event), event: input.event, identity,
|
|
353
494
|
});
|
|
@@ -564,7 +705,31 @@ function truncateSummary(thread) {
|
|
|
564
705
|
const characters = Array.from(text);
|
|
565
706
|
return characters.length > SUMMARY_LIMIT ? truncatedSummary(characters) : text;
|
|
566
707
|
}
|
|
567
|
-
|
|
708
|
+
/** The step loop's own account of why it stopped. Absent → this run's admission boundary closed
|
|
709
|
+
* it, or it left for a reason nobody recorded; either way it is not an approval to propose on. */
|
|
710
|
+
function proposalStopReason(control, outcome) {
|
|
711
|
+
return outcome.result?.stopReason ?? (control.reason ? 'admission_limit' : 'unavailable');
|
|
712
|
+
}
|
|
713
|
+
/** Decided here and applied nowhere: no broker call, no ledger write and no bus event. A run with
|
|
714
|
+
* no coder-review variant has no verdict-speaking role, and so has nothing to propose. */
|
|
715
|
+
function proposeOutcome(prepared, committed, thread, control, outcome) {
|
|
716
|
+
const variant = expectedVariant(prepared.request);
|
|
717
|
+
if (!variant)
|
|
718
|
+
return null;
|
|
719
|
+
const finalStep = thread.steps.at(-1) ?? null;
|
|
720
|
+
return variantProposal({
|
|
721
|
+
variant,
|
|
722
|
+
terminalState: committed.classified.state,
|
|
723
|
+
finalStep: finalStep && {
|
|
724
|
+
agentSlotId: finalStep.agentSlotId, stage: finalStep.stage, index: finalStep.stepIndex,
|
|
725
|
+
},
|
|
726
|
+
finalAssistantText: finalStep
|
|
727
|
+
? prepared.terminalAssistantText.get(finalStep.stepIndex) ?? null
|
|
728
|
+
: null,
|
|
729
|
+
stopReason: proposalStopReason(control, outcome),
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
function buildResult(prepared, committed, thread, proposal) {
|
|
568
733
|
return {
|
|
569
734
|
threadId: thread.id,
|
|
570
735
|
state: committed.classified.state,
|
|
@@ -577,6 +742,7 @@ function buildResult(prepared, committed, thread) {
|
|
|
577
742
|
costUsd: thread.totalCostUsd,
|
|
578
743
|
durationMs: Math.max(0, Date.now() - new Date(prepared.startedAt).getTime()),
|
|
579
744
|
summary: truncateSummary(thread),
|
|
745
|
+
proposal,
|
|
580
746
|
};
|
|
581
747
|
}
|
|
582
748
|
async function disposeSupervisor(session, waitMs) {
|
|
@@ -599,18 +765,59 @@ async function runBenchmarkThreadScoped(request) {
|
|
|
599
765
|
const prepared = await prepareRun(request);
|
|
600
766
|
const control = installControl(prepared);
|
|
601
767
|
try {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
768
|
+
// The lease is published for the whole run so each step's spawn config can read the state it
|
|
769
|
+
// was armed under, rather than one captured before the lease existed (16.1 LS3).
|
|
770
|
+
return await withActiveWorkspaceLease(control.lease, async () => {
|
|
771
|
+
const outcome = await executeRun(prepared, control, supervisorBinary);
|
|
772
|
+
const thread = threadStore.get(prepared.thread.id) ?? prepared.thread;
|
|
773
|
+
const classified = classifyRun(prepared, control, outcome);
|
|
774
|
+
const committed = commitTerminal(prepared, classified, thread);
|
|
775
|
+
const proposal = proposeOutcome(prepared, committed, thread, control, outcome);
|
|
776
|
+
return buildResult(prepared, committed, thread, proposal);
|
|
777
|
+
});
|
|
607
778
|
}
|
|
608
779
|
finally {
|
|
609
780
|
cleanupControl(control);
|
|
610
781
|
await disposeSupervisors(control);
|
|
611
782
|
}
|
|
612
783
|
}
|
|
784
|
+
/**
|
|
785
|
+
* Everything the per-step trial adapter needs, derived from the two paths the request carries and
|
|
786
|
+
* from nothing else: the compiled policy and the resolved run config from ONE call of the shipped
|
|
787
|
+
* loader over the arm-resolution document, the pinned trial paths from the trial root, and the
|
|
788
|
+
* supervisor from the shipped resolver. The policy is RE-COMPILED here, in the process that will
|
|
789
|
+
* run the thread, rather than transported — which is what makes the parent role-hash equality a
|
|
790
|
+
* comparison of two independent compiles instead of a tautology. A request that carried a
|
|
791
|
+
* pre-built `ResolvedAgentRunConfig`, `PinnedTrialPaths` or supervisor descriptor would let a
|
|
792
|
+
* caller supply what production must derive. Design section 16 (16.3.2) PW1 and PW2.
|
|
793
|
+
*/
|
|
794
|
+
export function trialThreadAdapterInput(runConfigPath, trialRoot) {
|
|
795
|
+
const loaded = loadAgentRunConfigWithPolicy({
|
|
796
|
+
runConfigFile: runConfigPath, agentSlot: 'parent',
|
|
797
|
+
});
|
|
798
|
+
if (!loaded.policy) {
|
|
799
|
+
throw new Error(`Benchmark run config compiled no trial policy: ${runConfigPath}`);
|
|
800
|
+
}
|
|
801
|
+
return {
|
|
802
|
+
policy: loaded.policy,
|
|
803
|
+
config: loaded.config,
|
|
804
|
+
paths: preparePinnedTrialPaths(trialRoot),
|
|
805
|
+
supervisor: { binary: resolveSupervisorBinary(), graceMs: SUPERVISOR_GRACE_MS },
|
|
806
|
+
leaseState: readActiveLeaseState,
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
/** The lifecycle hook runner reaches an agent through the unscoped module import, so an override
|
|
810
|
+
* that supplies one puts a second, unscoped model process on the thread path — outside the trial
|
|
811
|
+
* adapter, the pinned environment and the admission boundary. The benchmark path keeps the no-op.
|
|
812
|
+
* Keyed on the key's presence, not its value: an override carrying the key with an undefined value
|
|
813
|
+
* is spread over the no-op default, and the step path then falls back to the daemon runner. */
|
|
814
|
+
function refuseLifecycleHookOverride(overrides) {
|
|
815
|
+
if ('emitLifecycleHooks' in overrides) {
|
|
816
|
+
throw new Error('A benchmark thread may not supply a lifecycle hook runner');
|
|
817
|
+
}
|
|
818
|
+
}
|
|
613
819
|
export async function runBenchmarkThread(request, overrides = {}) {
|
|
820
|
+
refuseLifecycleHookOverride(overrides);
|
|
614
821
|
const deps = createLocalThreadRuntimeDeps(daemonRunThread, overrides);
|
|
615
822
|
return withLocalThreadRuntimeDeps(deps, () => runBenchmarkThreadScoped(request));
|
|
616
823
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Backend } from '../../agent-adapter/types.js';
|
|
1
2
|
import type { ThreadTemplate } from '../../core/types/thread-types.js';
|
|
2
|
-
import { type
|
|
3
|
+
import { type ResolvedTrialPolicy } from '../benchmark/resolved-policy.js';
|
|
4
|
+
import type { ResolvedProfileConfig } from '../agents/profile-manager.js';
|
|
3
5
|
import { type FrozenIdentity } from './identity.js';
|
|
4
6
|
export interface BenchmarkIdentityRequest {
|
|
5
7
|
workspaceCwd: string;
|
|
@@ -8,6 +10,10 @@ export interface BenchmarkIdentityRequest {
|
|
|
8
10
|
profileName: string;
|
|
9
11
|
rootRunId: string;
|
|
10
12
|
trajectoryRoot: string;
|
|
13
|
+
/** Present exactly when the policy below was compiled in this process from that document. Only
|
|
14
|
+
* then are the parent's compile and this one two independent compiles of the same bytes, which
|
|
15
|
+
* is what makes comparing them evidence rather than a tautology. */
|
|
16
|
+
runConfigPath?: string;
|
|
11
17
|
limits: {
|
|
12
18
|
maxSteps: number;
|
|
13
19
|
maxCostUsd: number;
|
|
@@ -23,11 +29,18 @@ export interface BenchmarkThreadIdentities {
|
|
|
23
29
|
entry: BenchmarkRoleIdentity;
|
|
24
30
|
roles: Map<string, BenchmarkRoleIdentity>;
|
|
25
31
|
modelProtocolProblem: string | null;
|
|
32
|
+
/** Divergence between the template projection and the compiled policy role for some slot. Null
|
|
33
|
+
* when no policy is present, because then the projection is the only source there is. */
|
|
34
|
+
roleIdentityProblem: string | null;
|
|
35
|
+
/** Divergence between the parent role surface this process compiled and the one the parent's own
|
|
36
|
+
* `agent-run` recorded in the started marker. Null unless the policy was compiled here from a
|
|
37
|
+
* named run config. Design section 16 (16.3.2) PW4. */
|
|
38
|
+
parentIdentityProblem: string | null;
|
|
26
39
|
}
|
|
27
40
|
export declare class BenchmarkIdentityProtocolError extends Error {
|
|
28
41
|
readonly reason: "protocol_violation";
|
|
29
42
|
}
|
|
30
|
-
export declare function freezeBenchmarkThreadIdentities(request: BenchmarkIdentityRequest, profile: ResolvedProfileConfig, template: ThreadTemplate): BenchmarkThreadIdentities;
|
|
43
|
+
export declare function freezeBenchmarkThreadIdentities(request: BenchmarkIdentityRequest, profile: ResolvedProfileConfig, template: ThreadTemplate, backend: Backend, trialPolicy?: ResolvedTrialPolicy): BenchmarkThreadIdentities;
|
|
31
44
|
export declare function benchmarkInstructionHashes(instruction: string, modelVisiblePrompt?: string): {
|
|
32
45
|
canonicalInstructionSha256: string;
|
|
33
46
|
modelVisiblePromptSha256: string;
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
// pos: Identity freezer for daemon-free benchmark threads
|
|
4
4
|
// >>> If I am updated, update my header and folder CORTEX.md <<<
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
|
+
import { fromCanonical, toCanonical } from '../../agent-adapter/normalize/tool-names.js';
|
|
7
|
+
import { compiledRoleSurface } from '../benchmark/resolved-policy.js';
|
|
6
8
|
import { buildAgentSpawnConfig, } from '../agents/facade.js';
|
|
7
|
-
import { listProfiles, resolveProfileConfig, } from '../agents/profile-manager.js';
|
|
8
9
|
import { resolveSystemVars, resolveTemplateAgents } from '../threads/index.js';
|
|
9
|
-
import { canonicalJsonSha256, computeBundleManifestHash, computeRoleToolSurfaceHash,
|
|
10
|
+
import { canonicalJsonSha256, computeBundleManifestHash, computeRoleToolSurfaceHash, } from './identity.js';
|
|
10
11
|
import { readStartedJournalIdentity } from './manifest.js';
|
|
11
12
|
import { roleSurfaceFromSpawnConfig } from './role-surface.js';
|
|
12
13
|
export class BenchmarkIdentityProtocolError extends Error {
|
|
@@ -37,12 +38,15 @@ function roleSpawnConfig(request, profile, agent) {
|
|
|
37
38
|
function manifests(role) {
|
|
38
39
|
return { plugin_dirs: role.pluginDirs, skills: role.skills };
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
/** The template projection's role surface (S-a). It omits the compiled guard by construction: the
|
|
42
|
+
* template has none, which is why it cannot be the record once the guard varies with the lease. */
|
|
43
|
+
function roleProjection(request, profile, agent) {
|
|
41
44
|
const spawn = roleSpawnConfig(request, profile, agent);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
45
|
+
return roleSurfaceFromSpawnConfig(spawn, resolveSystemVars(agent.directive ?? ''));
|
|
46
|
+
}
|
|
47
|
+
function identityFrom(request, agent, surface, modelExecutionIdentityHash, hashes) {
|
|
48
|
+
const roleToolSurfaceHash = hashes.roleToolSurfaceHash;
|
|
49
|
+
const bundleManifestHash = hashes.bundleManifestHash ?? computeBundleManifestHash({
|
|
46
50
|
runConfig: {
|
|
47
51
|
template: request.template, profile_name: request.profileName, agent_slot: agent.slotId,
|
|
48
52
|
},
|
|
@@ -60,43 +64,128 @@ function roleIdentity(request, profile, agent, modelExecutionIdentityHash) {
|
|
|
60
64
|
pluginManifestSha256: canonicalJsonSha256(manifests(surface)),
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
function compareText(left, right) {
|
|
68
|
+
if (left < right)
|
|
69
|
+
return -1;
|
|
70
|
+
if (left > right)
|
|
71
|
+
return 1;
|
|
72
|
+
return 0;
|
|
67
73
|
}
|
|
68
|
-
function
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
function sortedManifests(surface) {
|
|
75
|
+
return {
|
|
76
|
+
plugin_dirs: [...surface.pluginDirs].sort((a, b) => compareText(a.path, b.path)),
|
|
77
|
+
skills: [...surface.skills].sort((a, b) => compareText(a.name, b.name)),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The tool surfaces are compared through the transformation the launcher performs, not by raw
|
|
82
|
+
* bytes: one thread agent document serves both backends in Claude labels, while the compiled role
|
|
83
|
+
* carries the arm backend's own images. So the predicate asserts the image rather than erasing the
|
|
84
|
+
* difference — for each position, `fromCanonical(backend, toCanonical('claude', projected))` must
|
|
85
|
+
* equal the compiled name. A name that maps to nothing on either hop REFUSES: canonicalising both
|
|
86
|
+
* sides and comparing would let two different unknown names both become null and match, which is a
|
|
87
|
+
* divergence detector that goes blind exactly when both sides are wrong.
|
|
88
|
+
*/
|
|
89
|
+
function toolsProblem(slot, projected, compiled, backend) {
|
|
90
|
+
if (projected.length !== compiled.length) {
|
|
91
|
+
return `role ${slot} tools differ in length: ${projected.length} projected, ${compiled.length} compiled`;
|
|
92
|
+
}
|
|
93
|
+
for (const [index, name] of projected.entries()) {
|
|
94
|
+
const canonical = toCanonical('claude', name);
|
|
95
|
+
const image = canonical === null ? null : fromCanonical(backend, canonical);
|
|
96
|
+
if (image === null)
|
|
97
|
+
return `role ${slot} tool '${name}' has no ${backend} image`;
|
|
98
|
+
if (image !== compiled[index]) {
|
|
99
|
+
return `role ${slot} tools differ at ${index}: '${image}' projected, '${compiled[index]}' compiled`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
74
103
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
/** Field-wise over the six members both sources independently produce, plus `hookPolicy` for
|
|
105
|
+
* completeness. Never hash-wise: the compiled surface carries a guard member the projection cannot
|
|
106
|
+
* have, so the two hashes can never be equal on a correct run. */
|
|
107
|
+
function roleSurfaceProblem(slot, projected, compiled, backend) {
|
|
108
|
+
if (projected.systemPromptSha256 !== compiled.systemPromptSha256) {
|
|
109
|
+
return `role ${slot} system prompt differs between the template projection and the compiled policy`;
|
|
110
|
+
}
|
|
111
|
+
if (projected.directiveSha256 !== compiled.directiveSha256) {
|
|
112
|
+
return `role ${slot} directive differs between the template projection and the compiled policy`;
|
|
113
|
+
}
|
|
114
|
+
const tools = toolsProblem(slot, projected.tools, compiled.tools, backend);
|
|
115
|
+
if (tools !== null)
|
|
116
|
+
return tools;
|
|
117
|
+
if (canonicalJsonSha256(sortedManifests(projected)) !== canonicalJsonSha256(sortedManifests(compiled))) {
|
|
118
|
+
return `role ${slot} plugin dirs or skills differ between the template projection and the compiled policy`;
|
|
119
|
+
}
|
|
120
|
+
if (projected.mcpComposition !== compiled.mcpComposition) {
|
|
121
|
+
return `role ${slot} MCP composition differs between the template projection and the compiled policy`;
|
|
122
|
+
}
|
|
123
|
+
if (canonicalJsonSha256(projected.hookPolicy) !== canonicalJsonSha256(compiled.hookPolicy)) {
|
|
124
|
+
return `role ${slot} hook policy differs between the template projection and the compiled policy`;
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
78
127
|
}
|
|
79
|
-
function
|
|
80
|
-
const
|
|
128
|
+
function roleIdentityMap(request, profile, template, backend, modelExecutionIdentityHash, policy) {
|
|
129
|
+
const roles = new Map();
|
|
130
|
+
let problem = null;
|
|
131
|
+
for (const agent of resolveTemplateAgents(template)) {
|
|
132
|
+
const projected = roleProjection(request, profile, agent);
|
|
133
|
+
const compiled = policy === undefined ? null : compiledRoleSurface(policy, agent.slotId);
|
|
134
|
+
if (policy === undefined) {
|
|
135
|
+
roles.set(agent.slotId, identityFrom(request, agent, projected, modelExecutionIdentityHash, {
|
|
136
|
+
roleToolSurfaceHash: computeRoleToolSurfaceHash(projected),
|
|
137
|
+
}));
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (compiled === null) {
|
|
141
|
+
problem ??= `role ${agent.slotId} has no compiled policy role`;
|
|
142
|
+
roles.set(agent.slotId, identityFrom(request, agent, projected, modelExecutionIdentityHash, {
|
|
143
|
+
roleToolSurfaceHash: computeRoleToolSurfaceHash(projected),
|
|
144
|
+
}));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
problem ??= roleSurfaceProblem(agent.slotId, projected, compiled, backend);
|
|
148
|
+
// The compiled policy role is the record, and the projection above is now discarded.
|
|
149
|
+
roles.set(agent.slotId, identityFrom(request, agent, compiled, modelExecutionIdentityHash, {
|
|
150
|
+
roleToolSurfaceHash: policy.identity.role_tool_surface_hash[agent.slotId],
|
|
151
|
+
bundleManifestHash: policy.identity.bundle_manifest_hash,
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
return { roles, problem };
|
|
155
|
+
}
|
|
156
|
+
function parentModelObservationProblem(parent, profile, backend) {
|
|
157
|
+
const matches = parent.agentSlot === 'parent' && profile.backend === backend
|
|
81
158
|
&& parent.requestedModel === profile.model && parent.provider === profile.provider;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
159
|
+
return matches ? null : 'Benchmark resolved profile does not match parent model observation';
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* PW4. The parent's `agent-run` compiled the arm resolution in its own process and recorded the
|
|
163
|
+
* parent role's surface hash in the started marker; this process compiled the same document again.
|
|
164
|
+
* Unequal means the two processes did not compile the same role, so the thread would run under an
|
|
165
|
+
* identity the trial record does not describe — refused before the thread takes the workspace.
|
|
166
|
+
*/
|
|
167
|
+
function parentRoleSurfaceProblem(parent, request, policy) {
|
|
168
|
+
if (policy === undefined || request.runConfigPath === undefined)
|
|
169
|
+
return null;
|
|
170
|
+
const compiled = policy.identity.role_tool_surface_hash.parent;
|
|
171
|
+
if (compiled !== undefined && compiled === parent.roleToolSurfaceHash)
|
|
172
|
+
return null;
|
|
173
|
+
return 'Benchmark compiled parent role surface does not match the parent started marker';
|
|
174
|
+
}
|
|
175
|
+
export function freezeBenchmarkThreadIdentities(request, profile, template, backend, trialPolicy) {
|
|
90
176
|
const parent = readStartedJournalIdentity({
|
|
91
177
|
trajectoryRoot: request.trajectoryRoot, canonicalTrajectoryRoot: true,
|
|
92
178
|
rootRunId: request.rootRunId, threadId: null,
|
|
93
179
|
});
|
|
94
|
-
const modelProtocolProblem = parentModelObservationProblem(parent, profile);
|
|
95
|
-
const
|
|
96
|
-
const entry = roles.get(template.entryAgent);
|
|
180
|
+
const modelProtocolProblem = parentModelObservationProblem(parent, profile, backend);
|
|
181
|
+
const record = roleIdentityMap(request, profile, template, backend, parent.modelExecutionIdentityHash, trialPolicy);
|
|
182
|
+
const entry = record.roles.get(template.entryAgent);
|
|
97
183
|
if (!entry)
|
|
98
184
|
throw new Error(`Missing benchmark entry identity: ${template.entryAgent}`);
|
|
99
|
-
return {
|
|
185
|
+
return {
|
|
186
|
+
entry, roles: record.roles, modelProtocolProblem, roleIdentityProblem: record.problem,
|
|
187
|
+
parentIdentityProblem: parentRoleSurfaceProblem(parent, request, trialPolicy),
|
|
188
|
+
};
|
|
100
189
|
}
|
|
101
190
|
export function benchmarkInstructionHashes(instruction, modelVisiblePrompt = instruction) {
|
|
102
191
|
return {
|