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.0.tar.gz (19.7 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.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: juniper_cascor_protocol-0.1.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for juniper_cascor_protocol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f4dc75bac1ec8806be6d0ab73a732db166c863471bba6d8e1396b931bfeda610
MD5 9bba949a57c85c818279f4f04a349b1f
BLAKE2b-256 2e3e613273f38da956ca82b3f8c40ad485d03b60a0e265b9c98bc94cebb61b69

See more details on using hashes here.

Provenance

The following attestation bundles were made for juniper_cascor_protocol-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for juniper_cascor_protocol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76915177ac5a1d94fff6fe5697e1517ef2ddd91da498572e4d31a7d0d2077331
MD5 0c2bae7e3f1e7d17056de1882ebb86f2
BLAKE2b-256 86111c2c4ba0ab08d1cc99ae688082ce875402ae1e0671f56967f98a68d586c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for juniper_cascor_protocol-0.1.0-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