deepline 0.3.247 → 0.3.249

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.
Files changed (67) hide show
  1. package/dist/bundling-sources/sdk/src/client.ts +177 -13
  2. package/dist/bundling-sources/sdk/src/index.ts +8 -0
  3. package/dist/bundling-sources/sdk/src/plays/input-example.ts +40 -0
  4. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  5. package/dist/bundling-sources/sdk/src/runs/overview.ts +457 -0
  6. package/dist/bundling-sources/sdk/src/runs/receipts.ts +23 -0
  7. package/dist/bundling-sources/sdk/src/tool-calls.ts +21 -1
  8. package/dist/bundling-sources/sdk/src/types.ts +16 -1
  9. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +19 -1
  10. package/dist/bundling-sources/shared_libs/play-data-plane/column-names.ts +17 -3
  11. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +40 -8
  12. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +26 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +144 -14
  14. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +2 -1
  15. package/dist/bundling-sources/shared_libs/play-runtime/daytona-runtime-config.ts +6 -3
  16. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +26 -21
  17. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-reaper.ts +23 -21
  18. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +17 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/log-context.ts +105 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +8 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/job.ts +1 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/ports.ts +1 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +9 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-event-transport.ts +40 -4
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +50 -5
  26. package/dist/bundling-sources/shared_libs/play-runtime/run-lifecycle-policy.ts +3 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/run-log-buffer.ts +28 -1
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +14 -1
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +56 -16
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +184 -0
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +327 -0
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +87 -30
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +24 -13
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-start-admission.ts +23 -6
  35. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +76 -33
  36. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +90 -35
  37. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +16 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +112 -50
  39. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +447 -77
  40. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +22 -4
  41. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +105 -121
  42. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +1648 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-queue-health.ts +16 -19
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-receipt-value-storage.ts +14 -6
  45. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +16 -0
  46. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +40 -0
  47. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +5 -2
  48. package/dist/bundling-sources/shared_libs/plays/dataset-summary.ts +11 -7
  49. package/dist/bundling-sources/shared_libs/plays/static-pipeline-storage-codec.ts +5 -2
  50. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +11 -2
  51. package/dist/cli/index.js +3504 -2368
  52. package/dist/cli/index.mjs +3188 -2052
  53. package/dist/{compiler-manifest-n8ZtPv2h.d.mts → compiler-manifest-DavmLa8y.d.mts} +1 -0
  54. package/dist/{compiler-manifest-n8ZtPv2h.d.ts → compiler-manifest-DavmLa8y.d.ts} +1 -0
  55. package/dist/index.d.mts +97 -5
  56. package/dist/index.d.ts +97 -5
  57. package/dist/index.js +135 -15
  58. package/dist/index.mjs +135 -15
  59. package/dist/install-integrity.json +9 -2
  60. package/dist/plays/bundle-play-file.d.mts +2 -2
  61. package/dist/plays/bundle-play-file.d.ts +2 -2
  62. package/dist/plays/bundle-play-file.mjs +1 -1
  63. package/dist/release.d.mts +1 -1
  64. package/dist/release.d.ts +1 -1
  65. package/dist/release.js +1 -1
  66. package/dist/release.mjs +1 -1
  67. package/package.json +1 -1
