@riddledc/riddle-proof 0.5.2 → 0.5.4

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.
@@ -34,6 +34,22 @@ function createHarnessStatePath(stateDir) {
34
34
  const stamp = timestamp().replace(/\D/g, "").slice(0, 14) || "unknown";
35
35
  return path.join(stateDir, `riddle-proof-run-${stamp}-${crypto.randomUUID().slice(0, 8)}.json`);
36
36
  }
37
+ function createEngineStatePath(state, config) {
38
+ const existing = nonEmptyString(state.request.engine_state_path);
39
+ if (existing) return existing;
40
+ const harnessStatePath = nonEmptyString(state.state_path);
41
+ if (harnessStatePath) {
42
+ const dir = path.dirname(harnessStatePath);
43
+ const base = path.basename(harnessStatePath);
44
+ if (base.startsWith("riddle-proof-run-")) {
45
+ return path.join(dir, base.replace("riddle-proof-run-", "riddle-proof-state-"));
46
+ }
47
+ return path.join(dir, `${base}.engine-state.json`);
48
+ }
49
+ const stateDir = config?.stateDir || "/tmp";
50
+ const stamp = timestamp().replace(/\D/g, "").slice(0, 14) || "unknown";
51
+ return path.join(stateDir, `riddle-proof-state-${stamp}-${crypto.randomUUID().slice(0, 8)}.json`);
52
+ }
37
53
  function ensureParent(filePath) {
38
54
  mkdirSync(path.dirname(filePath), { recursive: true });
39
55
  }
@@ -76,6 +92,18 @@ function heartbeat(state, input) {
76
92
  function jsonParam(payload) {
77
93
  return JSON.stringify(payload);
78
94
  }
95
+ function redactedWorkflowParams(params) {
96
+ const secretKeys = /* @__PURE__ */ new Set([
97
+ "auth_localStorage_json",
98
+ "auth_cookies_json",
99
+ "auth_headers_json"
100
+ ]);
101
+ const output = {};
102
+ for (const [key, value] of Object.entries(params)) {
103
+ output[key] = secretKeys.has(key) && value ? "[redacted]" : value;
104
+ }
105
+ return output;
106
+ }
79
107
  function engineStatePath(result, state) {
80
108
  return nonEmptyString(result.state_path) || nonEmptyString(state.request.engine_state_path);
81
109
  }
@@ -268,6 +296,20 @@ function requirePayload(action, payload, state, result) {
268
296
  }
269
297
  return null;
270
298
  }
