Skip to content

computer: Declare the exec tool's input without a $ref - #344

Open
scuffi wants to merge 1 commit into
mainfrom
computer/exec-input-object
Open

scuffi wants to merge 1 commit into
mainfrom
computer/exec-input-object

Conversation

@scuffi

@scuffi scuffi commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

The exec tool declares input, for callable backends, as an object of JSON values through a recursive Zod schema. A recursive schema can't be inlined, so z.toJSONSchema() emits it as a $ref into a definitions section, even with reused: "inline":

"input": {
  "type": "object",
  "additionalProperties": { "$ref": "#/definitions/__schema0" }
},
"definitions": { "__schema0": { "anyOf": [ … ] } }

toPiParameters asks for inlined schemas because some providers reject $ref pointers, so the pi tool set sends exactly what it means to avoid. A consumer that hit this rewrote the declaration itself, swapping input for { "type": "object" } and deleting definitions.

This declares input as an object of any values and checks the values with the runtime's own assertRuntimeValue when the call is validated. The tool still refuses, at its own boundary, an input the backend would refuse (NaN, a Date, a function), and the declaration is still a real object schema rather than the empty one that d6cc552 moved away from. The same schema backs the AI SDK, TanStack and pi tool sets.

Testing

exec.test.ts checks that the declaration has no $ref or definitions and that input is an object, and that nested JSON passes while NaN, a Date, a function and an array don't.

The exec tool declared `input` as an object of JSON values through a
recursive schema. A recursive schema can't be inlined, so it
serializes to a `$ref` into a definitions section, which some
providers reject. pi's declarations already ask for schemas to be
inlined for that reason, but this one came out with definitions
anyway, and a consumer had to rewrite the declaration to send it.

Declare `input` as an object of any values, and check that the values
are finite JSON with the runtime's own check when the call is
validated. The tool still refuses a value the backend would refuse,
at its own boundary, and the declaration stays a real object schema.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3931db

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

This PR includes changesets to release 5 packages
Name Type
@cloudflare/computer Patch
@cloudflare/dofs Patch
@cloudflare/computer-rpc Patch
@cloudflare/computerd Patch
@cloudflare/remote-exec 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 Nov 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@344

commit: b3931db

@scuffi
scuffi marked this pull request as ready for review November 27, 2026 10:48

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment on lines +106 to +114
it("declares input as an object, with no definitions to point into", () => {
const json = z.toJSONSchema(defineExec({ workspace: callable }).inputSchema, {
target: "draft-7",
io: "input",
});

expect(JSON.stringify(json)).not.toContain("$ref");
expect(json).not.toHaveProperty("definitions");
expect(json.properties?.input).toMatchObject({ type: "object" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Provider compatibility beyond reference removal

inputObjectSchema removes references but still emits propertyNames and additionalProperties: {}. The reported workaround omitted both, so the schema test does not establish compatibility with that provider.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +21 to +23
const inputObjectSchema = z.record(z.string(), z.unknown()).superRefine((value, context) => {
try {
assertRuntimeValue(value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Undefined fields now pass validation

inputObjectSchema accepts and retains explicitly undefined object fields that the old schema rejected. assertRuntimeValue treats those fields as absent during JSON validation.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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