fix(P2-06): remove @Optional() silent skip from AiInteractive/Background workers
All checks were successful
Deploy API Server / build-and-unit (push) Successful in 34s
Deploy API Server / current-integration (push) Successful in 3m2s
Deploy API Server / backward-compat (push) Successful in 0s
Deploy API Server / deploy (push) Successful in 1m3s

Engine is now a hard dependency — DI resolution failure prevents Worker
startup (fail-fast) instead of silently skipping all Unified Jobs.

Changes:
- ai-interactive.worker.ts: remove @Optional(), silent return guard
- ai-background.worker.ts: remove @Optional(), silent return guard
- docs: mark P2-06 as fixed

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-21 15:45:33 +08:00
parent 4f74c09d0f
commit a532b5163b
3 changed files with 8 additions and 25 deletions

View File

@ -288,7 +288,7 @@ E2E 场景 12 验证通过。
| P2-03 | FocusItem `knowledgeBaseId` 恒为 `unknown`M-AI-04-01 #3 | 否 |
| P2-04 | ModelRouter preferred/fallback 相同M-AI-04-01 #7 | 否 |
| P2-05 | ReviewCard 无 `jobId` 关联字段(表结构限制) | 否 |
| **P2-06** | **`@Optional()` 静默吞任务** — `AiInteractiveJobWorker``if (!this.engine) return` 会在模块依赖再次出错时静默跳过 Unified Job而非启动失败 | **生产 Unified 前移除** |
| **P2-06** | **`@Optional()` 静默吞任务** — ✅ 已修复 (`4f74c09`)`AiInteractiveJobWorker` + `AiBackgroundJobWorker` 移除 `@Optional()``if (!this.engine) return`。Engine 缺失时 DI 直接抛错阻止启动 | ✅ |
| **P2-07** | **Engine 硬编码 `active_recall`** — 通用 Engine 中 4 处 `if (job.jobType === 'active_recall')` 分支,应重构为 Definition Hook 或 Observer 模式 | 否(不阻塞 M-AI-05 |
### P3

View File

@ -1,5 +1,5 @@
import { Processor, WorkerHost } from '@nestjs/bullmq';
import { Logger, Inject, Optional } from '@nestjs/common';
import { Logger, Inject } from '@nestjs/common';
import type { Job } from 'bullmq';
import {
QUEUE_AI_BACKGROUND,
@ -25,11 +25,11 @@ export class AiBackgroundJobWorker extends WorkerHost {
private readonly logger = new Logger(AiBackgroundJobWorker.name);
constructor(
@Optional()
@Inject(AI_JOB_EXECUTION_ENGINE)
private readonly engine?: any,
private readonly engine: any,
) {
super();
// P2-06: Engine 是硬依赖。DI 解析失败 → Worker 启动 crashfail-fast
}
async process(job: Job<{ jobId: string }>): Promise<void> {
@ -40,15 +40,6 @@ export class AiBackgroundJobWorker extends WorkerHost {
throw new Error('Invalid job payload: missing jobId');
}
if (!this.engine) {
// M-AI-03-05~07 阶段 Engine 尚未实现,暂记日志并标记完成
this.logger.warn(
`Engine not available — skipping jobId=${jobId}. ` +
`Will be handled after M-AI-03-08 (#291).`,
);
return;
}
const context = {
jobId: job.id ?? '',
attemptMade: job.attemptsMade,

View File

@ -1,5 +1,5 @@
import { Processor, WorkerHost } from '@nestjs/bullmq';
import { Logger, Inject, Optional } from '@nestjs/common';
import { Logger, Inject } from '@nestjs/common';
import type { Job } from 'bullmq';
import {
QUEUE_AI_INTERACTIVE,
@ -25,11 +25,12 @@ export class AiInteractiveJobWorker extends WorkerHost {
private readonly logger = new Logger(AiInteractiveJobWorker.name);
constructor(
@Optional()
@Inject(AI_JOB_EXECUTION_ENGINE)
private readonly engine?: any,
private readonly engine: any,
) {
super();
// P2-06: Engine 是硬依赖。若 DI 解析失败Worker 启动即 crashfail-fast
// 不复静默跳过 Unified Job。Kubernetes/systemd 负责重启。
}
async process(job: Job<{ jobId: string }>): Promise<void> {
@ -40,15 +41,6 @@ export class AiInteractiveJobWorker extends WorkerHost {
throw new Error('Invalid job payload: missing jobId');
}
if (!this.engine) {
// M-AI-03-05~07 阶段 Engine 尚未实现,暂记日志并标记完成
this.logger.warn(
`Engine not available — skipping jobId=${jobId}. ` +
`Will be handled after M-AI-03-08 (#291).`,
);
return;
}
const context = {
jobId: job.id ?? '',
attemptMade: job.attemptsMade,