@rulvar/core 1.216.0 → 1.218.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/dist/index.d.ts CHANGED
@@ -6470,7 +6470,20 @@ declare class RunBudget {
6470
6470
  /**
6471
6471
  * Resume roll-forward: commits a reserve recovered from a journaled
6472
6472
  * spawn-admission decision entry without re-evaluating admission
6473
- * (reserves are recovered, never re-estimated).
6473
+ * (reserves are recovered, never re-estimated). The lifetime spawn
6474
+ * counter does NOT increment here (RV2201): every agent the
6475
+ * roll-forward re-covers already counted through the resume seed,
6476
+ * whose journal fold counts each dispatched agent entry, so an
6477
+ * incrementing roll-forward double-counts every recovered child.
6478
+ * The seventh subscription parity run resumed a killed 4-child
6479
+ * fan-out into a seed of 5, re-counted the children to 9 against a
6480
+ * cap of 8, and the post-acceptance tail starved on the counter
6481
+ * while the synthesis reserve's money sat whole: the judge declined
6482
+ * typed, the synthesis spawn refusal reached the terminal, and the
6483
+ * accepted dossier was lost. Each spawned agent counts a single
6484
+ * time across the run's whole life, never twice: at its fresh
6485
+ * admitSpawn, or through the seed of whichever segment rolls it
6486
+ * forward.
6474
6487
  */
6475
6488
  admitRecovered(reserveUsd: number, accountScope?: string): void;
6476
6489
  /**
@@ -9992,6 +10005,17 @@ interface OrchestrateClaimConsistencyMeta {
9992
10005
  /** Present when the judge invocation did not settle ok. */
9993
10006
  judgeFailed?: true;
9994
10007
  /**
10008
+ * Present when the judge invocation was refused ADMISSION and never
10009
+ * dispatched (RV2106): the ninth parity run's judge estimate did not
10010
+ * fit the orchestrator account's working room past the held
10011
+ * synthesis reserve, and the bare refusal killed a run whose fan-out
10012
+ * and draft were already complete. The declined pass degrades like a
10013
+ * failed judge (the meta names it, the journaled decision carries
10014
+ * the arithmetic, only the armed 'fail' posture stops the run) and
10015
+ * the synthesis its reserve was holding money for still dispatches.
10016
+ */
10017
+ judgeDeclined?: true;
10018
+ /**
9995
10019
  * The one field a consumer reads INSTEAD of inferring semantic
9996
10020
  * health from an empty findings array (RV1702):
9997
10021
  * {@link claimCoverageOf} over this meta, so `completion:
@@ -13068,6 +13092,29 @@ interface PreflightOrchestratorSpec {
13068
13092
  exposeChildResultTools?: boolean; /** Mirrors OrchestrateSynthesis.context; default 'digests'. */
13069
13093
  context?: "digests" | "full";
13070
13094
  };
13095
+ /**
13096
+ * The claim-consistency judge's admission estimate (RV2106), exactly
13097
+ * OrchestrateClaimConsistency.judge.estCost: the post-fan-in judge
13098
+ * admits against the ORCHESTRATOR account, whose working room past
13099
+ * the held synthesis reserve the coordination loop's own turns spend
13100
+ * from first. Declaring the estimate lets the estimator judge that
13101
+ * room statically (`orchestrator-working-room`); absent, the finding
13102
+ * stays silent, exactly like every other undeclared input.
13103
+ */
13104
+ claimConsistency?: {
13105
+ judge?: {
13106
+ estCost?: number;
13107
+ };
13108
+ };
13109
+ /**
13110
+ * The `reserve-line-headroom` threshold in coordination turn floors
13111
+ * (RV2201; previously hardwired to 2): the finding warns when the
13112
+ * admitted wave's steady state sits closer to the reserve line than
13113
+ * this many coordination turn floors. Raise it for waves whose
13114
+ * children routinely overrun their declared estimates; 0 silences
13115
+ * the finding entirely. Default 2.
13116
+ */
13117
+ headroomTurns?: number;
13071
13118
  }
