@suifei/dsh-ai-team 0.4.50 → 0.4.52

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.52 - 2026-11-12
4
+
5
+ **批 17:reconcile 项目级互斥 + 修复区间上报**
6
+
7
+ - **同一项目的 reconcile 互斥**:PMO tick 与 `skillopt_jobs` 工具会同时收割同一批 job,两边都在「读 job 状态 → 写回」,并发时后到的一次判断会覆盖前一次的结果(`done` 冻结与原子写只是兜底)。现在按项目目录加锁,被跳过的一侧记 `skillopt.reconcile.skip`(`reason: in-flight`),不再静默。
8
+ - **`ledger.repair()` 报告恢复区间**:返回 `acceptedRange: { from, to }` 与 `seqGaps[]`(最多 20 条)。一次失败的 `appendMany` 可能把前缀留在盘上,只说「修好了」不够——运维需要知道接受到哪个 seq、有没有洞。`project.repair` 命令一并透传。
9
+ - 测试:`node --test` **253 通过 / 1 跳过**(新增 1 例:健康账本的 `project.repair` 返回空缺口)。
10
+
11
+ ## 0.4.51 - 2026-11-12
12
+
13
+ **批 16:卸载闸门(teardown 不再被在途异步链穿透)**
14
+
15
+ 插件卸载后仍在飞的异步链此前会继续写状态:
16
+
17
+ - `ensureParent()` 在卸载后才解析出的父代理:句柄留在进程里,且继续往每个项目账本写 `team/host-bound`;
18
+ - 激活在卸载后才完成:`activations.set(...)` 把句柄塞进**已经清空**的表里,再也没人 dispose 它;
19
+ - 归档修复的 2s×30 重试窗口在卸载后继续跑,且可能在清理之后重建 PMO 定时器。
20
+
21
+ 现在统一用一个 `disposed` 闸门:teardown 第一步置位;父代理迟到的句柄立即 `dispose()` 并记 `host.created.after-dispose`;迟到的激活立即释放并返回 503(记 `member.activated.after-dispose`);重试循环与定时器创建都先看闸门。
22
+
23
+ - 测试:`node --test` **252 通过 / 1 跳过**(这部分是防御性改动,未新增用例——没有可观测的对外行为变化,已在报告里如实标注)。
24
+
3
25
  ## 0.4.50 - 2026-11-12
4
26
 
5
27
  **首次使用必须先设定目录;新建项目必须指定目录**
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * dsh-ai-team — Host half.
3
3
  *
4
4
  * M1: one default Project backed by the plugin-owned append-only ledger.
