Skip to content

Conversation

@deathbyknowledge
Copy link
Contributor

Fixes #598

Callable methods returning this.state broke stub types because unknown, the default type, didn't satisfy the SerializableReturnValue check in RPCMethod.

Added an IsUnknown helper to allow unknown return types while still rejecting explicitly non-serializable types.

@changeset-bot
Copy link

changeset-bot bot commented Jan 16, 2026

🦋 Changeset detected

Latest commit: 7e0a4cf

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

This PR includes changesets to release 1 package
Name Type
agents 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

@deathbyknowledge deathbyknowledge marked this pull request as ready for review January 16, 2026 10:20
@claude
Copy link

claude bot commented Jan 16, 2026

Claude Code Review

Issue: The IsUnknown helper accepts any types, not just unknown.

In serializable.ts:28-32, the type helper IsUnknown<T> returns true for both unknown AND any:

type IsUnknown<T> = [unknown] extends [T]
  ? [T] extends [unknown]
    ? true
    : false
  : false;

For IsUnknown<any>: both [unknown] extends [any] and [any] extends [unknown] are true, so the result is true.

This allows methods returning any to bypass serialization checks, potentially allowing non-serializable return types to slip through.

Fix: Add an explicit check to exclude any:

type IsUnknown<T> = 0 extends (1 & T)
  ? false  // T is any
  : [unknown] extends [T]
    ? [T] extends [unknown]
      ? true
      : false
    : false;

The 0 extends (1 & T) check is a standard TypeScript pattern that returns true only for any, allowing us to reject it first.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@786

commit: 7e0a4cf

@mattzcarey
Copy link
Contributor

dude you hero

@deathbyknowledge deathbyknowledge merged commit 395f461 into main Jan 16, 2026
6 checks passed
@deathbyknowledge deathbyknowledge deleted the fix-callable-state-return-type branch January 16, 2026 12:01
@github-actions github-actions bot mentioned this pull request Jan 16, 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.

agent.stub types break when callable returns this.state

3 participants