@tangle-network/agent-bench 4.0.3 → 6.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.0
4
+
5
+ Bench uses Runtime 14's protected candidate-execution types. Consumers that
6
+ install Runtime alongside Bench should use Runtime 14 with this release.
7
+
8
+ Stock Pier executes sealed graph commands and binds the exact captured patch
9
+ to the evaluator's graph receipt. Declared check files remain available after
10
+ the sandbox closes. A graph that stops without a delivery stays unscored.
11
+
12
+ ## 5.0.0
13
+
14
+ Bench's public candidate-execution types now use Runtime 12. When installing
15
+ Runtime alongside Bench for a candidate executor, use the same Runtime major
16
+ for both packages.
17
+
3
18
  ## 4.0.3
4
19
 
5
20
  Terminal-Bench leaves interrupted verifiers unscored. Set
package/HARNESS.md CHANGED
@@ -117,9 +117,15 @@ They establish no live learning gain or provider session restoration.
117
117
 
118
118
  ```bash
119
119
  cd bench
120
+ export FINAL_EVIDENCE_LEDGER=/path/to/shared/final-evidence.jsonl
121
+ export FINAL_EVIDENCE_REQUEST_ID=swe-comparison-01
120
122
  pnpm tsx src/swe-self-improve.mts
121
123
  ```
122
124
 
125
+ Keep the same ledger, request ID and output directory on resume. For a historical unbound run,
126
+ leave both evidence variables unset and use its original output directory. Calibration does not
127
+ open a sealed search.
128
+
123
129
  This fixture uses `runStrategyEvolution` with SWE-bench tasks split into train, selection and sealed test slices.
124
130
  It does not exercise `improve`.
125
131
  It keeps its run directory, whose search ledger is the checkpoint and the lineage record of one search.
package/README.md CHANGED
@@ -124,6 +124,12 @@ An experiment can execute a code workspace, a materialized profile, and a measur
124
124
  Pier owns the task container and verifier; protected model usage and traces stay in `@tangle-network/agent-eval` and are finalized by the shared runtime.
125
125
  `FilePierCandidateTrialController` atomically reserves a unique Pier job, then persists the supervisor PID, process-session identity, and that job's exact Docker projects so a fresh evaluator process can stop and remove an abandoned trial.
126
126
  Use `createPierTaskTrialController` when each approved task digest already maps to an evaluator-owned Pier task directory. Give it the pinned Pier command and jobs directory. It launches exactly that task and reads the official result and patch through the same controller on completion or recovery. The evaluator still owns task staging and authorization.
127
+
128
+ For a zero-model task, set `graphDispatch: true` on `createPierTaskTrialController`. The bundled coordinator runs one command at a time in each task container under the candidate UID, so it can stop the command and its descendants before accepting evidence. Separate trials still run concurrently. Pier keeps the graph run record in its evaluator-owned trial log and captures the task patch through its usual artifact hook. A graph that ends without a deliverable retains its run record as failure evidence and skips Runtime grading.
129
+
130
+ Stock Pier copies only the files declared in a command node's `outputs` after its candidate processes have stopped. Runtime checks their size and retains them in the trial's artifact store, including when the command fails. An unchanged, missing or unsafe file makes that check incomplete.
131
+
132
+ Custom evaluators can use `FilePierCandidateTrialController` with a graph-aware launcher and durable result reader. The launcher receives `staged.graphInvocationPath` from Runtime's signed plan and calls `runProtectedCandidateGraph` with its isolated command and agent executors. The durable reader returns the graph registry record and the digest of the evaluator-captured task patch.
127
133
  Run `PIER_REPO=/path/to/pier pnpm verify:pier` for the zero-model failure/pass and fresh-process recovery proof, and see `HARNESS.md` for the exact invocation and failure contract.
128
134
  From an installed npm package, expose the shipped Python module with `export PYTHONPATH="$(npm root)/@tangle-network/agent-bench${PYTHONPATH:+:$PYTHONPATH}"` before invoking Pier.
