@suifei/dsh-ai-team 0.4.51 → 0.4.53

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,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.53 - 2026-11-12
4
+
5
+ **修 0.4.52 引入的回归:PMO tick 每轮抛 ReferenceError**
6
+
7
+ 0.4.52 的 reconcile 锁把返回值写在 `try` 块里(`const reconciled = ...`),而我加的「跳过诊断」在 `try/catch` **之外**读它——于是每个 tick 都抛 `ReferenceError: reconciled is not defined`,被 tick 外层的 `console.warn` 吞成一行日志:**PMO 派发与 job 收割整条链路当时是停的**。
8
+
9
+ - 修复:`let reconciled = true;` 提到 `try` 之前。
10
+ - **加一道守卫**:`management` 用例现在接管 `console.error` 与 `console.warn`,正常流程结束后不允许出现 `[ai-team] … failed/error`。这条守卫我做了对照组:撤掉 `let reconciled` 后用例立即失败,恢复后通过——0.4.52 那个 bug 正是「断言全绿但日志里在报错」溜过去的。
11
+ - 测试:`node --test` **253 通过 / 1 跳过**。
12
+
13
+ ## 0.4.52 - 2026-11-12
14
+
15
+ **批 17:reconcile 项目级互斥 + 修复区间上报**
16
+
17
+ - **同一项目的 reconcile 互斥**:PMO tick 与 `skillopt_jobs` 工具会同时收割同一批 job,两边都在「读 job 状态 → 写回」,并发时后到的一次判断会覆盖前一次的结果(`done` 冻结与原子写只是兜底)。现在按项目目录加锁,被跳过的一侧记 `skillopt.reconcile.skip`(`reason: in-flight`),不再静默。
18
+ - **`ledger.repair()` 报告恢复区间**:返回 `acceptedRange: { from, to }` 与 `seqGaps[]`(最多 20 条)。一次失败的 `appendMany` 可能把前缀留在盘上,只说「修好了」不够——运维需要知道接受到哪个 seq、有没有洞。`project.repair` 命令一并透传。
19
+ - 测试:`node --test` **253 通过 / 1 跳过**(新增 1 例:健康账本的 `project.repair` 返回空缺口)。
20
+
3
21
  ## 0.4.51 - 2026-11-12
4
22
 
5
23
  **批 16:卸载闸门(teardown 不再被在途异步链穿透)**
package/index.js CHANGED
@@ -563,6 +563,20 @@ export function apply(ctx, config = {}) {
563
563
  // PMO tick 是 fire-and-forget:慢 tick(模型/IO)会被下一分钟的定时器再入,
564
564
  // 造成 autoAnswerDecisions/reconcileJobs 并发执行同一条账本。按 Project 去重。
565
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
+ };
566
580
  // 本次请求的连续失败计数(按成员会话、10 分钟窗口)。
567
581
  const requestAttempts = new Map();
568
582
  const activationTasks = new Map();
@@ -775,8 +789,9 @@ export function apply(ctx, config = {}) {
775
789
  // PMO 自动关闭时也必须收敛(否则 job 永远停在 generating)。
776
790
  // 两阶段异步优化 job 收割:与任务派发无关,放在停止门之前——
777
791
  // Human 启动的 job 必须在任意运行态下收敛(生成/评审/落盘)。
792
+ let reconciled = true;
778
793
  try {
779
- await reconcileJobs({
794
+ reconciled = await reconcileWithLock(projectRuntime.dir, {
780
795
  ctx,
781
796
  // job 归属项目数据目录(与 skillopt_optimize 写入处一致):
782
797
  // 与工作区/激活项目无关,保证任意 tick 都能找到待收割 job。
@@ -805,6 +820,7 @@ export function apply(ctx, config = {}) {
805
820
  } catch (error) {
806
821
  diag.append({ ev: 'skillopt.job.tick.fail', message: error?.message ?? String(error) });
807
822
  }
823
+ if (reconciled === false) diag.append({ ev: 'skillopt.reconcile.skip', projectId: projectRuntime.id, reason: 'in-flight' });
808
824
  // 门禁必须在 await 之后重新取:reconcileJobs 可能耗时数秒,期间 Human
809
825
  // 可能已经停用 PMO / 归档 / 停止项目,用 await 之前的快照会继续写账本。
810
826
  const project = projectRuntime.service.state.projects?.[projectRuntime.id];
@@ -1250,7 +1266,7 @@ export function apply(ctx, config = {}) {
1250
1266
  for (const jobRoot of jobRoots) {
1251
1267
  if (typeof jobRoot !== 'string' || jobRoot === '') continue;
1252
1268
  try {
1253
- await reconcileJobs({
1269
+ const reconciledHere = await reconcileWithLock(jobRoot, {
1254
1270
  ctx,
1255
1271
  projectDir: jobRoot,
1256
1272
  deps: {
@@ -1273,6 +1289,9 @@ export function apply(ctx, config = {}) {
1273
1289
  } catch (error) {
1274
1290
  diag.append({ ev: 'skillopt.jobs.step.fail', message: error?.message ?? String(error), jobRoot });
1275
1291
  }
1292
+ if (reconciledHere === false) {
1293
+ diag.append({ ev: 'skillopt.reconcile.skip', projectId: jobRoot, reason: 'in-flight' });
1294
+ }
1276
1295
  }
1277
1296
  const roots = jobRoots.length > 0 ? jobRoots : [process.cwd()];
1278
1297
  const jobs = roots.flatMap((jobRoot) => listJobs(jobRoot));
@@ -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.51",
3
+ "version": "0.4.53",
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",