@suifei/dsh-ai-team 0.4.82 → 0.4.83

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/index.js CHANGED
@@ -49,7 +49,7 @@ import { buildModelCatalog, buildModelEfforts } from './lib/host/model-catalog.j
49
49
  import { createTeamTool } from './lib/host/member-tools.js';
50
50
  import { describeTaskContext, describeWake, planWakes } from './lib/host/waker.js';
51
51
  import { describeCauseChain } from './lib/runtime/error-chain.js';
52
- import { classifyWakeFailure } from './lib/runtime/wake-failure.js';
52
+ import { classifyWakeFailure, isMalformedTurnError } from './lib/runtime/wake-failure.js';
53
53
  import { registerShellGuard } from './lib/runtime/shell-guard.js';
54
54
  import { createActivationBudget } from './lib/runtime/activation-budget.js';
55
55
  import { blocksActivation, probeProviderRegistration } from './lib/runtime/subagent-probe.js';
@@ -672,6 +672,11 @@ export function apply(ctx, config = {}) {
672
672
  });
673
673
  // blocked 最常见的原因是归档 gate:立刻复核一次血缘归档状态。
674
674
  if (endKind === 'blocked') void repairArchivedHosts();
675
+ // 工具参数在传输中截断(MALFORMED_RESPONSE):那次调用没有执行,成员
676
+ // 停在半路。重发一次通常就好,交给带预算的续跑(见 retryMalformedTurn)。
677
+ if (endKind === 'error' && isMalformedTurnError(event?.data?.reason)) {
678
+ void retryMalformedTurn(eventRuntime, member);
679
+ }
675
680
  return;
676
681
  }
677
682
  if (member.lastFailure === undefined || member.lastFailure === null) return;