299
+ function engineFailureBlocker(result, checkpoint) {
300
+ if (result.ok !== false) return null;
301
+ if (!checkpoint.endsWith("_failed") && !checkpoint.endsWith("_blocked")) return null;
302
+ return {
303
+ code: checkpoint,
304
+ checkpoint,
305
+ message: result.summary || `Riddle Proof engine stopped at ${checkpoint}.`,
306
+ details: compactRecord({
307
+ error: result.error,
308
+ approval: result.approval,
309
+ checkpointContract: result.checkpointContract || null
310
+ })
311
+ };
312
+ }
271
313
  function terminalResult(state, status, result, summary, raw = {}) {
272
314
  setRunStatus(state, status);
273
315
  const metadata = normalizeTerminalMetadata({
@@ -425,6 +467,10 @@ async function routeCheckpoint(request, state, result, agent, input) {
425
467
  terminal: terminalResult(state, "completed", result, result.summary || "Riddle Proof engine completed.")
426
468
  };
427
469
  }
470
+ const failureBlocker = engineFailureBlocker(result, checkpoint);
471
+ if (failureBlocker) {
472
+ return { blocker: failureBlocker };
473
+ }
428
474
  if ([
429
475
  "recon_human_escalation",
430
476
  "verify_human_escalation",
@@ -582,6 +628,7 @@ function readRiddleProofRunStatus(state_path) {
582
628
  async function runRiddleProofEngineHarness(input) {
583
629
  const state = loadRunState(input);
584
630
  state.request = normalizeRunParams({ ...state.request, ...input.request });
631
+ state.request.engine_state_path = nonEmptyString(input.resume_params?.state_path) || nonEmptyString(state.request.engine_state_path) || createEngineStatePath(state, input.config);
585
632
  const request = state.request;
586
633
  const agent = input.agent || createDisabledRiddleProofAgentAdapter();
587
634
  const maxIterations = Math.max(
@@ -637,24 +684,41 @@ async function runRiddleProofEngineHarness(input) {
637
684
  branch: state.branch || null
638
685
  }
639
686
  });
687
+ const engineCallStartedAt = timestamp();
688
+ const engineCallStartedMs = Date.now();
640
689
  recordEvent(state, {
641
690
  kind: "engine.call",
642
691
  checkpoint: "engine_call",
643
692
  stage,
644
693
  summary: "Calling Riddle Proof engine.",
645
- details: { params: nextParams }
694
+ details: {
695
+ params: redactedWorkflowParams(nextParams),
696
+ started_at: engineCallStartedAt
697
+ }
646
698
  });
647
699
  let result;
648
700
  try {
649
701
  result = await engine.execute(nextParams);
650
702
  } catch (error) {
651
703
  const message = error instanceof Error ? error.message : String(error);
704
+ recordEvent(state, {
705
+ kind: "engine.exception",
706
+ checkpoint: "engine_call_failed",
707
+ stage,
708
+ summary: message,
709
+ details: {
710
+ duration_ms: Date.now() - engineCallStartedMs,
711
+ started_at: engineCallStartedAt,
712
+ finished_at: timestamp()
713
+ }
714
+ });
652
715
  return blockerResult(state, lastResult, {
653
716
  code: "riddle_engine_exception",
654
717
  checkpoint: "engine_call_failed",
655
718
  message
656
719
  });
657
720
  }
721
+ const engineCallDurationMs = Date.now() - engineCallStartedMs;
658
722
  lastResult = result;
659
723
  const engineState = engineStatePath(result, state);
660
724
  if (engineState) state.request.engine_state_path = engineState;
@@ -679,7 +743,10 @@ async function runRiddleProofEngineHarness(input) {
679
743
  details: {
680
744
  ok: result.ok ?? null,
681
745
  engine_state_path: engineState || null,
682
- checkpoint: result.checkpoint || null
746
+ checkpoint: result.checkpoint || null,
747
+ duration_ms: engineCallDurationMs,
748
+ started_at: engineCallStartedAt,
749
+ finished_at: timestamp()
683
750
  }
684
751
  });
685
752
  const routed = await routeCheckpoint(request, state, result, agent, input);
@@ -947,6 +947,87 @@ function updateState(statePath, mutate) {
947
947
  writeState(statePath, state);
948
948
  return state;
949
949
  }
950
+ function nowIso() {
951
+ return (/* @__PURE__ */ new Date()).toISOString();
952
+ }
953
+ function appendRuntimeEventToState(state, event) {
954
+ const events = Array.isArray(state.runtime_events) ? state.runtime_events : [];
955
+ state.runtime_events = [...events, event].slice(-RUNTIME_EVENT_LIMIT);
956
+ state.runtime_updated_at = event.ts;
957
+ }
958
+ function beginRuntimeStep(statePath, action, step, workflowPath) {
959
+ const timer = {
960
+ startedAt: nowIso(),
961
+ startedMs: Date.now()
962
+ };
963
+ updateState(statePath, (state) => {
964
+ const current = {
965
+ step,
966
+ action,
967
+ status: "running",
968
+ started_at: timer.startedAt,
969
+ workflow_file: import_node_path2.default.basename(workflowPath)
970
+ };
971
+ state.current_runtime_step = current;
972
+ appendRuntimeEventToState(state, {
973
+ ts: timer.startedAt,
974
+ kind: "workflow.step.started",
975
+ step,
976
+ action,
977
+ summary: `Started ${step} workflow step.`,
978
+ details: {
979
+ workflow_file: import_node_path2.default.basename(workflowPath)
980
+ }
981
+ });
982
+ });
983
+ return timer;
984
+ }
985
+ function finishRuntimeStep(statePath, action, result, timer) {
986
+ const finishedAt = nowIso();
987
+ const durationMs = Date.now() - timer.startedMs;
988
+ const summary = result.haltedForApproval ? `${result.step} halted for approval.` : result.ok ? `Finished ${result.step} workflow step.` : `${result.step} workflow step failed.`;
989
+ updateState(statePath, (state) => {
990
+ const completed = {
991
+ step: result.step,
992
+ action,
993
+ status: result.haltedForApproval ? "approval_required" : result.ok ? "completed" : "failed",
994
+ started_at: timer.startedAt,
995
+ finished_at: finishedAt,
996
+ duration_ms: durationMs,
997
+ ok: result.ok,
998
+ halted_for_approval: result.haltedForApproval || false,
999
+ auto_approved: result.autoApproved || false,
1000
+ error: result.error || null
1001
+ };
1002
+ state.current_runtime_step = null;
1003
+ state.last_runtime_step = completed;
1004
+ appendRuntimeEventToState(state, {
1005
+ ts: finishedAt,
1006
+ kind: "workflow.step.finished",
1007
+ step: result.step,
1008
+ action,
1009
+ summary,
1010
+ details: completed
1011
+ });
1012
+ });
1013
+ return {
1014
+ ...result,
1015
+ started_at: timer.startedAt,
1016
+ finished_at: finishedAt,
1017
+ duration_ms: durationMs
1018
+ };
1019
+ }
1020
+ function executedStep(res, extra = {}) {
1021
+ const output = {
1022
+ step: res.step,
1023
+ ok: res.ok,
1024
+ haltedForApproval: res.haltedForApproval || false,
1025
+ autoApproved: res.autoApproved || false,
1026
+ ...extra
1027
+ };
1028
+ if (typeof res.duration_ms === "number") output.duration_ms = res.duration_ms;
1029
+ return output;
1030
+ }
950
1031
  function hasSupervisorProofAssessment(state) {
951
1032
  const proofAssessment = state?.proof_assessment || {};
952
1033
  const source = String(proofAssessment?.source || state?.proof_assessment_source || "").trim().toLowerCase();
@@ -1409,53 +1490,74 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
1409
1490
  const lobsterPrefix = process.env.RIDDLE_PROOF_LOBSTER_SCRIPT ? [process.env.RIDDLE_PROOF_LOBSTER_SCRIPT] : [];
1410
1491
  const runOne = (step) => {
1411
1492
  const args = step === "setup" ? buildSetupArgs(params, config) : {};
1493
+ const stepWorkflowFile = workflowFile(config.riddleProofDir, step);
1494
+ const timer = beginRuntimeStep(config.statePath, action, step, stepWorkflowFile);
1412
1495
  let output;
1413
1496
  try {
1414
1497
  output = JSON.parse(
1415
- (0, import_node_child_process.execFileSync)(lobsterCommand, [...lobsterPrefix, "run", "--file", workflowFile(config.riddleProofDir, step), "--args-json", JSON.stringify(args)], {
1498
+ (0, import_node_child_process.execFileSync)(lobsterCommand, [...lobsterPrefix, "run", "--file", stepWorkflowFile, "--args-json", JSON.stringify(args)], {
1416
1499
  encoding: "utf-8",
1417
1500
  env
1418
1501
  })
1419
1502
  );
1420
1503
  } catch (error) {
1421
- return {
1504
+ return finishRuntimeStep(config.statePath, action, {
1422
1505
  ok: false,
1423
1506
  step,
1424
1507
  error: error?.message || String(error),
1425
1508
  stdout: String(error?.stdout || ""),
1426
1509
  stderr: String(error?.stderr || "")
1427
- };
1510
+ }, timer);
1428
1511
  }
1429
1512
  if (output?.status === "needs_approval") {
1430
1513
  if (!params.auto_approve) {
1431
- return {
1514
+ return finishRuntimeStep(config.statePath, action, {
1432
1515
  ok: false,
1433
1516
  haltedForApproval: true,
1434
1517
  step,
1435
1518
  approval: output.requiresApproval || null,
1436
1519
  raw: output
1437
- };
1520
+ }, timer);
1438
1521
  }
1439
1522
  const token = output?.requiresApproval?.resumeToken;
1440
- if (!token) throw new Error(`${step} requested approval without a resume token.`);
1441
- const resumed = JSON.parse(
1442
- (0, import_node_child_process.execFileSync)(lobsterCommand, [...lobsterPrefix, "resume", "--token", token, "--approve", "yes"], {
1443
- encoding: "utf-8",
1444
- env
1445
- })
1446
- );
1447
- return {
1523
+ if (!token) {
1524
+ return finishRuntimeStep(config.statePath, action, {
1525
+ ok: false,
1526
+ step,
1527
+ error: `${step} requested approval without a resume token.`,
1528
+ raw: output
1529
+ }, timer);
1530
+ }
1531
+ let resumed;
1532
+ try {
1533
+ resumed = JSON.parse(
1534
+ (0, import_node_child_process.execFileSync)(lobsterCommand, [...lobsterPrefix, "resume", "--token", token, "--approve", "yes"], {
1535
+ encoding: "utf-8",
1536
+ env
1537
+ })
1538
+ );
1539
+ } catch (error) {
1540
+ return finishRuntimeStep(config.statePath, action, {
1541
+ ok: false,
1542
+ step,
1543
+ autoApproved: true,
1544
+ error: error?.message || String(error),
1545
+ stdout: String(error?.stdout || ""),
1546
+ stderr: String(error?.stderr || "")
1547
+ }, timer);
1548
+ }
1549
+ return finishRuntimeStep(config.statePath, action, {
1448
1550
  ok: resumed?.ok !== false,
1449
1551
  step,
1450
1552
  autoApproved: true,
1451
1553
  raw: resumed
1452
- };
1554
+ }, timer);
1453
1555
  }
1454
- return {
1556
+ return finishRuntimeStep(config.statePath, action, {
1455
1557
  ok: output?.ok !== false,
1456
1558
  step,
1457
1559
  raw: output
1458
- };
1560
+ }, timer);
1459
1561
  };
1460
1562
  let effectiveAdvanceStage = params.advance_stage || null;
1461
1563
  const recordAttempt = (stage, status, summary, extra = {}) => {
@@ -1581,7 +1683,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
1581
1683
  let state = readState(config.statePath);
1582
1684
  if (!state || !state.workspace_ready || params.advance_stage === "setup") {
1583
1685
  const setupRes = runOne("setup");
1584
- executed.push({ step: "setup", ok: setupRes.ok, haltedForApproval: setupRes.haltedForApproval || false, autoApproved: setupRes.autoApproved || false });
1686
+ executed.push(executedStep(setupRes));
1585
1687
  if (!setupRes.ok || setupRes.haltedForApproval) {
1586
1688
  return failedRun("setup", setupRes.haltedForApproval ? "setup halted for approval" : "setup failed", setupRes, {
1587
1689
  checkpoint: "setup_blocked"
@@ -1791,7 +1893,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
1791
1893
  }
1792
1894
  if (!state?.recon_results || state?.stage === "setup" || state?.stage === "preflight" || ["needs_agent_decision", "needs_supervisor_judgment"].includes(state?.recon_status || "") || requestedStage === "recon") {
1793
1895
  const reconRes = runOne("recon");
1794
- executed.push({ step: "recon", ok: reconRes.ok, haltedForApproval: reconRes.haltedForApproval || false, autoApproved: reconRes.autoApproved || false });
1896
+ executed.push(executedStep(reconRes));
1795
1897
  if (!reconRes.ok || reconRes.haltedForApproval) {
1796
1898
  return failedRun("recon", reconRes.haltedForApproval ? "recon halted for approval" : "recon failed", reconRes, {
1797
1899
  checkpoint: "recon_failed",
@@ -1839,7 +1941,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
1839
1941
  state = readState(config.statePath);
1840
1942
  if (!authorReady(state) || effectiveAdvanceStage === "author") {
1841
1943
  const authorRes = runOne("author");
1842
- executed.push({ step: "author", ok: authorRes.ok, haltedForApproval: authorRes.haltedForApproval || false, autoApproved: authorRes.autoApproved || false });
1944
+ executed.push(executedStep(authorRes));
1843
1945
  if (!authorRes.ok || authorRes.haltedForApproval) {
1844
1946
  return failedRun("author", authorRes.haltedForApproval ? "author halted for approval" : "author failed", authorRes, {
1845
1947
  checkpoint: "author_failed",
@@ -1954,7 +2056,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
1954
2056
  }
1955
2057
  if (effectiveAdvanceStage === "implement") {
1956
2058
  const implementRes = runOne("implement");
1957
- executed.push({ step: "implement", ok: implementRes.ok, haltedForApproval: implementRes.haltedForApproval || false, autoApproved: implementRes.autoApproved || false });
2059
+ executed.push(executedStep(implementRes));
1958
2060
  if (implementRes.haltedForApproval) {
1959
2061
  return failedRun("implement", "implement halted for approval", implementRes, {
1960
2062
  checkpoint: "implement_blocked",
@@ -2044,7 +2146,7 @@ ${implementRes.stderr || ""}`;
2044
2146
  let verifyRes = { ok: true, step: "verify", reusedEvidence: canReuseVerifyEvidence };
2045
2147
  if (!canReuseVerifyEvidence) {
2046
2148
  verifyRes = runOne("verify");
2047
- executed.push({ step: "verify", ok: verifyRes.ok, haltedForApproval: verifyRes.haltedForApproval || false, autoApproved: verifyRes.autoApproved || false });
2149
+ executed.push(executedStep(verifyRes));
2048
2150
  if (!verifyRes.ok || verifyRes.haltedForApproval) {
2049
2151
  return failedRun("verify", verifyRes.haltedForApproval ? "verify halted for approval" : "verify failed", verifyRes, {
2050
2152
  checkpoint: "verify_failed",
@@ -2053,7 +2155,7 @@ ${implementRes.stderr || ""}`;
2053
2155
  });
2054
2156
  }
2055
2157
  } else {
2056
- executed.push({ step: "verify", ok: true, reusedEvidence: true, haltedForApproval: false, autoApproved: false });
2158
+ executed.push(executedStep(verifyRes, { reusedEvidence: true }));
2057
2159
  }
2058
2160
  state = readState(config.statePath);
2059
2161
  const verifyStatus = state?.verify_status || ((state?.after_cdn || "").trim() ? "evidence_captured" : "capture_incomplete");
@@ -2190,7 +2292,7 @@ ${implementRes.stderr || ""}`;
2190
2292
  details: { ...verifyDetails, shipGate }
2191
2293
  });
2192
2294
  const shipRes = runOne("ship");
2193
- executed.push({ step: "ship", ok: shipRes.ok, haltedForApproval: shipRes.haltedForApproval || false, autoApproved: shipRes.autoApproved || false });
2295
+ executed.push(executedStep(shipRes));
2194
2296
  if (!shipRes.ok || shipRes.haltedForApproval) {
2195
2297
  const shipNextAction = shipRes?.error && String(shipRes.error).includes("temporary proof branch") ? "product bug: ship resolved a temporary proof branch; resolve the PR head branch before retrying ship" : "inspect the ship error, confirm the PR head branch and verified commit, then retry ship";
2196
2298
  return failedRun("ship", shipRes.haltedForApproval ? "ship halted for approval" : "ship failed", shipRes, {
@@ -2369,7 +2471,7 @@ ${implementRes.stderr || ""}`;
2369
2471
  return shipGateBlocked(state, executed, { shipAssessment: shipAssessment.raw });
2370
2472
  }
2371
2473
  const shipRes = runOne("ship");
2372
- executed.push({ step: "ship", ok: shipRes.ok, haltedForApproval: shipRes.haltedForApproval || false, autoApproved: shipRes.autoApproved || false });
2474
+ executed.push(executedStep(shipRes));
2373
2475
  if (!shipRes.ok || shipRes.haltedForApproval) {
2374
2476
  return failedRun("ship", shipRes.haltedForApproval ? "ship halted for approval" : "ship failed", shipRes, {
2375
2477
  checkpoint: "ship_failed",
@@ -2495,7 +2597,7 @@ function createRiddleProofEngine(pluginConfig = {}) {
2495
2597
  }
2496
2598
  };
2497
2599
  }
2498
- var import_node_child_process, import_node_fs2, import_node_path2;
2600
+ var import_node_child_process, import_node_fs2, import_node_path2, RUNTIME_EVENT_LIMIT;
2499
2601
  var init_proof_run_engine = __esm({
2500
2602
  "src/proof-run-engine.ts"() {
2501
2603
  "use strict";
@@ -2503,6 +2605,7 @@ var init_proof_run_engine = __esm({
2503
2605
  import_node_fs2 = require("fs");
2504
2606
  import_node_path2 = __toESM(require("path"), 1);
2505
2607
  init_proof_run_core();
2608
+ RUNTIME_EVENT_LIMIT = 100;
2506
2609
  }
2507
2610
  });
2508
2611
 
@@ -2901,6 +3004,22 @@ function createHarnessStatePath(stateDir) {
2901
3004
  const stamp = timestamp2().replace(/\D/g, "").slice(0, 14) || "unknown";
2902
3005
  return import_node_path3.default.join(stateDir, `riddle-proof-run-${stamp}-${import_node_crypto2.default.randomUUID().slice(0, 8)}.json`);
2903
3006
  }
3007
+ function createEngineStatePath(state, config) {
3008
+ const existing = nonEmptyString(state.request.engine_state_path);
3009
+ if (existing) return existing;
3010
+ const harnessStatePath = nonEmptyString(state.state_path);
3011
+ if (harnessStatePath) {
3012
+ const dir = import_node_path3.default.dirname(harnessStatePath);
3013
+ const base = import_node_path3.default.basename(harnessStatePath);
3014
+ if (base.startsWith("riddle-proof-run-")) {
3015
+ return import_node_path3.default.join(dir, base.replace("riddle-proof-run-", "riddle-proof-state-"));
3016
+ }
3017
+ return import_node_path3.default.join(dir, `${base}.engine-state.json`);
3018
+ }
3019
+ const stateDir = config?.stateDir || "/tmp";
3020
+ const stamp = timestamp2().replace(/\D/g, "").slice(0, 14) || "unknown";
3021
+ return import_node_path3.default.join(stateDir, `riddle-proof-state-${stamp}-${import_node_crypto2.default.randomUUID().slice(0, 8)}.json`);
3022
+ }
2904
3023
  function ensureParent(filePath) {
2905
3024
  (0, import_node_fs3.mkdirSync)(import_node_path3.default.dirname(filePath), { recursive: true });
2906
3025
  }
@@ -2943,6 +3062,18 @@ function heartbeat(state, input) {
2943
3062
  function jsonParam(payload) {
2944
3063
  return JSON.stringify(payload);
2945
3064
  }
3065
+ function redactedWorkflowParams(params) {
3066
+ const secretKeys = /* @__PURE__ */ new Set([
3067
+ "auth_localStorage_json",
3068
+ "auth_cookies_json",
3069
+ "auth_headers_json"
3070
+ ]);
3071
+ const output = {};
3072
+ for (const [key, value] of Object.entries(params)) {
3073
+ output[key] = secretKeys.has(key) && value ? "[redacted]" : value;
3074
+ }
3075
+ return output;
3076
+ }
2946
3077
  function engineStatePath(result, state) {
2947
3078
  return nonEmptyString(result.state_path) || nonEmptyString(state.request.engine_state_path);
2948
3079
  }
@@ -3135,6 +3266,20 @@ function requirePayload(action, payload, state, result) {
3135
3266
  }
3136
3267
  return null;
3137
3268
  }
3269
+ function engineFailureBlocker(result, checkpoint) {
3270
+ if (result.ok !== false) return null;
3271
+ if (!checkpoint.endsWith("_failed") && !checkpoint.endsWith("_blocked")) return null;
3272
+ return {
3273
+ code: checkpoint,
3274
+ checkpoint,
3275
+ message: result.summary || `Riddle Proof engine stopped at ${checkpoint}.`,
3276
+ details: compactRecord({
3277
+ error: result.error,
3278
+ approval: result.approval,
3279
+ checkpointContract: result.checkpointContract || null
3280
+ })
3281
+ };
3282
+ }
3138
3283
  function terminalResult(state, status, result, summary, raw = {}) {
3139
3284
  setRunStatus(state, status);
3140
3285
  const metadata = normalizeTerminalMetadata({
@@ -3292,6 +3437,10 @@ async function routeCheckpoint(request, state, result, agent, input) {
3292
3437
  terminal: terminalResult(state, "completed", result, result.summary || "Riddle Proof engine completed.")
3293
3438
  };
3294
3439
  }
3440
+ const failureBlocker = engineFailureBlocker(result, checkpoint);
3441
+ if (failureBlocker) {
3442
+ return { blocker: failureBlocker };
3443
+ }
3295
3444
  if ([
3296
3445
  "recon_human_escalation",
3297
3446
  "verify_human_escalation",
@@ -3449,6 +3598,7 @@ function readRiddleProofRunStatus(state_path) {
3449
3598
  async function runRiddleProofEngineHarness(input) {
3450
3599
  const state = loadRunState(input);
3451
3600
  state.request = normalizeRunParams({ ...state.request, ...input.request });
3601
+ state.request.engine_state_path = nonEmptyString(input.resume_params?.state_path) || nonEmptyString(state.request.engine_state_path) || createEngineStatePath(state, input.config);
3452
3602
  const request = state.request;
3453
3603
  const agent = input.agent || createDisabledRiddleProofAgentAdapter();
3454
3604
  const maxIterations = Math.max(
@@ -3504,24 +3654,41 @@ async function runRiddleProofEngineHarness(input) {
3504
3654
  branch: state.branch || null
3505
3655
  }
3506
3656
  });
3657
+ const engineCallStartedAt = timestamp2();
3658
+ const engineCallStartedMs = Date.now();
3507
3659
  recordEvent(state, {
3508
3660
  kind: "engine.call",
3509
3661
  checkpoint: "engine_call",
3510
3662
  stage,
3511
3663
  summary: "Calling Riddle Proof engine.",
3512
- details: { params: nextParams }
3664
+ details: {
3665
+ params: redactedWorkflowParams(nextParams),
3666
+ started_at: engineCallStartedAt
3667
+ }
3513
3668
  });
3514
3669
  let result;
3515
3670
  try {
3516
3671
  result = await engine.execute(nextParams);
3517
3672
  } catch (error) {
3518
3673
  const message = error instanceof Error ? error.message : String(error);
3674
+ recordEvent(state, {
3675
+ kind: "engine.exception",
3676
+ checkpoint: "engine_call_failed",
3677
+ stage,
3678
+ summary: message,
3679
+ details: {
3680
+ duration_ms: Date.now() - engineCallStartedMs,
3681
+ started_at: engineCallStartedAt,
3682
+ finished_at: timestamp2()
3683
+ }
3684
+ });
3519
3685
  return blockerResult(state, lastResult, {
3520
3686
  code: "riddle_engine_exception",
3521
3687
  checkpoint: "engine_call_failed",
3522
3688
  message
3523
3689
  });
3524
3690
  }
3691
+ const engineCallDurationMs = Date.now() - engineCallStartedMs;
3525
3692
  lastResult = result;
3526
3693
  const engineState = engineStatePath(result, state);
3527
3694
  if (engineState) state.request.engine_state_path = engineState;
@@ -3546,7 +3713,10 @@ async function runRiddleProofEngineHarness(input) {
3546
3713
  details: {
3547
3714
  ok: result.ok ?? null,
3548
3715
  engine_state_path: engineState || null,
3549
- checkpoint: result.checkpoint || null
3716
+ checkpoint: result.checkpoint || null,
3717
+ duration_ms: engineCallDurationMs,
3718
+ started_at: engineCallStartedAt,
3719
+ finished_at: timestamp2()
3550
3720
  }
3551
3721
  });
3552
3722
  const routed = await routeCheckpoint(request, state, result, agent, input);
@@ -2,7 +2,7 @@ import {
2
2
  createDisabledRiddleProofAgentAdapter,
3
3
  readRiddleProofRunStatus,
4
4
  runRiddleProofEngineHarness
5
- } from "./chunk-5GZZZ6JA.js";
5
+ } from "./chunk-GC7C2NRA.js";
6
6
  import "./chunk-GVPCSXN7.js";
7
7
  import "./chunk-TMMKRKY5.js";
8
8
  export {