Cross-process WebSocket frame schemas for the juniper-cascor protocol (envelope + worker)
Project description
juniper-cascor-protocol
Cross-process WebSocket frame schemas for the juniper-cascor ecosystem.
This package is the canonical, single-sourced wire-protocol surface for the three Juniper WebSocket endpoints:
| Endpoint | Schema source |
|---|---|
/ws/training (server → client broadcast) |
juniper_cascor_protocol.envelope (Pydantic v2) |
/ws/control (bidirectional command/response) |
juniper_cascor_protocol.envelope (Pydantic v2) |
/ws/v1/workers (cascor ↔ worker JSON + binary side-channel) |
juniper_cascor_protocol.worker (StrEnum + numpy BinaryFrame) |
Why two subpackages?
The envelope subpackage uses Pydantic v2 for declarative validation of JSON-only frames.
The worker subpackage stays Pydantic-free so juniper-cascor-worker
can adopt the canonical type enum and binary codec without pulling Pydantic into its slim image —
preserving the METRICS-MON R2 exit-gate decision.
Importing juniper_cascor_protocol.worker does not load Pydantic (verified by the test suite).
Install
pip install juniper-cascor-protocol
Pinned by the cascor server, juniper-cascor-client, juniper-canopy, and juniper-cascor-worker — each consumer imports only the subpackage it needs.
Quick start
Validating an inbound /ws/training frame
import json
from juniper_cascor_protocol.envelope import (
UnknownEnvelope,
MetricsEnvelope,
validate_envelope,
)
raw = ws.recv() # ``websockets`` text frame
frame = json.loads(raw)
envelope = validate_envelope(frame) # never raises on bad input
if isinstance(envelope, MetricsEnvelope):
handle_metrics(envelope.data)
elif isinstance(envelope, UnknownEnvelope):
# ``envelope.type`` is the cardinality-bounded label
# (collapses to ``"_unmatched"`` after N distinct unknowns).
log_unrecognized_frame(envelope.type)
validate_envelope never raises on schema mismatch — chaos-testing of malformed frames is part of the package's contract so a misbehaving server cannot crash a consumer.
Worker-side BinaryFrame codec
import numpy as np
from juniper_cascor_protocol.worker import BinaryFrame, WorkerMessageType
# Send tensor as a binary side-channel frame
weights = np.zeros((128, 128), dtype="float32")
ws.send(BinaryFrame.encode(weights))
# Receive and decode
raw = await ws.recv() # bytes
arr = BinaryFrame.decode(raw) # owned numpy array
# Dispatch JSON envelope by canonical message type
msg = json.loads(text_frame)
if msg.get("type") == WorkerMessageType.TASK_ASSIGN:
...
Cardinality-bound details
The validate_envelope helper tracks distinct unknown type strings up to UNKNOWN_TYPE_BUDGET = 16 per process; subsequent unknowns return as UNMATCHED_TYPE_LABEL = "_unmatched". This mirrors the juniper_observability.UNMATCHED_ENDPOINT_LABEL strategy used for HTTP cardinality bounds. Tests reset state via reset_unknown_label_state() in juniper_cascor_protocol.envelope.
Versioning
Follows PEP 440 + Keep a Changelog. Consumers should pin juniper-cascor-protocol>=A.B,<A+1. Additive envelope fields are minor bumps; field removals/renames are major bumps.
See CHANGELOG.md for the per-version contract.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file juniper_cascor_protocol-0.1.0a0.tar.gz.
File metadata
- Download URL: juniper_cascor_protocol-0.1.0a0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
177368faa78e32f34311e73ded253aa24304ed17d98dc208564fe0434fbfc246
|
|
| MD5 |
f31361736641b1320adb6b9749c3c266
|
|
| BLAKE2b-256 |
53f9eb23ab4900f9b3bd9b03af56a145a553459e9c98509963988369deed7615
|
Provenance
The following attestation bundles were made for juniper_cascor_protocol-0.1.0a0.tar.gz:
Publisher:
publish-protocol.yml on pcalnon/juniper-cascor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
juniper_cascor_protocol-0.1.0a0.tar.gz -
Subject digest:
177368faa78e32f34311e73ded253aa24304ed17d98dc208564fe0434fbfc246 - Sigstore transparency entry: 1409677832
- Sigstore integration time:
-
Permalink:
pcalnon/juniper-cascor@062a4b9ed771fcc56f220eaf5115bd5e9a3955ca -
Branch / Tag:
refs/tags/juniper-cascor-protocol-v0.1.0a0 - Owner: https://github.com/pcalnon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-protocol.yml@062a4b9ed771fcc56f220eaf5115bd5e9a3955ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file juniper_cascor_protocol-0.1.0a0-py3-none-any.whl.
File metadata
- Download URL: juniper_cascor_protocol-0.1.0a0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49a41e7c7a0dc2c6e840193b08a82e46afa3ac5fa348e74715523e2a09dc023e
|
|
| MD5 |
9642fe800548f12588bb2be4b80663bf
|
|
| BLAKE2b-256 |
d4ae1aa99d8a5d742a4e0a801dba6d53bf2f9197a2e8569e2670699a60725c1a
|
Provenance
The following attestation bundles were made for juniper_cascor_protocol-0.1.0a0-py3-none-any.whl:
Publisher:
publish-protocol.yml on pcalnon/juniper-cascor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
juniper_cascor_protocol-0.1.0a0-py3-none-any.whl -
Subject digest:
49a41e7c7a0dc2c6e840193b08a82e46afa3ac5fa348e74715523e2a09dc023e - Sigstore transparency entry: 1409677843
- Sigstore integration time:
-
Permalink:
pcalnon/juniper-cascor@062a4b9ed771fcc56f220eaf5115bd5e9a3955ca -
Branch / Tag:
refs/tags/juniper-cascor-protocol-v0.1.0a0 - Owner: https://github.com/pcalnon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-protocol.yml@062a4b9ed771fcc56f220eaf5115bd5e9a3955ca -
Trigger Event:
push
-
Statement type: