mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-05 01:48:44 +00:00
Reduce state-push coalescing from 100 ms to 25 ms so transport batching does not combine successive response updates into large visible bursts. The existing per-connection timer and in-flight push guards still bound work and coalesce dirty state. Skip inner Scroller measurements for root response bodies, which grow with the chat viewport. The existing chat scroller owns following, and the collapse handler still resets collapsed content. Other message bodies retain their scrolling behavior. Update the owning docs and regressions. Validation: - 42 focused streaming, state-sync, snapshot and WebUI tests passed. - 31 WebSocket security, CSRF and handler tests passed. - Live DeepSeek and Opus checks showed roughly halved median visible update intervals; response scrolling and collapse/expand were checked. Live browser checks used headless Chromium. Long Opus responses still show occasional dropped frames as more frequent updates increase render work.
3.9 KiB
3.9 KiB
state_monitor.py DOX
Purpose
- Own the
state_monitor.pyhelper module. - This module tracks dirty state and connection projections for WebUI sync.
- Keep this file-level DOX profile synchronized with
state_monitor.pybecause this directory is intentionally flat.
Ownership
state_monitor.pyowns the runtime implementation.state_monitor.py.dox.mdowns durable notes about responsibilities, contracts, side effects, and verification for that implementation.- Classes:
ConnectionProjection(no explicit base class)StateMonitor(no explicit base class)bind_manager(self, manager: 'WsManager', handler_id: str | None=...) -> Noneregister_sid(self, namespace: str, sid: str) -> Noneunregister_sid(self, namespace: str, sid: str) -> Nonemark_dirty_all(self, reason: str | None=...) -> Nonemark_dirty_for_context(self, context_id: str, reason: str | None=..., include_collections: bool=...) -> Noneupdate_projection(self, namespace: str, sid: str, request: StateRequestV1, seq_base: int) -> Nonemark_dirty(self, namespace: str, sid: str, reason: str | None=..., wave_id: str | None=..., include_collections: bool=...) -> None
- Top-level functions:
get_state_monitor() -> StateMonitor_reset_state_monitor_for_testing() -> None- Notable constants/configuration names:
_STATE_MONITOR_HOLDER,_STATE_MONITOR_LOCK.
Runtime Contracts
- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
- Observed side-effect areas: filesystem deletion, WebSocket state, settings/state persistence, scheduler state.
- Imported dependency areas include:
__future__,asyncio,dataclasses,helpers,helpers.print_style,helpers.state_snapshot,helpers.ws,helpers.ws_manager,os,threading,time,typing.
Key Concepts
- Important called helpers/classes observed in the source:
threading.RLock,field,ws_debug,_ws_debug_enabled,context_id.strip,loop.call_soon_threadsafe,self._schedule_debounce_on_loop,asyncio.get_running_loop,asyncio.current_task,loop.is_closed,self._debounce_handles.pop,self._push_tasks.pop,self._projections.pop,self.mark_dirty,self._mark_dirty_on_loop,runtime.is_development,loop.call_later,StateMonitor,ConnectionProjection,handle.cancel. - The default monitor coalesces dirty waves into at most one state push per 25 ms per connection without postponing an already scheduled push. Keep this window below the agent's response-stream cadence so transport batching does not turn live text into large bursts.
- Collection-dirty versions are coalesced independently from ordinary stream dirties. Only clients that explicitly negotiate
collections_deltamay receivecontexts: nullandtasks: null; legacy clients remain on full snapshots. - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
Work Guidance
- Preserve public helper APIs used by core code and plugins unless every caller is updated.
- Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded.
- Prefer adding cohesive helper functions here only when behavior is reused across modules.
Verification
- Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
- Related tests observed by source search:
tests/test_model_config_api_keys.pytests/test_multi_tab_isolation.pytests/test_state_monitor.pytests/test_state_sync_handler.pytests/test_state_sync_welcome_screen.pytests/test_ws_handlers.py
Child DOX Index
No child DOX files.