@@ -733,6 +738,67 @@ export function apply(ctx, config = {}) {
733
738
  const projectWorkspace = (projectRuntime, member) => member?.workspace
734
739
  || projectRuntime?.service?.state?.projects?.[projectRuntime.id]?.workspacePath
735
740
  || null;
741
+ // 工具参数截断的续跑预算:与「会话重建」分开计数——重建会丢上下文,
742
+ // 续跑只是重发一条消息,成本低但也不能无限。
743
+ const malformedRetries = createActivationBudget({ limit: 3, windowMs: 10 * 60 * 1000 });
744
+ const retryMalformedTurn = async (projectRuntime, member) => {
745
+ try {
746
+ const project = projectRuntime?.service?.state?.projects?.[projectRuntime.id];
747
+ if (project !== undefined && project.runState === 'stopped') return;
748
+ const budget = malformedRetries.take(member.id);
749
+ if (budget.allowed !== true) {
750
+ diag.append({
751
+ ev: 'member.malformed.retry.suppressed.fail',
752
+ projectId: projectRuntime?.id ?? null,
753
+ memberId: member.id,
754
+ count: budget.count,
755
+ limit: budget.limit,
756
+ windowMs: budget.windowMs,
757
+ });
758
+ return;
759
+ }
760
+ const cwd = projectWorkspace(projectRuntime, member);
761
+ if (typeof cwd !== 'string' || cwd === '') return;
762
+ const parentInfo = await ensureParent();
763
+ if (parentInfo?.agent === undefined) return;
764
+ const subagents = serviceOf(ctx, 'subagents');
765
+ const sessionRuntime = new MemberRuntime({
766
+ subagents,
767
+ sessions: serviceOf(ctx, 'sessions'),
768
+ permissionPresets: serviceOf(ctx, 'permissionPresets'),
769
+ sandboxPolicy: serviceOf(ctx, 'sandboxPolicy'),
770
+ agents: serviceOf(ctx, 'agents'),
771
+ agentPresets: serviceOf(ctx, 'agentPresets'),
772
+ direct: false,
773
+ parent: parentInfo.agent,
774
+ provider: (typeof subagents?.list === 'function' ? subagents.list() : [])[0],
775
+ preset: 'standard',
776
+ cwd,
777
+ trackHandle: (sessionId, handle) => resumedHandles.set(sessionId, handle),
778
+ });
779
+ const delivered = await sessionRuntime.wake(member, {
780
+ prompt: [
781
+ '上一轮你发起的工具调用在传输中被截断(Unexpected end of JSON input),那次调用没有执行。',
782
+ '请重新发起同一次调用:参数写成一行紧凑 JSON,不要在参数里展开大段文本;',
783
+ '需要写长内容时改用更短的措辞,或先落盘再引用路径。',
784
+ ].join(''),
785
+ });
786
+ diag.append({
787
+ ev: 'member.malformed.retry',
788
+ projectId: projectRuntime?.id ?? null,
789
+ memberId: member.id,
790
+ attempt: budget.count,
791
+ messageId: delivered?.messageId ?? null,
792
+ });
793
+ } catch (error) {
794
+ diag.append({
795
+ ev: 'member.malformed.retry.fail',
796
+ projectId: projectRuntime?.id ?? null,
797
+ memberId: member?.id ?? null,
798
+ message: error?.message ?? String(error),
799
+ });
800
+ }
801
+ };
736
802
  const wakeFromResult = async (projectRuntime, result, actor = {}) => {
737
803
  if (projectRuntime === null || projectRuntime === undefined) return;
738
804
  // P6 停止门(事件 hook 侧):stopped 项目停止**自动派发**;Human
@@ -1,22 +1,42 @@
1
- /**
2
- * 唤醒失败的归类。
3
- *
4
- * 实机根因(2026-11-12 确诊):成员回合结束后会话仍被一个活跃写句柄占用,
5
- * `sessionQuery.observeSession` 拒绝发放读租约,冷恢复必然失败:
6
- *
7
- * subagent "X" is unavailable
8
- * cause: session "X" is already owned by an active write handle
9
- *
10
- * 插件无法释放这个租约(属 Harness 侧的句柄泄漏),只能重建会话。这类失败是
11
- * **可预期的**,不应按未知故障刷告警;其它原因仍然算真实失败。
12
- */
13
-
14
- const BUSY_HANDLE = /active write handle/i;
15
-
16
- /**
17
- * @param {string|null|undefined} causeChain `describeCauseChain()` 的输出
18
- * @returns {'wake.session-busy'|'wake.fail'} busy 表示「写租约被占用,必然需要重建」
19
- */
20
- export function classifyWakeFailure(causeChain) {
21
- return typeof causeChain === 'string' && BUSY_HANDLE.test(causeChain) ? 'wake.session-busy' : 'wake.fail';
22
- }
1
+ /**
2
+ * 唤醒失败的归类。
3
+ *
4
+ * 实机根因(2026-11-12 确诊):成员回合结束后会话仍被一个活跃写句柄占用,
5
+ * `sessionQuery.observeSession` 拒绝发放读租约,冷恢复必然失败:
6
+ *
7
+ * subagent "X" is unavailable
8
+ * cause: session "X" is already owned by an active write handle
9
+ *
10
+ * 插件无法释放这个租约(属 Harness 侧的句柄泄漏),只能重建会话。这类失败是
11
+ * **可预期的**,不应按未知故障刷告警;其它原因仍然算真实失败。
12
+ */
13
+
14
+ const BUSY_HANDLE = /active write handle/i;
15
+
16
+ /**
17
+ * @param {string|null|undefined} causeChain `describeCauseChain()` 的输出
18
+ * @returns {'wake.session-busy'|'wake.fail'} busy 表示「写租约被占用,必然需要重建」
19
+ */
20
+ export function classifyWakeFailure(causeChain) {
21
+ return typeof causeChain === 'string' && BUSY_HANDLE.test(causeChain) ? 'wake.session-busy' : 'wake.fail';
22
+ }
23
+
24
+ /**
25
+ * 回合是否因「工具参数在传输中截断」而失败。
26
+ *
27
+ * 实机(2026-11-13):成员在第 4 步发起的 `team` 调用只到
28
+ * `{"action": "tasks", "qaChecklist": ` 就断了,宿主解析不出 JSON,整轮以
29
+ * `MALFORMED_RESPONSE` 结束——工具没执行、成员也没被唤醒,任务停在半路。
30
+ * 这类失败是**传输/采样**造成的,与任务本身无关:重发一次通常就好,所以值得
31
+ * 自动续跑一次(预算见调用方),而不是让成员静默停摆。
32
+ *
33
+ * @param {{kind?: string, error?: {code?: string, message?: string}}|null|undefined} reason `turn/end` 的 reason
34
+ * @returns {boolean}
35
+ */
36
+ export function isMalformedTurnError(reason) {
37
+ if (reason === null || typeof reason !== 'object' || reason.kind !== 'error') return false;
38
+ const error = reason.error;
39
+ if (error === null || typeof error !== 'object') return false;
40
+ if (String(error.code ?? '').toUpperCase() === 'MALFORMED_RESPONSE') return true;
41
+ return /unexpected end of json input/i.test(String(error.message ?? ''));
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.82",
3
+ "version": "0.4.83",
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",