Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

juniper_cascor_protocol-0.1.0a0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

juniper_cascor_protocol-0.1.0a0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file juniper_cascor_protocol-0.1.0a0.tar.gz.

File metadata

File hashes

Hashes for juniper_cascor_protocol-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 177368faa78e32f34311e73ded253aa24304ed17d98dc208564fe0434fbfc246
MD5 f31361736641b1320adb6b9749c3c266
BLAKE2b-256 53f9eb23ab4900f9b3bd9b03af56a145a553459e9c98509963988369deed7615

See more details on using hashes here.

Provenance

The following attestation bundles were made for juniper_cascor_protocol-0.1.0a0.tar.gz:

Publisher: publish-protocol.yml on pcalnon/juniper-cascor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file juniper_cascor_protocol-0.1.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for juniper_cascor_protocol-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 49a41e7c7a0dc2c6e840193b08a82e46afa3ac5fa348e74715523e2a09dc023e
MD5 9642fe800548f12588bb2be4b80663bf
BLAKE2b-256 d4ae1aa99d8a5d742a4e0a801dba6d53bf2f9197a2e8569e2670699a60725c1a

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page