10 Commits

Author SHA1 Message Date
wangdl
c0594c518d test: add concurrent resolveSnapshot race test (API-AI-R01)
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 47s
- Simulates two concurrent getSnapshot calls with no valid snapshot
- Documents the known race: both trigger buildSnapshot, second update overwrites first
- Verifies both calls complete without error (accepted-risk behavior)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-18 11:41:35 +08:00
wangdl
7725b3d2ea perf: replace N+1 dedup queries with batch pre-fetch in convertCandidates
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
- convertQuizCandidates: batch findMany all stems before loop, dedup in-memory
- convertFlashcardCandidates: batch findMany all fronts before loop, dedup in-memory
- 50 items now = 1 query instead of 50
- Update tests: mock findMany instead of per-item findFirst

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-18 11:40:41 +08:00
wangdl
c2e5590718 fix: add observability to fire-and-forget persistResult & notifyJobComplete
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 44s
- Add static counters: persistResultFailures, notifyFailures
- Replace .catch(() => {}) with logger.error + counter increment
- Add error-path unit tests for both counter increments
- Reset counters in beforeEach for test isolation

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-18 11:38:30 +08:00
wangdl
c88af39673 feat: AI Runtime 完整业务逻辑实现
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 45s
- runtime-internal.service: resolveSnapshot 自动重建、persistResult 5种jobType持久化、validateOutput 校验、convertQuizCandidates/convertFlashcardCandidates 候选转换、notifyJobComplete 通知、JOB_CANCELLED处理、heartbeat 双阶段更新+取消检测
- user-ai.service: createAnalysisJob 11步流程、cancelJob、publishQuiz/publishFlashcard、getAnalysis/listAnalyses等
- user-ai.controller: 20+ 用户API端点
- 新增服务: SnapshotBuilderService、PriorityRulesService、SnapshotCleanupService、JobReaperService
- 新增模块: admin-learning (CRUD管理)
- Prisma schema: cancelRequestedAt/cancelledAt/sourceBlockIds 字段、expiresAt 索引
- 文档: ai-runtime-user-api.md、Issue 记录

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-18 11:22:03 +08:00
wangdl
eba9632a4e test: sync runtime-internal.service tests with current implementation (API-AI-062)
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 45s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-18 11:12:02 +08:00
wangdl
02979e3c24 test: add unit tests for runtime-internal.service (API-AI-062)
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-18 11:03:23 +08:00
wangdl
012e26b950 feat: API-Runtime 版本兼容协议 (API-AI-072)
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
- pollJobs: 记录/更新 RuntimeInstance (capabilities + heartbeat)
- submitResult: 校验 schemaVersion 匹配 job.outputSchemaVersion
- heartbeat: 首次调用设置 startedAt
- 错误码: RESULT_SCHEMA_UNSUPPORTED + RUNTIME_VERSION_INCOMPATIBLE

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-11 21:42:02 +08:00
wangdl
cc2ccbad59 fix: audit fixes for Runtime Internal API
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
1. heartbeat: locked→running transition on first heartbeat
2. submitResult: validate job is locked/running before accepting
3. submitFailure: validate job is locked/running before accepting
4. resolveCredentialForJob: update lastUsedAt on credential
5. pollJobs: filter by capabilities (snapshotVersion + outputSchemaVersion)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-11 21:38:44 +08:00
wangdl
43e6e9029c feat: Runtime Internal API (API-AI-028~034)
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
- RuntimeInternalController: 7 个 /internal/runtime/* 端点
- RuntimeInternalService: Poll/Lock/Heartbeat/Snapshot/Credential/Result/Fail/Log
- 复用 InternalAuthGuard + x-runtime-instance-id 追踪
- Job lock 防并发 (updateMany WHERE status=pending)
- Result 幂等 (resultIdempotencyKey)
- Failure retryable/non-retryable 处理

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-11 21:23:52 +08:00
wangdl
eea9e3e7c6 feat: API-Runtime 内部通信协议与 DTO (API-AI-001)
Some checks failed
Deploy API Server / build-and-deploy (push) Has been cancelled
定义 9 个 internal/runtime 接口的完整协议:Poll/Lock/Heartbeat/Snapshot/
Credential Resolve/Result/Fail/InvocationLog/Health。新增 RuntimeInternalDto
类型文件,复用 InternalAuthGuard 鉴权,与 Rust 侧可直接对齐。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-11 20:35:20 +08:00