deepline 0.1.158 → 0.1.159

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.
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  chooseMapChunkSize,
3
+ EXECUTION_PLAN_DEFAULTS,
3
4
  type ExecutionPlan,
4
5
  } from '../../../../shared_libs/play-runtime/execution-plan';
5
6
  import { TOOL_CALLING_MAP_CHUNK_SIZE } from '../../../../shared_libs/play-runtime/map-chunk-limits';
6
7
 
7
8
  export const CACHE_ENABLED_SIMPLE_MAP_CHUNK_SIZE = 10_000;
8
9
  export { TOOL_CALLING_MAP_CHUNK_SIZE };
10
+ export const WORKER_SUBREQUEST_SAFE_TOOL_CALLS_PER_CHUNK =
11
+ TOOL_CALLING_MAP_CHUNK_SIZE;
9
12
 
10
13
  export type WorkerMapChunkPlanInput = {
11
14
  mapName: string;
@@ -29,11 +32,52 @@ export function chooseWorkerMapRowsPerChunk(
29
32
  preferredChunkSize: planMap?.defaultChunkSize,
30
33
  softWorkflowStepBudget: plan?.chunkPlan.softWorkflowStepBudget,
31
34
  });
35
+ const estimatedSubrequestProducingSteps =
36
+ estimateSubrequestProducingStepsForMap(plan, planMap);
37
+ if (estimatedSubrequestProducingSteps > 0) {
38
+ const subrequestSafeRows = Math.max(
39
+ 1,
40
+ Math.floor(
41
+ WORKER_SUBREQUEST_SAFE_TOOL_CALLS_PER_CHUNK /
42
+ estimatedSubrequestProducingSteps,
43
+ ),
44
+ );
45
+ if (subrequestSafeRows < rowsPerChunk) {
46
+ if (input.rowCountHint === null || !Number.isFinite(input.rowCountHint)) {
47
+ return subrequestSafeRows;
48
+ }
49
+ const totalRows = Math.max(0, Math.floor(input.rowCountHint));
50
+ const mapCount = Math.max(1, plan?.maps.length ?? 1);
51
+ const softBudget =
52
+ plan?.chunkPlan.softWorkflowStepBudget ??
53
+ EXECUTION_PLAN_DEFAULTS.workflowSoftStepBudget;
54
+ const maxChunksPerMap = Math.max(
55
+ 1,
56
+ Math.floor(
57
+ Math.max(
58
+ mapCount,
59
+ Math.floor(
60
+ (softBudget -
61
+ EXECUTION_PLAN_DEFAULTS.ingestStepCount -
62
+ EXECUTION_PLAN_DEFAULTS.finalizationStepCount) /
63
+ estimatedSubrequestProducingSteps,
64
+ ),
65
+ ) / mapCount,
66
+ ),
67
+ );
68
+ const requiredChunks = Math.ceil(totalRows / subrequestSafeRows);
69
+ if (requiredChunks <= maxChunksPerMap) return subrequestSafeRows;
70
+ throw new Error(
71
+ `Worker budget exceeded for map "${input.mapName}": ${requiredChunks}/${maxChunksPerMap} chunks.`,
72
+ );
73
+ }
74
+ return rowsPerChunk;
75
+ }
32
76
 
33
77
  const toolFreeSimpleMap =
34
78
  !!planMap &&
35
79
  planMap.stepsPerChunk === 1 &&
