Skip to content

feat(core,ops,bindings): RFC-0049 compact GenerateTextResult wire, IncludeOptions, and 7-language accessors - #539

Merged
eric8810 merged 1 commit into
arcships:masterfrom
cunninghamcard-bit:perf/rfc-0049-0050-breaking-v07
Nov 27, 2026
Merged

eric8810 merged 1 commit into
arcships:masterfrom
cunninghamcard-bit:perf/rfc-0049-0050-breaking-v07

Conversation

@cunninghamcard-bit

@cunninghamcard-bit cunninghamcard-bit commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Rebased cleanly onto master (f4b208253, post-#538, v0.7.0 #546, #537, and #517) as a single standalone commit (4e062e24f).

Target release: 0.8.0 (pre-1.0 breaking wire change; documented under CHANGELOG.md ## [Unreleased]).
abiVersion compatibility: AIMUX_ABI_VERSION remains 65536 (1.0) because the 16 exported C ABI function signatures, memory ownership rules, and error/stream calling conventions are unchanged. Wire payload and schema compatibility are enforced at handshake time by AIMUX_MANIFEST_DIGEST (6914772fdc03df08cba497def41cb354fe52e40eba49844a66938b4cd38c5d83) so mismatched native libraries and bindings fail fast on load.

Summary

Breaking wire and schema changes from RFC-0049:

  1. Compact GenerateTextResult wire format with lossless 3-state output encoding:
    • text.generate, text.consume, toolRepair.applyResult, and language-model replay.live serialize only the wire facts (steps, totalUsage, optional output, and optional outputParsed) instead of duplicating text, content, reasoning, files, sources, toolCalls, toolResults, warnings, request, response, and responseMessages at the top level.
    • Three output states on the wire:
      • OutputState::PlainText (hot path): output omitted, outputParsed omitted — zero duplicate bytes; Rust and all 7 bindings expose the final step's derived text.
      • OutputState::Parsed(value) (including JSON null): output key present ("output": null preserved); Rust and all 7 bindings expose the exact parsed value.
      • OutputState::NotParsed (e.g., final tool-calls step without an output spec, or failed streamed parse): output omitted and "outputParsed": false; Rust round-trips back to OutputState::NotParsed (result.output() -> Err(NoOutputGenerated)), and all 7 bindings expose absent output (undefined in Node, None in Python, nil in Go, null + hasOutput() == false in Java/Kotlin, Field.absent() in Dart, .missing in Swift).
      • Contradictory wire objects carrying both output and outputParsed: false are rejected across Rust and all 7 bindings.
    • GenerateTextResult provides derived methods in Rust (aimux-core) and generated accessors across all 7 language bindings.
  2. IncludeOptions body opt-in (default false):
    • include.requestBody and include.responseBody default to false (including when include is omitted), eliminating large body round-trips across FFI unless opted in.
    • Adds StreamResponseInfo.body so streamed responses can opt into returning response bodies when supplied by the model.
    • Trace fingerprints and recording capture retain full request body access.
  3. Manifest snapshot, schema, DTO vectors, and migration docs:
    • Refreshes embedded snapshot aimux-ops/src/manifest.json.zlib, aimux-ops/src/manifest.digest, schema/manifest.json, and all 7 bindings to 6914772fdc03df08cba497def41cb354fe52e40eba49844a66938b4cd38c5d83 (aimux-codegen --check: 680 files in sync, preserving #517 per-type schema hashes and closed-type checks).
    • Adds IncludeOptions schema and DTO contract vectors (273 vectors total, including GenerateTextResult/001.json plain text, 002.json parsed null, and 003.json outputParsed: false).
    • Documents the compact wire field derivation table under CHANGELOG.md ## [Unreleased] (preserving #537 and leaving ## [0.7.0] untouched) and docs/upgrading-to-ops-abi.md.
    • Enables the Stage 2 request-200k-no-bodies wire-size contract check in .github/workflows/ci.yml.
  4. Release profile hygiene (opt-level = "z" preserved):
    • Root [profile.release] remains opt-level = "z" and workspace Cargo.toml stays version = "0.7.0".

Verification (on 4e062e24f / base f4b208253)

  • cargo fmt --all -- --check: PASS
  • cargo run -p aimux-codegen -- --check: PASS (680 generated files, digest 6914772fdc03df08cba497def41cb354fe52e40eba49844a66938b4cd38c5d83)
  • cargo clippy -p aimux-ops -p aimux-ffi --no-default-features --all-targets -- -D warnings: PASS
  • cargo test -p aimux-ops --no-default-features: PASS
  • cargo test -p aimux-ops -p aimux-codegen: PASS
  • C/C++: header parity (aimux.h == aimux_ops.h) + scripts/test-c-abi.sh --asan-compile-only: PASS (4/4)
  • Go: ./bindings/go/test-abi.sh -count=1, ./bindings/go/test-native.sh -count=1 (-race), check_dto_vectors.py go (273/273 vectors): PASS
  • Node: npm run build:typed, node --experimental-strip-types --test __test__/dto.test.ts __test__/facade.test.ts (29/29), check_dto_vectors.py node (273/273 vectors): PASS
  • Python (3.12): check_dto_vectors.py python (273/273 vectors), pytest bindings/python/tests/test_dto_types.py (5/5): PASS

@cunninghamcard-bit
cunninghamcard-bit force-pushed the perf/rfc-0049-0050-breaking-v07 branch from 3aab9c3 to cd1a179 Compare November 25, 2026 03:11
@cunninghamcard-bit
cunninghamcard-bit marked this pull request as ready for review November 25, 2026 03:11
@cunninghamcard-bit cunninghamcard-bit changed the title feat(core,ops,bindings): [Stacked on #538] RFC-0049 0.7.0 compact GenerateTextResult wire and 7-language accessors feat(core,ops,bindings): RFC-0049 compact GenerateTextResult wire, IncludeOptions, and 7-language accessors Nov 25, 2026

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CD1A179B 复审。compact wire 本身做得扎实:我用同一组 scripted 调用在 base/head 做了差分,12 个 Rust 派生访问器逐字节一致,7 个 binding 的派生规则一致,trace fingerprint 在 body 剥离前计算所以安全,include 默认 false 对直接 Rust 调用无回归,codegen --check 在 head 通过,CI 22/22 绿。

[P2] output 在 Rust 和所有 binding 之间语义不一致,且相对 0.7.0 是静默变化。 对未解析结果(如 finishReason: tool-calls、无 output spec),compact wire 没有 output key。实测:原生 Rust result.output() → Err(NoOutputGenerated);但 TryFrom 把 absent 映射成 PlainText(step.text())(generate.rs:588-595),wire 往返后 Rust 返回 Ok(text);7 个 binding 全部返回 Ok(text)。0.7.0 时旧 wire 文档明确 output "Absent when the output was not parsed",binding 返回 undefined;现在变成文本字符串。Swift 测试 WireTests.swift 甚至把这个行为固化了(finishReason tool-calls + 无 output → .value(.string("hello"))),但 CHANGELOG 只说"Otherwise use the derived text",没说这与 Rust 不一致。请二选一:在 wire 上区分 NotParsed(例如 output: null 保留语义,或加标志),或者显式文档化 Rust/binding 的分歧并修正 output() 的 rustdoc。

[必须] rebase。 #537 已合入,现在 CONFLICTING。我在 scratch 里 cherry-pick 验证过:真实冲突只有 CHANGELOG.md(两边 Breaking 块都保留),manifest.rs/generated-files.json 自动合并;但 #537 后 manifest 走嵌入式快照,rebase 后 codegen --check 会因 manifest.digest / manifest.json.zlib 过期而失败——重跑 codegen 即可,digest 仍是 2b2e518b… 所以 binding 常量和 manifest.rs:294-297 的断言都不用改。

非阻塞:generate.rs:166 rustdoc 仍说 "Both are included by default",实际默认 false;PR 没写目标版本(这是 breaking wire,按 pre-1.0 规则应是 0.8.0),abiVersion 未 bump 是否合适请明确。

@cunninghamcard-bit
cunninghamcard-bit force-pushed the perf/rfc-0049-0050-breaking-v07 branch from cd1a179 to ebbfae6 Compare November 26, 2026 11:58
@cunninghamcard-bit

Copy link
Copy Markdown
Contributor Author

@eric8810 Thanks for the thorough review! All items have been addressed in ebbfae68d:

  1. [P2] Lossless NotParsed vs PlainText vs Parsed(null) wire encoding:
    • Added optional "outputParsed": false to GenerateTextResultWire (emitted only for OutputState::NotParsed / failed streamed parse; omitted on the PlainText hot path so zero bytes are added to normal text responses — request-200k-no-bodies stays at 101,326 B).
    • Three states are now unambiguous and 100% consistent across native Rust, wire round-trip, and all 7 language bindings:
      • PlainText: output omitted, outputParsed omitted -> derived text.
      • Parsed(value) (including Parsed(Value::Null)): output key present ("output": null kept) -> exact parsed value.
      • NotParsed: output omitted, "outputParsed": false -> Rust TryFrom restores OutputState::NotParsed (result.output() returns Err(NoOutputGenerated)), and all 7 bindings return absent output (undefined in Node, None in Python, nil in Go, null with hasOutput() == false in Java/Kotlin, Field.absent() in Dart, .missing in Swift).
    • Providing both output and outputParsed: false is rejected in Rust and all 7 bindings.
    • Added DTO contract vector contract-tests/dto/GenerateTextResult/003.json (246 total), fixed bindings/swift/Tests/AimuxTests/WireTests.swift (tool-calls fixture now carries "outputParsed": false and asserts original.output == .missing), and added tri-state + contradictory tests across Rust, Node (including a native end-to-end tool_calls test), Python, Go, Java, Flutter, and Swift. Updated CHANGELOG.md and docs/upgrading-to-ops-abi.md.
  2. [Rebase + #537 snapshot]:
    • Rebased cleanly onto origin/master (6c2954e9a), keeping both #537 and RFC-0049 Breaking entries under ## [Unreleased] (without touching ## [0.7.0]).
    • Re-ran cargo run -p aimux-codegen to refresh aimux-ops/src/manifest.json.zlib, aimux-ops/src/manifest.digest, and all 678 generated files (new digest 2f8a4b75a02f46fa1822db74c2368c5958cf5f7878515034207d918eb7db93a8 due to the new outputParsed field). Verified aimux-codegen --check and cargo clippy/test -p aimux-ops --no-default-features pass.
  3. [Non-blocking items]:
    • Fixed aimux-core/src/generate.rs:166 rustdoc (Both default to false).
    • Clarified in the PR body that this breaking wire change targets 0.8.0 (pre-1.0 SemVer).
    • AIMUX_ABI_VERSION intentionally stays 65536 because the 16 C ABI export signatures, ownership rules, and calling conventions are unchanged; breaking wire/schema changes are gated at runtime handshake by AIMUX_MANIFEST_DIGEST (so mismatched native binaries and bindings fail fast on load).

Local gates (fmt, codegen --check, aimux-ops --no-default-features clippy/test, workspace clippy -D warnings, Rust core/ops/ffi/codegen tests, Go ABI + native -race + 246 DTO vectors, Node typed + 246 DTO + native 55/55 + request-200k-no-bodies/stream-burst, Python 3.12 246 DTO + tri-state checks, C ABI compile-only) are all green. Ready for re-review!

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ebbfae6 复审。

outputParsed 方案通过。 三态编码(PlainText / Parsed 含 null / NotParsed)在 Rust 侧正确;我用同一 scripted 调用在 6c2954e 和 ebbfae6 做了差分,stop、tool-calls、结构化输出三个 case 原生 Rust output() 与 wire 往返一致;output + outputParsed:false 矛盾输入在 Rust 和 Node/Python/Go/Java/Dart/Swift 六个生成路径都被拒绝(Kotlin 复用 Java);codegen --check 通过,2f8a4b75… 是真实派生的 digest;[0.7.0] 段未碰,版本号未动。rustdoc、0.8.0 目标、abiVersion 说明也都补了。

[P2] CI 的 Java 失败是真失败,且与 JDK 版本无关。 MultimodalTypesTest > generateTextResultOutputStates() 在 JDK 8 红,但我在 JDK 17 上复现了同样的失败——"Java passes locally" 应该是跑的不是这个状态。

根因在测试 fixture,不在 outputParsed 逻辑:roundTrip 第 22 行做 valueToTree(readValue(encoded)) 等于 readTree(encoded) 的严格比较,而 StepResultPerformance 的四个字段是 BigDecimal,fixture 里写的是整数 0。valueToTree 给 DecimalNode,readTree(开了 USE_BIG_INTEGER_FOR_INTS)给 BigIntegerNode,DecimalNode(0).equals(BigIntegerNode(0)) 为 false。第一个 case(plain,第 40 行调用)就挂在这。

把 bindings/java/src/test/.../MultimodalTypesTest.java fixture 里 performance 的 0 改成 0.0(和 contract-tests/dto/GenerateTextResult/003.json 里 12.0 / 60.0 / 260.0 的写法一致,那个就是对的)三个 case 全过。改完 CI 绿我就 approve。

非阻塞:这个测试只覆盖 JDK 8 跑失败就 skip 后面的设计,让"JDK 8 红"看起来像 JDK 问题;CI 的 Java tests (JDK 11/17/21) 是 skipped 而不是独立跑,建议改成不受前一个 JDK 结果影响,否则下次还会误判。

@eric8810

Copy link
Copy Markdown
Contributor

补一句:#517 刚合入 master(f4b20825),两边都改了 manifest 快照,这个 PR 现在 CONFLICTING。修完 Java fixture 后 rebase 时需要重跑 codegen 刷新 manifest.digest / manifest.json.zlib,新 digest 会同时包含 #517 的 schemaHash/sources 和你的 outputParsed,各 binding 的 MANIFEST_DIGEST 跟着更新。

@cunninghamcard-bit
cunninghamcard-bit force-pushed the perf/rfc-0049-0050-breaking-v07 branch from ebbfae6 to 4e062e2 Compare November 27, 2026 03:42
@cunninghamcard-bit

Copy link
Copy Markdown
Contributor Author

@eric8810 Thanks for the review! Both items are done in 4e062e24f:

  1. Java test fixture: Updated the four StepResultPerformance fields in MultimodalTypesTest.generateTextResultOutputStates() from 0 to 0.0 so Jackson's DecimalNode round-trip equality matches cleanly.
  2. Rebase onto master (f4b208253, post-feat(ops): add manifest per-type schema hashes, HandleExhausted checks, and DTO vectors (#274) #517): Rebased cleanly onto #517 (preserving per-type schema hashes, schema/manifest.json, and closed-type validation), kept Cargo.toml version = "0.7.0", root [profile.release] opt-level = "z", and CHANGELOG.md [0.7.0] untouched, and refreshed codegen/snapshot (manifest.digest = 6914772fdc03df08cba497def41cb354fe52e40eba49844a66938b4cd38c5d83, 680 files in sync).

Local Rust (fmt, aimux-codegen --check, --no-default-features clippy/tests, aimux-ops + aimux-codegen tests), C/C++, Go (ABI, -race native, 273/273 DTO vectors), Node (build:typed, 29/29 DTO/facade tests, 273/273 DTO vectors), and Python (273/273 DTO vectors, 5/5 DTO tests) are all green. Ready for approval once CI turns green.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4e062e2 复审通过。Java fixture 四个 StepResultPerformance 字段已改为 0.0,JDK 8 job 绿(17/21 现在也跑了);rebase 到 #517 后 codegen 刷新,manifest.digest = 6914772f… = schema/manifest.json 的 digest/inputHash = 6 个 binding 的 MANIFEST_DIGEST,且已包含 #517 的 schemaHash/sources 和你的 outputParsed;版本号未动,[0.7.0] 段与 master 逐字节一致;20/20 CI 绿。outputParsed 三态方案上一轮已通过差分验证。Approve,合入后进 0.8.0。

非阻塞:CI 的 Java tests (JDK 11/17/21) 仍依赖 JDK 8 先过,建议后续拆成独立 job,避免再出现"JDK 8 红"被误读为 JDK 问题。

@eric8810
eric8810 merged commit f7961f8 into arcships:master Nov 27, 2026
20 checks passed
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