7 Commits

Author SHA1 Message Date
wangdl
8987598eb8 feat(M-AI-05): track Feynman unified engine migration implementation
23 files (+4676/-10):
- Contract: m-ai-05-feynman-migration-contract.md (737 lines)
- Gate audit: m-ai-05-gate-audit.md (318 lines)
- Job Definition + Snapshot Builder + Registration
- Executor + BusinessValidator + ReferenceValidator
- Projector (atomic transaction + 3-layer idempotency)
- ExecutionRouter (FeatureFlag + idempotencyKey)
- ObservabilityService (structured logging + counters)
- Engine: feynman_evaluation execution branch
- AiJobCreationService: feynman_evaluation safety branch
- Controller/Module: Router injection
- CI: path detection for m-ai-05
- E2E: 8 HTTP-layer scenarios (14 total)
- Unit tests: 104 new tests (5 spec files)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-21 17:44:58 +08:00
wangdl
f8bd950f1a fix(M-AI-04-GATE-FIX-02): Worker AiJobModule, Projector observability, E2E fail-closed
Some checks failed
Deploy API Server / build-and-unit (push) Successful in 35s
Deploy API Server / backward-compat (push) Has been cancelled
Deploy API Server / deploy (push) Has been cancelled
Deploy API Server / current-integration (push) Has been cancelled
P1-01: WorkerModule imports AiJobModule → AI_JOB_EXECUTION_ENGINE resolved
       → AiInteractiveJobWorker can execute Unified Jobs (not silently skip)
P1-02: Engine PROJECT phase wrapped in try-catch → incrementProjectorFailed
       on ActiveRecall projector errors (independent of executor failures)
P2-01: E2E beforeAll fail() → throw new Error() → no ReferenceError risk

Observability coverage after fix:
- Creation: incrementUnifiedRequests, logRequest, logJobCreated, logJobCreateFailed 
- Execute success: incrementUnifiedExecuteSuccess, logExecutionCompleted 
- Execute failure: incrementUnifiedExecuteFailed, incrementUnifiedRetry, logExecutionFailed 
- Projector failure: incrementProjectorFailed  (NEW)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-21 15:29:33 +08:00
wangdl
0ec58669dd feat(M-AI-04): Active Recall 端到端迁移至统一 Job Engine
Some checks failed
Deploy API Server / build-and-unit (push) Successful in 37s
Deploy API Server / current-integration (push) Failing after 1m35s
Deploy API Server / backward-compat (push) Successful in 17s
Deploy API Server / deploy (push) Has been skipped
M-AI-04-01: 审计并冻结迁移契约 (文档)
M-AI-04-02: 注册 JobDefinition + SnapshotBuilder (28 tests)
M-AI-04-03: Executor + BusinessValidator + ReferenceValidator (31 tests)
M-AI-04-04: Projector + Artifact + 幂等写入 (19 tests)
M-AI-04-05: 入口集成 (Router + CreationService + Engine + Executor)
M-AI-04-06: 状态兼容 + 结构化日志 + 指标计数器 (255 tests)
M-AI-04-07: 真实业务 E2E + CI 触发 + FeatureFlag 受控切换 (11 tests)

P0 修复:
- 跨用户 question 所有权校验 (active-recall.service.ts)
- E2E infra 不可用时 HARD FAIL (fail() 替代静默 skip)

添加文件:
- docs/architecture/m-ai-04-active-recall-migration-contract.md
- 12 个 ai-job 模块文件 (Definition/Snapshot/Executor/Validator/Projector/Router/Observability)
- test/m-ai-04-active-recall.e2e-spec.ts + setup

修改文件:
- active-recall.service.ts, active-recall.module.ts
- ai-job-creation.service.ts, ai-job-execution-engine.ts, ai-job.module.ts
- .gitea/workflows/deploy.yml (CI 变更检测)
- test/jest-e2e.json (setupFiles + globals)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-21 14:55:33 +08:00
wangdl
4cfcb7afe5 feat: M-AI-03 Result Projector 与 Artifact 原子提交框架
Some checks failed
Deploy API Server / build-and-unit (push) Failing after 29s
Deploy API Server / current-integration (push) Has been skipped
Deploy API Server / backward-compat (push) Has been skipped
Deploy API Server / deploy (push) Has been skipped
- result-projector.interface.ts: ResultProjector 接口冻结(ADR-003 §6.1)
  project(tx, context) → ArtifactReference[]
