Skip to content

[Backend][Frontend] websocket & payload: relay-only broker, TopicPayload and backend/message - #687

Merged
JavierRibaldelRio merged 16 commits into
backend/websocketfrom
backend/ws-javier-Ribal
Dec 4, 2026
Merged

JavierRibaldelRio merged 16 commits into
backend/websocketfrom
backend/ws-javier-Ribal

Conversation

@JavierRibaldelRio

@JavierRibaldelRio JavierRibaldelRio commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Warning

THIS PR MODIFIES THE FRONTEND, NOT ONLY THE BACKEND.

Frontend packages changed: frontend-kit, testing-view, competition-view and logging-view.
It changes the WebSocket contract (heartbeat, telemetry and message payloads), so it needs a review from someone working on the frontend as well.

Frontend changes (this PR modifies the frontend)

  • Heartbeat (frontend-kit): the kit sends connection/heartbeat as soon as the socket opens and then every 25 ms (it was every 1000 ms). The backend now gives up on the frontends after 100 ms without a message from any of them.
    Files: kit/src/core/websocket.ts, kit/src/core/types.ts (SocketConfig.heartbeatIntervalMs docs).
  • hexValue removed from the telemetry types:
    • kit/src/core/types.ts (TelemetryPacket)
    • logging-view/src/types/telemetry.ts
    • testing-view/src/types/data/telemetryCatalogItem.ts (RawPacket)
    • testing-view/src/mocks/telemetry.ts
    • competition-view/scripts/mock-backend.mjs
  • counter removed from MessageTimestamp:
    • testing-view/src/types/data/message.ts and its formatTimestamp test
    • competition-view/src/types/message.ts
    • competition-view/scripts/mock-backend.mjs

Not migrated yet (follow-up PRs):

  • measurementUpdates keys are now numeric measurement ids. The apps still look values up by the Go catalog key (e.g. testing-view TelemetryValue.tsx).
  • The apps still fetch the Go routes /backend/podDataStructure and /backend/orderStructures.
  • No app reads the new origin field of message/update or the new backend/message topic yet.

Wire changes the frontend sees

Topic Change
connection/heartbeat 100 ms timeout, counted across all sessions
podData/update no hexValue; measurementUpdates keyed by numeric measurement id
message/update kind is info, warning, fault or panic (no ok); new origin field; no counter in timestamp
protection/update timestamp uses the calendar format of message/update: {second, minute, hour, day, month, year}
order/stateOrders removed
backend/message new: messages the backend itself produces

Backend: websocket

  • The broker only relays. Telemetry batching, its timer and the pending map are gone. The publisher (pipeline) sends complete snapshots and decides how often. State topics use watch; event topics use broadcast (128 events each).
  • Heartbeat: run returns FrontendDisconnected after DEFAULT_HEARTBEAT_TIMEOUT (100 ms) without a valid message from any frontend, and traces it with error!.
  • Shutdown cascade: when the broker stops, every session closes. A Subscriber does not keep the broker alive.
  • Traces: info! when a frontend connects, when a session ends (with the active count) and when the broker stops.
  • Outgoing topic names live with their payloads (TopicPayload::TOPIC). The sender writes each frame with to_message().
  • New event topic backend/message: publish_backend_message and subscribe_backend_messages.

Backend: payload

  • TopicPayload trait: a const TOPIC and a default to_message() that serializes {topic, payload} in one pass. Every backend → frontend payload implements it.
    ConnectionUpdate, DataUpdate and LoggerResponse are now newtypes; their JSON is unchanged.
  • MessageKind replaced by core's MessageLevel. protection_level(Severity) gives the level a protection is shown with.
  • message/update gains origin: where on the board the message was produced, taken from MessagePacket.origin. It is empty for messages the backend produces itself.
  • protection/update: ProtectionUpdate::new(packet, timestamp) with a MessageTimestamp.
  • Removed: order/stateOrders, hexValue and counter.
  • New BackendMessage (backend/message): kind (MessageLevel), board (null when not known), text and timestamp. It carries the Problems from event.
  • Docs and tests: the README templates and examples are updated, and tests check to_message() against every example file.

Pending

  • Send FrontendDisconnected to event as a fatal Problem once backend/event is merged (TODOs in websocket::run and main.rs).
  • Pipeline: build a BackendMessage from each Problem (ProblemKind → MessageLevel, date from at, board name from the ADJ).
  • Frontend: Rust catalog routes, numeric measurement ids, show origin and backend/message.
  • clippy -D warnings reports 5 errors that predate this PR (websocket/order.rs, http/server.rs). cargo fmt of untouched files is deferred.

Testing

  • cargo test -p station: 47 passed.
  • testing-view and competition-view: tsc clean; vitest: 116 passed.
  • competition-view run against its mock backend: messages show HH:MM:SS without counter, and telemetry arrives without hexValue.
  • testing-view run in its own mock mode: loads with no page errors.

@JavierRibaldelRio JavierRibaldelRio changed the title Backend/ws javier ribal [Backend][Frontend] websocket & payload: relay-only broker, TopicPayload and backend/message Dec 4, 2026
@JavierRibaldelRio
JavierRibaldelRio marked this pull request as ready for review December 4, 2026 01:04
Comment thread backend/crates/core/src/hello.rs Resolved

@pminmic pminmic left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the comments, especially those in data.rs and broker.rs. Now I’m going to test it with #685 and see how it works.

@JavierRibaldelRio
JavierRibaldelRio merged commit 682ffa7 into backend/websocket Dec 4, 2026
2 checks passed
@JavierRibaldelRio
JavierRibaldelRio deleted the backend/ws-javier-Ribal branch December 4, 2026 16:11
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.

3 participants