36
- !mapDoesExternalWork(planMap, plan);
80
+ estimateSubrequestProducingStepsForMap(plan, planMap) === 0;
37
81
  if (
38
82
  toolFreeSimpleMap &&
39
83
  (input.rowCountHint === null ||
@@ -42,55 +86,75 @@ export function chooseWorkerMapRowsPerChunk(
42
86
  return Math.max(rowsPerChunk, CACHE_ENABLED_SIMPLE_MAP_CHUNK_SIZE);
43
87
  }
44
88
 
45
- if (
46
- mapDoesExternalWork(planMap, plan) &&
47
- input.rowCountHint !== null &&
48
- input.rowCountHint <= rowsPerChunk
49
- ) {
50
- return Math.min(rowsPerChunk, TOOL_CALLING_MAP_CHUNK_SIZE);
51
- }
52
-
53
89
  return rowsPerChunk;
54
90
  }
55
91
 
56
- function mapDoesExternalWork(
57
- planMap: ExecutionPlan['maps'][number] | undefined,
92
+ function estimateSubrequestProducingStepsForMap(
58
93
  plan: ExecutionPlan | null,
59
- ): boolean {
60
- if (Array.isArray(planMap?.externalStepFields)) {
61
- return planMap.externalStepFields.length > 0;
62
- }
63
- if (!plan?.toolDeclarations.length) {
64
- return false;
65
- }
94
+ planMap: ExecutionPlan['maps'][number] | undefined,
95
+ ): number {
96
+ const toolDeclarations = plan?.toolDeclarations ?? [];
66
97
  if (!planMap) {
67
- return true;
98
+ return toolDeclarations.length;
99
+ }
100
+ const explicitExternalSteps = Array.isArray(planMap.externalStepFields)
101
+ ? planMap.externalStepFields.length
102
+ : 0;
103
+ const mapStepsPerChunk =
104
+ explicitExternalSteps > 0
105
+ ? 0
106
+ : (planMap.stepsPerChunk ?? 1) > 1
107
+ ? (planMap.stepsPerChunk ?? 1)
108
+ : 0;
109
+ if (toolDeclarations.length === 0) {
110
+ return Math.max(mapStepsPerChunk, explicitExternalSteps);
68
111
  }
69
- const outputFields = new Set(planMap.outputFields);
112
+ const outputFields = new Set(
113
+ planMap.outputFields.map((field) => field.trim()).filter(Boolean),
114
+ );
115
+ const explicitExternalStepFields = new Set(
116
+ (planMap.externalStepFields ?? [])
117
+ .map((field) => field.trim())
118
+ .filter(Boolean),
119
+ );
120
+ const hasModernStepMetadata =
121
+ Array.isArray(planMap.stepFields) ||
122
+ Array.isArray(planMap.externalStepFields);
70
123
  const mapFields = new Set([
71
124
  planMap.mapName,
72
125
  planMap.tableNamespace,
73
126
  ...planMap.outputFields,
74
- ...(planMap.stepFields ?? []),
75
127
  ...(planMap.externalStepFields ?? []),
128
+ ...(hasModernStepMetadata ? [] : (planMap.stepFields ?? [])),
76
129
  ...planMap.waterfallStages.flatMap((stage) => [
77
130
  stage.waterfallId,
78
131
  ...stage.stageIds,
79
132
  ]),
80
133
  ]);
81
- return plan.toolDeclarations.some((tool) => {
82
- const field = tool.field?.trim();
83
- if (!field) {
84
- return false;
85
- }
134
+ let scopedToolDeclarations = 0;
135
+ for (const declaration of toolDeclarations) {
136
+ const field = declaration.field?.trim();
137
+ if (!field) continue;
86
138
  if (mapFields.has(field)) {
87
- return true;
139
+ scopedToolDeclarations += 1;
140
+ continue;
88
141
  }
89
142
  if (!field.includes('.')) {
90
- return false;
143
+ continue;
91
144
  }
92
145
  const firstSegment = field.slice(0, field.indexOf('.'));
93
146
  const lastSegment = field.slice(field.lastIndexOf('.') + 1);
94
- return outputFields.has(firstSegment) || outputFields.has(lastSegment);
95
- });
147
+ if (
148
+ outputFields.has(firstSegment) ||
149
+ explicitExternalStepFields.has(lastSegment) ||
150
+ (!hasModernStepMetadata && outputFields.has(lastSegment))
151
+ ) {
152
+ scopedToolDeclarations += 1;
153
+ }
154
+ }
155
+ return Math.max(
156
+ mapStepsPerChunk,
157
+ explicitExternalSteps,
158
+ scopedToolDeclarations,
159
+ );
96
160
  }
@@ -104,10 +104,10 @@ export const SDK_RELEASE = {
104
104
  // 0.1.111 ships dataset-native tool list getters and result row datasets.
105
105
  // 0.1.154 removes the short-lived generated enrich StepOptions recompute
106
106
  // fields shipped in 0.1.153.
107
- version: '0.1.158',
107
+ version: '0.1.159',
108
108
  apiContract: '2026-06-dataset-handle-results-hard-cutover',
109
109
  supportPolicy: {
110
- latest: '0.1.158',
110
+ latest: '0.1.159',
111
111
  minimumSupported: '0.1.53',
112
112
  deprecatedBelow: '0.1.53',
113
113
  commandMinimumSupported: [
@@ -1 +1 @@
1
- export const TOOL_CALLING_MAP_CHUNK_SIZE = 25;
1
+ export const TOOL_CALLING_MAP_CHUNK_SIZE = 20;
@@ -612,6 +612,24 @@ function conflictingTerminalSnapshot(
612
612
  );
613
613
  }
614
614
 
615
+ function retryablePlatformDeployFailureSnapshot(
616
+ base: PlayRunLedgerSnapshot,
617
+ eventError?: string | null,
618
+ ): PlayRunLedgerSnapshot | null {
619
+ if (
620
+ isTerminalPlayRunLedgerStatus(base.status) ||
621
+ !eventError ||
622
+ normalizePlayRunFailure(eventError).code !== 'PLATFORM_DEPLOY_INTERRUPTED'
623
+ ) {
624
+ return null;
625
+ }
626
+ return withTiming(
627
+ appendLogLines(base, [
628
+ `[ledger] retryable platform deploy run.failed ignored; status remains ${base.status}`,
629
+ ]),
630
+ );
631
+ }
632
+
615
633
  function settleRunningStepsOnTerminal(
616
634
  snapshot: PlayRunLedgerSnapshot,
617
635
  status: Extract<PlayRunLedgerStepStatus, 'completed' | 'failed'>,
@@ -714,6 +732,7 @@ export function reducePlayRunLedgerEvent(
714
732
  );
715
733
  case 'run.failed':
716
734
  return (
735
+ retryablePlatformDeployFailureSnapshot(base, event.error) ??
717
736
  conflictingTerminalSnapshot(
718
737
  base,
719
738
  event.type,
@@ -610,6 +610,23 @@ async function ensureRuntimeSheetForPreloadedSession(
610
610
  phase: 'ensure_sheet_for_preloaded_session',
611
611
  ms: Date.now() - ensureStartedAt,
612
612
  });
613
+ const recheckStartedAt = Date.now();
614
+ const readyAfterEnsure = await isRuntimeSheetSchemaReady(input.session, {
615
+ sheetContract: input.sheetContract,
616
+ });
617
+ input.timings?.push({
618
+ phase: 'schema_check_after_preloaded_session_ensure',
619
+ ms: Date.now() - recheckStartedAt,
620
+ ready: readyAfterEnsure,
621
+ });
622
+ if (!readyAfterEnsure) {
623
+ if (runtimeSheetEnsureCache.get(cacheKey)?.promise === promise) {
624
+ runtimeSheetEnsureCache.delete(cacheKey);
625
+ }
626
+ throw new Error(
627
+ `Runtime sheet schema for ctx.dataset("${input.tableNamespace}") is still not ready after ensure_sheet.`,
628
+ );
629
+ }
613
630
  } catch (error) {
614
631
  if (runtimeSheetEnsureCache.get(cacheKey)?.promise === promise) {
615
632
  runtimeSheetEnsureCache.delete(cacheKey);
package/dist/cli/index.js CHANGED
@@ -657,10 +657,10 @@ var SDK_RELEASE = {
657
657
  // 0.1.111 ships dataset-native tool list getters and result row datasets.
658
658
  // 0.1.154 removes the short-lived generated enrich StepOptions recompute
659
659
  // fields shipped in 0.1.153.
660
- version: "0.1.158",
660
+ version: "0.1.159",
661
661
  apiContract: "2026-06-dataset-handle-results-hard-cutover",
662
662
  supportPolicy: {
663
- latest: "0.1.158",
663
+ latest: "0.1.159",
664
664
  minimumSupported: "0.1.53",
665
665
  deprecatedBelow: "0.1.53",
666
666
  commandMinimumSupported: [
@@ -642,10 +642,10 @@ var SDK_RELEASE = {
642
642
  // 0.1.111 ships dataset-native tool list getters and result row datasets.
643
643
  // 0.1.154 removes the short-lived generated enrich StepOptions recompute
644
644
  // fields shipped in 0.1.153.
645
- version: "0.1.158",
645
+ version: "0.1.159",
646
646
  apiContract: "2026-06-dataset-handle-results-hard-cutover",
647
647
  supportPolicy: {
648
- latest: "0.1.158",
648
+ latest: "0.1.159",
649
649
  minimumSupported: "0.1.53",
650
650
  deprecatedBelow: "0.1.53",
651
651
  commandMinimumSupported: [
package/dist/index.js CHANGED
@@ -421,10 +421,10 @@ var SDK_RELEASE = {
421
421
  // 0.1.111 ships dataset-native tool list getters and result row datasets.
422
422
  // 0.1.154 removes the short-lived generated enrich StepOptions recompute
423
423
  // fields shipped in 0.1.153.
424
- version: "0.1.158",
424
+ version: "0.1.159",
425
425
  apiContract: "2026-06-dataset-handle-results-hard-cutover",
426
426
  supportPolicy: {
427
- latest: "0.1.158",
427
+ latest: "0.1.159",
428
428
  minimumSupported: "0.1.53",
429
429
  deprecatedBelow: "0.1.53",
430
430
  commandMinimumSupported: [
package/dist/index.mjs CHANGED
@@ -351,10 +351,10 @@ var SDK_RELEASE = {
351
351
  // 0.1.111 ships dataset-native tool list getters and result row datasets.
352
352
  // 0.1.154 removes the short-lived generated enrich StepOptions recompute
353
353
  // fields shipped in 0.1.153.
354
- version: "0.1.158",
354
+ version: "0.1.159",
355
355
  apiContract: "2026-06-dataset-handle-results-hard-cutover",
356
356
  supportPolicy: {
357
- latest: "0.1.158",
357
+ latest: "0.1.159",
358
358
  minimumSupported: "0.1.53",
359
359
  deprecatedBelow: "0.1.53",
360
360
  commandMinimumSupported: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepline",
3
- "version": "0.1.158",
3
+ "version": "0.1.159",
4
4
  "description": "Deepline SDK + CLI — B2B data enrichment powered by durable cloud execution",
5
5
  "license": "MIT",
6
6
  "repository": {