deepline 0.3.252 → 0.3.254

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.252',
203
+ version: '0.3.254',
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: {
@@ -7,7 +7,19 @@
7
7
  */
8
8
  export const SCHEDULED_WORK_CONTROL_CONTRACT_VERSION = 1 as const;
9
9
 
10
- export type ScheduledWorkControlAction = 'run';
10
+ export const SCHEDULED_WORK_CONTROL_ACTIONS = [
11
+ 'run',
12
+ 'start',
13
+ 'pause',
14
+ 'resume',
15
+ 'retry',
16
+ 'verify',
17
+ 'activate',
18
+ 'rollback',
19
+ ] as const;
20
+
21
+ export type ScheduledWorkControlAction =
22
+ (typeof SCHEDULED_WORK_CONTROL_ACTIONS)[number];
11
23
 
12
24
  export type ScheduledWorkControlContext = {
13
25
  readonly jobId: string;
@@ -38,6 +50,10 @@ export type ScheduledWorkControlConnector = {
38
50
  run?: (
39
51
  context: ScheduledWorkControlContext,
40
52
  ) => Promise<ScheduledWorkRunResult>;
53
+ execute?: (
54
+ context: ScheduledWorkControlContext,
55
+ action: Exclude<ScheduledWorkControlAction, 'run'>,
56
+ ) => Promise<ScheduledWorkRunResult>;
41
57
  };
42
58
 
43
59
  export type ScheduledWorkControlRegisterOptions = {
@@ -88,6 +104,14 @@ export class ScheduledWorkControlRegistry {
88
104
  `Scheduled-work connector ${connector.id} declares run without an implementation.`,
89
105
  );
90
106
  }
107
+ if (
108
+ connector.actions.some((action) => action !== 'run') &&
109
+ typeof connector.execute !== 'function'
110
+ ) {
111
+ throw new Error(
112
+ `Scheduled-work connector ${connector.id} declares lifecycle controls without an implementation.`,
113
+ );
114
+ }
91
115
  if (
92
116
  connector.actions.length === 0 &&
93
117
  Object.keys(connector.unavailableActions ?? {}).length === 0
@@ -7037,7 +7037,7 @@ export async function resumePostgresSchedulerDetachedRunnerAttempt(
7037
7037
  SELECT 1 FROM ${tableName('control', options)} AS control
7038
7038
  WHERE control.key = 'runtime_cancel:' || $1
7039
7039
  )
7040
- FOR UPDATE
7040
+ FOR NO KEY UPDATE
7041
7041
  ), detached_attempt AS MATERIALIZED (
7042
7042
  SELECT attempt.run_id, attempt.attempt, attempt.status, attempt.lease_token
7043
7043
  FROM ${tableName('attempts', options)} AS attempt
@@ -7060,7 +7060,7 @@ export async function resumePostgresSchedulerDetachedRunnerAttempt(
7060
7060
  WHERE target.run_id = detached_attempt.run_id
7061
7061
  AND target.attempt = detached_attempt.attempt
7062
7062
  AND target.lease_token = detached_attempt.lease_token
7063
- AND target.status = 'running'
7063
+ AND detached_attempt.status = 'running'
7064
7064
  RETURNING target.run_id
7065
7065
  ), restored_run AS (
7066
7066
  UPDATE ${tableName('runs', options)} AS target
@@ -7073,8 +7073,12 @@ export async function resumePostgresSchedulerDetachedRunnerAttempt(
7073
7073
  (target.suspension_json ->> 'ceilingMs')::double precision) / 1000
7074
7074
  ) ELSE target.wait_deadline END,
7075
7075
  updated_at = now()
7076
- WHERE target.run_id IN (SELECT run_id FROM detached_attempt)
7077
- AND target.status = 'running'
7076
+ -- The locked CTE may have followed a concurrent resume's new version.
7077
+ -- Qualify by that version, not the UPDATE scan's earlier snapshot.
7078
+ FROM detached_run
7079
+ WHERE target.run_id = detached_run.run_id
7080
+ AND target.run_id IN (SELECT run_id FROM detached_attempt)
7081
+ AND detached_run.status = 'running'
7078
7082
  RETURNING target.run_id
7079
7083
  ), restored_outbox AS (
7080
7084
  INSERT INTO ${tableName('outbox', options)} (
@@ -7290,7 +7294,15 @@ export async function markPostgresSchedulerAttemptRunning(
7290
7294
  const outboxEventId = `run-resumed:${input.runId}:${randomUUID()}`;
7291
7295
  const running = await client.query<{ run_id: string; event_id: string }>(
7292
7296
  `
7293
- WITH running_attempt AS (
7297
+ WITH waiting_run AS MATERIALIZED (
7298
+ SELECT target.run_id, target.suspension_json
7299
+ FROM ${tableName('runs', options)} AS target
7300
+ WHERE target.run_id = $1 AND target.status = 'waiting'
7301
+ -- Match detached restore's Run -> attempt order. NO KEY UPDATE also
7302
+ -- allows the outbox reference while its trigger owns the log mutex.
7303
+ FOR NO KEY UPDATE
7304
+ ),
7305
+ running_attempt AS (
7294
7306
  UPDATE ${tableName('attempts', options)} AS target
7295
7307
  SET status = 'running',
7296
7308
  heartbeat_at = CASE WHEN $5::boolean THEN heartbeat_at ELSE now() END,
@@ -7299,6 +7311,7 @@ export async function markPostgresSchedulerAttemptRunning(
7299
7311
  AND target.attempt = $2
7300
7312
  AND target.status = 'waiting'
7301
7313
  AND target.lease_token = $3
7314
+ AND target.run_id IN (SELECT run_id FROM waiting_run)
7302
7315
  AND NOT EXISTS (
7303
7316
  SELECT 1
7304
7317
  FROM ${tableName('attempts', options)} AS newer
@@ -7308,13 +7321,6 @@ export async function markPostgresSchedulerAttemptRunning(
7308
7321
  )
7309
7322
  RETURNING run_id
7310
7323
  ),
7311
- waiting_run AS (
7312
- SELECT target.run_id, target.suspension_json
7313
- FROM ${tableName('runs', options)} AS target
7314
- WHERE target.run_id IN (SELECT run_id FROM running_attempt)
7315
- AND target.status = 'waiting'
7316
- FOR UPDATE
7317
- ),
7318
7324
  running_run AS (
7319
7325
  UPDATE ${tableName('runs', options)} AS target
7320
7326
  SET status = 'running',
@@ -7325,6 +7331,7 @@ export async function markPostgresSchedulerAttemptRunning(
7325
7331
  updated_at = now()
7326
7332
  FROM waiting_run
7327
7333
  WHERE target.run_id = waiting_run.run_id
7334
+ AND target.run_id IN (SELECT run_id FROM running_attempt)
7328
7335
  RETURNING target.run_id, waiting_run.suspension_json
7329
7336
  ),
7330
7337
  resumed_outbox AS (
@@ -7392,7 +7399,7 @@ export async function claimPostgresSchedulerCompletedDetachedRunnerTerminal(
7392
7399
  AND status = 'waiting'
7393
7400
  AND suspension_json ->> 'kind' = 'detached_runner'
7394
7401
  AND suspension_json -> 'runnerAttempt' = to_jsonb($2::integer)
7395
- FOR UPDATE
7402
+ FOR NO KEY UPDATE
7396
7403
  ),
7397
7404
  running_attempt AS (
7398
7405
  UPDATE ${tableName('attempts', options)} AS target
@@ -7540,7 +7547,8 @@ export async function claimPostgresSchedulerOverdueDetachedRunnerCeilings(
7540
7547
  END
7541
7548
  ) ASC, runs.run_id ASC
7542
7549
  LIMIT $2
7543
- FOR UPDATE OF runs, attempts SKIP LOCKED
7550
+ FOR NO KEY UPDATE OF runs SKIP LOCKED
7551
+ FOR UPDATE OF attempts SKIP LOCKED
7544
7552
  ),
7545
7553
  running_attempts AS (
7546
7554
  UPDATE ${tableName('attempts', options)} AS target
@@ -8277,7 +8285,13 @@ export async function handoffPostgresSchedulerAttemptContinuation(
8277
8285
  const outboxEventId = `run-resumed:${input.runId}:${randomUUID()}`;
8278
8286
  const handedOff = await client.query<{ run_id: string; event_id: string }>(
8279
8287
  `
8280
- WITH continuation_attempt AS (
8288
+ WITH waiting_run AS MATERIALIZED (
8289
+ SELECT target.run_id, target.suspension_json
8290
+ FROM ${tableName('runs', options)} AS target
8291
+ WHERE target.run_id = $1 AND target.status = 'waiting'
8292
+ FOR NO KEY UPDATE
8293
+ ),
8294
+ continuation_attempt AS (
8281
8295
  UPDATE ${tableName('attempts', options)}
8282
8296
  SET status = 'stale',
8283
8297
  lease_expires_at = NULL,
@@ -8287,15 +8301,9 @@ export async function handoffPostgresSchedulerAttemptContinuation(
8287
8301
  AND attempt = $2
8288
8302
  AND status = 'waiting'
8289
8303
  AND lease_token = $3
8304
+ AND run_id IN (SELECT run_id FROM waiting_run)
8290
8305
  RETURNING run_id
8291
8306
  ),
8292
- waiting_run AS (
8293
- SELECT target.run_id, target.suspension_json
8294
- FROM ${tableName('runs', options)} AS target
8295
- WHERE target.run_id IN (SELECT run_id FROM continuation_attempt)
8296
- AND target.status = 'waiting'
8297
- FOR UPDATE
8298
- ),
8299
8307
  continuation_run AS (
8300
8308
  UPDATE ${tableName('runs', options)} AS target
8301
8309
  SET status = 'queued',
@@ -8305,6 +8313,7 @@ export async function handoffPostgresSchedulerAttemptContinuation(
8305
8313
  updated_at = now()
8306
8314
  FROM waiting_run
8307
8315
  WHERE target.run_id = waiting_run.run_id
8316
+ AND target.run_id IN (SELECT run_id FROM continuation_attempt)
8308
8317
  RETURNING target.run_id, waiting_run.suspension_json
8309
8318
  ),
8310
8319
  resumed_outbox AS (
@@ -18091,6 +18100,9 @@ export async function listPostgresSchedulerOutboxMaterializationPlans(
18091
18100
  */
18092
18101
  export type RunLedgerOutboxTokenAuthority = 'local_mint' | 'gateway';
18093
18102
 
18103
+ /** Cross-run service policy; causal order within a run is always unchanged. */
18104
+ export type RunLedgerOutboxHeadPriority = 'admission_first' | 'oldest_ready';
18105
+
18094
18106
  const POSTGRES_SCHEDULER_CANCELLATION_OUTBOX_LEASE_SECONDS =
18095
18107
  // The direct projection can run for the full app-runtime request deadline.
18096
18108
  // Keep another 30 seconds for dispatch setup and acknowledgement so a
@@ -18132,6 +18144,8 @@ export type RunLedgerOutboxDispatchInput = {
18132
18144
  runId?: string | null;
18133
18145
  leaseOwner?: string | null;
18134
18146
  leaseSeconds?: number;
18147
+ /** Defaults to the compatible admission-first claim order. */
18148
+ headPriority?: RunLedgerOutboxHeadPriority;
18135
18149
  /**
18136
18150
  * Token authority for the outbox dispatch. Defaults to `local_mint` for the
18137
18151
  * app-side authoritative projector. The Fly worker MUST pass `gateway`.
@@ -18393,7 +18407,11 @@ export async function dispatchRunLedgerOutboxToLedgerBatchOnceWithClientScope(
18393
18407
  AND active.lease_owner IS NOT NULL
18394
18408
  AND active.lease_expires_at > now()
18395
18409
  )
18396
- ORDER BY CASE WHEN head.event_type = 'run.created' THEN 0 ELSE 1 END,
18410
+ ORDER BY ${
18411
+ input.headPriority === 'oldest_ready'
18412
+ ? ''
18413
+ : "CASE WHEN head.event_type = 'run.created' THEN 0 ELSE 1 END,"
18414
+ }
18397
18415
  head.created_at, runs.run_id
18398
18416
  FOR UPDATE OF runs SKIP LOCKED LIMIT 1
18399
18417
  `);
@@ -14,6 +14,7 @@ import {
14
14
  readPostgresSchedulerOutboxNextDueAt,
15
15
  type PostgresSchedulerOptions,
16
16
  type PostgresSchedulerOutboxProjectionResult,
17
+ type RunLedgerOutboxHeadPriority,
17
18
  } from './postgres';
18
19
  import {
19
20
  acquirePgNotifyHub,
@@ -59,6 +60,11 @@ export const RUN_LEDGER_OUTBOX_RECOVERY_MAX_IN_FLIGHT = 32;
59
60
  // The higher exported ceiling remains available to isolated recovery callers,
60
61
  // but it is not the steady-state production setting.
61
62
  const RUN_LEDGER_OUTBOX_RECOVERY_PRODUCTION_IN_FLIGHT = 8;
63
+ // Admissions retain three of four claim opportunities. The fourth selects
64
+ // the oldest eligible causal head across all runs, preventing terminal work
65
+ // from starving behind continuous new admissions. An empty class never costs
66
+ // another query: either order can select any eligible run.
67
+ const ADMISSION_TURNS_PER_OLDEST_READY_TURN = 3;
62
68
 
63
69
  type RecoveryTimer = ReturnType<typeof setTimeout>;
64
70
 
@@ -66,7 +72,9 @@ export type RunLedgerOutboxRecoveryLogger = Pick<Console, 'info' | 'warn'>;
66
72
 
67
73
  export type RunLedgerOutboxRecoveryDeps = {
68
74
  /** One bounded durable claim/delivery attempt. */
69
- dispatchOnce: () => Promise<PostgresSchedulerOutboxProjectionResult>;
75
+ dispatchOnce: (
76
+ headPriority: RunLedgerOutboxHeadPriority,
77
+ ) => Promise<PostgresSchedulerOutboxProjectionResult>;
70
78
  /** Earliest pending retry time or active lease expiry in the durable outbox. */
71
79
  readNextDueAt: () => Promise<Date | null>;
72
80
  /** A direct LISTEN connection. It is a hint only; a null lease is safe. */
@@ -131,6 +139,14 @@ export function startRunLedgerOutboxRecovery(
131
139
  let unsubscribeNotify: (() => void) | undefined;
132
140
  let unsubscribeState: (() => void) | undefined;
133
141
  let requestDrain: (reason: string) => void = () => undefined;
142
+ let admissionTurns = 0;
143
+
144
+ const dispatchOnce = () => {
145
+ const oldestReady =
146
+ admissionTurns === ADMISSION_TURNS_PER_OLDEST_READY_TURN;
147
+ admissionTurns = oldestReady ? 0 : admissionTurns + 1;
148
+ return deps.dispatchOnce(oldestReady ? 'oldest_ready' : 'admission_first');
149
+ };
134
150
 
135
151
  const clearWakeTimer = () => {
136
152
  if (!timer) return;
@@ -254,7 +270,9 @@ export function startRunLedgerOutboxRecovery(
254
270
  const drain = async (reason: string): Promise<void> => {
255
271
  type Delivery = {
256
272
  id: symbol;
257
- result: PromiseSettledResult<PostgresSchedulerOutboxProjectionResult> | { status: 'skipped' };
273
+ result:
274
+ | PromiseSettledResult<PostgresSchedulerOutboxProjectionResult>
275
+ | { status: 'skipped' };
258
276
  };
259
277
  const pending = new Set<symbol>();
260
278
  const deliveries: Delivery[] = [];
@@ -303,7 +321,7 @@ export function startRunLedgerOutboxRecovery(
303
321
  return;
304
322
  }
305
323
  try {
306
- settle({ status: 'fulfilled', value: await deps.dispatchOnce() });
324
+ settle({ status: 'fulfilled', value: await dispatchOnce() });
307
325
  } catch (reason) {
308
326
  settle({ status: 'rejected', reason });
309
327
  }
@@ -410,10 +428,10 @@ export function startRunLedgerOutboxRecoveryController(input: {
410
428
  schedulerOptions,
411
429
  }),
412
430
  ),
413
- dispatchOnce: () =>
431
+ dispatchOnce: (headPriority) =>
414
432
  dispatchRunLedgerOutboxToLedgerBatchOnceWithClientScope(
415
433
  (operation) => withRuntimeSchedulerClient(input.poolOptions, operation),
416
- { tokenAuthority: 'gateway', limit: 8 },
434
+ { tokenAuthority: 'gateway', limit: 8, headPriority },
417
435
  schedulerOptions,
418
436
  ),
419
437
  // `dispatchRunLedgerOutboxToLedgerBatchOnceWithClientScope` releases each
package/dist/cli/index.js CHANGED
@@ -3507,7 +3507,7 @@ var SDK_RELEASE = {
3507
3507
  // getters keep their established compatibility behavior.
3508
3508
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
3509
3509
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
3510
- version: "0.3.252",
3510
+ version: "0.3.254",
3511
3511
  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.",
3512
3512
  packageCapabilities: {
3513
3513
  updatePreferences: 1
@@ -3502,7 +3502,7 @@ var SDK_RELEASE = {
3502
3502
  // getters keep their established compatibility behavior.
3503
3503
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
3504
3504
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
3505
- version: "0.3.252",
3505
+ version: "0.3.254",
3506
3506
  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.",
3507
3507
  packageCapabilities: {
3508
3508
  updatePreferences: 1
package/dist/index.js CHANGED
@@ -1320,7 +1320,7 @@ var SDK_RELEASE = {
1320
1320
  // getters keep their established compatibility behavior.
1321
1321
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
1322
1322
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
1323
- version: "0.3.252",
1323
+ version: "0.3.254",
1324
1324
  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.",
1325
1325
  packageCapabilities: {
1326
1326
  updatePreferences: 1
package/dist/index.mjs CHANGED
@@ -1224,7 +1224,7 @@ var SDK_RELEASE = {
1224
1224
  // getters keep their established compatibility behavior.
1225
1225
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
1226
1226
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
1227
- version: "0.3.252",
1227
+ version: "0.3.254",
1228
1228
  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.",
1229
1229
  packageCapabilities: {
1230
1230
  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.252";
152
+ readonly version: "0.3.254";
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.252";
152
+ readonly version: "0.3.254";
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.252",
77
+ version: "0.3.254",
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.252",
51
+ version: "0.3.254",
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.252",
3
+ "version": "0.3.254",
4
4
  "description": "GTM data CLI and TypeScript SDK for coding agents",
5
5
  "license": "MIT",
6
6
  "homepage": "https://code.deepline.com",