@@ -262,6 +262,9 @@ export function apply(ctx, config = {}) {
262
262
 
263
263
  let booted = null;
264
264
  let bootError = null;
265
+ // 卸载闸门:teardown 之后仍在飞的异步链(boot 续体、ensureParent、归档修复重试)
266
+ // 不能继续写状态,否则会把句柄塞进已清空的表里、或在清理之后重建定时器。
267
+ let disposed = false;
265
268
  const projectRuntime = (projectId) => booted?.runtimes?.get(projectId) ?? null;
266
269
  const runtimeForAgent = (sessionId) => {
267
270
  if (sessionId === undefined || sessionId === null) return null;
@@ -371,11 +374,13 @@ export function apply(ctx, config = {}) {
371
374
  // 再用一个短重试窗口(2s × 30)兜住就绪时间,不必等 60s 的 tick。
372
375
  void (async () => {
373
376
  for (let attempt = 0; attempt < 30; attempt += 1) {
377
+ if (disposed) return;
374
378
  await repairArchivedHosts();
375
- if (hostRepaired) return;
379
+ if (hostRepaired || disposed) return;
376
380
  await new Promise((resolve) => { const timer = setTimeout(resolve, 2000); timer.unref?.(); });
377
381
  }
378
382
  })();
383
+ if (disposed) return;
379
384
  if (pmoTimer === null) {
380
385
  pmoTimer = setInterval(() => {
381
386
  for (const runtime of booted?.runtimes?.values() ?? []) {
@@ -558,6 +563,20 @@ export function apply(ctx, config = {}) {
558
563
  // PMO tick 是 fire-and-forget:慢 tick(模型/IO)会被下一分钟的定时器再入,
559
564
  // 造成 autoAnswerDecisions/reconcileJobs 并发执行同一条账本。按 Project 去重。
560
565
  const pmoBusy = new Set();
566
+ // 同一项目目录的 reconcile 互斥:PMO tick 与 skillopt_jobs 工具会同时收割同一批
567
+ // job,两边都在「读 job 状态 → 写回」,并发时后到的一次判断会覆盖前一次的结果。
568
+ const reconcileBusy = new Set();
569
+ const reconcileWithLock = async (projectDir, options) => {
570
+ const key = typeof projectDir === 'string' ? projectDir : '';
571
+ if (key !== '' && reconcileBusy.has(key)) return false;
572
+ if (key !== '') reconcileBusy.add(key);
573
+ try {
574
+ await reconcileJobs(options);
575
+ return true;
576
+ } finally {
577
+ if (key !== '') reconcileBusy.delete(key);
578
+ }
579
+ };
561
580
  // 本次请求的连续失败计数(按成员会话、10 分钟窗口)。
562
581
  const requestAttempts = new Map();
563
582
  const activationTasks = new Map();
@@ -771,7 +790,7 @@ export function apply(ctx, config = {}) {
771
790
  // 两阶段异步优化 job 收割:与任务派发无关,放在停止门之前——
772
791
  // Human 启动的 job 必须在任意运行态下收敛(生成/评审/落盘)。
773
792
  try {
774
- await reconcileJobs({
793
+ const reconciled = await reconcileWithLock(projectRuntime.dir, {
775
794
  ctx,
776
795
  // job 归属项目数据目录(与 skillopt_optimize 写入处一致):
777
796
  // 与工作区/激活项目无关,保证任意 tick 都能找到待收割 job。
@@ -800,6 +819,7 @@ export function apply(ctx, config = {}) {
800
819
  } catch (error) {
801
820
  diag.append({ ev: 'skillopt.job.tick.fail', message: error?.message ?? String(error) });
802
821
  }
822
+ if (reconciled === false) diag.append({ ev: 'skillopt.reconcile.skip', projectId: projectRuntime.id, reason: 'in-flight' });
803
823
  // 门禁必须在 await 之后重新取:reconcileJobs 可能耗时数秒,期间 Human
804
824
  // 可能已经停用 PMO / 归档 / 停止项目,用 await 之前的快照会继续写账本。
805
825
  const project = projectRuntime.service.state.projects?.[projectRuntime.id];
@@ -1245,7 +1265,7 @@ export function apply(ctx, config = {}) {
1245
1265
  for (const jobRoot of jobRoots) {
1246
1266
  if (typeof jobRoot !== 'string' || jobRoot === '') continue;
1247
1267
  try {
1248
- await reconcileJobs({
1268
+ const reconciledHere = await reconcileWithLock(jobRoot, {
1249
1269
  ctx,
1250
1270
  projectDir: jobRoot,
1251
1271
  deps: {
@@ -1268,6 +1288,9 @@ export function apply(ctx, config = {}) {
1268
1288
  } catch (error) {
1269
1289
  diag.append({ ev: 'skillopt.jobs.step.fail', message: error?.message ?? String(error), jobRoot });
1270
1290
  }
1291
+ if (reconciledHere === false) {
1292
+ diag.append({ ev: 'skillopt.reconcile.skip', projectId: jobRoot, reason: 'in-flight' });
1293
+ }
1271
1294
  }
1272
1295
  const roots = jobRoots.length > 0 ? jobRoots : [process.cwd()];
1273
1296
  const jobs = roots.flatMap((jobRoot) => listJobs(jobRoot));
@@ -1492,6 +1515,12 @@ export function apply(ctx, config = {}) {
1492
1515
  cwd: hostCwd(),
1493
1516
  resumeSessionId: existingHost,
1494
1517
  }).then(async (value) => {
1518
+ // 卸载后才完成的父代理:句柄不能留在进程里,也不能写账本。
1519
+ if (disposed) {
1520
+ try { await value.dispose?.(); } catch { /* already gone */ }
1521
+ diag.append({ ev: 'host.created.after-dispose', sessionId: value.sessionId ?? null });
1522
+ return value;
1523
+ }
1495
1524
  // Host 会话必须落账:它决定冷恢复与 sendMessage 的 parent,也决定归档
1496
1525
  // 修复 sweep 能不能看见根会话。除了「首次创建」,从 roots() 里选中
1497
1526
  // 既有会话、以及父级发生变化(换成了另一条根会话)时同样要重绑——
@@ -1610,6 +1639,12 @@ export function apply(ctx, config = {}) {
1610
1639
  try { await result.activation.dispose?.(); } catch { /* already gone */ }
1611
1640
  throw error;
1612
1641
  }
1642
+ // 卸载后才完成的激活:直接释放,不登记(否则句柄留在已清空的表里)。
1643
+ if (disposed) {
1644
+ try { await result.activation.dispose?.(); } catch { /* already gone */ }
1645
+ diag.append({ ev: 'member.activated.after-dispose', memberId: member.id, sessionId: result.childId });
1646
+ return { error: { code: 'E_RUNTIME', message: 'plugin is shutting down' }, status: 503 };
1647
+ }
1613
1648
  activations.set(result.childId, result.activation);
1614
1649
  await attachMemberWorkspace(projectRuntime, result.childId);
1615
1650
  persistModelSelection(result.childId, activationMember.config, member.name);
@@ -2351,6 +2386,7 @@ export function apply(ctx, config = {}) {
2351
2386
  // Teardown must fully settle before the loader activates the next
2352
2387
  // composition: a racing parent-agent dispose left the previous
2353
2388
  // session-controller graph half-disposed and broke plugin toggles.
2389
+ disposed = true;
2354
2390
  const cleanup = [];
2355
2391
  for (const client of sseClients) {
2356
2392
  try { client.res.end(); } catch { /* socket already gone */ }
@@ -554,6 +554,9 @@ export class TeamService {
554
554
  repairs: Array.isArray(result?.repairs) ? result.repairs : [],
555
555
  events: result?.events ?? null,
556
556
  stateLastSeq: result?.stateLastSeq ?? null,
557
+ // 恢复区间与缺口:一次失败的批次可能把前缀留在盘上,调用方要能看出来。
558
+ acceptedRange: result?.acceptedRange ?? null,
559
+ seqGaps: Array.isArray(result?.seqGaps) ? result.seqGaps : [],
557
560
  };
558
561
  }
559
562
  async changeProjectWorkspace(command, payload) {
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 单项目账本写入器:append-only JSONL、分段、fsync、单写者锁、尾撕裂修复。
3
3
  *
4
4
  * 对应 03-架构设计报告 §6.5 / §6.6 / §8.1、附录 B §B.3.6:
@@ -1235,11 +1235,24 @@ export function openLedger(options = {}) {
1235
1235
  state = fold(events);
1236
1236
  eventsSinceCheckpoint = 0;
1237
1237
  if (checkpointOptions) saveCheckpointNow();
1238
+ // 恢复区间与缺口:一次失败的 appendMany 可能把「前缀」留在盘上,光说
1239
+ // 「修好了」不够——运维需要知道接受到了哪个 seq、有没有洞。
1240
+ const gaps = [];
1241
+ for (let index = 0; index < events.length; index += 1) {
1242
+ if (events[index]?.seq !== index + 1) {
1243
+ gaps.push({ at: index, seq: events[index]?.seq ?? null });
1244
+ if (gaps.length >= 20) break;
1245
+ }
1246
+ }
1238
1247
  return {
1239
1248
  ...result,
1240
1249
  refolded: true,
1241
1250
  events: events.length,
1242
1251
  stateLastSeq: state.lastSeq ?? null,
1252
+ acceptedRange: events.length === 0
1253
+ ? null
1254
+ : { from: events[0].seq ?? null, to: events[events.length - 1].seq ?? null },
1255
+ seqGaps: gaps,
1243
1256
  };
1244
1257
  },
1245
1258
  close() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.50",
3
+ "version": "0.4.52",
4
4
  "type": "module",
5
5
  "description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
6
6
  "license": "MIT",