@deepseek-ai/dsh-jobs-local 0.2.1-alpha.2 → 0.2.1-alpha.4

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/README.i18n.yaml CHANGED
@@ -29,9 +29,12 @@
29
29
  /deepseek-ai-dsh-jobs-local/use-this-package/lifecycle:
30
30
  en: 91dd372f742dcdb8
31
31
  zh: 58eeee0254d33cd1
32
+ /deepseek-ai-dsh-jobs-local/use-this-package/session-timing-records:
33
+ en: ae926795d8aaa88f
34
+ zh: 0e6ec0265eefccf7
32
35
  /deepseek-ai-dsh-jobs-local/use-this-package/what-can-go-wrong:
33
- en: dcf5bc26dbc018e5
34
- zh: 3dbe65c2df463ec0
36
+ en: e1f4511c458dff3b
37
+ zh: bea247c2a365a646
35
38
  /deepseek-ai-dsh-jobs-local/understand-the-implementation:
36
39
  en: f782557ca8da3138
37
40
  zh: e8f0082b9692cacc
@@ -51,8 +54,8 @@
51
54
  en: 49e8bd5e2c1f6ffd
52
55
  zh: ad3e1aa712fd59b3
53
56
  /deepseek-ai-dsh-jobs-local/further-exploration:
54
- en: 987d5d15aae77dda
55
- zh: 5b0fa8cfc71a44ad
57
+ en: bb0334d20bfb0b5f
58
+ zh: 1b02ec08f9618bef
56
59
  /deepseek-ai-dsh-jobs-local/model-experience:
57
60
  en: 873ef364fc8d6f2f
58
61
  zh: 4d0bb38a9c9639c0
@@ -60,8 +63,8 @@
60
63
  en: e290ccc9b3c92c08
61
64
  zh: d75d48f485447a74
62
65
  /deepseek-ai-dsh-jobs-local/known-limitations-and-deferred-work:
63
- en: 5284107cbd22e3dd
64
- zh: 9aa0048908c94e25
66
+ en: 8b3e2d5505caf2cd
67
+ zh: 46435d6a6b3c9aff
65
68
  /deepseek-ai-dsh-jobs-local/known-limitations-and-deferred-work/dev-note:
66
69
  en: e67f633dc6fe7773
67
70
  zh: 3bb0c20c93f16f98
package/README.md CHANGED
@@ -56,9 +56,15 @@ The limit counts the exact owner's `running` and `stopping` records; all unowned
56
56
 
57
57
  Jobs belong to their owner and backend, not to the producer tool, so producer or controller reloads do not stop them. When an agent that owns jobs is disposed, its jobs are cancelled, their producers awaited, and their snapshots removed; service disposal does the same for every remaining job. A cancellation that throws during teardown force-fails the record and warns that the work may be orphaned, so teardown never deadlocks.
58
58
 
