Skip to content

Make optional Python RPC requests omittable - #2556

Open
kondv wants to merge 1 commit into
github:mainfrom
kondv:dev/kondv/python-get-quota-optional
Open

Make optional Python RPC requests omittable#2556
kondv wants to merge 1 commit into
github:mainfrom
kondv:dev/kondv/python-get-quota-optional

Conversation

@kondv

@kondv kondv commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #1946

Summary

Generate optional Python RPC request parameters when the original JSON Schema accepts the caller omitting the request object.

Optionality is evaluated against the original draft-2019-09 schema before codegen normalization, including references, Boolean schemas, combinators, property-count constraints, and injected session fields. Required nullable fields remain required, and explicitly supplied None values are preserved as JSON null. The generated Python API and quota documentation are updated accordingly.

Validation

  • Deterministic Python generation
  • Python codegen tests: 11/11
  • Generated RPC tests: 13/13
  • ESLint, TypeScript typecheck, Ruff, and ty
  • Built wheel and sdist, then installed the wheel into a fresh CFS-only virtual environment outside the repository
  • Verified imports resolved from the installed package
  • Real Copilot CLI 1.0.83 validation over stdio and in-process transports:
    • get_quota() succeeded without an argument
    • required methods rejected omission
    • required nullable subagents=None crossed the RPC boundary as JSON null
    • child and in-process runtimes shut down cleanly

@kondv
kondv requested a review from a team as a code owner September 7, 2026 05:17
Copilot AI balanced review requested due to automatic review settings September 7, 2026 05:17

Copilot AI 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.

🟡 Changes recommended

Two moderate required-null handling issues remain unresolved in Python code generation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Enables omission of Python RPC request objects when allowed by the original schema while preserving required nullable fields.

Changes:

  • Adds draft-2019-09 schema validation for request optionality.
  • Regenerates Python RPC APIs and adds regression tests.
  • Updates dependencies and quota documentation.
File summaries
File Review
scripts/codegen/python.ts Two moderate issues: required nulls are dropped in optional session requests, and required opaque-JSON fields remain optional.
scripts/codegen/package.json Adds AJV dependency.
scripts/codegen/package-lock.json Locks codegen dependencies.
python/test_rpc_generated.py Adds generated signature and serialization tests.
python/copilot/generated/rpc.py Updates generated Python RPC models and methods.
nodejs/test/python-codegen.test.ts Tests schema evaluation and code generation.
nodejs/package.json Adds AJV for codegen tests.
nodejs/package-lock.json Locks test dependencies.
docs/features/usage-and-billing.md Documents argument-free quota retrieval.
Review details

Files not reviewed (2)

  • nodejs/package-lock.json: Generated file
  • scripts/codegen/package-lock.json: Generated file

Suppressed comments (1)

scripts/codegen/python.ts:3957

  • The server-method path has the same optional-wrapper/required-nullable interaction: filtering None here drops a required field when the request object is supplied explicitly. Select params.to_dict() when preserveRequiredNulls is true, while retaining {} for an omitted request.
            if (paramsOptional) {
                lines.push(`        params_dict = {k: v for k, v in params.to_dict().items() if v is not None} if params is not None else {}`);
            } else if (preserveRequiredNulls) {
                lines.push(`        params_dict = params.to_dict()`);
  • Files reviewed: 6/9 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/codegen/python.ts
Comment on lines +3220 to 3224
if (requiredNullableFields.size > 0) {
requiredNullableRequestFieldsByClass.set(
paramsTypeName,
new Set([...requiredNullableFields].map(toSnakeCase))
);
Comment thread scripts/codegen/python.ts
Comment on lines 3940 to 3945
if (paramsOptional) {
lines.push(` params_dict: dict[str, Any] = {k: v for k, v in params.to_dict().items() if v is not None} if params is not None else {}`);
} else if (preserveRequiredNulls) {
lines.push(` params_dict: dict[str, Any] = params.to_dict()`);
} else {
lines.push(` params_dict: dict[str, Any] = {k: v for k, v in params.to_dict().items() if v is not None}`);
@kondv
kondv force-pushed the dev/kondv/python-get-quota-optional branch from eb61822 to fd63cf1 Compare September 7, 2026 12:45
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.

What 's the new usage of get_quota?

2 participants