copilot-sdk icon indicating copy to clipboard operation
copilot-sdk copied to clipboard

What 's the new usage of get_quota?

Open zeerd opened this issue 4 months ago • 5 comments

After upgraded:

  • copilot_version from 1.0.12 to 1.0.68
  • copilot_sdk_version from v0.2.2 to v1.0.5

The get_quota fails.

result = await client.rpc.account.get_quota()

failed, and report:

ServerAccountApi.get_quota() missing 1 required positional argument: 'params'

Reference: #1151

zeerd avatar Jul 08 '26 09:07 zeerd

Investigation findings

This is a confirmed bug in the Python SDK v1.0.5.

What I investigated

  • python/copilot/generated/rpc.py — the generated ServerAccountApi.get_quota() signature
  • scripts/codegen/python.ts — the isParamsOptional() function and emitMethod() logic controlling how method signatures are generated
  • python/e2e/test_rpc_e2e.py line 70 — the SDK's own e2e test, which calls get_quota() with no arguments
  • nodejs/src/generated/rpc.ts — the TypeScript equivalent for comparison

Root cause

The Python codegen marks params as required unless the schema uses the Zod optional-params pattern (anyOf: [{ not: {} }, { $ref }]). The account.getQuota schema does not use this pattern, so the generated signature becomes:

async def get_quota(self, params: AccountGetQuotaRequest, *, timeout: float | None = None) -> AccountGetQuotaResult:

However, AccountGetQuotaRequest has only one optional field (git_hub_token: str | None = None), so there is no meaningful scenario where passing params would be required. The SDK's own e2e test (test_rpc_e2e.py, line 70) calls it without any argument:

result = await client.rpc.account.get_quota()

This confirms the no-args form was the intended API design.

Workaround (until fixed)

Import AccountGetQuotaRequest and pass an empty instance:

from copilot.rpc import AccountGetQuotaRequest

result = await client.rpc.account.get_quota(AccountGetQuotaRequest())
# or with a custom token:
result = await client.rpc.account.get_quota(AccountGetQuotaRequest(git_hub_token="your-token"))

Fix needed

The account.getQuota schema should use the optional-params pattern so the codegen produces:

async def get_quota(self, params: AccountGetQuotaRequest | None = None, ...) -> AccountGetQuotaResult:

Generated by Bug Handler for issue #1946 · sonnet46 1.7M · ◷

github-actions[bot] avatar Jul 08 '26 10:07 github-actions[bot]

async def get_quota(self, params: AccountGetQuotaRequest | None = None, ...) -> AccountGetQuotaResult:

Trustinbtc999-hue avatar Jul 09 '26 02:07 Trustinbtc999-hue

async def get_quota(self, params: AccountGetQuotaRequest, *, timeout: float | None = None) -> AccountGetQuotaResult:

Trustinbtc999-hue avatar Jul 09 '26 02:07 Trustinbtc999-hue

The Python generator did carry the optional-request wrapper, but account.getQuota declares its params as a $ref, and the optionality check only inspected the unresolved reference — so the wrapper inside AccountGetQuotaRequest was never seen. #2556 resolves the schema before that check, which fixes the same defect on models.list, plugins.marketplaces.refresh, sessions.list, and sessions.stopRemoteControl too. Verified against the real CLI with wheels installed outside the repo: unpatched main raised missing 1 required positional argument: 'params', the patched wheel returned real quota snapshots, and explicit requests plus required-params methods behaved unchanged.

— kondv's Copilot 🤖

kondv avatar Sep 08 '26 16:09 kondv

Thanks for the detailed original report and investigation. After digging further, I don't think this should be fixed in the Python (or TypeScript) codegen.

account.getQuota's params schema is a $ref to a named type that itself is marked optional, rather than being marked optional at the call/argument position the way most other list-style RPC methods are. Both representations accept identical JSON payloads on the wire, so nothing was ever incorrectly rejecting valid calls — but the current codegen only recognizes the "optional at the argument position" form (which is how e.g. session.agent.list and session.model.list are declared, and those already generate correctly as omittable). Teaching the codegen to also infer omittability by following a $ref to a named type would only be safe as long as that named type is never reused in a context where it should be required — which the schema doesn't guarantee, so we don't want to build that assumption into the generator.

In the meantime, the existing workaround remains correct and supported:

from copilot.rpc import AccountGetQuotaRequest
result = await client.rpc.account.get_quota(AccountGetQuotaRequest())

The right long-term fix is for the account.getQuota (and similarly-shaped) request schemas to declare optionality inline at the parameter position, matching the pattern already used elsewhere. That's a runtime/schema change, not an SDK codegen change, so I'm closing this issue — please reopen or file against the runtime if you'd like to track that schema change specifically.

SteveSandersonMS avatar Sep 10 '26 14:09 SteveSandersonMS