129
135
 
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import { BenchEvaluation, BenchPayload, BenchRuntime, BenchTask, JudgeArtifactFi
11
11
  import { AgentProfile, SandboxClient, SandboxRun, TurnResult, sumSandboxUsage } from "@tangle-network/agent-runtime/kernel";
12
12
  import { RunTerminalOutcome, TraceStore } from "@tangle-network/agent-eval";
13
13
  import { SandboxEvent } from "@tangle-network/sandbox";
14
- import { AgentCandidateBenchmarkGraderPort, AgentCandidateExecutionClaimStore, AgentCandidateExecutionFormat, AgentCandidateExecutorPort, AgentCandidateExecutorRequest, AgentCandidateExecutorStopRequest, AgentCandidateOutputArtifactPort, AgentCandidateRunFinalization, ExecutePreparedAgentCandidateOptions, PreparedAgentCandidateExecution } from "@tangle-network/agent-runtime/candidate-execution";
14
+ import { AgentCandidateBenchmarkGraderPort, AgentCandidateExecutionClaimStore, AgentCandidateExecutionFormat, AgentCandidateExecutorFinalCapture, AgentCandidateExecutorPort, AgentCandidateExecutorRequest, AgentCandidateExecutorStopRequest, AgentCandidateOutputArtifactPort, AgentCandidateRunFinalization, ExecutePreparedAgentCandidateOptions, PreparedAgentCandidateExecution } from "@tangle-network/agent-runtime/candidate-execution";
15
15
  interface ResolveBenchClientOptions {
16
16
  /** The selector (the `BACKEND` env value): `router` = off-box; anything else = in-box Sandbox. */
17
17
  backend: string;
@@ -212,6 +212,8 @@ interface StagedPierCandidateExecution {
212
212
  readonly profileDirectory: string;
213
213
  readonly planPath: string;
214
214
  readonly receiptPath: string;
215
+ /** Evaluator-owned copy of the exact graph invocation when the controller supports it. */
216
+ readonly graphInvocationPath?: string;
215
217
  readonly agentArgs: readonly string[];
216
218
  /** Executor-only model and trace bindings; never present on the prepared object or disk. */
217
219
  readonly evaluatorEnv: Readonly<Record<string, string>>;
@@ -238,6 +240,8 @@ type PierCandidateTrialIdentity = Readonly<AgentCandidateExecutorStopRequest>;
238
240
  * handle returned by `start`.
239
241
  */
240
242
  interface PierCandidateTrialController<Format extends AgentCandidateExecutionFormat = 'experiment'> {
243
+ /** This controller runs the sealed graph through the protected Pier trial. */
244
+ readonly graphDispatch?: true;
241
245
  start(staged: StagedPierCandidateExecution, context: {
242
246
  readonly request: AgentCandidateExecutorRequest<Format>;
243
247
  readonly traceStore: TraceStore;
@@ -256,6 +260,10 @@ interface PierCandidateTrialResult {
256
260
  readonly resultBytes: Uint8Array;
257
261
  /** Exact `/logs/artifacts/model.patch` bytes emitted before official tests. */
258
262
  readonly taskPatch: Uint8Array;
263
+ /** Retained evaluator graph record. Agent metadata and stdout cannot supply this field. */
264
+ readonly graphExecution?: AgentCandidateExecutorFinalCapture['graphExecution'];
265
+ /** The trusted coordinator reached a graph deliverable that may be independently graded. */
266
+ readonly graphDelivered?: boolean;
259
267
  }
260
268
  interface PierCandidateOfficialResult {
261
269
  readonly value: unknown;
@@ -313,6 +321,8 @@ interface PierDockerConnection {
313
321
  interface FilePierCandidateTrialControllerOptions<Format extends AgentCandidateExecutionFormat = 'experiment'> {
314
322
  /** Shared evaluator-owned control root, available to crash-recovery workers. */
315
323
  readonly directory: string;
324
+ /** Both the registered launch and durable result reader handle sealed graph dispatch. */
325
+ readonly graphDispatch?: true;
316
326
  readonly launch?: (staged: StagedPierCandidateExecution, context: {
317
327
  readonly request: AgentCandidateExecutorRequest<Format>;
318
328
  readonly traceStore: TraceStore;
@@ -344,10 +354,13 @@ interface CreatePierTaskTrialControllerOptions {
344
354
  readonly prefix?: readonly string[];
345
355
  };
346
356
  readonly dockerConnection?: PierDockerConnection;
357
+ /** Allow the bundled graph coordinator for the approved zero-model task cohort. */
358
+ readonly graphDispatch?: true;
347
359
  }
348
360
  /** Run one approved Pier task and reopen its official result through the durable controller. */
349
361
  export declare function createPierTaskTrialController<Format extends AgentCandidateExecutionFormat = 'experiment'>(options: CreatePierTaskTrialControllerOptions): FilePierCandidateTrialController<Format>;
350
362
  export declare class FilePierCandidateTrialController<Format extends AgentCandidateExecutionFormat = 'experiment'> implements PierCandidateTrialController<Format> {
363
+ readonly graphDispatch?: true;
351
364
  private readonly directory;
352
365
  private readonly launch?;
353
366
  private readonly readResult?;
package/dist/index.js CHANGED
@@ -1217,8 +1217,10 @@ async function stageKnowledge(directory, prepared, request) {
1217
1217
  * arguments. No benchmark-specific plan or candidate-authored telemetry exists.
1218
1218
  */
1219
1219
  /** @internal Package-private transport seam exercised by adapter tests. */
1220
- async function stagePreparedPierCandidateExecution(options, request) {
1220
+ async function stagePreparedPierCandidateExecution(options, request, graphDispatch) {
1221
1221
  const { prepared } = options;
1222
+ const graph = request.executionPlan.value.material.launch.graph;
1223
+ if (graph && graphDispatch !== true) throw new Error("this Pier process adapter cannot execute a sealed graph invocation");
1222
1224
  nonEmpty$1(options.pierVersion, "pierVersion");
1223
1225
  const directory = absoluteHostPath(options.directory, "directory");
1224
1226
  await mkdir(directory, { mode: 448 });
@@ -1247,6 +1249,7 @@ async function stagePreparedPierCandidateExecution(options, request) {
1247
1249
  assert.deepEqual(parseExactJson(request.materializationReceipt.bytes, "materialization receipt"), receiptMaterial, "prepared receipt bytes differ from runtime material");
1248
1250
  const planPath = join(directory, "execution-plan.json");
1249
1251
  const receiptPath = join(directory, "materialization-receipt.json");
1252
+ const graphInvocationPath = graph ? await stageGraphInvocation(directory, graph.invocation, request.graphInvocation) : void 0;
1250
1253
  await Promise.all([writeFile(planPath, request.executionPlan.bytes, {
1251
1254
  mode: 384,
1252
1255
  flag: "wx"
@@ -1284,6 +1287,7 @@ async function stagePreparedPierCandidateExecution(options, request) {
1284
1287
  profileDirectory,
1285
1288
  planPath,
1286
1289
  receiptPath,
1290
+ ...graphInvocationPath ? { graphInvocationPath } : {},
1287
1291
  agentArgs,
1288
1292
  evaluatorEnv: protectedEnvironment(prepared, request),
1289
1293
  attemptArgs: [
@@ -1294,6 +1298,15 @@ async function stagePreparedPierCandidateExecution(options, request) {
1294
1298
  ]
1295
1299
  };
1296
1300
  }
1301
+ async function stageGraphInvocation(directory, artifact, bytes) {
1302
+ if (!bytes || bytes.byteLength !== artifact.byteLength || sha256$1(bytes) !== artifact.sha256) throw new Error("Pier graph invocation bytes differ from the sealed plan");
1303
+ const path = join(directory, "graph-invocation.json");
1304
+ await writeFile(path, bytes, {
1305
+ mode: 384,
1306
+ flag: "wx"
1307
+ });
1308
+ return path;
1309
+ }
1297
1310
  function exceptionType(value) {
1298
1311
  const info = value && typeof value === "object" ? value : void 0;
1299
1312
  for (const key of [
@@ -1342,6 +1355,12 @@ function sealPierTrialResult(value) {
1342
1355
  assert.deepEqual(parsed, value.value, "Pier parsed result differs from result.json bytes");
1343
1356
  const resultBytes = Uint8Array.from(value.resultBytes);
1344
1357
  const taskPatch = Uint8Array.from(value.taskPatch);
1358
+ const graph = value.graphExecution;
1359
+ if (graph && !(graph.record instanceof Uint8Array)) throw new Error("Pier graph execution requires raw evaluator record bytes");
1360
+ const graphExecution = graph && Object.freeze({
1361
+ ...graph,
1362
+ record: Uint8Array.from(graph.record)
1363
+ });
1345
1364
  return Object.freeze({
1346
1365
  value: parsed,
1347
1366
  get resultBytes() {
@@ -1349,7 +1368,9 @@ function sealPierTrialResult(value) {
1349
1368
  },
1350
1369
  get taskPatch() {
1351
1370
  return Uint8Array.from(taskPatch);
1352
- }
1371
+ },
1372
+ ...graphExecution ? { graphExecution } : {},
1373
+ ...value.graphDelivered === void 0 ? {} : { graphDelivered: value.graphDelivered }
1353
1374
  });
1354
1375
  }
1355
1376
  function abortReason(signal) {
@@ -1401,10 +1422,11 @@ function createPierCandidateExecutionOptions(options) {
1401
1422
  const trialIdentity = (executionId, executionPlanDigest) => JSON.stringify([executionId, executionPlanDigest]);
1402
1423
  return {
1403
1424
  executor: {
1425
+ ...options.controller.graphDispatch ? { graphDispatch: true } : {},
1404
1426
  execute: async (request, context) => {
1405
1427
  context.signal.throwIfAborted();
1406
1428
  if (request.executionId !== options.prepared.executionId || request.materializationReceipt.digest !== options.prepared.materializationReceipt.digest) throw new Error("Pier executor received a different prepared candidate");
1407
- const staged = await stagePreparedPierCandidateExecution(options, request);
1429
+ const staged = await stagePreparedPierCandidateExecution(options, request, options.controller.graphDispatch);
1408
1430
  context.signal.throwIfAborted();
1409
1431
  const identity = trialIdentity(request.executionId, request.executionPlan.value.digest);
1410
1432
  if (trials.has(identity)) throw new Error("Pier trial identity is already active");
@@ -1457,6 +1479,11 @@ function createPierCandidateExecutionOptions(options) {
1457
1479
  result = recovered ? sealPierTrialResult(recovered) : void 0;
1458
1480
  }
1459
1481
  if (!result) return {};
1482
+ if (result.graphExecution && result.graphDelivered === false) {
1483
+ trials.delete(identity);
1484
+ officialResults.delete(request.executionId);
1485
+ return { graphExecution: result.graphExecution };
1486
+ }
1460
1487
  officialResults.set(request.executionId, result);
1461
1488
  const task = options.prepared.benchmark.task;
1462
1489
  if (task.outcome.kind !== "workspace") throw new Error("Pier candidate execution requires a workspace task outcome");
@@ -1469,7 +1496,10 @@ function createPierCandidateExecutionOptions(options) {
1469
1496
  patch: result.taskPatch
1470
1497
  });
1471
1498
  trials.delete(identity);
1472
- return { taskOutcome };
1499
+ return {
1500
+ taskOutcome,
1501
+ ...result.graphExecution ? { graphExecution: result.graphExecution } : {}
1502
+ };
1473
1503
  }
1474
1504
  },
1475
1505
  grader: {
@@ -1521,15 +1551,18 @@ function createPierTaskTrialController(options) {
1521
1551
  const { prefix = [], env, ...command } = options.command;
1522
1552
  const argumentsPrefix = [...prefix];
1523
1553
  const environment = { ...env };
1554
+ const graphDriver = fileURLToPath(new URL("../pier_agents/graph_driver.mjs", import.meta.url));
1524
1555
  const readResult = async ({ jobsDirectory, jobName }) => readOfficialTrial(join(jobsDirectory, jobName), maxEvidenceBytes);
1525
1556
  return new FilePierCandidateTrialController({
1526
1557
  directory: options.directory,
1527
1558
  dockerConnection: options.dockerConnection,
1559
+ ...options.graphDispatch ? { graphDispatch: true } : {},
1528
1560
  readResult,
1529
1561
  launch(staged, { request }) {
1530
1562
  const task = tasks.get(request.benchmark.task.digest);
1531
1563
  if (!task) throw new Error("Pier has no directory for this approved task");
1532
1564
  assertRealDirectory(task, "Pier task directory");
1565
+ if (staged.graphInvocationPath && request.benchmark.task.limits.maxModelCalls !== 0) throw new Error("The bundled Pier graph coordinator requires a zero-model task");
1533
1566
  const jobName = `candidate-${trialKey({
1534
1567
  executionId: request.executionId,
1535
1568
  executionPlanDigest: request.executionPlan.value.digest
@@ -1542,6 +1575,14 @@ function createPierTaskTrialController(options) {
1542
1575
  "--path",
1543
1576
  task,
1544
1577
  ...staged.agentArgs,
1578
+ ...staged.graphInvocationPath ? [
1579
+ "--agent-kwarg",
1580
+ `graph_invocation_path=${staged.graphInvocationPath}`,
1581
+ "--agent-kwarg",
1582
+ `graph_node_path=${process.execPath}`,
1583
+ "--agent-kwarg",
1584
+ `graph_driver_path=${graphDriver}`
1585
+ ] : [],
1545
1586
  ...staged.attemptArgs,
1546
1587
  ...Object.keys(staged.evaluatorEnv).flatMap((name) => ["--agent-env", `${name}=\${${name}}`]),
1547
1588
  "--env",
@@ -1587,14 +1628,34 @@ function readOfficialTrial(directory, maxEvidenceBytes) {
1587
1628
  if (result) throw new Error("Expected one official result for the approved Pier task");
1588
1629
  const artifacts = join(trial, "artifacts");
1589
1630
  assertRealDirectory(artifacts, "Pier trial artifacts directory");
1631
+ const taskPatch = readOfficialTrialFile(join(artifacts, "model.patch"), maxEvidenceBytes);
1590
1632
  result = {
1591
1633
  value,
1592
1634
  resultBytes,
1593
- taskPatch: readOfficialTrialFile(join(artifacts, "model.patch"), maxEvidenceBytes)
1635
+ taskPatch,
1636
+ ...readOfficialGraph(value, taskPatch)
1594
1637
  };
1595
1638
  }
1596
1639
  return result;
1597
1640
  }
1641
+ function readOfficialGraph(value, patch) {
1642
+ const raw = value.agent_result?.metadata?.graphExecution;
1643
+ if (raw === void 0) return {};
1644
+ const graph = raw;
1645
+ if (typeof graph.runId !== "string" || !graph.runId || !sha256Pattern.test(graph.graphDigest) || !sha256Pattern.test(graph.invocationDigest) || typeof graph.delivered !== "boolean" || typeof graph.record !== "string") throw new Error("Pier emitted invalid evaluator graph evidence");
1646
+ const record = Buffer.from(graph.record, "base64");
1647
+ if (!record.length || record.toString("base64") !== graph.record) throw new Error("Pier emitted invalid evaluator graph record bytes");
1648
+ return {
1649
+ graphDelivered: graph.delivered,
1650
+ graphExecution: {
1651
+ runId: graph.runId,
1652
+ graphDigest: graph.graphDigest,
1653
+ invocationDigest: graph.invocationDigest,
1654
+ taskArtifactDigest: `sha256:${createHash("sha256").update(patch).digest("hex")}`,
1655
+ record
1656
+ }
1657
+ };
1658
+ }
1598
1659
  function readOfficialTrialFile(path, maxEvidenceBytes) {
1599
1660
  const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
1600
1661
  try {
@@ -1870,6 +1931,7 @@ function assertRealDirectory(path, label) {
1870
1931
  if (!resolvedStats.isDirectory() || resolvedStats.isSymbolicLink()) throw new Error(`${label} must resolve to a real directory`);
1871
1932
  }
1872
1933
  var FilePierCandidateTrialController = class {
1934
+ graphDispatch;
1873
1935
  directory;
1874
1936
  launch;
1875
1937
  readResult;
@@ -1880,6 +1942,8 @@ var FilePierCandidateTrialController = class {
1880
1942
  this.directory = absolutePath(options.directory, "Pier controller directory");
1881
1943
  this.launch = options.launch;
1882
1944
  this.readResult = options.readResult;
1945
+ if (options.graphDispatch && (!options.launch || !options.readResult)) throw new Error("Pier graph dispatch requires both launch and durable graph capture");
1946
+ this.graphDispatch = options.graphDispatch;
1883
1947
  const configuredDocker = options.dockerConnection;
1884
1948
  if (configuredDocker?.id === defaultDockerConnectionId) throw new Error(`${defaultDockerConnectionId} is reserved for the implicit local connection`);
1885
1949
  const dockerConnection = configuredDocker ?? {