Skip to content

capnweb-validate: ignore extra args instead of refusing the call - #227

Merged
teamchong merged 2 commits into
cloudflare:mainfrom
teamchong:ignore-extra-args
Aug 4, 2026
Merged

capnweb-validate: ignore extra args instead of refusing the call#227
teamchong merged 2 commits into
cloudflare:mainfrom
teamchong:ignore-extra-args

Conversation

@teamchong

Copy link
Copy Markdown
Collaborator

validateArgs refused any call carrying more args than the method's declared parameter list. That breaks schema evolution: a caller built against a newer signature cannot pass a new parameter to a peer whose validator was generated from the old one, even though plain JS drops the unused arg.

Before:

// signature: greet(name: string)
stub.greet("bob", { locale: "en" });  // TypeError: refused Api.greet: no extra argument

After:

stub.greet("bob", { locale: "en" });  // extra arg ignored

Declared parameters are still validated, and a rest parameter still validates every extra arg.

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a4e5bfe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
capnweb-validate Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/capnweb@227

commit: a4e5bfe

@teamchong
teamchong force-pushed the ignore-extra-args branch 4 times, most recently from 172f252 to f3aee16 Compare July 31, 2026 18:18
Extra args past a method's declared parameters no longer fail the call: a
newer caller passing a parameter this build's signature doesn't know about is
normal schema evolution in JS/TS.

Ignored means the implementation never sees them. Args past what the spec
declares are dropped before the call, so the impl cannot read a value no
validator checked:

  // spec generated from: greet(name: string)
  greet(name: string, ...rest: unknown[]) { /* rest is always empty */ }

  // spec generated from: sum(label: string, ...values: number[])
  sum(label: string, ...values: number[]) { /* gets every arg, each validated */ }

Truncation only applies when the spec declares its params; a client-side spec
omits `args` entirely, so nothing is dropped there.

@dimitropoulos dimitropoulos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not 100% sold on the premise - but I understand the reasoning. maybe later it can be configurable (strict mode?)

@dimitropoulos
dimitropoulos self-requested a review August 3, 2026 17:46

@dimitropoulos dimitropoulos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's document allowable evolution places (e.g. extra args, extra fields).

Adds a Schema Evolution section to the validate README: which type
changes survive a version skew between peers, that extra object
properties reach the implementation unvalidated while extra arguments
are dropped, and that building without strictNullChecks emits a
validator that refuses null values a strict peer considers valid.
@teamchong
teamchong requested a review from dimitropoulos August 4, 2026 03:21
@teamchong
teamchong merged commit 2b292e4 into cloudflare:main Aug 4, 2026
5 checks passed
@teamchong
teamchong deleted the ignore-extra-args branch August 4, 2026 13:53
@github-actions github-actions Bot mentioned this pull request Aug 4, 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