## Description
Two fixes to the browser state signal:
1. **Suppress "Browser is closed" when the agent never used the
browser** — if there's no previous state signal (browser was never
reported as open) and the browser is currently closed, the signal is
suppressed entirely. This prevents confusing messages when an agent has
a browser configured but the user/agent hasn't actually used it.
2. **Add `closeReason` to differentiate why the browser closed** — new
optional field on `BrowserContext` with values `'agent' | 'user' |
'process_restart' | 'error'`. The formatted state signal message changes
based on the reason:
- `process_restart` → "The session process restarted, which closed the
browser."
- `user` → "The user closed the browser."
- `error` → "Browser closed unexpectedly due to an error."
- `agent`/default → "Browser is closed."
The `closeReason: 'error'` is now set in `agent.ts` when
`getBrowserState()` throws. Other reasons (`process_restart`, `user`)
can be set by callers that have that context (e.g. the session runtime
or viewer registry).
## Related issue(s)
Fixes the issue discussed in Slack where the state signal showed
"Browser is closed" even when the agent hadn't used the browser at all.
## Type of change
- [x] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
## Checklist
- [x] I have linked the related issue(s) in the description above
- [x] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have addressed all Coderabbit comments on this PR
Link to Devin session:
https://app.devin.ai/sessions/34fece46417c4d0cb01a1a73e3871126
Requested by: @TylerBarnes
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5
The PR prevents a misleading "Browser is closed" message when the agent
never opened the browser and attaches a short reason for why a browser
closed (agent, user, process restart, or error) so state messages are
accurate and useful.
## Changes Summary
### Core Changes
- Suppress spurious closed signals
- computeStateSignal() no longer emits a plain "Browser is closed" state
when the thread has never previously reported the browser open; closed
signals are only emitted when there is a meaningful prior open-state in
the thread history.
- Adds logic to avoid emitting ambiguous "bare closed" deltas.
- Close reason tracking and messaging
- BrowserContext / persisted BrowserState gains optional closeReason?:
'agent' | 'user' | 'process_restart' | 'error'.
- computeStateSignal preserves or infers closeReason and uses it to
format messages:
- process_restart → "The session process restarted, which closed the
browser."
- user → "The user closed the browser."
- error → "Browser closed unexpectedly due to an error."
- agent/default → "Browser is closed."
- Delta formatting for open: false uses the closeReason text instead of
a generic closed message.
- Agent error-handling
- packages/core/src/agent/agent.ts: when getBrowserState() throws, the
resolver returns { isOpen: false, closeReason: 'error' } so exceptions
are attributed to 'error'.
### Browser / Agent-Browser Changes
- AgentBrowser
- Tracks per-thread (and default) close reasons and agent-driven
active-URL changes.
- Persists thread-aware closed state including tracked closeReason and
activeUrlChangeSource.
- Clears tracking maps on launch; closeThreadSession override saves
thread-specific last state.
- getBrowserState(threadId) routes through thread-aware logic to include
closeReason/activeUrlChangeSource.
- Close tool
- createCloseTool records agent-initiated closeReason ('agent')
(thread-aware) before closing.
- Navigation tools
- goto/back/new/switch record agent-driven URL changes so
activeUrlChangeSource can be attributed correctly.
### Persistence & Thread Manager
- Thread-manager persistence schema updated to include optional
closeReason and activeUrlChangeSource.
- updateBrowserState now shallow-copies incoming state and preserves
extra fields (so closeReason/activeUrlChangeSource are not dropped).
### Mastracode / UI Streaming Fix
- Anchors streamed state_signal components before the active assistant
text component so later assistant text updates do not push the signal
down the chat stream.
- Adds a TUI regression test ensuring the state signal is inserted and
the streamed assistant text renders correctly.
### Tests & Docs
- Extensive tests added/updated:
- computeStateSignal tests expanded to cover suppression when browser
was never opened, open-from-remembered-closed with active URL
propagation, close reason attribution (process_restart, user, error),
activeUrlChangeSource attribution (agent vs user), and suppression when
only source metadata toggles.
- agent-browser tests verify preservation and correct inheritance of
closeReason and activeUrlChangeSource behavior.
- mastracode TUI tests added to verify anchored state signal behavior.
- Changesets updated to document patch releases for `@mastra/core`,
`@mastra/agent-browser`, and `mastracode`.
- Minor CI/test/ESLint adjustments included.
### API / Interface Changes
- Interface updates:
- BrowserContext / BrowserState: added closeReason?: 'agent' | 'user' |
'process_restart' | 'error'
- BrowserState: added activeUrlChangeSource?: 'agent' | 'user'
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: tyler <tylerdbarnes@gmail.com>
Co-authored-by: Mastra Code (openai/gpt-5.5) <noreply@mastra.ai>
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and publish to npm
yourself or [setup this action to publish
automatically](https://github.com/changesets/action#with-publishing). If
you're not ready to do a release yet, that's fine, whenever you add more
changesets to main, this PR will be updated.
⚠️⚠️⚠️⚠️⚠️⚠️
`main` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `main`.
⚠️⚠️⚠️⚠️⚠️⚠️
# Releases
> The changelog information of each package has been omitted from this
message, as the content exceeds the size limit.
## @mastra/openai@0.1.0-alpha.1
## @mastra/client-js@1.24.0-alpha.0
## @mastra/core@1.42.0-alpha.0
## @mastra/playground-ui@33.0.0-alpha.0
## @mastra/server@1.42.0-alpha.0
## @mastra/pg@1.13.0-alpha.0
## @mastra/claude@0.1.1-alpha.0
## @mastra/react@0.5.3-alpha.0
## @mastra/deployer-cloud@1.42.0-alpha.0
## @mastra/deployer-cloudflare@1.1.43-alpha.0
## @mastra/deployer-netlify@1.1.19-alpha.0
## @mastra/deployer-vercel@1.1.37-alpha.0
## @mastra/longmemeval@1.0.49-alpha.0
## @mastra/opencode@0.0.46-alpha.0
## mastracode@0.22.3-alpha.0
## @mastra/arize@1.2.2-alpha.0
## @mastra/arthur@0.3.2-alpha.0
## @mastra/laminar@1.2.2-alpha.0
## @mastra/langfuse@1.3.5-alpha.0
## @mastra/otel-bridge@1.2.2-alpha.0
## @mastra/otel-exporter@1.2.2-alpha.0
## @mastra/posthog@1.0.28-alpha.0
## @mastra/sentry@1.1.3-alpha.0
## mastra@1.12.3-alpha.0
## @mastra/deployer@1.42.0-alpha.0
## @mastra/editor@0.11.2-alpha.0
## @mastra/mcp@1.9.2-alpha.0
## @mastra/mcp-docs-server@1.1.46-alpha.0
## @mastra/express@1.3.30-alpha.0
## @mastra/fastify@1.3.30-alpha.0
## @mastra/hono@1.4.25-alpha.0
## @mastra/koa@1.5.13-alpha.0
## @mastra/nestjs@0.1.14-alpha.0
## @mastra/dsql@1.0.2-alpha.0
## @mastra/dynamodb@1.0.8-alpha.0
## @mastra/s3vectors@1.0.6-alpha.0
## @mastra/spanner@1.1.1-alpha.0
## @mastra/voice-aws-nova-sonic@0.1.3-alpha.0
## @mastra/voice-google@0.12.2-alpha.0
## @mastra/voice-google-gemini-live@0.12.1-alpha.0
## @mastra/temporal@0.1.13-alpha.0
## @mastra/agentcore@0.2.1-alpha.0
## @mastra/blaxel@0.4.1-alpha.0
## @mastra/e2b@0.3.3-alpha.0
## @mastra/gcs@0.2.2-alpha.0
## @mastra/s3@0.5.2-alpha.0
## create-mastra@1.12.3-alpha.0
## @internal/playground@1.12.3-alpha.0
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>