Use z.strictObject for protocol schemas - #2434
Merged
Merged
Conversation
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Architecture diagram
sequenceDiagram
participant Client
participant ClientSDK as Client SDK (TypeScript)
participant Protocol as Protocol Schemas (z.strictObject)
participant JSONSchema as JSON Schema Validation (Python)
participant Server as Stagehand Server
participant LLMProvider as LLM Provider
participant Runtime as Browser Runtime
Note over Client,Server: RPC Call Flow (e.g., stagehandAct)
Client->>ClientSDK: act(input, options)
ClientSDK->>ClientSDK: Merge with client-specific options (page)
ClientSDK->>Protocol: parse(StagehandClientActOptionsSchema) -> NEW: strict object rejects unknown keys
alt Extra field (e.g., "tiemout")
Protocol-->>ClientSDK: ZodError: unknown field
ClientSDK-->>Client: throw validation error
else Known fields
Protocol-->>ClientSDK: validated options
ClientSDK->>Server: JSON-RPC request with validated params
Server->>Protocol: parse(StagehandActParamsSchema) -> NEW: strict object rejects unknown keys
alt Extra field in options
Protocol-->>Server: ZodError
Server-->>ClientSDK: JSON-RPC error response
else Valid
Protocol-->>Server: parsed params
Server->>LLMProvider: generate() with parsed messages/tools
Note over LLMProvider: LLMGenerateResult schema now rejects extra fields (e.g., providerMetadata)
LLMProvider-->>Server: LLM generate result
Server->>Protocol: parse(LLMGenerateResultSchema) -> NEW: strict object, no .catchall()
alt Contains unknown keys (e.g., providerMetadata)
Protocol-->>Server: rejection
Server-->>ClientSDK: error
else Valid
Protocol-->>Server: parsed result
Server-->>ClientSDK: success response
end
end
end
Note over Runtime,Protocol: Runtime Descriptor Negotiation
Server->>Runtime: evaluate("__stagehand_runtimeMarker")
Runtime-->>Server: descriptor object
Server->>Protocol: parse(RuntimeDescriptorSchema) -> NEW: strict, rejects unknown fields (e.g., "status")
alt Unknown field present
Protocol-->>Server: rejection
Server-->>ClientSDK: unreadable marker -> negotiation fails
else Known fields only
Protocol-->>Server: parsed descriptor
Server-->>ClientSDK: compatible marker
end
Note over Client,Server: PageLocator serialization
ClientSDK->>Protocol: serialize(PageLocatorSchema) -> NEW: strict, rejects stale handles (page, frame, element)
alt Contains stale handle
Protocol-->>ClientSDK: error
else Valid
Protocol-->>ClientSDK: strict PageLocator
ClientSDK->>Server: locator in request
end
Note over JSONSchema,Python: Python SDK disallows extras
Client->>JSONSchema: parse with Pydantic (extra="forbid") -> NEW: rejects unknown fields at runtime
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
monadoid
force-pushed
the
simplify-acknowledgement-results
branch
from
July 27, 2026 15:34
169d61b to
e1ed7c8
Compare
monadoid
force-pushed
the
use-strict-object
branch
from
July 27, 2026 15:34
8a390fb to
5f683c0
Compare
monadoid
force-pushed
the
simplify-acknowledgement-results
branch
from
July 27, 2026 15:35
e1ed7c8 to
dab7665
Compare
monadoid
force-pushed
the
use-strict-object
branch
from
July 27, 2026 15:35
5f683c0 to
ad27e80
Compare
seanmcguire12
approved these changes
Jul 27, 2026
monadoid
force-pushed
the
use-strict-object
branch
from
July 28, 2026 11:03
ad27e80 to
dbea4f1
Compare
monadoid
changed the base branch from
simplify-acknowledgement-results
to
v4-spike
July 28, 2026 11:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packages/protocol/schemas.tsto usez.strictObjectz.json()andz.record()fields.unwrap()callsSummary by cubic
Make all protocol and SDK schemas strict. Unknown fields now error across the wire and in both SDKs, reducing typos and hidden bugs.
Refactors
z.strictObject(); removed.strict(),.loose(),.passthrough(), and.catchall().additionalProperties: false(e.g., LLM results, Browserbase configs, proxy configs).providerMetadata) are rejected. Tests updated.RuntimeDescriptorSchemaandPageLocatorSchemaare strict; unknown fields and stale locator handles now error.optionsare optional at call sites (act/observe/extract, page methods); typos in options fail tests.CdpBrowserSourceSchemausesz.strictObject; client options extend protocol options.extra="forbid"(including LLM results) to disallow unknown fields.rules/ast-grep/protocol-schema-strictness.test.tsto enforcez.strictObjectin protocol schemas.packages/evals(CLI, datasets, core tools); targetsstagehand-v3and is wired into workspace checks without changing v4 runtime.previewlabel builds the TS package tarball, Python wheel, and extension ZIP as one artifact (no version bumps or releases). README andjust _previewadded;oxlintoverride allows console inpackages/evals; repocheckcompilespackages/evals.stagehand-v4withstagehandin v4 install and AI‑rules examples.Migration
page,frame,element) inPageLocator.protocolVersion,serverInfo,status).Written for commit dbea4f1. Summary will update on new commits.