deepline 0.3.226 → 0.3.228

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.
@@ -200,7 +200,7 @@ export const SDK_RELEASE = {
200
200
  // getters keep their established compatibility behavior.
201
201
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
202
202
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
203
- version: '0.3.226',
203
+ version: '0.3.228',
204
204
  updateSummary:
205
205
  'Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.',
206
206
  packageCapabilities: {
@@ -132,3 +132,32 @@ export function selectRunEventsForAppRuntimeProjectionChunk(
132
132
  const batches = partitionRunEventsForAppRuntime(events);
133
133
  return batches.length === chunk.count ? batches[chunk.index] : undefined;
134
134
  }
135
+
136
+ /**
137
+ * Return the wire shapes accepted by the lease verifier. Older projectors sent
138
+ * the canonical events directly; current projectors also split large log
139
+ * events before grouping them into HTTP batches. A split can still fit in one
140
+ * HTTP batch, so that request has no projection chunk marker.
141
+ */
142
+ export function runEventsForAppRuntimeProjectionCandidates(
143
+ events: readonly PlayRunLedgerIngressEvent[],
144
+ chunk?: RunLedgerProjectionChunk,
145
+ ): Array<PlayRunLedgerIngressEvent[] | null> {
146
+ if (chunk) {
147
+ return [selectRunEventsForAppRuntimeProjectionChunk(events, chunk) ?? null];
148
+ }
149
+
150
+ const candidates: PlayRunLedgerIngressEvent[][] = [[...events]];
151
+ const batches = partitionRunEventsForAppRuntime(events);
152
+ if (batches.length === 1) {
153
+ const transportBatch = batches[0];
154
+ if (
155
+ transportBatch &&
156
+ (transportBatch.length !== events.length ||
157
+ transportBatch.some((event, index) => event !== events[index]))
158
+ ) {
159
+ candidates.push(transportBatch);
160
+ }
161
+ }
162
+ return candidates;
163
+ }
@@ -15,6 +15,10 @@ type ComparableRunLedgerEvent =
15
15
  | AcceptedPlayRunLedgerEvent
16
16
  | PlayRunLedgerIngressEvent;
17
17
 
18
+ type RunLedgerProjectionEventCandidate =
19
+ | readonly ComparableRunLedgerEvent[]
20
+ | null;
21
+
18
22
  /**
19
23
  * A newer app may receive a projection from a worker that predates optional
20
24
  * wait metadata. Normalize only those absent fields before the exact compare.
@@ -95,7 +99,7 @@ function safeMismatchedFields(
95
99
  */
96
100
  export function runLedgerProjectionMismatch(input: {
97
101
  projectedEvents: readonly AcceptedPlayRunLedgerEvent[];
98
- expectedEvents: readonly ComparableRunLedgerEvent[] | null;
102
+ expectedEvents: RunLedgerProjectionEventCandidate;
99
103
  chunk?: RunLedgerProjectionChunk;
100
104
  }): RunLedgerProjectionMismatchDiagnostic | null {
101
105
  const chunkIndex = input.chunk?.index ?? null;
@@ -149,3 +153,41 @@ export function runLedgerProjectionMismatch(input: {
149
153
  }
150
154
  return null;
151
155
  }
156
+
157
+ /**
158
+ * Compare a received projection against every wire shape accepted for its
159
+ * canonical prefix. Prefer a mismatch with the same event count as the
160
+ * received projection, since it identifies the first content difference
161
+ * instead of reporting a secondary count difference.
162
+ */
163
+ export function runLedgerProjectionMismatchAcrossCandidates(input: {
164
+ projectedEvents: readonly AcceptedPlayRunLedgerEvent[];
165
+ expectedEventCandidates: readonly RunLedgerProjectionEventCandidate[];
166
+ chunk?: RunLedgerProjectionChunk;
167
+ }): RunLedgerProjectionMismatchDiagnostic | null {
168
+ if (input.expectedEventCandidates.length === 0) {
169
+ return runLedgerProjectionMismatch({
170
+ projectedEvents: input.projectedEvents,
171
+ expectedEvents: null,
172
+ ...(input.chunk ? { chunk: input.chunk } : {}),
173
+ });
174
+ }
175
+
176
+ let bestMismatch: RunLedgerProjectionMismatchDiagnostic | null = null;
177
+ for (const expectedEvents of input.expectedEventCandidates) {
178
+ const mismatch = runLedgerProjectionMismatch({
179
+ projectedEvents: input.projectedEvents,
180
+ expectedEvents,
181
+ ...(input.chunk ? { chunk: input.chunk } : {}),
182
+ });
183
+ if (mismatch === null) return null;
184
+ if (
185
+ bestMismatch === null ||
186
+ (mismatch.expectedEventCount === input.projectedEvents.length &&
187
+ bestMismatch.expectedEventCount !== input.projectedEvents.length)
188
+ ) {
189
+ bestMismatch = mismatch;
190
+ }
191
+ }
192
+ return bestMismatch;
193
+ }
@@ -39,6 +39,11 @@ type Waiter<T> = {
39
39
  timer: ReturnType<typeof setTimeout>;
40
40
  };
41
41
 
42
+ type DrainWaiter = Waiter<void> & {
43
+ idleStartedAt: number;
44
+ onTimeout: () => void;
45
+ };
46
+
42
47
  export class RuntimeMapRowFeed {
43
48
  #appended = 0;
44
49
  #dispatched = 0;
@@ -47,7 +52,7 @@ export class RuntimeMapRowFeed {
47
52
  #failure: unknown = null;
48
53
  #failed = false;
49
54
  readonly #rowWaiters = new Map<Waiter<boolean>, number>();
50
- #drainWaiter: Waiter<void> | null = null;
55
+ #drainWaiter: DrainWaiter | null = null;
51
56
  #onAppended: ((fromIndex: number, toIndex: number) => void) | null = null;
52
57
  readonly #maxWaitMs: number;
53
58
 
@@ -70,7 +75,9 @@ export class RuntimeMapRowFeed {
70
75
  throw new Error('Runtime map row feed is closed; cannot append rows.');
71
76
  }
72
77
  if (!Number.isInteger(rowCount) || rowCount < 0) {
73
- throw new Error(`Runtime map row feed append count must be a non-negative integer, got ${String(rowCount)}.`);
78
+ throw new Error(
79
+ `Runtime map row feed append count must be a non-negative integer, got ${String(rowCount)}.`,
80
+ );
74
81
  }
75
82
  const fromIndex = this.#appended;
76
83
  this.#appended += rowCount;
@@ -111,13 +118,29 @@ export class RuntimeMapRowFeed {
111
118
  }
112
119
 
113
120
  markDispatched(count = 1): void {
114
- this.#dispatched += count;
115
- if (this.#dispatched > this.#appended) {
121
+ if (!Number.isInteger(count) || count < 0) {
116
122
  throw new Error(
117
- `Runtime map row feed dispatched ${this.#dispatched} rows but only ${this.#appended} were appended.`,
123
+ `Runtime map row feed dispatch count must be a non-negative integer, got ${String(count)}.`,
118
124
  );
119
125
  }
126
+ const dispatched = this.#dispatched + count;
127
+ if (dispatched > this.#appended) {
128
+ throw new Error(
129
+ `Runtime map row feed dispatched ${dispatched} rows but only ${this.#appended} were appended.`,
130
+ );
131
+ }
132
+ this.#dispatched = dispatched;
120
133
  this.#settleDrainWaiter();
134
+ const waiter = this.#drainWaiter;
135
+ if (count > 0 && waiter) {
136
+ // A slow page can take longer than the idle bound to dispatch. Only
137
+ // advancing its pending work resets the diagnostic, never page age,
138
+ // provider logs, or unrelated activity.
139
+ clearTimeout(waiter.timer);
140
+ waiter.idleStartedAt = Date.now();
141
+ waiter.timer = setTimeout(waiter.onTimeout, this.#maxWaitMs);
142
+ waiter.timer.unref?.();
143
+ }
121
144
  }
122
145
 
123
146
  /**
@@ -149,7 +172,7 @@ export class RuntimeMapRowFeed {
149
172
  });
150
173
  }
151
174
 
152
- /** Resolves once every appended row has been dispatched to a worker. */
175
+ /** Resolves on full dispatch; rejects after the bound with no dispatch progress. */
153
176
  waitUntilDrained(): Promise<void> {
154
177
  if (this.#failed) return Promise.reject(this.#failure);
155
178
  if (this.#dispatched >= this.#appended) return Promise.resolve();
@@ -159,22 +182,25 @@ export class RuntimeMapRowFeed {
159
182
  );
160
183
  }
161
184
  return new Promise<void>((resolve, reject) => {
162
- const startedAt = Date.now();
163
- this.#drainWaiter = {
185
+ const waiter: DrainWaiter = {
164
186
  resolve,
165
187
  reject,
166
- timer: setTimeout(() => {
188
+ idleStartedAt: Date.now(),
189
+ onTimeout: () => {
190
+ if (this.#drainWaiter !== waiter) return;
167
191
  this.#drainWaiter = null;
168
192
  reject(
169
193
  new RuntimeMapRowFeedStalledError({
170
194
  waiter: 'pump',
171
- waitMs: Date.now() - startedAt,
195
+ waitMs: Date.now() - waiter.idleStartedAt,
172
196
  snapshot: this.snapshot(),
173
197
  }),
174
198
  );
175
- }, this.#maxWaitMs),
199
+ },
200
+ timer: setTimeout(() => waiter.onTimeout(), this.#maxWaitMs),
176
201
  };
177
- this.#drainWaiter.timer.unref?.();
202
+ this.#drainWaiter = waiter;
203
+ waiter.timer.unref?.();
178
204
  });
179
205
  }
180
206
 
@@ -93,7 +93,6 @@ import {
93
93
  } from '../log-provenance';
94
94
  import {
95
95
  buildRunLedgerEventsIdempotencyKey,
96
- isRunLedgerProjectionChunk,
97
96
  RunLedgerProjectionLeaseLostError,
98
97
  type RunLedgerProjectionChunk,
99
98
  type RunLedgerProjectionLeaseLostReason,
@@ -101,8 +100,8 @@ import {
101
100
  buildRunLedgerStartIdempotencyKey,
102
101
  buildRunLedgerTerminalIdempotencyKey,
103
102
  } from '../run-ledger-projection-contract';
104
- import { runLedgerProjectionMismatch } from '../run-ledger-projection-diagnostics';
105
- import { selectRunEventsForAppRuntimeProjectionChunk } from '../run-ledger-event-transport';
103
+ import { runLedgerProjectionMismatchAcrossCandidates } from '../run-ledger-projection-diagnostics';
104
+ import { runEventsForAppRuntimeProjectionCandidates } from '../run-ledger-event-transport';
106
105
  import {
107
106
  assertTerminalRunResultWithinLimit,
108
107
  isLedgerTerminalResultRef,
@@ -16106,32 +16105,22 @@ export async function assertPostgresRunLedgerDelivery(
16106
16105
  }),
16107
16106
  );
16108
16107
  }
16109
- let expectedProjectionEvents:
16110
- | readonly (AcceptedPlayRunLedgerEvent | PlayRunLedgerIngressEvent)[]
16111
- | undefined;
16112
- if (input.projectionChunk) {
16113
- const chunk = input.projectionChunk;
16114
- // The sender partitions ingress events before the route sanitizes each chunk.
16115
- const expectedTransportChunk = isRunLedgerProjectionChunk(chunk)
16116
- ? selectRunEventsForAppRuntimeProjectionChunk(prefixEvents, chunk)
16117
- : undefined;
16118
- expectedProjectionEvents =
16119
- expectedTransportChunk === undefined
16120
- ? undefined
16108
+ const expectedProjectionCandidates =
16109
+ runEventsForAppRuntimeProjectionCandidates(
16110
+ prefixEvents,
16111
+ input.projectionChunk,
16112
+ ).map((candidate) =>
16113
+ candidate === null
16114
+ ? null
16121
16115
  : input.sanitizeExpectedProjectionEvents
16122
- ? input.sanitizeExpectedProjectionEvents(expectedTransportChunk)
16123
- : expectedTransportChunk;
16124
- } else {
16125
- expectedProjectionEvents = input.sanitizeExpectedProjectionEvents
16126
- ? input.sanitizeExpectedProjectionEvents(prefixEvents)
16127
- : prefixEvents;
16128
- }
16129
- const projectionMismatch: RunLedgerProjectionMismatchDiagnostic | null =
16130
- runLedgerProjectionMismatch({
16131
- projectedEvents: input.projectedEvents,
16132
- expectedEvents: expectedProjectionEvents ?? null,
16133
- ...(input.projectionChunk ? { chunk: input.projectionChunk } : {}),
16134
- });
16116
+ ? input.sanitizeExpectedProjectionEvents(candidate)
16117
+ : candidate,
16118
+ );
16119
+ const projectionMismatch = runLedgerProjectionMismatchAcrossCandidates({
16120
+ projectedEvents: input.projectedEvents,
16121
+ expectedEventCandidates: expectedProjectionCandidates,
16122
+ ...(input.projectionChunk ? { chunk: input.projectionChunk } : {}),
16123
+ });
16135
16124
  if (projectionMismatch === null) return;
16136
16125
  throw new RunLedgerProjectionLeaseLostError(
16137
16126
  'projected_events_mismatch',
package/dist/cli/index.js CHANGED
@@ -3051,7 +3051,7 @@ var SDK_RELEASE = {
3051
3051
  // getters keep their established compatibility behavior.
3052
3052
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
3053
3053
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
3054
- version: "0.3.226",
3054
+ version: "0.3.228",
3055
3055
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
3056
3056
  packageCapabilities: {
3057
3057
  updatePreferences: 1
@@ -3046,7 +3046,7 @@ var SDK_RELEASE = {
3046
3046
  // getters keep their established compatibility behavior.
3047
3047
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
3048
3048
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
3049
- version: "0.3.226",
3049
+ version: "0.3.228",
3050
3050
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
3051
3051
  packageCapabilities: {
3052
3052
  updatePreferences: 1
package/dist/index.js CHANGED
@@ -864,7 +864,7 @@ var SDK_RELEASE = {
864
864
  // getters keep their established compatibility behavior.
865
865
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
866
866
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
867
- version: "0.3.226",
867
+ version: "0.3.228",
868
868
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
869
869
  packageCapabilities: {
870
870
  updatePreferences: 1
package/dist/index.mjs CHANGED
@@ -768,7 +768,7 @@ var SDK_RELEASE = {
768
768
  // getters keep their established compatibility behavior.
769
769
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
770
770
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
771
- version: "0.3.226",
771
+ version: "0.3.228",
772
772
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
773
773
  packageCapabilities: {
774
774
  updatePreferences: 1
@@ -149,7 +149,7 @@ type SdkRelease = {
149
149
  supportPolicy: SdkSupportPolicy;
150
150
  };
151
151
  declare const SDK_RELEASE: {
152
- readonly version: "0.3.226";
152
+ readonly version: "0.3.228";
153
153
  readonly updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.";
154
154
  readonly packageCapabilities: {
155
155
  readonly updatePreferences: 1;
package/dist/release.d.ts CHANGED
@@ -149,7 +149,7 @@ type SdkRelease = {
149
149
  supportPolicy: SdkSupportPolicy;
150
150
  };
151
151
  declare const SDK_RELEASE: {
152
- readonly version: "0.3.226";
152
+ readonly version: "0.3.228";
153
153
  readonly updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.";
154
154
  readonly packageCapabilities: {
155
155
  readonly updatePreferences: 1;
package/dist/release.js CHANGED
@@ -74,7 +74,7 @@ var SDK_RELEASE = {
74
74
  // getters keep their established compatibility behavior.
75
75
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
76
76
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
77
- version: "0.3.226",
77
+ version: "0.3.228",
78
78
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
79
79
  packageCapabilities: {
80
80
  updatePreferences: 1
package/dist/release.mjs CHANGED
@@ -48,7 +48,7 @@ var SDK_RELEASE = {
48
48
  // getters keep their established compatibility behavior.
49
49
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
50
50
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
51
- version: "0.3.226",
51
+ version: "0.3.228",
52
52
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
53
53
  packageCapabilities: {
54
54
  updatePreferences: 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepline",
3
- "version": "0.3.226",
3
+ "version": "0.3.228",
4
4
  "description": "GTM data CLI and TypeScript SDK for coding agents",
5
5
  "license": "MIT",
6
6
  "homepage": "https://code.deepline.com",