Skip to content

Ws rework#44

Merged
keyboardstaff merged 9 commits intomainfrom
ws-rework
Mar 28, 2026
Merged

Ws rework#44
keyboardstaff merged 9 commits intomainfrom
ws-rework

Conversation

@keyboardstaff
Copy link
Copy Markdown
Owner

No description provided.

…ation

- Add WsHandler base class, WsManager (connection tracking / event routing / buffering), WsResult
- Extract network.py (is_loopback_address) and context_utils.py (use_context) to eliminate duplication
- Migrate three handlers to api/ following the ws_* py naming convention
- Simplify run_ui.py WebSocket init from ~170 lines to ~10
- Update import paths in api.py, plugins.py, state_monitor.py
- websocket.js: addHandlers, _handlers Set, auth callback, envelope validation, exponential backoff, 50 MB cap
- Three store components: namespace /webui → /ws, wire up addHandlers
- Fix websocket-test-store.js detach) accidentally killing syncStore event listeners
- Fixes 500 error when uploading images with non-ASCII filenames via /api/image_get
- Improves file path handling to support both development and Docker environments
- Adds exception handling to gracefully fall back to Docker path logic if path correction fails
- Ensures robust error handling so path issues do not crash the entire endpoint
…ch unification

- Fix Memory Leaks: Resolved SID retention in _known_sids after disconnection and cleaned up unreferenced broadcast tasks in _schedule_lifecycle_broadcast.
- Unify Dispatching Paths: Unified client and server event dispatching through the process_client_event() method to ensure diagnostic consistency.
- Optimization & Cleanup: Expanded the _OPTION_KEYS whitelist, removed dead code (iter_event_types), and deleted unused websocket exports.
- Robustness: Added handling for None responses in process_client_event to prevent cluttering responses with empty results.
- Testing: Added test cases to verify SID TTL expiration and stale SID cleanup on disconnect.
1. Extract _collect_results method — Deduplicated ~30 lines of identical result processing from route_event and process_client_event (Exception→error / WsResult→as_result / dict→wrap / None→strategy branch) into a private method with a skip_none parameter.
    * route_event calls _collect_results(skip_none=False) — None becomes ok=True (server-initiated, callers expect a result for every handler)
    * process_client_event calls _collect_results(skip_none=True) — None is skipped (client-initiated, matching legacy _dispatch fire-and-forget semantics)
2. Document None semantics difference — Added # NOTE: comment at the route_event call site explaining why skip_none=False differs from process_client_event.
3. Unify _timestamp() usage — Replaced inline timestamp formatting in _wrap_envelope and handle_connect with self._timestamp() method reuse.#
- move _ws_contexts snapshot inside _contexts_lock critical section, add ctx is None skip logic to prevent security check bypass during concurrent disconnects
- Fix two error returns in ws_dev_test.py using non-standard {"_error": True, ...} format, which _collect_results misidentifies as a success response and wraps as ok=True, sending a false-success to the client
- Switch to WsResult.error(code=..., message=...) standard API, consistent with all other handlers
- Fix 5 occurrences of process_event → process in documentation examples
- Remove non-existent HANDLER_ID and HANDLED_EVENTS class attribute examples from docs
- Fix validate_event_types (plural) → validate_event_type (singular) in docs
@keyboardstaff keyboardstaff merged commit f2fd0ee into main Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant