Skip to content
This repository was archived by the owner on Sep 22, 2026. It is now read-only.

fix(proxy): handle large requests and TUI daemon paths - #3

Merged
CallmeLins merged 6 commits into
CallmeLins:mainfrom
ChangAn-1314:main
Jul 26, 2026
Merged

CallmeLins merged 6 commits into
CallmeLins:mainfrom
ChangAn-1314:main

Conversation

@ChangAn-1314

Copy link
Copy Markdown
Contributor

Summary

  • raise the Axum request body limit from the default 2 MiB to a bounded, configurable limit
  • resolve bin/pi-switch.js from the package root when the native TUI starts a daemon outside the repository directory
  • add a regression test covering model requests larger than Axum's default limit

Problem

Large multimodal requests can exceed Axum's default 2 MiB body limit and fail before reaching the proxy handler with:

413 Failed to buffer the request body: length limit exceeded

Separately, the native TUI starts daemons without a project_dir argument. When pi-switch tui is launched outside the repository, daemon startup falls back to the current working directory and fails with:

pi-switch.js not found at "bin/pi-switch.js"

Changes

  • apply DefaultBodyLimit to the proxy router
  • default to 32 MiB and allow PI_SWITCH_MAX_REQUEST_BODY_MIB values clamped to 4-256 MiB
  • export PI_SWITCH_PROJECT_DIR from the JavaScript entrypoint
  • consult that package root before executable-relative and current-directory fallbacks in the native daemon path resolver
  • enable Tower's util feature for router regression testing
  • format only the Rust modules changed by these fixes, as required by the repository CI

Verification

  • cargo test: 16 passed
  • pnpm build:native
  • node --check bin/pi-switch.js
  • changed-file rustfmt --check
  • CI Rust/WebUI verification
  • CI native builds for Linux GNU, Linux musl, Windows x64, macOS x64, and macOS ARM64

@CallmeLins
CallmeLins merged commit 73258d9 into CallmeLins:main Jul 26, 2026
7 checks passed
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Aug 30, 2026
- Gateway 预览干跑不写盘,发布原子写 models.json + notify_gateway_changed,校验失败 400 且不触 models
- 双向错误隔离:profiles 与 gateway 分属独立 Router,错误不串扰;前端 PanelErrorBoundary 隔离,网关离线不阻断 supplier
- 发布闭环:成功刷新 preview、清 pending、更新 lastPublishAt、消横幅;失败保留 draft 可重试
- 供应商权威:merge_gateway_extra 仅透传未知字段不提权

测试:cargo 304 / webui 183 全绿;typecheck 通过
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Sep 11, 2026
上一轮 review 的 Spec CallmeLins#2/CallmeLins#3 与 Standards CallmeLins#1。

- basicAuthMiddleware 改为由调用方传入本面的 401 信封:管理面仍是
  {"error":"Unauthorized"},/v1 推理面改为 OpenAI
  {"error":{"message":"Unauthorized","type":"invalid_request_error"}},
  补上 system-contract §2.8 唯一未遵守的路径(共享 middleware 此前把管理面
  信封用在了推理面)
- config 删除 rejectNullExposedModels 影子 schema:`exposedModels:null` 的
  拒绝规则移到 Upstream.UnmarshalJSON,字段名只有一个 owner,不再存在
  「字段改名后守卫静默失效」的风险
  取舍:错误信息由 profiles.<name>.upstreams[i].exposedModels 变为
  `profiles: exposedModels must not be null`;仍点名字段(满足 §2.2
  「报出字段错误」),但不再带 profile/index 索引路径
- 测试:/v1 401 断言 OpenAI 信封、管理面 401 断言字符串信封、config 断言
  null 错误点名字段

验证:gofmt -l / go vet 无输出;scripts/test-limited.sh go 全绿。

review-fixes-2
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants