Commit 6a5496f
authored
kill cua agent on stagehand.close (#1399)
# Why
CUA agent loops continued running after `stagehand.close()` was called,
causing errors like "Cannot read properties of null (reading
'awaitActivePage')".
# What Changed
- Added `StagehandClosedError` class to detect when Stagehand session is
closed
- `V3CuaAgentHandler` now checks if context is null before executing
actions/screenshots and throws `StagehandClosedError`
- All CUA clients (Anthropic, Google, OpenAI, Microsoft) re-throw
`StagehandClosedError` in catch blocks to stop the agent loop
immediately instead of swallowing the error
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Stops CUA agent loops immediately after stagehand.close() to prevent
null-context errors and stray actions. Adds a clear signal so clients
and handlers halt cleanly.
- **Bug Fixes**
- Introduced StagehandClosedError to indicate a closed session.
- V3CuaAgentHandler checks context before screenshots/actions and throws
StagehandClosedError.
- Anthropic, Google, and OpenAI CUA clients rethrow StagehandClosedError
to exit loops.
<sup>Written for commit d34c5cd.
Summary will update automatically on new commits.</sup>
<!-- End of auto-generated description by cubic. -->1 parent 934f492 commit 6a5496f
File tree
7 files changed
+49
-2
lines changed- .changeset
- packages/core
- lib/v3
- agent
- handlers
- types/public
- tests/public-api
7 files changed
+49
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
320 | 323 | | |
321 | 324 | | |
322 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
323 | 329 | | |
324 | 330 | | |
325 | 331 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
486 | 487 | | |
487 | 488 | | |
488 | 489 | | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
489 | 493 | | |
490 | 494 | | |
491 | 495 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
547 | 550 | | |
548 | 551 | | |
549 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
550 | 556 | | |
551 | 557 | | |
552 | 558 | | |
| |||
613 | 619 | | |
614 | 620 | | |
615 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
616 | 625 | | |
617 | 626 | | |
618 | 627 | | |
| |||
688 | 697 | | |
689 | 698 | | |
690 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
691 | 703 | | |
692 | 704 | | |
693 | 705 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| 63 | + | |
52 | 64 | | |
53 | 65 | | |
54 | 66 | | |
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
58 | 70 | | |
| 71 | + | |
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
0 commit comments