Skip to content

fix: safety hardening for protocol implementation#8

Merged
w4bremer merged 16 commits into
mainfrom
fix/safety-hardening
Apr 9, 2026
Merged

fix: safety hardening for protocol implementation#8
w4bremer merged 16 commits into
mainfrom
fix/safety-hardening

Conversation

@w4bremer
Copy link
Copy Markdown
Contributor

@w4bremer w4bremer commented Apr 9, 2026

Summary

  • Harden ObjectLink protocol against malformed input, crashes, and unsafe patterns
  • Fix instance isolation bugs (shared class-level state, registry singletons)
  • Fix broken example code (wrong imports, setattr, arg unpacking)
  • Add 30 safety tests covering all fixes

Changes

Critical fixes

  • Fix broken setattr call in examples/server.py
  • Fix shared class-level node/queue in examples/server.py RemoteEndpoint
  • Fix broken import paths (olink.remotenodeolink.remote) in examples
  • Fix wrong **args*args unpacking in examples/server.py

Safety hardening (wire protocol unchanged)

  • Validate message length before unpacking in Protocol.handle_message (silent drop, >= for forward-compat)
  • Replace unsafe getattr/setattr with explicit dispatch tables in examples
  • Fix sender task deadlock on disconnect (cancel task before join)
  • Prevent phantom registry entries (_get_entry for reads, _entry for writes)
  • Fix KeyError on double-unlink and unregister of unknown sink
  • Add configurable message size limit (1MB default)
  • Narrow exception handling from except Exception to except (json.JSONDecodeError, ValueError)
  • Forward node logger to Protocol for validation error visibility

Instance isolation fixes

  • Ensure independent state for ClientNode, ClientRegistry, RemoteRegistry, MockSink, MockSource, RemoteEndpoint instances
  • Fix self parameter in interface methods
  • Filter inf values from JSON serialization

Cosmetic

  • Fix ProptocolType typo, enum tuple syntax, missing self in ILogger.log

Test plan

  • All 31 original tests pass
  • 30 new safety tests pass (malformed messages, registry edge cases, phantom entries, size limits)
  • Zero wire protocol changes — other language implementations unaffected
  • Manual test with starlette/uvicorn (examples require starlette installed)

w4bremer and others added 16 commits January 14, 2026 17:28
- Validate message length before unpacking in Protocol.handle_message
  (silent drop on malformed input, uses >= for forward-compat)
- Replace unsafe getattr/setattr with dispatch tables in examples
- Fix broken setattr, import paths, and **args in examples/server.py
- Fix shared class-level state in examples/server.py RemoteEndpoint
- Fix sender task deadlock on disconnect (cancel before join)
- Prevent phantom registry entries by splitting _entry into read/write
- Fix KeyError on double-unlink and unregister of unknown sink
- Add configurable message size limit (1MB default)
- Narrow exception handling to json.JSONDecodeError and ValueError
- Forward node logger to Protocol for validation error visibility
- Fix cosmetic issues: typos, enum syntax, missing self parameter
- Add 30 safety tests covering all fixes
- Test matrix: Python 3.9-3.13 on Ubuntu, macOS, and Windows (15 cells)
- Lint job with ruff (format + check)
- Optional deps job for starlette/demo_server tests
- Coverage collection on py3.12/Ubuntu
- Add ruff.toml config, replace black with ruff in Taskfile
- Add extras_require (dev, examples) to setup.cfg
- Sort imports (isort)
- Fix == None to is None comparisons
- Replace % format with f-strings in examples/app.py
- Remove unused import (BaseNode in test_safety.py)
- Reformat files to ruff style
The TestCounter stub was missing the increment method, causing
AttributeError when building the dispatch table. Also add
fail-fast: false to test-optional-deps job.
- Add CI, PyPI, Python version, and license badges
- Add quick start with source/sink/wiring examples
- Document wire protocol message types and formats
- Add architecture diagram and package structure table
- Include test matrix, development setup, and contributing guide
@w4bremer w4bremer merged commit 86405e8 into main Apr 9, 2026
18 checks passed
@w4bremer w4bremer deleted the fix/safety-hardening branch April 9, 2026 17:57
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