59
+ ### Session timing records
60
+
61
+ Owned jobs record registration and settlement in their original Session, independently of model output collection. SDK consumers receive the same events through `session.event`; the [jobs reference](../../../docs/subsystems/jobs.md#session-lifecycle-records) defines identities, timestamps, and producer settlement reports. Events already persisted remain available after process exit; live jobs and output rings are not resumed.
62
+
63
+ Lifecycle facts are appended synchronously at the registration or settlement commit, before live hub subscribers and completion waiters react. Append failures warn without abandoning execution or blocking cleanup; consumers must retain incomplete histories as incomplete.
64
+
59
65
  ### What can go wrong
60
66
 
61
- Starting work fails without a controller that serves the owner — loading `dsh-tool-jobs` attaches one, and `start()` otherwise refuses with a message naming it. A producer cancel that returns without settling `done` stays indistinguishable from a slow stop and can stall teardown while holding one capacity slot. Every record disappears when the harness process exits.
67
+ Starting work fails without a controller that serves the owner — loading `dsh-tool-jobs` attaches one, and `start()` otherwise refuses with a message naming it. A producer cancel that returns without settling `done` stays indistinguishable from a slow stop and can stall teardown while holding one capacity slot. Live registry records disappear when the harness process exits; persisted lifecycle events remain.
62
68
 
63
69
  -----
64
70
 
@@ -114,6 +120,7 @@ Read these pages when the package-level contract is not enough. They move from t
114
120
  - [Registry contract](../jobs/README.md) — the abstract `ctx.jobs` service this package implements.
115
121
  - [Model-facing job controls](../tool-jobs/README.md) — the `job_output`, `job_list`, and `job_kill` tools and completion notices.
116
122
  - [Generic long-running tool runtime reference](../jobs/README.md) — the design behind the background-job runtime.
123
+ - [Job lifecycle recording decision](../../../.agents/notes/implemented/bug-fix/2026-09-30-job-session-lifecycle.md) — durable timing, execution identity, and recording-failure behavior.
117
124
  - [job-registry seam Agent Note](../../../.agents/notes/archived/architecture/2026-07-26-job-registry-seam.md) — the owner-fenced registry contract and its rationale.
118
125
 
119
126
  -----
@@ -134,7 +141,8 @@ No direct invalidation; the named consumers own any request-prefix changes.
134
141
 
135
142
  These limits define when the registry is a poor fit. They are current package constraints, not a task backlog.
136
143
 
137
- - **Jobs are process-local** — records die with the harness process; durable or cross-restart execution needs a separate backend implementing the seam.
144
+ - **Jobs are process-local** — live execution and output rings die with the harness process; durable or cross-restart execution needs a separate backend implementing the seam.
145
+ - **Final settlement persistence is not guaranteed during teardown** — normal one-shot completion, signal shutdown, or hard exit can stop Session routing or close its writer before the final `job/settled` reaches storage. Consumers must retain the interval as incomplete when settlement is absent; cross-fiber shutdown ordering is outside this journal's contract.
138
146
  - **A silently ineffective cancel can stall teardown and hold capacity** — if `cancel` returns without settling `done`, the registry cannot distinguish it from a slow stop; the job keeps one bucket slot for the rest of the service lifetime, and only an explicit throw can be force-failed safely.
139
147
 
140
148
  <a id="dev-note"></a>
package/README.zh.md CHANGED
@@ -56,9 +56,15 @@ kind: "package-reference"
56
56
 
57
57
  任务属于其所有者和后端,而非生产方工具,因此重载生产方或控制器不会停止任务。拥有任务的 agent 被释放时,其任务会被取消、生产方会被等待、快照会被移除;服务释放对每个剩余任务执行同样的操作。销毁期间抛出的取消会强制失败记录并警告工作可能成为孤立工作,因此销毁永远不会死锁。
58
58
 
59
+ ### Session 时间记录
60
+
61
+ 有所有者的 job 在原始 Session 中记录注册与结算,不依赖模型收集输出。SDK 消费方通过 `session.event` 收到同样的事件;[jobs 参考](../../../docs/subsystems/jobs.zh.md#session-lifecycle-records)定义标识、时间戳和生产方结算报告。已持久化的事件在进程退出后仍可读取;运行中的 job 和输出环不会被恢复。
62
+
63
+ 生命周期事实在注册或结算提交时同步追加,先于运行期 hub 订阅者和完成等待方的反应。追加失败会记录警告,不放弃执行或阻塞清理;消费方必须将不完整历史保留为不完整。
64
+
59
65
  ### 可能出什么问题
60
66
 
61
- 没有服务于所有者的控制器时无法启动工作——加载 `dsh-tool-jobs` 即附加一个,否则 `start()` 会以指出它的消息拒绝。返回但始终未结算 `done` 的生产方取消与缓慢停止无法区分,可能使销毁停滞并持续占用一个容量名额。每条记录都会在 harness 进程退出时消失。
67
+ 没有服务于所有者的控制器时无法启动工作——加载 `dsh-tool-jobs` 即附加一个,否则 `start()` 会以指出它的消息拒绝。返回但始终未结算 `done` 的生产方取消与缓慢停止无法区分,可能使销毁停滞并持续占用一个容量名额。运行期注册表记录会在 harness 进程退出时消失;已持久化的生命周期事件会保留。
62
68
 
63
69
  -----
64
70
 
@@ -114,6 +120,7 @@ kind: "package-reference"
114
120
  - [注册表约定](../jobs/README.zh.md)——本包实现的抽象 `ctx.jobs` 服务。
115
121
  - [模型侧任务控制](../tool-jobs/README.zh.md)——`job_output`、`job_list` 与 `job_kill` 工具及完成通知。
116
122
  - [通用长时间运行工具运行时 reference](../jobs/README.zh.md)——后台任务运行时背后的设计。
123
+ - [job 生命周期记录决策](../../../.agents/notes/implemented/bug-fix/2026-09-30-job-session-lifecycle.zh.md)——持久化时间、执行标识及记录失败行为。
117
124
  - [任务注册表 seam Agent Note](../../../.agents/notes/archived/architecture/2026-07-26-job-registry-seam.md)——按所有者隔离的注册表约定及其理由。
118
125
 
119
126
  -----
@@ -134,7 +141,8 @@ kind: "package-reference"
134
141
 
135
142
  这些限制说明注册表何时不合适。它们是当前包约束,不是任务积压。
136
143
 
137
- - **任务只存在于进程本地**——记录会随 harness 进程终止而消失;持久或跨重启执行需要一个单独实现该 seam 的后端。
144
+ - **任务只存在于进程本地**——运行期执行与输出环会随 harness 进程终止而消失;持久或跨重启执行需要一个单独实现该 seam 的后端。
145
+ - **销毁期间不保证最后一条结算持久化**——正常的一次性运行结束、信号关停或硬退出,都可能在最后一条 `job/settled` 写入存储前停止 Session 路由或关闭写句柄。缺少结算时,消费方必须将区间保留为不完整;跨 fiber 的关停顺序不属于本日志的约定。
138
146
  - **静默无效的取消可能使销毁停滞并持续占用容量**——如果 `cancel` 返回后始终未结算 `done`,注册表就无法将其与缓慢停止区分开;该任务会在服务剩余生命周期内持续占用一个桶名额,只有显式抛出异常才能安全地强制标为失败。
139
147
 
140
148
  <a id="dev-note"></a>
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import z from "@deepseek-ai/schemastery";
2
3
  import { AnonymousEntries, ScopedLayers, scopeOf } from "@deepseek-ai/dsh-scope";
3
4
  import { deadline, timeoutOf } from "@deepseek-ai/dsh-timeout";
@@ -368,7 +369,6 @@ var LocalJobRegistry = class extends JobRegistry {
368
369
  /** Schemastery-defaulted pull-source poll interval. */
369
370
  pumpPollMs;
370
371
  store = /* @__PURE__ */ new Map();
371
- counters = /* @__PURE__ */ new Map();
372
372
  /**
373
373
  * Controllers and scoped subscriptions layered by the scope that registered
374
374
  * them, in the tools-registry shape: a contribution files into its
@@ -417,9 +417,11 @@ var LocalJobRegistry = class extends JobRegistry {
417
417
  if (spec.outputLimitBytes !== void 0 && (!Number.isSafeInteger(spec.outputLimitBytes) || spec.outputLimitBytes <= 0)) throw new Error(`invalid outputLimitBytes: expected a positive safe integer, got ${JSON.stringify(spec.outputLimitBytes)}`);
418
418
  if (owner !== void 0) this.ensureOwnerCleanup(owner);
419
419
  if (this.activeJobCount(owner) >= this.maxConcurrentJobsPerOwner) throw new Error(`background job limit reached for this owner (limit: ${this.maxConcurrentJobsPerOwner}); use job_kill to stop an unneeded job, wait for it to finish, then retry`);
420
- const count = (this.counters.get(spec.kind) ?? 0) + 1;
421
- this.counters.set(spec.kind, count);
422
- const id = JobId(`${spec.kind}-${count}`);
420
+ let id;
421
+ do
422
+ id = JobId(`${spec.kind}-${randomUUID().replaceAll("-", "").slice(0, 16)}`);
423
+ while (this.store.has(id));
424
+ const toolCall = spec.toolCall === void 0 ? void 0 : { ...spec.toolCall };
423
425
  const ring = new OutputRing();
424
426
  const state = {
425
427
  progress: void 0,
@@ -441,6 +443,7 @@ var LocalJobRegistry = class extends JobRegistry {
441
443
  });
442
444
  const job = {
443
445
  id,
446
+ toolCall,
444
447
  kind: spec.kind,
445
448
  label: spec.label,
446
449
  outputLimitBytes: spec.outputLimitBytes,
@@ -465,15 +468,22 @@ var LocalJobRegistry = class extends JobRegistry {
465
468
  };
466
469
  state.job = job;
467
470
  this.store.set(id, job);
471
+ this.recordSessionEvent(job);
468
472
  this.emit({
469
473
  type: "registered",
470
474
  job: this.view(job)
471
475
  }, owner);
472
- const producerDone = hooks.done.then((outcome) => outcome, (error) => {
476
+ const producerDone = hooks.done.then((outcome) => ({
477
+ outcome,
478
+ producerReported: true
479
+ }), (error) => {
473
480
  this.selfCtx.logger.warn(`jobs: job ${job.id} producer done promise rejected (producer contract violation): ${String(error)}`);
474
481
  return {
475
- status: "failed",
476
- detail: String(error)
482
+ outcome: {
483
+ status: "failed",
484
+ detail: String(error)
485
+ },
486
+ producerReported: false
477
487
  };
478
488
  });
479
489
  if (spec.output !== void 0 && spec.output.length > 0) job.pump = startPump(spec.output.map((source) => this.guardSource(job, source)), {
@@ -484,9 +494,9 @@ var LocalJobRegistry = class extends JobRegistry {
484
494
  job.spillPaths[index] = path;
485
495
  }
486
496
  }, this.pumpPollMs, Promise.race([producerDone, settled]));
487
- producerDone.then(async (outcome) => {
497
+ producerDone.then(async ({ outcome, producerReported }) => {
488
498
  if (job.pump !== void 0) await job.pump.done;
489
- this.settle(job, outcome, job.settleCause ?? "producer");
499
+ this.settle(job, outcome, job.settleCause ?? "producer", producerReported);
490
500
  });
491
501
  return id;
492
502
  }
@@ -590,6 +600,29 @@ var LocalJobRegistry = class extends JobRegistry {
590
600
  emit(event, owner) {
591
601
  this.hub.emit(event, owner);
592
602
  }
603
+ /** Publish committed facts before live subscribers or completion waiters react. */
604
+ recordSessionEvent(job, settlement) {
605
+ const owner = job.owner;
606
+ if (owner === void 0) return;
607
+ const session = owner.session;
608
+ const data = {
609
+ jobId: job.id,
610
+ owner: owner.id,
611
+ kind: job.kind,
612
+ label: job.label,
613
+ startedAt: job.startedAt,
614
+ ...job.toolCall !== void 0 ? { toolCall: job.toolCall } : {}
615
+ };
616
+ try {
617
+ if (settlement === void 0) session.append("job/registered", data);
618
+ else session.append("job/settled", {
619
+ ...data,
620
+ ...settlement
621
+ });
622
+ } catch (error) {
623
+ this.selfCtx.logger.warn(`jobs: failed to record lifecycle for ${job.id}: ${String(error)}`);
624
+ }
625
+ }
593
626
  /**
594
627
  * Consume the ring from the model cursor; the result rides the first read
595
628
  * after settlement. A terminal read is the point the settled stream drops
@@ -733,7 +766,7 @@ var LocalJobRegistry = class extends JobRegistry {
733
766
  * reports whether it released one: a timed-out or aborted wait has already
734
767
  * left the set, so only a wait still owed the projection counts.
735
768
  */
736
- settle(job, outcome, cause) {
769
+ settle(job, outcome, cause, producerReported) {
737
770
  if (isTerminal(job.status)) return;
738
771
  job.status = outcome.status;
739
772
  if (outcome.status === "killed" && job.killReason !== void 0) job.detail = outcome.detail !== void 0 ? `${outcome.detail}; ${job.killReason}` : job.killReason;
@@ -741,6 +774,13 @@ var LocalJobRegistry = class extends JobRegistry {
741
774
  job.state.progress = void 0;
742
775
  job.result = outcome.result;
743
776
  job.finishedAt = Date.now();
777
+ this.recordSessionEvent(job, {
778
+ finishedAt: job.finishedAt,
779
+ status: outcome.status,
780
+ cause,
781
+ producerReported,
782
+ ...job.detail !== void 0 ? { detail: job.detail } : {}
783
+ });
744
784
  job.ring.trim(Math.max(this.settledRetainBytes, job.ring.total - job.modelCursor));
745
785
  const waitResolvers = [...job.waitResolvers];
746
786
  job.waitResolvers.clear();
@@ -819,7 +859,7 @@ var LocalJobRegistry = class extends JobRegistry {
819
859
  this.settle(job, {
820
860
  status: "failed",
821
861
  detail
822
- }, "teardown");
862
+ }, "teardown", false);
823
863
  }
824
864
  }
825
865
  }
@@ -50,7 +50,6 @@ export declare class LocalJobRegistry extends JobRegistry {
50
50
  /** Schemastery-defaulted pull-source poll interval. */
51
51
  private readonly pumpPollMs;
52
52
  private store;
53
- private counters;
54
53
  /**
55
54
  * Controllers and scoped subscriptions layered by the scope that registered
56
55
  * them, in the tools-registry shape: a contribution files into its
@@ -113,6 +112,8 @@ export declare class LocalJobRegistry extends JobRegistry {
113
112
  /** Project a fresh read-only view from the mutable record. */
114
113
  private view;
115
114
  private emit;
115
+ /** Publish committed facts before live subscribers or completion waiters react. */
116
+ private recordSessionEvent;
116
117
  /**
117
118
  * Consume the ring from the model cursor; the result rides the first read
118
119
  * after settlement. A terminal read is the point the settled stream drops
package/locale/en.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "meta": {
3
+ "title": "jobs-local"
4
+ }
5
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "本地后台任务",
4
+ "description": "管理当前进程中的后台任务及其运行状态。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-jobs-local",
3
3
  "description": "Process-local implementation of the DeepSeek Harness background job registry seam",
4
- "version": "0.2.1-alpha.2",
4
+ "version": "0.2.1-alpha.4",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -19,33 +19,35 @@
19
19
  "default": "./lib/index.js"
20
20
  },
21
21
  "./src/*": "./src/*",
22
- "./package.json": "./package.json"
22
+ "./package.json": "./package.json",
23
+ "./locale/*.json": "./locale/*.json"
23
24
  },
24
25
  "files": [
26
+ "locale/*.json",
25
27
  "lib/index.js",
26
28
  "lib/types/**/*.d.ts"
27
29
  ],
28
30
  "license": "MIT",
29
31
  "peerDependencies": {
30
- "@deepseek-ai/dsh-agent": "0.2.1-alpha.2",
31
- "@deepseek-ai/dsh-scope": "0.2.1-alpha.2",
32
- "@deepseek-ai/dsh-jobs": "0.2.1-alpha.2",
33
- "@deepseek-ai/dsh-timeout": "0.2.1-alpha.2",
34
- "@deepseek-ai/cordis": "~4.0.5-alpha.1"
32
+ "@deepseek-ai/dsh-agent": "0.2.1-alpha.4",
33
+ "@deepseek-ai/dsh-scope": "0.2.1-alpha.4",
34
+ "@deepseek-ai/dsh-jobs": "0.2.1-alpha.4",
35
+ "@deepseek-ai/dsh-timeout": "0.2.1-alpha.4",
36
+ "@deepseek-ai/cordis": "~4.0.5-alpha.2"
35
37
  },
36
38
  "dependencies": {
37
- "@deepseek-ai/schemastery": "~3.18.5-alpha.1"
39
+ "@deepseek-ai/schemastery": "~3.18.5-alpha.2"
38
40
  },
39
41
  "devDependencies": {
40
- "@deepseek-ai/cordis-plugin-include": "~1.0.10-alpha.1",
41
- "@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.1",
42
- "@deepseek-ai/dsh-agent": "0.2.1-alpha.2",
43
- "@deepseek-ai/dsh-agent-loop-testkit": "0.2.1-alpha.2",
44
- "@deepseek-ai/dsh-brand": "0.2.1-alpha.2",
45
- "@deepseek-ai/dsh-scope": "0.2.1-alpha.2",
46
- "@deepseek-ai/dsh-session": "0.2.1-alpha.2",
47
- "@deepseek-ai/dsh-jobs": "0.2.1-alpha.2",
48
- "@deepseek-ai/dsh-timeout": "0.2.1-alpha.2",
49
- "@deepseek-ai/cordis": "~4.0.5-alpha.1"
42
+ "@deepseek-ai/cordis-plugin-include": "~1.0.10-alpha.2",
43
+ "@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.2",
44
+ "@deepseek-ai/dsh-agent": "0.2.1-alpha.4",
45
+ "@deepseek-ai/dsh-agent-loop-testkit": "0.2.1-alpha.4",
46
+ "@deepseek-ai/dsh-brand": "0.2.1-alpha.4",
47
+ "@deepseek-ai/dsh-scope": "0.2.1-alpha.4",
48
+ "@deepseek-ai/dsh-session": "0.2.1-alpha.4",
49
+ "@deepseek-ai/dsh-jobs": "0.2.1-alpha.4",
50
+ "@deepseek-ai/dsh-timeout": "0.2.1-alpha.4",
51
+ "@deepseek-ai/cordis": "~4.0.5-alpha.2"
50
52
  }
51
53
  }