[feat]: expose timeout param in ts & protocol - #3033
seanmcguire12 wants to merge 3 commits into
Conversation
|
There was a problem hiding this comment.
2 issues found across 24 files
Confidence score: 3/5
- In
packages/sdk-python/src/stagehand/_generated/models.py,LocatorFillParamsreferencesLocatorOptionsbefore it is defined, which can leavelocator.fill()validation incomplete; defineLocatorOptionsearlier or rebuild the model afterward. - In
packages/sdk-python/src/stagehand/_generated/models.py, strict-float timeout fields reject ordinary integer values such as0and5000, making the timeout option unusable with common Python inputs; accept strict integers alongside strict floats.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/sdk-python/src/stagehand/_generated/models.py">
<violation number="1" location="packages/sdk-python/src/stagehand/_generated/models.py:1064">
P2: These `StrictFloat` timeout fields reject integer millisecond values such as `0` and `5000`, making the new timeout option unusable with normal Python inputs. Accept strict integers alongside strict floats while retaining the nonnegative constraint.</violation>
<violation number="2" location="packages/sdk-python/src/stagehand/_generated/models.py:1111">
P1: `LocatorFillParams` now references `LocatorOptions` before its definition, leaving this Pydantic model incomplete for `locator.fill()` validation. Define `LocatorOptions` earlier or rebuild `LocatorFillParams` after all generated classes are defined.</violation>
</file>
Architecture diagram
sequenceDiagram
participant TS as TypeScript SDK (Locator)
participant RPC as RPCClient
participant EXT as Extension Runtime
participant ACT as Locator Actions
participant FAC as Playwright Compat Facade
Note over TS,FAC: Locator timeout propagation across all 17 methods
TS->>RPC: send(locator.click, {pageId, selector, options:{timeout}})
Note over RPC: NEW: rpcResponseTimeoutMs = timeout + grace (default 20s + 10s)
Note over RPC: timeout=0 -> no response deadline
RPC->>EXT: JSON-RPC request with LocatorParams
EXT->>EXT: runLocator() starts Progress deadline
Note over EXT: timeout=0 -> Infinity budget
EXT->>ACT: locator.click(options, progress)
ACT->>ACT: frame readiness + element lookup
ACT->>ACT: typing delays / highlight duration
alt Timeout expires
ACT-->>EXT: TimeoutError
EXT-->>RPC: error with name="TimeoutError"
RPC-->>TS: reject TimeoutError (name preserved)
else Operation succeeds
ACT-->>EXT: result
EXT-->>RPC: success response
RPC-->>TS: resolve result
end
Note over FAC,RPC: Compatibility facade forwards remaining budget
FAC->>FAC: withTaggedTarget computes deadline
FAC->>FAC: locatorTimeoutOptions(deadline) = remaining ms
FAC->>RPC: locator.click({timeout: remaining})
Note over FAC: Remaining budget includes frame resolution time
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| page_id: StrictStr | ||
| selector: Annotated[StrictStr, Field(min_length=1)] | ||
| nth: Annotated[Optional[StrictInt], Field(ge=0, le=9007199254740991)] = None | ||
| options: Optional[LocatorOptions] = None |
There was a problem hiding this comment.
P1: LocatorFillParams now references LocatorOptions before its definition, leaving this Pydantic model incomplete for locator.fill() validation. Define LocatorOptions earlier or rebuild LocatorFillParams after all generated classes are defined.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/sdk-python/src/stagehand/_generated/models.py, line 1111:
<comment>`LocatorFillParams` now references `LocatorOptions` before its definition, leaving this Pydantic model incomplete for `locator.fill()` validation. Define `LocatorOptions` earlier or rebuild `LocatorFillParams` after all generated classes are defined.</comment>
<file context>
@@ -1106,6 +1108,7 @@ class LocatorFillParams(WireModel):
page_id: StrictStr
selector: Annotated[StrictStr, Field(min_length=1)]
nth: Annotated[Optional[StrictInt], Field(ge=0, le=9007199254740991)] = None
+ options: Optional[LocatorOptions] = None
value: StrictStr
</file context>
| extra="forbid", | ||
| validate_by_name=True, | ||
| ) | ||
| timeout: Annotated[Optional[StrictFloat], Field(ge=0.0)] = None |
There was a problem hiding this comment.
P2: These StrictFloat timeout fields reject integer millisecond values such as 0 and 5000, making the new timeout option unusable with normal Python inputs. Accept strict integers alongside strict floats while retaining the nonnegative constraint.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/sdk-python/src/stagehand/_generated/models.py, line 1064:
<comment>These `StrictFloat` timeout fields reject integer millisecond values such as `0` and `5000`, making the new timeout option unusable with normal Python inputs. Accept strict integers alongside strict floats while retaining the nonnegative constraint.</comment>
<file context>
@@ -1061,6 +1061,8 @@ class LocatorClickOptions(WireModel):
extra="forbid",
validate_by_name=True,
)
+ timeout: Annotated[Optional[StrictFloat], Field(ge=0.0)] = None
+ """Milliseconds for the whole locator call. Zero disables the timeout."""
button: Optional[MouseButton] = None
</file context>
d88f114 to
bf86ce1
Compare
why
this PR adds the
timeoutparam to the protocol, & exposes it publicly in ts. the default timeout is 20 secondswhat changed
click({ timeout: 5000 }),fill("hello", { timeout: 5000 }), orcount({ timeout: 0 }).test plan
locator-timeouts.test.tschecks every registered locator method accepts zero & positive timeouts, rejects invalid values, preserves omission, & keeps existing options working. timeout settings stay separate from locator identity.runtime-locator-timeouts.test.tsuses controlled time to verify every entry point starts its deadline before resolution, applies the default or override, rejects stalled work, & leaves zero unlimited.iframeLocatorReadiness.test.tsruns against real chrome with same-process frames & frames in a separate process. it verifies nested frame readiness & typing share one budget, explicit timeouts can exceed the old readiness cap, zero waits successfully, & loading a frame after expiry does not cause a late click.locatorActions.test.tsexercises highlight & upload cleanup through the runtime: stalled cleanup preserves an earlier action error & does not delay timeout rejection.Summary by cubic
Adds a
timeoutoption to all 17 terminal locator methods in the protocol and TypeScript SDK. The default is 20 seconds, and{ timeout: 0 }disables the deadline.What changed
0disabling them.TimeoutErrorname and message, and long timeouts work around the JS timer limit.Written for commit bf86ce1. Summary will update on new commits.