13072
13119
  /** The full input: engine surface, run surface, and the declared wave. */
13073
13120
  interface PreflightInput {
package/dist/index.js CHANGED
@@ -13909,10 +13909,12 @@ var RunBudget = class {
13909
13909
  const committed = account.spentUsd + account.committedReserveUsd + account.finalizeReserveUsd + account.synthesisReserveUsd;
13910
13910
  if (committed >= account.ceilingUsd || committed + reserveUsd > account.ceilingUsd) {
13911
13911
  if (account.scope === "run") this.exhaustedInternal = true;
13912
- throw new BudgetExhaustedError(`budget ceiling reached on account '${account.scope}': spent ${account.spentUsd.toFixed(4)} USD plus committed reserves ${(account.committedReserveUsd + account.finalizeReserveUsd).toFixed(4)} USD plus the proposed reserve ${reserveUsd.toFixed(4)} USD does not fit the ceiling ${account.ceilingUsd.toFixed(4)} USD`, { data: {
13912
+ throw new BudgetExhaustedError(`budget ceiling reached on account '${account.scope}': spent ${account.spentUsd.toFixed(4)} USD plus committed reserves ${(account.committedReserveUsd + account.finalizeReserveUsd).toFixed(4)} USD ` + (account.synthesisReserveUsd > 0 ? `plus the held synthesis reserve ${account.synthesisReserveUsd.toFixed(4)} USD ` : "") + `plus the proposed reserve ${reserveUsd.toFixed(4)} USD does not fit the ceiling ${account.ceilingUsd.toFixed(4)} USD`, { data: {
13913
13913
  account: account.scope,
13914
13914
  spentUsd: account.spentUsd,
13915
13915
  committedReserveUsd: account.committedReserveUsd,
13916
+ finalizeReserveUsd: account.finalizeReserveUsd,
13917
+ synthesisReserveUsd: account.synthesisReserveUsd,
13916
13918
  proposedReserveUsd: reserveUsd,
13917
13919
  ceilingUsd: account.ceilingUsd
13918
13920
  } });
@@ -13928,10 +13930,22 @@ var RunBudget = class {
13928
13930
  /**
13929
13931
  * Resume roll-forward: commits a reserve recovered from a journaled
13930
13932
  * spawn-admission decision entry without re-evaluating admission
13931
- * (reserves are recovered, never re-estimated).
13933
+ * (reserves are recovered, never re-estimated). The lifetime spawn
13934
+ * counter does NOT increment here (RV2201): every agent the
13935
+ * roll-forward re-covers already counted through the resume seed,
13936
+ * whose journal fold counts each dispatched agent entry, so an
13937
+ * incrementing roll-forward double-counts every recovered child.
13938
+ * The seventh subscription parity run resumed a killed 4-child
13939
+ * fan-out into a seed of 5, re-counted the children to 9 against a
13940
+ * cap of 8, and the post-acceptance tail starved on the counter
13941
+ * while the synthesis reserve's money sat whole: the judge declined
13942
+ * typed, the synthesis spawn refusal reached the terminal, and the
13943
+ * accepted dossier was lost. Each spawned agent counts a single
13944
+ * time across the run's whole life, never twice: at its fresh
13945
+ * admitSpawn, or through the seed of whichever segment rolls it
13946
+ * forward.
13932
13947
  */
13933
13948
  admitRecovered(reserveUsd, accountScope = "run") {
13934
- this.agentsSpawnedInternal += 1;
13935
13949
  for (const account of this.chainOf(accountScope)) account.committedReserveUsd += reserveUsd;
13936
13950
  this.emitUpdate();
13937
13951
  }
@@ -23402,7 +23416,42 @@ function makeOrchestratorWorkflow(goal, opts) {
23402
23416
  ...spec.judge?.effort === void 0 ? {} : { effort: spec.judge.effort },
23403
23417
  ...spec.judge?.estCost === void 0 ? {} : { estCost: spec.judge.estCost }
23404
23418
  };
23405
- const judged = await runtime.runInScope(judgeState, () => ctx.agent(judgePrompt, judgeOpts));
23419
+ let judged;
23420
+ try {
23421
+ judged = await runtime.runInScope(judgeState, () => ctx.agent(judgePrompt, judgeOpts));
23422
+ } catch (declined) {
23423
+ if (!(declined instanceof BudgetExhaustedError)) throw declined;
23424
+ claimConsistencyMeta = finishMeta({
23425
+ judgeInvoked: false,
23426
+ judgeDeclined: true
23427
+ });
23428
+ const declineKey = deriverV2.deriveKey({ kind: "orchestrator-claim-judge-declined" });
23429
+ if (!internals.replayer.snapshot().some((entry) => entry.kind === "decision" && entry.key === declineKey)) await internals.replayer.appendSinglePhase({
23430
+ scope: callingState.scope,
23431
+ key: declineKey,
23432
+ kind: "decision",
23433
+ status: "ok",
23434
+ spanId: internals.spans.mint(callingState.spanId),
23435
+ site: "orchestrator-budget",
23436
+ value: {
23437
+ decisionType: "orchestrator_claim_judge_declined",
23438
+ reason: declined.message.slice(0, 300),
23439
+ remainingUsd: internals.budget.remainingUsd(orchestratorAccount ?? "run") ?? null
23440
+ }
23441
+ });
23442
+ internals.events.emit({
23443
+ type: "log",
23444
+ level: "warn",
23445
+ msg: "orchestrator claim consistency judge declined by admission",
23446
+ data: { reason: declined.message.slice(0, 300) }
23447
+ }, callingState.spanId);
23448
+ if (onFound === "fail") throw new FailRunError("the claim-consistency judge could not be admitted within the orchestrator account, so the armed fail posture cannot pass the draft: " + declined.message.slice(0, 300), { data: {
23449
+ source: "orchestrator_claim_consistency",
23450
+ claimConsistencyMeta,
23451
+ ...snapshot ?? {}
23452
+ } });
23453
+ return;
23454
+ }
23406
23455
  if (judged.status !== "ok" || judged.output === null || judged.output === void 0) {
23407
23456
  claimConsistencyMeta = finishMeta({
23408
23457
  judgeInvoked: true,
@@ -24031,6 +24080,26 @@ function makeOrchestratorWorkflow(goal, opts) {
24031
24080
  * rejection-past-the-bound error keeps its own
24032
24081
  * repairsUsed/maxRepairs/failed untouched.
24033
24082
  */
24083
+ const journalSynthesisAdmissionDecline = async (thrown) => {
24084
+ if (!(thrown instanceof BudgetExhaustedError)) return;
24085
+ const declineKey = deriverV2.deriveKey({ kind: "orchestrator-synthesis-redemption-declined" });
24086
+ if (internals.replayer.snapshot().some((entry) => entry.kind === "decision" && entry.key === declineKey)) return;
24087
+ await internals.replayer.appendSinglePhase({
24088
+ scope: callingState.scope,
24089
+ key: declineKey,
24090
+ kind: "decision",
24091
+ status: "ok",
24092
+ spanId: internals.spans.mint(callingState.spanId),
24093
+ site: "orchestrator-budget",
24094
+ value: {
24095
+ decisionType: "orchestrator_synthesis_redemption_declined",
24096
+ reason: thrown.message.slice(0, 300),
24097
+ remainingUsd: internals.budget.remainingUsd() ?? null,
24098
+ spawnHeadroom: internals.budget.spawnHeadroom,
24099
+ path: "accepted-finish"
24100
+ }
24101
+ });
24102
+ };
24034
24103
  const enrichSynthesisFailure = (thrown, snapshot) => {
24035
24104
  if (!(thrown instanceof FailRunError)) throw thrown;
24036
24105
  const base = thrown.data ?? {};
@@ -24059,6 +24128,7 @@ function makeOrchestratorWorkflow(goal, opts) {
24059
24128
  try {
24060
24129
  return await runSynthesis(result.output);
24061
24130
  } catch (thrown) {
24131
+ await journalSynthesisAdmissionDecline(thrown);
24062
24132
  return enrichSynthesisFailure(thrown);
24063
24133
  }
24064
24134
  }
@@ -24265,6 +24335,7 @@ function makeOrchestratorWorkflow(goal, opts) {
24265
24335
  try {
24266
24336
  synthesizedFinal = await runSynthesis(result.output);
24267
24337
  } catch (thrown) {
24338
+ await journalSynthesisAdmissionDecline(thrown);
24268
24339
  enrichSynthesisFailure(thrown, {
24269
24340
  completion: decision.completion,
24270
24341
  childStatusCounts: decision.childStatusCounts,
@@ -24524,6 +24595,7 @@ function preflightEstimate(input) {
24524
24595
  if (input.orchestrator !== void 0) {
24525
24596
  if (input.orchestrator.estInputTokens !== void 0) requireNonNegativeInteger(input.orchestrator.estInputTokens, "preflight.orchestrator.estInputTokens");
24526
24597
  if (input.orchestrator.acceptance?.minSpawnedChildren !== void 0) requirePositiveInteger$2(input.orchestrator.acceptance.minSpawnedChildren, "preflight.orchestrator.acceptance.minSpawnedChildren");
24598
+ if (input.orchestrator.claimConsistency?.judge?.estCost !== void 0) requireNonNegativeNumber(input.orchestrator.claimConsistency.judge.estCost, "preflight.orchestrator.claimConsistency.judge.estCost");
24527
24599
  const spec = input.orchestrator.budget;
24528
24600
  const fraction = spec?.capFraction ?? .2;
24529
24601
  const fromFraction = ceilingUsd === void 0 ? void 0 : fraction * ceilingUsd;
@@ -25055,11 +25127,38 @@ function preflightEstimate(input) {
25055
25127
  const requiredMinimumCeilingUsd = wave.length === 0 ? void 0 : wave.reduce((sum, row) => sum + row.reserveUsd, 0) + reservedForFinalizationUsd + synthesisHoldUsd + liveRootExposureTermUsd;
25056
25128
  const reserveLineUsd = ceilingUsd === void 0 || synthesisHoldUsd <= 0 ? void 0 : ceilingUsd - synthesisHoldUsd;
25057
25129
  const reserveLineHeadroomUsd = reserveLineUsd === void 0 ? void 0 : reserveLineUsd - wave.filter((row) => row.admitted).reduce((sum, row) => sum + row.reserveUsd, 0);
25058
- if (orchestrateWave && reserveLineUsd !== void 0 && reserveLineHeadroomUsd !== void 0 && wave.some((row) => row.admitted) && reserveLineHeadroomUsd < 2 * Math.max(liveRootExposureTermUsd, 1e-4)) say({
25130
+ const headroomTurns = input.orchestrator?.headroomTurns ?? 2;
25131
+ if (orchestrateWave && reserveLineUsd !== void 0 && reserveLineHeadroomUsd !== void 0 && wave.some((row) => row.admitted) && headroomTurns > 0 && reserveLineHeadroomUsd < headroomTurns * Math.max(liveRootExposureTermUsd, 1e-4)) say({
25059
25132
  severity: "warning",
25060
25133
  code: "reserve-line-headroom",
25061
- message: `the admitted wave's steady state sits ${reserveLineHeadroomUsd.toFixed(4)} USD under the reserve line ${reserveLineUsd.toFixed(4)} USD (the ceiling minus the synthesis reserve), less than two coordination turn floors of headroom (${liveRootExposureTermUsd.toFixed(4)} USD each): child spend past the declared estimates eats that headroom, the coordination loop is then refused at the line, and the run settles partial with the synthesis redeemed from its reserve (RV2101); size the wave below the line or raise the ceiling to keep coordinating past it`
25134
+ message: `the admitted wave's steady state sits ${reserveLineHeadroomUsd.toFixed(4)} USD under the reserve line ${reserveLineUsd.toFixed(4)} USD (the ceiling minus the synthesis reserve), less than ${String(headroomTurns)} coordination turn floors of headroom (${liveRootExposureTermUsd.toFixed(4)} USD each): child spend past the declared estimates eats that headroom, the coordination loop is then refused at the line, and the run settles partial with the synthesis redeemed from its reserve (RV2101); size the wave below the line or raise the ceiling to keep coordinating past it`
25062
25135
  });
25136
+ {
25137
+ const judgeEstUsd = input.orchestrator?.claimConsistency?.judge?.estCost;
25138
+ if (judgeEstUsd !== void 0 && effectiveCapUsd !== void 0 && synthesisHoldUsd > 0) {
25139
+ const workingRoomUsd = effectiveCapUsd - synthesisHoldUsd;
25140
+ if (workingRoomUsd < liveRootExposureTermUsd + judgeEstUsd) say({
25141
+ severity: "warning",
25142
+ code: "orchestrator-working-room",
25143
+ message: `the orchestrator account's working room past the held synthesis reserve is ${workingRoomUsd.toFixed(4)} USD (cap ${effectiveCapUsd.toFixed(4)} minus the ${synthesisHoldUsd.toFixed(4)} USD hold), below one coordination turn floor (${liveRootExposureTermUsd.toFixed(4)} USD) plus the declared ${judgeEstUsd.toFixed(4)} USD claim-consistency judge estimate: the judge admission will be declined once the coordination loop has taken even one turn, and the pass degrades to its journaled declined verdict (RV2106); raise the cap, shrink the judge estimate, or shrink the synthesis reserve`
25144
+ });
25145
+ }
25146
+ }
25147
+ if (orchestrateWave && wave.length > 0 && admitted === wave.length) {
25148
+ const lifetimeSpawnCap = input.engine?.budgetDefaults?.lifetimeSpawnCap ?? 500;
25149
+ const judgeDeclared = input.orchestrator?.claimConsistency?.judge !== void 0;
25150
+ const synthesisDeclared = input.orchestrator?.synthesis !== void 0;
25151
+ const plannedSpawns = wave.length + (judgeDeclared ? 1 : 0) + (synthesisDeclared ? 1 : 0);
25152
+ const spawnHeadroom = lifetimeSpawnCap - plannedSpawns;
25153
+ if (spawnHeadroom <= 0) {
25154
+ const breakdown = `the admitted wave of ${String(wave.length)} agent invocations` + (judgeDeclared ? " plus the claim-consistency judge" : "") + (synthesisDeclared ? " plus the synthesis invocation" : "") + ` is ${String(plannedSpawns)} against budgetDefaults.lifetimeSpawnCap ` + String(lifetimeSpawnCap);
25155
+ say({
25156
+ severity: "warning",
25157
+ code: "tail-spawn-budget",
25158
+ message: spawnHeadroom < 0 ? breakdown + ": the post-fan-in tail starves on the counter with its money whole: the judge admission declines typed (RV2106) and the synthesis spawn journals its declined verdict (RV2201) instead of composing; raise the cap to seat the declared tail" : breakdown + ": an exact fill leaves zero spawn headroom, so nothing the plan did not name (a re-spawned child, a second pass) can ever be admitted; raise the cap for margin"
25159
+ });
25160
+ }
25161
+ }
25063
25162
  if (wave.length > 0 && denied > 0) {
25064
25163
  const deniedLabels = wave.filter((row) => !row.admitted).map((row) => row.label);
25065
25164
  if (admitted === 0) say({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/core",
3
- "version": "1.216.0",
3
+ "version": "1.218.0",
4
4
  "description": "Rulvar core: L0 contracts, journal kernel, ctx primitives, agent runtime, model router, tool system, dynamic orchestrator, InMemory and JSONL stores, event stream.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",