e15e3b455f
Project CI / Repository checks (push) Successful in 3m12s
Project CI / Frontend tests (push) Successful in 3m21s
Project CI / Backend tests (push) Successful in 7m42s
Project CI / Native shell tests (push) Successful in 20m14s
Project CI / Frontend tests (pull_request) Successful in 50m43s
Project CI / Repository checks (pull_request) Successful in 20m21s
Project CI / Backend tests (pull_request) Successful in 6m18s
Project CI / Native shell tests (pull_request) Successful in 18m19s
## 背景与问题 AGC(AI 游戏创作智能体 App)Direct Codex 模式在携带图片工具结果等大上下文调用 LLM 时,`/api/llm/responses` 与 `/api/llm/chat/completions` 会命中 Axum 默认 **2 MiB** 请求体上限,直接被 413 拒绝,大上下文任务无法执行;同时 Codex app-server 的 failed turn 未把上游 413 映射为稳定错误分类,前端只能显示笼统的“其他错误”,无法引导用户处理。 ## 改动内容 **1. api-server(server-rs)** - 新增常量 `LLM_REQUEST_MAX_BODY_BYTES = 32 MiB`,作为两个 LLM 代理路由的正式请求体上限; - 两个路由显式配置 `DefaultBodyLimit::max(32 MiB)`,避免 Axum 默认 2 MiB 提前拒绝;handler 内保留超限检查,超过 32 MiB 仍返回 `413 PAYLOAD_TOO_LARGE`; - 补充回归测试:>2 MiB 大上下文请求不再命中默认限制;超过 32 MiB 仍返回 413。 **2. AGC 壳(apps/ai-game-creator-shell)** - `codex_app_server` 错误映射:上游/连接层 HTTP 413、`PAYLOAD_TOO_LARGE`、`provider request too large` 等统一映射为稳定分类 `codex-app-server-error:request-too-large`,不再落入 `other` 或误判为权限/安全策略错误; - 前端新增用户可见文案“模型请求体过大,请减少参考图或上下文后重试”,并补充单测断言。 **3. 文档** - 【技术方案】AI游戏创作智能体App实施计划-2026-06-24.md 补充“2026-09-06 AGC LLM 代理请求体合同”:明确 32 MiB 上限、必须显式配置 `DefaultBodyLimit`、413 映射规则与用户文案。 ## 验证 - `cargo test -p api-server llm_routes_accept_large_context_bodies_beyond_axum_default` 通过 - `cargo test -p api-server llm_responses_rejects_bodies_above_explicit_limit` 通过 - `cargo test ... ai-game-creator-shell ... codex_app_server_failed_turn_maps_request_too_large_details` 通过 - `npm run test -- apps/ai-game-creator-shell/tests/agentRuntimeModel.test.ts`(27 通过) 全量 workspace 测试与 CI 门禁待推送后由 CI 覆盖。 Reviewed-on: #295 Reviewed-by: 段舒康 <kdletters@qq.com> Co-authored-by: 董羽秦 <suzmii@qq.com> Co-committed-by: 董羽秦 <suzmii@qq.com>
server-rs 工作区说明
更新时间:2026-05-15
server-rs/ 是当前唯一后端工作区,承载 Rust api-server、SpacetimeDB module、领域模块、平台副作用适配和共享契约。旧 server-node、Express、PostgreSQL、Go 服务端和 maincloud 口径均为历史残留,不再作为当前实现目标。
当前职责
crates/api-server:Axum HTTP / SSE / BFF 门面、鉴权、中间件、外部服务编排和 DTO 映射。crates/spacetime-module:SpacetimeDB 表、reducer、procedure、事务 adapter、row mapper 和迁移。crates/spacetime-client:后端访问 SpacetimeDB 的 typed facade。crates/module-*:领域模型、命令、应用规则、领域事件和领域错误。crates/platform-*:OSS、LLM、语音、认证等外部平台能力。crates/shared-contracts:前后端共享 DTO 与公开契约。crates/shared-kernel、crates/shared-logging、crates/tests-support:跨模块基础能力、日志和测试支撑。
开发规则
server-rs/Cargo.toml是 workspace 成员和依赖版本事实源;第三方依赖和 workspace 内 crate path 优先放在[workspace.dependencies]。module-*不直接依赖 Axum、SpacetimeDB table/reducer/procedure、reqwest、OSS、LLM、spacetime-client、tokio或文件系统。api-server不承接领域真相;发现领域规则时优先沉到对应module-*。- SpacetimeDB schema 变化必须同步
spacetime-module/src/migration.rs、生成绑定和当前后端架构文档的表目录。 - 人工命令、本地联调和文档示例不要使用
spacetime --root-dir。
常用命令
cargo check -p api-server --manifest-path server-rs/Cargo.toml
cargo test -p api-server --manifest-path server-rs/Cargo.toml
npm run check:server-rs-ddd
npm run check:spacetime-schema
npm run spacetime:generate
npm run dev:api-server
涉及 API smoke 时用 npm run dev:api-server 启动后端并检查 /healthz,不要使用旧 api-server:maincloud。
当前文档
- ../docs/【后端架构】server-rs与SpacetimeDB数据契约-2026-05-15.md:DDD 边界、API 分组、schema 变更规则和表目录。
- ../docs/【开发运维】本地开发验证与生产运维-2026-05-15.md:本地启动、检查、SpacetimeDB 操作和生产运维。