@@ -20,6 +20,10 @@ import {
20
20
  import type { PlayVisualNodeProgressMap } from '../worker-api-types';
21
21
  import type { PlayExecutionEvent } from '../ctx-types';
22
22
  import type { PlayActivityObservation } from '../activity-observation';
23
+ import {
24
+ normalizePlayLogContext,
25
+ type PlayLogContext,
26
+ } from '../log-context';
23
27
  import type {
24
28
  PlayRunnerLogEvent,
25
29
  PlayRunnerResult,
@@ -232,7 +236,8 @@ export type PostgresSchedulerProgressReporter = {
232
236
  };
233
237
 
234
238
  export type PostgresSchedulerDurableLogMode =
235
- 'progress_reporter' | 'direct_worker';
239
+ | 'progress_reporter'
240
+ | 'direct_worker';
236
241
 
237
242
  function shouldPublishDurableLogEvent(
238
243
  mode: PostgresSchedulerDurableLogMode,
@@ -274,33 +279,53 @@ type TerminalLogReplayPayload = NonNullable<
274
279
  RuntimeStatusUpdate['terminalLogReplay']
275
280
  >;
276
281
 
277
- function terminalReplayLinesForMode(input: {
282
+ function terminalReplayEntriesForMode(input: {
278
283
  resultLogs: readonly string[];
284
+ resultLogContexts?: readonly (PlayLogContext | null)[];
279
285
  durableLogMode: PostgresSchedulerDurableLogMode;
280
- }): string[] {
281
- return input.resultLogs
282
- .map((line) => line.trim())
283
- .filter(
284
- (line) =>
285
- line.length > 0 &&
286
- shouldPublishTerminalResultLog(input.durableLogMode, line),
287
- );
286
+ }): Array<{ line: string; context: PlayLogContext | null }> {
287
+ if (
288
+ input.resultLogContexts !== undefined &&
289
+ input.resultLogContexts.length !== input.resultLogs.length
290
+ ) {
291
+ throw new TypeError('Terminal log contexts must align with result logs.');
292
+ }
293
+ return input.resultLogs.flatMap((rawLine, index) => {
294
+ const line = rawLine.trim();
295
+ if (
296
+ line.length === 0 ||
297
+ !shouldPublishTerminalResultLog(input.durableLogMode, line)
298
+ ) {
299
+ return [];
300
+ }
301
+ return [
302
+ {
303
+ line,
304
+ context: normalizePlayLogContext(input.resultLogContexts?.[index]),
305
+ },
306
+ ];
307
+ });
288
308
  }
289
309
 
290
310
  function terminalReplayPayloadForMode(input: {
291
311
  resultLogs: readonly string[];
312
+ resultLogContexts?: readonly (PlayLogContext | null)[];
292
313
  durableLogMode: PostgresSchedulerDurableLogMode;
293
314
  liveLogs: readonly string[];
315
+ liveLogContexts: readonly (PlayLogContext | null)[];
294
316
  liveLogsTotalCount: number;
295
317
  replayAllTerminalLogs: boolean;
296
318
  producerAttempt?: number;
297
319
  }): TerminalLogReplayPayload | null {
298
- let lines = terminalReplayLinesForMode(input);
320
+ if (input.liveLogs.length !== input.liveLogContexts.length) {
321
+ throw new TypeError('Live log contexts must align with live log lines.');
322
+ }
323
+ let entries = terminalReplayEntriesForMode(input);
299
324
  // Detached recovery is a complete attempt-local buffer. Its total count
300
325
  // gives the replay an offset of zero on that attempt's positional channel;
301
326
  // producerAttempt fences stale deliveries while the ledger absorbs only an
302
327
  // exact retransmission from that same attempt.
303
- let totalCount = lines.length;
328
+ let totalCount = entries.length;
304
329
  if (
305
330
  input.durableLogMode === 'direct_worker' &&
306
331
  !input.replayAllTerminalLogs
@@ -311,24 +336,27 @@ function terminalReplayPayloadForMode(input: {
311
336
  if (!key) continue;
312
337
  observedCounts.set(key, (observedCounts.get(key) ?? 0) + 1);
313
338
  }
314
- const boundedLines: string[] = [];
315
- for (const line of lines) {
316
- const key = line.trim().replace(CTX_LOG_TIMESTAMP_PREFIX_RE, '');
339
+ const boundedEntries: typeof entries = [];
340
+ for (const entry of entries) {
341
+ const key = entry.line.trim().replace(CTX_LOG_TIMESTAMP_PREFIX_RE, '');
317
342
  const remaining = observedCounts.get(key) ?? 0;
318
343
  if (remaining > 0) {
319
344
  observedCounts.set(key, remaining - 1);
320
345
  continue;
321
346
  }
322
- boundedLines.push(line);
347
+ boundedEntries.push(entry);
323
348
  }
324
- lines = boundedLines;
325
- totalCount = input.liveLogsTotalCount + lines.length;
349
+ entries = boundedEntries;
350
+ totalCount = input.liveLogsTotalCount + entries.length;
326
351
  }
327
- if (lines.length === 0) {
352
+ if (entries.length === 0) {
328
353
  return null;
329
354
  }
355
+ const lines = entries.map((entry) => entry.line);
356
+ const lineContexts = entries.map((entry) => entry.context);
330
357
  return {
331
358
  lines,
359
+ ...(lineContexts.some(Boolean) ? { lineContexts } : {}),
332
360
  ...(input.replayAllTerminalLogs ? { dedupeMode: 'exact' as const } : {}),
333
361
  ...(typeof input.producerAttempt === 'number'
334
362
  ? { producerAttempt: input.producerAttempt }
@@ -385,12 +413,14 @@ export function createPostgresSchedulerProgressReporter(input: {
385
413
  let liveNodeProgress: PlayVisualNodeProgressMap = {};
386
414
  let liveNodeProgressDirty = false;
387
415
  let liveLogs: string[] = [];
416
+ let liveLogContexts: Array<PlayLogContext | null> = [];
388
417
  let liveLogsTotalCount = input.initialLiveLogTotalCount ?? 0;
389
418
  let liveLogsDirty = false;
390
419
  let workCounters: RuntimeStatusUpdate['workCounters'];
391
420
  let workCountersDirty = false;
392
421
  let lastFlushAt = 0;
393
- let delayedFlushTimer: ReturnType<typeof setTimeout> | null = null;
422
+ let lastProgressFlushAt = 0;
423
+ let deferredFlushTimer: ReturnType<typeof setTimeout> | null = null;
394
424
  let totalRows = 0;
395
425
  let activeMapNodeId: string | null = null;
396
426
  let pendingDatasetLifecycleEvents: Array<
@@ -403,6 +433,7 @@ export function createPostgresSchedulerProgressReporter(input: {
403
433
 
404
434
  type ProgressFlushRequest = {
405
435
  status: 'running' | 'completed' | 'failed';
436
+ force: boolean;
406
437
  required: boolean;
407
438
  terminalLogReplay: TerminalLogReplayPayload | null;
408
439
  waiters: Array<{
@@ -423,6 +454,7 @@ export function createPostgresSchedulerProgressReporter(input: {
423
454
  next.status !== 'running'
424
455
  ? next.status
425
456
  : (current?.status ?? next.status),
457
+ force: next.force || current?.force === true,
426
458
  required: next.required || current?.required === true,
427
459
  terminalLogReplay:
428
460
  next.terminalLogReplay ?? current?.terminalLogReplay ?? null,
@@ -459,17 +491,32 @@ export function createPostgresSchedulerProgressReporter(input: {
459
491
  const request = pendingProgressUpload;
460
492
  pendingProgressUpload = null;
461
493
 
462
- const nextProgress = { ...liveNodeProgress };
494
+ // Customer log latency is independent of row-count progress sampling.
495
+ const includeProgress =
496
+ request.force ||
497
+ request.required ||
498
+ request.status !== 'running' ||
499
+ Date.now() - lastProgressFlushAt >=
500
+ getAdaptiveRunEventIntervalMs(totalRows);
501
+ const nextProgress = includeProgress
502
+ ? { ...liveNodeProgress }
503
+ : undefined;
463
504
  const nextLogs = liveLogs.slice();
505
+ const nextLogContexts = liveLogContexts.slice();
464
506
  const nextLogTotalCount = liveLogsTotalCount;
465
- const nextDatasetLifecycleEvents = pendingDatasetLifecycleEvents;
466
- pendingDatasetLifecycleEvents = [];
467
- const nextActivityObservations = [
468
- ...pendingActivityObservations.values(),
469
- ];
507
+ const nextDatasetLifecycleEvents = includeProgress
508
+ ? pendingDatasetLifecycleEvents
509
+ : [];
510
+ const nextActivityObservations = includeProgress
511
+ ? [...pendingActivityObservations.values()]
512
+ : [];
470
513
  const nextWorkCounters = workCountersDirty ? workCounters : undefined;
471
- pendingActivityObservations.clear();
472
- liveNodeProgressDirty = false;
514
+ if (includeProgress) {
515
+ pendingDatasetLifecycleEvents = [];
516
+ pendingActivityObservations.clear();
517
+ liveNodeProgressDirty = false;
518
+ lastProgressFlushAt = Date.now();
519
+ }
473
520
  liveLogsDirty = false;
474
521
  workCountersDirty = false;
475
522
 
@@ -480,6 +527,7 @@ export function createPostgresSchedulerProgressReporter(input: {
480
527
  status: request.status,
481
528
  liveNodeProgress: nextProgress,
482
529
  liveLogs: nextLogs,
530
+ liveLogContexts: nextLogContexts,
483
531
  liveLogTotalCount: nextLogTotalCount,
484
532
  liveLogProducerAttempt: producerAttempt,
485
533
  datasetLifecycleEvents: nextDatasetLifecycleEvents,
@@ -531,30 +579,31 @@ export function createPostgresSchedulerProgressReporter(input: {
531
579
  pendingDatasetLifecycleEvents.length === 0 &&
532
580
  pendingActivityObservations.size === 0
533
581
  ) {
534
- if (delayedFlushTimer) {
535
- clearTimeout(delayedFlushTimer);
536
- delayedFlushTimer = null;
582
+ if (deferredFlushTimer) {
583
+ clearTimeout(deferredFlushTimer);
584
+ deferredFlushTimer = null;
537
585
  }
538
586
  return activeProgressUpload ?? Promise.resolve();
539
587
  }
540
588
  const now = Date.now();
541
- const intervalMs = getAdaptiveRunEventIntervalMs(totalRows);
542
- if (!force && now - lastFlushAt < intervalMs) {
543
- if (!delayedFlushTimer) {
544
- delayedFlushTimer = setTimeout(
545
- () => {
546
- delayedFlushTimer = null;
547
- void flush().catch(() => undefined);
548
- },
549
- Math.max(1, intervalMs - (now - lastFlushAt)),
550
- );
551
- delayedFlushTimer.unref?.();
552
- }
589
+ const interval = liveLogsDirty
590
+ ? 1_500
591
+ : getAdaptiveRunEventIntervalMs(totalRows);
592
+ const remaining = interval - (now - lastFlushAt);
593
+ if (!force && remaining > 0) {
594
+ // Quiet runs must flush too: waiting for another event can retain one
595
+ // customer log until a long-running operation finally completes.
596
+ if (deferredFlushTimer !== null) clearTimeout(deferredFlushTimer);
597
+ deferredFlushTimer = setTimeout(() => {
598
+ deferredFlushTimer = null;
599
+ void flush().catch(() => undefined);
600
+ }, remaining);
601
+ deferredFlushTimer.unref?.();
553
602
  return activeProgressUpload ?? Promise.resolve();
554
603
  }
555
- if (delayedFlushTimer) {
556
- clearTimeout(delayedFlushTimer);
557
- delayedFlushTimer = null;
604
+ if (deferredFlushTimer !== null) {
605
+ clearTimeout(deferredFlushTimer);
606
+ deferredFlushTimer = null;
558
607
  }
559
608
  lastFlushAt = now;
560
609
  const requested = new Promise<void>((resolve, reject) => {
@@ -562,6 +611,7 @@ export function createPostgresSchedulerProgressReporter(input: {
562
611
  pendingProgressUpload,
563
612
  {
564
613
  status,
614
+ force,
565
615
  required,
566
616
  terminalLogReplay: input?.terminalLogReplay ?? null,
567
617
  },
@@ -579,15 +629,19 @@ export function createPostgresSchedulerProgressReporter(input: {
579
629
  void flush({ force }).catch(() => undefined);
580
630
  };
581
631
 
582
- const appendLiveLog = (line: string) => {
632
+ const appendLiveLog = (line: string, context?: unknown) => {
583
633
  const trimmed = line.trim();
584
634
  if (!trimmed) {
585
635
  return;
586
636
  }
587
637
  liveLogsTotalCount += 1;
588
638
  liveLogs = [...liveLogs, trimmed];
639
+ liveLogContexts = [...liveLogContexts, normalizePlayLogContext(context)];
589
640
  if (liveLogs.length > LIVE_LOG_TAIL_LIMIT) {
590
641
  liveLogs = liveLogs.slice(liveLogs.length - LIVE_LOG_TAIL_LIMIT);
642
+ liveLogContexts = liveLogContexts.slice(
643
+ liveLogContexts.length - LIVE_LOG_TAIL_LIMIT,
644
+ );
591
645
  }
592
646
  liveLogsDirty = true;
593
647
  };
@@ -1138,13 +1192,17 @@ export function createPostgresSchedulerProgressReporter(input: {
1138
1192
  return;
1139
1193
  }
1140
1194
  if (type === 'log') {
1141
- const logEvent = event as { line?: unknown; source?: unknown };
1195
+ const logEvent = event as {
1196
+ line?: unknown;
1197
+ source?: unknown;
1198
+ context?: unknown;
1199
+ };
1142
1200
  const rawLine = logEvent.line;
1143
1201
  if (typeof rawLine !== 'string' || !rawLine) {
1144
1202
  return;
1145
1203
  }
1146
1204
  if (shouldPublishDurableLogEvent(durableLogMode, logEvent)) {
1147
- appendLiveLog(rawLine);
1205
+ appendLiveLog(rawLine, logEvent.context);
1148
1206
  }
1149
1207
  markMapStartedFromLog(rawLine);
1150
1208
  markMapStartedFromPerfLog(rawLine);
@@ -1373,7 +1431,8 @@ export function createPostgresSchedulerProgressReporter(input: {
1373
1431
  ): Promise<void> => {
1374
1432
  const terminalCounters = runtimeWorkCountersFromStats(result?.stats);
1375
1433
  const terminalSegment = result?.stats?.runtimeWorkCounterSegment as
1376
- { invocationSeq?: unknown; segmentId?: unknown } | undefined;
1434
+ | { invocationSeq?: unknown; segmentId?: unknown }
1435
+ | undefined;
1377
1436
  if (
1378
1437
  terminalCounters &&
1379
1438
  terminalCounters.provider429s !== undefined &&
@@ -1423,8 +1482,10 @@ export function createPostgresSchedulerProgressReporter(input: {
1423
1482
  ? null
1424
1483
  : terminalReplayPayloadForMode({
1425
1484
  resultLogs: result.logs,
1485
+ resultLogContexts: result.logContexts,
1426
1486
  durableLogMode,
1427
1487
  liveLogs,
1488
+ liveLogContexts,
1428
1489
  liveLogsTotalCount,
1429
1490
  replayAllTerminalLogs: options.replayAllTerminalLogs === true,
1430
1491
  producerAttempt:
@@ -1502,6 +1563,7 @@ export async function collectGatewayRunnerTerminalProgressLedgerEvents(input: {
1502
1563
  lastCheckpointAt: finalUpdate.lastCheckpointAt,
1503
1564
  liveNodeProgress: finalUpdate.liveNodeProgress,
1504
1565
  liveLogs,
1566
+ liveLogContexts: finalUpdate.liveLogContexts,
1505
1567
  liveLogsChannelOffset: Math.max(0, liveLogTotalCount - liveLogs.length),
1506
1568
  liveLogsProducerAttempt:
1507
1569
  finalUpdate.liveLogProducerAttempt ?? input.attempt,