- synthetic-result-projector.ts: 测试用 Synthetic Projector
  幂等:已有 Artifact 时直接返回
- projection-executor.service.ts: ProjectionExecutor
  事务内:projector.project(tx) + markSucceeded(tx) 原子提交
  幂等检查:Job 已终态 → 跳过
  NestJS multi-provider 注入 RESULT_PROJECTORS
- ai-job-execution-engine.ts: PROJECT 阶段改为调用 ProjectionExecutor
- ai-job.module.ts: 注册 ProjectionExecutor + SyntheticResultProjector

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-21 09:49:25 +08:00
wangdl
aa1ce45d80 fix: N1-N3 — crypto 顶层导入 + 移除冗余 AbortController + _def 重命名
Some checks failed
Deploy API Server / build-and-unit (push) Failing after 27s
Deploy API Server / current-integration (push) Has been skipped
Deploy API Server / backward-compat (push) Has been skipped
Deploy API Server / deploy (push) Has been skipped
- N1: require('crypto') 内联 → import * as crypto 顶层导入
- N2: 移除 Engine 内未连接的 AbortController(timeout 委托给 AiGatewayService)
- N3: writeUsageLog 的 _def 参数 → definition

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-20 18:44:32 +08:00
wangdl
cdcf056ba5 fix: B1 — lockJob 原子递增 attemptCount + Engine 重试解锁逻辑
Some checks failed
Deploy API Server / build-and-unit (push) Failing after 28s
Deploy API Server / current-integration (push) Has been skipped
Deploy API Server / backward-compat (push) Has been skipped
Deploy API Server / deploy (push) Has been skipped
- lockJob updateMany 新增 attemptCount: { increment: 1 }
- Engine retryable 错误: unlockForRetry() 重置为 queued 后再抛给 BullMQ
- Engine permanent 错误: 直接 markFailed + return(不抛错,BullMQ 不重试)
- unlockForRetry: 重置 lifecycleStatus→queued + 清除 lockedBy/lockedAt/lockUntil
- 更新测试: lockJob 验证 attemptCount 递增; schema validation 验证不抛错

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-20 18:42:19 +08:00
wangdl
d82ae8ba71 feat: M-AI-03 统一 AiJob Worker Execution Engine
Some checks failed
Deploy API Server / build-and-unit (push) Failing after 29s
Deploy API Server / current-integration (push) Has been skipped
Deploy API Server / backward-compat (push) Has been skipped
Deploy API Server / deploy (push) Has been skipped
- AiJobExecutionEngineImpl: 完整 5 阶段管线
  PREPARE: read Job → terminal check → cancel check → Registry.get → CAS lockJob
  RESOLVE: load Snapshot → schemaVersion check → AbortController timeout
  EXECUTE: AiGatewayService.generate() (不直接导入 Provider SDK)
  PROJECT: write validatedOutput + outputHash (#292 替换为 Projector)
  COMPLETE: usageLog → markSucceeded
- 错误分类: classifyError() — 7 种错误码, retryable/permanent 分流
  provider_rate_limited/timeout/unavailable → retryable → 抛给 BullMQ
  schema/business/reference validation → permanent → markFailed
  cancelled → markCancelled (3 个检查点: 执行前/Provider前/Projector前)
- Usage logging: 每次 Provider 调用写 AiUsageLog (jobId/attemptNo/credentialMode/token)
- AiJobModule: 使用 AI_JOB_EXECUTION_ENGINE token 注册,替换 #288 的 no-op
- 10 个单元测试: 全链路成功/终态跳过/取消(2)/错误分类(3)/锁冲突/Schema不兼容/UsageLog

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-20 18:30:02 +08:00