Worker lifecycle
This page describes Shell-managed client App workers. Server-side Wasm resource limits are covered by Wasm resource limits.
Termination and recovery
Client Apps must tolerate abrupt worker termination. The Shell may stop a worker because it hangs, resources are under pressure, the App is no longer needed, the tab closes, or the App is uninstalled. In-memory UI state is lost when the worker stops.
The Shell does not snapshot an App’s UI tree. After a restart, the App rebuilds and paints its interface again. The Shell shows a loading or error state until then. A Host-mediated client cache may survive worker restarts and help the App recover. The cache is cleared when the App is uninstalled.
| Situation | Shell behavior |
|---|---|
| Tab closes, browser exits, or App is uninstalled | Stop the worker without prompting |
| A visible App appears hung | Ask the user what to do; if the App remains visible after termination, restart it |
| Background or otherwise non-visible worker is no longer needed | It may be stopped silently and remain stopped until the App is opened or an event requires a wake |
Exact worker creation and teardown timing—such as when navigating away, keeping a worker warm, or using least-recently-used eviction—is an implementation choice.
Background event wakes
When client-side work needs to process an event while its UI is closed, the Shell may start a headless worker without a UI tree. The Shell limits the number of concurrent background wakes, excess work waits. Apps should not be woken just to display badges. Use notifications for user-visible alerts.
Resource policy
Browsers do not provide a portable API for setting per-worker memory or CPU budgets. The Shell can terminate a worker and apply its own concurrency, heartbeat, or eviction policies, but it cannot promise precise browser-enforced metering. Experimental memory and compute-pressure APIs may provide hints, but the design must not depend on them.
The Host can enforce stricter server-side limits and will generally terminate overloaded work without asking the user, for fairness across accounts. This difference is intentional: browser limits do not weaken Host policy.
| Browser mechanism | Finding | Use in the design |
|---|---|---|
| Per-worker memory or CPU budgets | No portable API | Do not rely on browser-enforced budgets |
| Engine out-of-memory behavior | Often opaque and may affect the whole tab | Not a product control surface |
Worker.terminate() |
Provides an immediate stop | Shell’s hard control |
| Memory measurement and Compute Pressure APIs | Experimental, gated, and not broadly available | Optional hints only |
| Shell policy, such as concurrency caps, heartbeats, and eviction | Implemented by the product | Shell owns soft and hard limits |
Decision: Shell policy owns client worker limits: terminate and rebuild when necessary. Do not promise that the browser will fairly throttle one App worker against another, and do not weaken Host Wasm limits to match browser constraints.
For browser behavior and measurement details, see browser worker resource limits.