Skip to content

fix(model): reduce stack usage during provider request encoding - #6873

Merged
M4n5ter merged 2 commits into
apache:rust-previewfrom
sunrioa:codex/fix-wire-encoding-stack
Nov 13, 2026
Merged

M4n5ter merged 2 commits into
apache:rust-previewfrom
sunrioa:codex/fix-wire-encoding-stack

Conversation

@sunrioa

@sunrioa sunrioa commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The request encoder's async state can make the surrounding futures large enough to overflow a worker stack. The encoder now owns its pinned heap allocation: emit returns a concrete, statically dispatched future, and the counting, in-memory build and backed encoding paths await it directly. All paths continue to use the existing codec.

Verification

  • 29 maka-model unit tests and 8 integration tests passed on macOS arm64.
  • Target-crate Clippy with warnings denied, formatting and diff checks passed.
  • An isolated dev-build probe completed text and tool/media request preparation plus full wire replay with 512 KiB and 2 MiB thread stacks. Wire bytes, identities and SHA-256 digests matched the original PR, and allocation counts were unchanged. The public prepare_source future remained 2,184 bytes on Rust 1.99.1.
  • The original PR's invalid-image and compaction integration investigation is not independently rerun by this follow-up; the probe is a focused codec check.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex assisted with investigation, implementation, verification, and drafting, including centralizing the heap allocation in emit.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes
  • No
简体中文

编码器的 async state 会增大外层 future,导致工作线程栈溢出。现在由 emit 自己统一在堆上分配 pinned future,计数、内存构建和 backed 编码三个入口直接 await,保留原编码逻辑和静态分发。

macOS arm64 上通过 29 项模型单元测试、8 项集成测试、目标 crate 的 Clippy、格式和 diff 检查。独立 dev probe 在 512 KiB 和 2 MiB 线程栈上完成文本及 tool/media 请求准备和完整 wire replay,输出字节、identity、SHA-256 与原 PR 一致,分配次数不变。此前 invalid-image 和 compaction 的整机联调场景未在这次封装调整中独立重跑。

OpenAI Codex 协助排查、实现、验证和正文起草。

@M4n5ter
M4n5ter merged commit 76adb58 into apache:rust-preview Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants