Repository navigation
fix(codegen): keep an args parameter when no model can be named - #403
Conversation
`argsType === undefined` meant two different things and every non-JVM target read it as one: "this function takes no arguments". But it is also what a function gets when its arguments cannot be typed — a `v.bigint()`/`v.bytes()` schema is refused a model deliberately, and a backend that cannot name a shape leaves it undeclared. So Go, Python, Ruby, Rust and Swift emitted those methods with NO parameter and a hardcoded empty payload, making them uncallable with arguments at all — while the CLI told the user their "parameters stay untyped, so pass wire values directly", through a parameter that did not exist. The JVM targets always kept one, which is how the asymmetry surfaced. `SdkMethod` gains `takesArgs`, so the three cases are distinct: a typed parameter when a model was named, an untyped wire-shaped one when arguments exist but cannot be typed, and none at all when there are none. `argsChoice` in `spec.ts` names that decision once rather than leaving each of seven targets to re-derive it — collapsing the middle case is the whole bug, and it is easier to make in a conditional than in a named branch. The `typed` branch is a callback so the narrowed `argsType` is passed in; a record literal evaluates all three and leaves `string | undefined` in a template. Verified by reverting python and go to the old two-way branch: the new test fails for exactly those two and passes when restored. All seven still generate, compile and run a call from a scratch directory outside the repo. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AyG8dyPFieGYzRd7y1MMme
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for following the naming conventions! 🙏 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe SDK specification now records whether methods accept arguments without typed models. Go, Python, Ruby, Rust, and Swift generators preserve untyped arguments for RPC calls and query subscriptions. ChangesUntyped SDK argument handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant MethodSchema
participant parseMethod
participant argsChoice
participant SDKGenerator
participant GeneratedSDK
MethodSchema->>parseMethod: parse argument schema
parseMethod->>argsChoice: provide argsType and takesArgs
argsChoice->>SDKGenerator: select typed, untyped, or absent representation
SDKGenerator->>GeneratedSDK: generate call or subscription signature
GeneratedSDK->>GeneratedSDK: encode typed arguments or forward untyped arguments
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/codegen/src/sdk/targets/python.ts (1)
100-121: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winImport
Anyfor untyped arguments.Lines 100 and 121 emit
args: Any. TheneedsAnycondition only checksresultType. If all results are typed but one method has untyped arguments, generatedapi.pyomitsAnyfromtyping.Include
method.takesArgs && method.argsType === undefinedinneedsAny.Proposed fix
-const needsAny = allMethods(namespaces).some((method) => method.resultType === undefined); +const needsAny = allMethods(namespaces).some( + (method) => method.resultType === undefined || (method.takesArgs && method.argsType === undefined), +);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/codegen/src/sdk/targets/python.ts` around lines 100 - 121, Update the needsAny calculation in the Python SDK renderer to also return true when a method has arguments but method.argsType is undefined, covering the args: Any emitted by render methods such as renderSubscribe. Preserve the existing resultType check and ensure the generated api.py imports Any whenever either untyped arguments or untyped results are present.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/codegen/src/sdk/targets/rust.ts`:
- Around line 149-153: Update the untyped payload selection in
packages/codegen/src/sdk/targets/rust.ts lines 149-153 to forward the provided
args for methods with takesArgs === true, while retaining the empty WireValue
object only for no-argument methods. Apply the same selection in
packages/codegen/src/sdk/targets/rust.ts line 186 for subscriptions, preserving
the ownership required by Client::subscribe.
---
Outside diff comments:
In `@packages/codegen/src/sdk/targets/python.ts`:
- Around line 100-121: Update the needsAny calculation in the Python SDK
renderer to also return true when a method has arguments but method.argsType is
undefined, covering the args: Any emitted by render methods such as
renderSubscribe. Preserve the existing resultType check and ensure the generated
api.py imports Any whenever either untyped arguments or untyped results are
present.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c617bd57-6f9c-4557-a09b-f7a9b545fc8f
⛔ Files ignored due to path filters (2)
api-snapshots/codegen.api.mdis excluded by none and included by nonepackages/codegen/__tests__/sdk-targets.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**
📒 Files selected for processing (6)
packages/codegen/src/sdk/spec.tspackages/codegen/src/sdk/targets/go.tspackages/codegen/src/sdk/targets/python.tspackages/codegen/src/sdk/targets/ruby.tspackages/codegen/src/sdk/targets/rust.tspackages/codegen/src/sdk/targets/swift.ts
The previous commit gave Rust an untyped `args: &WireValue` parameter but left the
PAYLOAD branching on `argsType`, so the generated method accepted the argument and
sent `&WireValue::Object(Vec::new())` — silently discarding it.
That is worse than the bug it replaced. Before, passing arguments to such a
function was a compile error; after, it compiled and did nothing, so a caller had
no way to notice their arguments never reached the wire.
`Client::subscribe` takes the args by value while `call` takes a reference, so the
untyped arms are `args` and `args.clone()` respectively.
The test missed it because it asserted the ABSENCE of empty-payload spellings and
enumerated `{}` and `nil` — Rust spells its empty payload a third way. Rewritten to
assert positively that the call line forwards `args`, which cannot be defeated by a
spelling it did not anticipate. Verified by reinstating the discarding payload: the
test fails for rust alone, and passes when restored.
Compiling the untyped arms needs a spec that has them, which the committed fixture
does not, so that was checked separately — a two-function `v.bigint()` spec builds
clean, including the clone.
Found in review on #403.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AyG8dyPFieGYzRd7y1MMme
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #403 +/- ##
==========================================
- Coverage 87.09% 87.06% -0.03%
==========================================
Files 1172 1197 +25
Lines 63383 64917 +1534
Branches 15447 16010 +563
==========================================
+ Hits 55202 56520 +1318
- Misses 7654 7857 +203
- Partials 527 540 +13
🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 10.2%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | baseline (Object.keys + toInternal + path spread per field) |
71.9 µs | 65.2 µs | +10.2% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/sdk-untyped-args (276a903) with alpha (5126a91)2
Footnotes
-
10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
alpha(b3e29e5) during the generation of this report, so 5126a91 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
argsType === undefinedmeant two different things, and every non-JVM target read it as one: "this function takes no arguments."It is also what a function gets when its arguments cannot be typed — a
v.bigint()/v.bytes()schema is refused a model deliberately (a typed field would send a plain number where the wire needs the tagged form), and a backend that cannot name a shape leaves it undeclared.So Go, Python, Ruby, Rust and Swift emitted those methods with no parameter and a hardcoded empty payload:
Meanwhile the CLI told the user their "parameters stay untyped, so pass wire values directly" — through a parameter that did not exist. The JVM targets always kept one, which is how the asymmetry surfaced.
The change
SdkMethodgainstakesArgs, so the three cases are finally distinct:args: MessagesListArgs)args: Any,args any,args: &WireValue, …)argsChoiceinspec.tsnames that decision once instead of leaving seven targets to re-derive it — collapsing the middle case into the last is the entire bug, and it is much easier to make in an inline conditional than in a named branch. Itstypedarm is a callback so the narrowedargsTypeis passed in; a record literal evaluates all three arms and leavesstring | undefinedin a template expression.Verification
Reverted Python and Go to the old two-way branch — the new test fails for exactly those two and passes when restored:
All seven SDKs still generate, compile and run a call from a scratch directory outside the repo. 125 SDK codegen tests, conformance 7/7, lint 7/7,
api:checkgreen after a one-line snapshot update (takesArgs: boolean).Found while closing the JVM typed-models gap in #393.
Summary by CodeRabbit