From d5a2bd2b8bf35877ed5e44bd5d48fe5c98e00bea Mon Sep 17 00:00:00 2001 From: sjw1231 Date: Mon, 9 Nov 2026 13:25:30 +0800 Subject: [PATCH] fix(command-goal): report corrupt goal state from /goal The command mapped every GoalError to the generic invalid-command text, so GOAL_STATE_CORRUPT lost its replay diagnostic. It now rethrows that code so the command runtime reports the cause. Refs #7869 --- packages/goal/command-goal/README.i18n.yaml | 4 ++-- packages/goal/command-goal/README.md | 2 +- packages/goal/command-goal/README.zh.md | 2 +- packages/goal/command-goal/src/index.ts | 3 ++- packages/goal/command-goal/tests/command-goal.spec.ts | 9 ++++++++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/goal/command-goal/README.i18n.yaml b/packages/goal/command-goal/README.i18n.yaml index 9efbb3b229..7adba08b07 100644 --- a/packages/goal/command-goal/README.i18n.yaml +++ b/packages/goal/command-goal/README.i18n.yaml @@ -33,8 +33,8 @@ en: 7fba8a13f8452dc1 zh: bbaba056cda78ec9 /deepseek-ai-dsh-command-goal/understand-the-implementation/design: - en: ab637815b21bf065 - zh: 56eb4ae2ad368994 + en: 47880a3aa7c982a2 + zh: eed5b31970e01a51 /deepseek-ai-dsh-command-goal/understand-the-implementation/source-map: en: a34756578cce7cc4 zh: 61079561a2bf742d diff --git a/packages/goal/command-goal/README.md b/packages/goal/command-goal/README.md index a627a15e82..4d2eefe71e 100644 --- a/packages/goal/command-goal/README.md +++ b/packages/goal/command-goal/README.md @@ -76,7 +76,7 @@ This section explains how the command parses input and renders output; the obser ### Design - **Grammar, not free text.** The parser recognizes only the exact control words (`clear`, `pause`, `resume`, `edit`) when they fill the whole input; every other non-empty suffix is an objective. `edit` alone is invalid, and `edit` refuses to replace an unfinished goal directly. -- **Domain rejections become stable errors.** `GoalError` outcomes are converted into direct command errors with a fixed message; unexpected failures rethrow so adapters report a command failure rather than a domain result. Rendered output never exposes branded ids or revisions. +- **Domain rejections become stable errors.** `GoalError` outcomes other than `GOAL_STATE_CORRUPT` are converted into direct command errors with a fixed message; corrupt goal state and unexpected failures rethrow so adapters report a command failure rather than a domain result. Rendered output never exposes branded ids or revisions. - **Attachments accompany the objective.** On a successful create or edit, the command submits one user followup carrying the admitted image and file blocks in selection order plus the fixed text `Reference attachments for the goal objective.` Every other path submits nothing, so the dispatching composer keeps the draft and cards. ### Source map diff --git a/packages/goal/command-goal/README.zh.md b/packages/goal/command-goal/README.zh.md index 9e4bac63d9..89112857b9 100644 --- a/packages/goal/command-goal/README.zh.md +++ b/packages/goal/command-goal/README.zh.md @@ -76,7 +76,7 @@ kind: "package-reference" ### 设计 - **语法,而非自由文本。** 解析器只在控制词(`clear`、`pause`、`resume`、`edit`)填满整个输入时识别它们;其他任何非空后缀都是目标。单独的 `edit` 无效,且 `edit` 拒绝直接替换未完成的 goal。 -- **领域拒绝变成稳定错误。** `GoalError` 结果会转换为带固定消息的直接命令错误;意外失败会重新抛出,使适配器报告命令失败而非领域结果。渲染输出绝不暴露带品牌类型的 id 或 revision。 +- **领域拒绝变成稳定错误。** 除 `GOAL_STATE_CORRUPT` 外的 `GoalError` 结果会转换为带固定消息的直接命令错误;goal 状态损坏与意外失败会重新抛出,使适配器报告命令失败而非领域结果。渲染输出绝不暴露带品牌类型的 id 或 revision。 - **附件随目标提交。** create 或 edit 成功时,命令提交一条用户 followup 消息,按选择顺序携带已准入的图片块与文件块,再附加固定文本 `Reference attachments for the goal objective.`。其他路径不提交消息,因此分发方 composer 保留草稿和附件卡。 ### 源码地图 diff --git a/packages/goal/command-goal/src/index.ts b/packages/goal/command-goal/src/index.ts index 9238d76632..617ba4e0eb 100644 --- a/packages/goal/command-goal/src/index.ts +++ b/packages/goal/command-goal/src/index.ts @@ -176,7 +176,8 @@ function executeGoalCommand(ctx: Context, invocation: CommandInvocation): Comman default: return assertNever(command, 'goal command') } } catch (error: unknown) { - if (error instanceof GoalError) { + // Corrupt goal state is not a command-shape problem; the command runtime reports its cause. + if (error instanceof GoalError && error.code !== 'GOAL_STATE_CORRUPT') { return { kind: 'error', text: 'The goal command is not valid for the current state. Run /goal to view available commands.', diff --git a/packages/goal/command-goal/tests/command-goal.spec.ts b/packages/goal/command-goal/tests/command-goal.spec.ts index 6cb4cf83c9..4a3486a58e 100644 --- a/packages/goal/command-goal/tests/command-goal.spec.ts +++ b/packages/goal/command-goal/tests/command-goal.spec.ts @@ -5,7 +5,7 @@ import AgentRegistry from '@deepseek-ai/dsh-agent' import type { Agent, AgentStatus } from '@deepseek-ai/dsh-agent' import CommandRuntime from '@deepseek-ai/dsh-commands' import GoalService from '@deepseek-ai/dsh-goal' -import type { GoalRef } from '@deepseek-ai/dsh-goal' +import { GoalError, type GoalRef } from '@deepseek-ai/dsh-goal' import SessionStore, { Session, SessionId, type SessionEvent } from '@deepseek-ai/dsh-session' import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection' import * as commandGoal from '@deepseek-ai/dsh-command-goal' @@ -237,6 +237,13 @@ describe('/goal human command', () => { vi.spyOn(test.ctx.goals, 'get').mockImplementationOnce(() => { throw new Error('unexpected failure') }) await expect(run(test)).rejects.toThrow('unexpected failure') }) + + it('reports corrupt goal state instead of the generic invalid-command result', async () => { + const test = await harness() + const corrupt = new GoalError('goal replay failed at session event 3: invalid goal stream', 'GOAL_STATE_CORRUPT') + vi.spyOn(test.ctx.goals, 'get').mockImplementationOnce(() => { throw corrupt }) + await expect(run(test)).rejects.toBe(corrupt) + }) }) describe('/goal attachments', () => {