@reticlehq/engine 3.3.0 → 3.5.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/NOTICE +5 -0
- package/dist/disagreement/contradictions.js +20 -28
- package/dist/disagreement/echo-mismatch.js +16 -0
- package/dist/evidence/already-true.js +5 -1
- package/dist/evidence/instrumentation-gaps.js +8 -2
- package/dist/evidence/unsettled.js +7 -1
- package/dist/question/declared.js +9 -1
- package/dist/question/predicate/predicate-asks.js +7 -1
- package/dist/question/predicate/predicate-compare.d.ts +18 -0
- package/dist/question/predicate/predicate-compare.js +226 -0
- package/dist/question/predicate/predicate-element.d.ts +2 -0
- package/dist/question/predicate/predicate-element.js +58 -9
- package/dist/question/predicate/predicate-eval-kit.d.ts +43 -2
- package/dist/question/predicate/predicate-eval-kit.js +107 -14
- package/dist/question/predicate/predicate-eval.js +47 -6
- package/dist/question/predicate/predicate-parse.js +1 -0
- package/dist/question/predicate/predicate-precheck.js +3 -5
- package/dist/question/predicate/predicate-request-body.js +7 -3
- package/dist/question/predicate/predicate-schema.d.ts +2 -0
- package/dist/question/predicate/predicate-schema.js +18 -0
- package/dist/question/predicate/predicate-session.d.ts +7 -0
- package/dist/question/predicate/predicate-to-links.js +3 -1
- package/dist/question/predicate/predicate.js +65 -8
- package/dist/window/ring-buffer.d.ts +14 -0
- package/dist/window/ring-buffer.js +69 -1
- package/package.json +4 -5
|
@@ -2,6 +2,21 @@ import { CHURN_TYPES, RING_BUFFER_DEFAULTS } from '@reticlehq/core';
|
|
|
2
2
|
import { byteSizeOf } from './byte-size.js';
|
|
3
3
|
/** How far forward to look for a churn event to sacrifice before falling back to plain FIFO. */
|
|
4
4
|
const CHURN_SCAN_LIMIT = 256;
|
|
5
|
+
/**
|
|
6
|
+
* Extra events the count cap may hold while a verdict window is armed.
|
|
7
|
+
*
|
|
8
|
+
* A predicate's own match being evicted INSIDE the window it is being graded against is the worst
|
|
9
|
+
* shape of false negative: the verdict says the flow is red while the flow was green, and the
|
|
10
|
+
* caller cannot detect it, because `dropped` is a session-wide counter with no way to attribute a
|
|
11
|
+
* loss to this assertion's own `since` (#668).
|
|
12
|
+
*
|
|
13
|
+
* The buffer is time-ordered and eviction takes from the head, so "pin the armed window" is the
|
|
14
|
+
* same thing as "let the buffer run over its count cap rather than eat into that window". The
|
|
15
|
+
* allowance is a constant, so a wait that never ends cannot grow the buffer without bound, and the
|
|
16
|
+
* BYTE cap is deliberately left hard -- bytes are the real memory bound, and a window that floods
|
|
17
|
+
* past it degrades through the existing honest path rather than through this one.
|
|
18
|
+
*/
|
|
19
|
+
const ARMED_WINDOW_OVERFLOW = 2000;
|
|
5
20
|
/**
|
|
6
21
|
* Bounded, time-aware event store per session. The single data structure that powers
|
|
7
22
|
* observe/wait_for/assert — it lets us look both backward (recent buffer) and
|
|
@@ -34,6 +49,15 @@ export class RingBuffer {
|
|
|
34
49
|
* `lostSince` and `ring-buffer-window-loss.test.ts`.
|
|
35
50
|
*/
|
|
36
51
|
#lastScarceLossT;
|
|
52
|
+
/**
|
|
53
|
+
* Cursors of the verdict windows currently being graded, one entry per armed wait.
|
|
54
|
+
*
|
|
55
|
+
* A multiset rather than a single value: concurrent waits are ordinary (an `act_and_wait` whose
|
|
56
|
+
* `until` is an `allOf`, a background `wait_for`), and the buffer must protect back to the
|
|
57
|
+
* EARLIEST of them. Held as counts so releasing one wait does not unprotect another armed on the
|
|
58
|
+
* same cursor.
|
|
59
|
+
*/
|
|
60
|
+
#armedWindows = new Map();
|
|
37
61
|
constructor(options = {}) {
|
|
38
62
|
this.#maxEvents = options.maxEvents ?? RING_BUFFER_DEFAULTS.MAX_EVENTS;
|
|
39
63
|
this.#maxAgeMs = options.maxAgeMs ?? RING_BUFFER_DEFAULTS.MAX_AGE_MS;
|
|
@@ -83,7 +107,15 @@ export class RingBuffer {
|
|
|
83
107
|
// `dropped` moved. Bytes is a soft cap and per-value serialization already bounds any one event, so
|
|
84
108
|
// keeping the sole survivor over the budget is the correct trade. The count cap (maxEvents, ~2000)
|
|
85
109
|
// is a hard bound and stays `> maxEvents`.
|
|
86
|
-
|
|
110
|
+
// While a verdict window is armed, the count cap gets a bounded allowance -- but only while the
|
|
111
|
+
// event about to be dropped actually belongs to that window. A buffer full of events older than
|
|
112
|
+
// every armed cursor is evicted exactly as before, so an idle-but-armed session does not sit on
|
|
113
|
+
// a larger buffer for nothing.
|
|
114
|
+
const floor = this.#armedFloor();
|
|
115
|
+
const countCap = () => floor !== undefined && (this.#events[this.#head]?.t ?? -Infinity) >= floor
|
|
116
|
+
? this.#maxEvents + ARMED_WINDOW_OVERFLOW
|
|
117
|
+
: this.#maxEvents;
|
|
118
|
+
while (this.#liveCount() > countCap() ||
|
|
87
119
|
(this.#totalBytes > this.#maxBytes && this.#liveCount() > 1)) {
|
|
88
120
|
if (CHURN_TYPES.has(this.#events[this.#head]?.type ?? '')) {
|
|
89
121
|
this.#totalBytes -= this.#eventBytes[this.#head] ?? 0;
|
|
@@ -117,6 +149,42 @@ export class RingBuffer {
|
|
|
117
149
|
this.#head = 0;
|
|
118
150
|
}
|
|
119
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Protect events at or after `cursor` from count-cap eviction until the returned function runs.
|
|
154
|
+
*
|
|
155
|
+
* Call it when a wait arms and call the result when the verdict is graded, in a `finally`: a
|
|
156
|
+
* leaked protection would hold the allowance open for the life of the session. Releasing twice is
|
|
157
|
+
* harmless.
|
|
158
|
+
*
|
|
159
|
+
* This is a bounded promise, not an absolute one. Past {@link ARMED_WINDOW_OVERFLOW} events, or
|
|
160
|
+
* under byte pressure, the window is evicted anyway and the loss is recorded as scarce -- so
|
|
161
|
+
* `lostSince` turns the verdict undecidable instead of returning the false red that pinning
|
|
162
|
+
* exists to prevent. Degrading into "I could not see" is right; degrading into "it did not
|
|
163
|
+
* happen" is the defect.
|
|
164
|
+
*/
|
|
165
|
+
protect(cursor) {
|
|
166
|
+
this.#armedWindows.set(cursor, (this.#armedWindows.get(cursor) ?? 0) + 1);
|
|
167
|
+
let released = false;
|
|
168
|
+
return () => {
|
|
169
|
+
if (released)
|
|
170
|
+
return;
|
|
171
|
+
released = true;
|
|
172
|
+
const remaining = (this.#armedWindows.get(cursor) ?? 1) - 1;
|
|
173
|
+
if (remaining <= 0)
|
|
174
|
+
this.#armedWindows.delete(cursor);
|
|
175
|
+
else
|
|
176
|
+
this.#armedWindows.set(cursor, remaining);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/** The earliest armed cursor, or `undefined` when no verdict window is open. */
|
|
180
|
+
#armedFloor() {
|
|
181
|
+
let floor;
|
|
182
|
+
for (const cursor of this.#armedWindows.keys()) {
|
|
183
|
+
if (floor === undefined || cursor < floor)
|
|
184
|
+
floor = cursor;
|
|
185
|
+
}
|
|
186
|
+
return floor;
|
|
187
|
+
}
|
|
120
188
|
/** Record an eviction at `index` as scarce loss, unless it was the churn floor being sacrificed. */
|
|
121
189
|
#noteScarceLoss(index) {
|
|
122
190
|
const victim = this.#events[index];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reticlehq/engine",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "The rules that decide a verdict: read what happened in a running app and say whether the declared consequence held. No browser, no daemon, no command line - an implementation of the OpenVerification specification you can use on its own.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"verification",
|
|
@@ -49,16 +49,15 @@
|
|
|
49
49
|
},
|
|
50
50
|
"files": [
|
|
51
51
|
"dist",
|
|
52
|
-
"README.md"
|
|
52
|
+
"README.md",
|
|
53
|
+
"NOTICE"
|
|
53
54
|
],
|
|
54
55
|
"publishConfig": {
|
|
55
56
|
"access": "public"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
59
|
"zod": "^3.24.1",
|
|
59
|
-
"@reticlehq/core": "3.
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
60
|
+
"@reticlehq/core": "3.5.0",
|
|
62
61
|
"open-verification": "1.0.0"
|
|
63
62
|
},
|
|
64
63
|
"scripts": {
|