@verax-ai/proxy 0.4.5 → 0.4.7

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/ledger.d.ts CHANGED
@@ -122,6 +122,7 @@ export declare class FileLedger implements Ledger {
122
122
  private readonly countedAt;
123
123
  countsReadable: boolean;
124
124
  private readonly heartbeatPath;
125
+ readonly startedAtMs: number;
125
126
  private decisionCount;
126
127
  private effectCount;
127
128
  private lastDecisionMs;
@@ -210,6 +211,8 @@ export declare class FileLedger implements Ledger {
210
211
  countedTimes(): number[];
211
212
  hasPrimaryEffect(ref: string): boolean;
212
213
  private pulse;
214
+ /** A running body pulses even when no decision or effect is appended. */
215
+ pulseHeartbeat(beat: "timer" | "row"): void;
213
216
  private storeEffect;
214
217
  }
215
218
  export declare function lookupDecisionByRef(ledger: Ledger, ref: string, key?: string): Promise<DecisionIndexRow | null>;
package/dist/ledger.js CHANGED
@@ -352,6 +352,7 @@ export class FileLedger {
352
352
  countedAt = [];
353
353
  countsReadable = true;
354
354
  heartbeatPath;
355
+ startedAtMs = Date.now();
355
356
  decisionCount = 0;
356
357
  effectCount = 0;
357
358
  lastDecisionMs = null;
@@ -1018,12 +1019,19 @@ export class FileLedger {
1018
1019
  this.decisionCount += 1;
1019
1020
  else
1020
1021
  this.effectCount += 1;
1021
- writeFileSync(this.heartbeatPath, `${JSON.stringify({
1022
+ this.pulseHeartbeat("row");
1023
+ }
1024
+ /** A running body pulses even when no decision or effect is appended. */
1025
+ pulseHeartbeat(beat) {
1026
+ this.assertOwned();
1027
+ writeFileAtomic(this.heartbeatPath, `${JSON.stringify({
1022
1028
  atMs: Date.now(),
1023
1029
  pid: process.pid,
1030
+ startedAtMs: this.startedAtMs,
1031
+ beat,
1024
1032
  lastDecisionN: this.decisionCount,
1025
1033
  lastEffectN: this.effectCount,
1026
- })}\n`, { encoding: "utf8", mode: 0o600 });
1034
+ })}\n`);
1027
1035
  }
1028
1036
  async storeEffect(row, witnessClass, resultHash, externalReceipt) {
1029
1037
  // Never ask the body or its same-org witness to sign an external receipt.
package/dist/reconcile.js CHANGED
@@ -363,10 +363,26 @@ export function reconcile(channelRows, effects, opts) {
363
363
  const rowTol = rowToleranceMs(row, toleranceMs);
364
364
  const marked = { ...row, toleranceMs: rowTol };
365
365
  if (typeof row.ref === "string" && row.ref !== "") {
366
- const idx = effects.findIndex((e, i) => !used.has(i) &&
366
+ const findFor = (ref) => effects.findIndex((e, i) => !used.has(i) &&
367
367
  decided(e) &&
368
- (e.row.ref === row.ref ||
369
- opts?.approvals?.some((a) => a.ref === row.ref && a.allowRef === e.row.ref)));
368
+ (e.row.ref === ref || opts?.approvals?.some((a) => a.ref === ref && a.allowRef === e.row.ref)));
369
+ let idx = findFor(row.ref);
370
+ if (idx === -1) {
371
+ // The brain is answered with its own `_ref`, so the statement may carry the raw
372
+ // ref of a scoped defer `<tenantKey>:<raw>`. Taken only when one tenant has it.
373
+ const scoped = [
374
+ ...new Set((opts?.approvals ?? [])
375
+ .filter((a) => a.ref.endsWith(`:${row.ref}`))
376
+ .map((a) => a.ref)
377
+ .filter((ref) => findFor(ref) !== -1)),
378
+ ];
379
+ if (scoped.length > 1) {
380
+ ghost.push(asGhost(marked, effects, "ref-ambiguous"));
381
+ continue;
382
+ }
383
+ if (scoped.length === 1)
384
+ idx = findFor(scoped[0]);
385
+ }
370
386
  if (idx === -1) {
371
387
  ghost.push(asGhost(marked, effects));
372
388
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verax-ai/proxy",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {