Skip to content

feat: meet riders from other apps on the shared Herne Hill track - #89

Draft
RalfLeonFasler wants to merge 4 commits into
pepperstm:mainfrom
RalfLeonFasler:feature/openbikenet
Draft

RalfLeonFasler wants to merge 4 commits into
pepperstm:mainfrom
RalfLeonFasler:feature/openbikenet

Conversation

@RalfLeonFasler

Copy link
Copy Markdown
Contributor

What and why

Meet riders from other indoor cycling apps on the Herne Hill velodrome through OpenBikeNet, the open protocol for shared presence. Refs #69.

Since #75 the track is built in and its measuring line is exactly 450 m, so this starts with Herne Hill instead of adding velodrome-250: herne-hill is herne-hill-450, and herne-hill-clockwise is herne-hill-450-clockwise. velodrome-250 can follow later if wanted.

How it works

  • crates/core/src/obn.rs: the pure protocol v0.2 messages, display-name cleaning (Cc/Cf/Co/Zl/Zp except U+200D), lap and position mapping, and the track → route table. Written from the spec, not ported: OpenRadlr is AGPL-3.0 and this repo is GPL-3.0.
  • src-tauri/src/obn.rs: one backend WebSocket per ride. It says hello as velopopuli, subscribes to the route in the public room, joins, sends one update a second, reconnects with backoff, and pings after 20 s of silence. Other apps' riders come back as remote rivals.
  • crates/core/src/ride.rs: remote riders move on at their last speed for at most 2 s between updates, so 1 Hz doesn't look jerky. This also smooths group-ride friends.
  • Settings → Other apps: off by default, public server preset, a server address, and a share power/cadence switch (off by default).
  • On Herne Hill, a group-ride room is off while OpenBikeNet is on; the setup screen says so. The track card says "shared with other apps" when it is on.
  • The HUD chip says "OpenBikeNet · 3 riders from other apps", and other riders are labelled "Anna · openradlr".

What is sent

Display name, position, lap and speed. Power and cadence only when the rider turns them on. Never heart rate. Names are cleaned before they are sent and before other apps' names are shown. The server keeps only per-app counts (spec 10).

Checked

  • cargo fmt --all --check, cargo clippy --workspace -- -D clippy::correctness, cargo test --workspace (including 8 new protocol tests and a smoothing test), npx tsc --noEmit, Prettier and npm run build:web.
  • The link has a test against a local WebSocket server: hello/subscribe/join order, snapshot and updates become remote riders, an update carries no power unless allowed, left, and leaving closes the connection.
  • Not yet: a live ride with another app, and a screenshot on the track. I don't have a second app running here. The message shapes are checked against the public server and the local server; happy to do the live check with you if you want.

Not sure about

  • Power and cadence off by default, or on like the group ride? I chose off because OpenBikeNet is a new server and off is the privacy-safe default.
  • The public server (wss://openbikenet.cloud/v0) as the preset, or leave it empty and make people paste one? The issue proposed the public server.

Share the built-in Herne Hill velodrome through OpenBikeNet (protocol v0.2): one backend WebSocket per ride, off by default, with the rider's name, position, lap and speed. Power and cadence go only when the rider allows it, and heart rate is never sent.

Riders from other apps appear on the track with their app next to their name, and remote riders move on smoothly between one-second updates. On the track, a group-ride room is off while OpenBikeNet is on.

The wire messages, name rules, route mapping and smoothing are unit-tested; the link is tested against a local WebSocket server. See pepperstm#69.

@pepperstm pepperstm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hi Ralf, thanks for picking this up, and for starting on Herne Hill. I like the shape of it: off by default, power/cadence opt-in, and written from the spec rather than ported. I've had a read through and most of what I spotted is around what happens when the connection drops.

The ones I'd want sorted before it goes in:

  • If the link drops and someone leaves while we're offline, they never get removed (obn.rs:161). The known-riders set starts fresh on reconnect, so anyone missing from the new snapshot just stays in the engine, frozen, and still counts as a rival. Could you diff the snapshot against what's already in the engine?
  • While we're backing off, the session keeps queueing an update every second, and on reconnect they all go out in one go (obn.rs:169). After a long outage that's a lot of stale positions well over 4 Hz, and other apps would see the rider rewind. Probably easiest to only ever send the latest position, e.g. a watch channel instead of the mpsc.
  • If the server sends welcome and then a fatal error (room full, bad name, unknown route), we end up with Retry { connected: true } and the backoff resets, so it hammers the server about once a second forever (obn.rs:130). I'd stop retrying on fatal errors, and pass the server's message through to the UI rather than "the server refused the connection".
  • In session.rs:383, GroupLink::join gets called before we decide to drop the group room because OpenBikeNet is on. Its task is already running by then, and nothing calls leave(), so the relay connection sits in the room until the app quits. Checking OpenBikeNet first should do it.
  • When the ride is paused or finished, we keep sending the last speed (session.rs:749), because tick returns early without zeroing it. So other people see you roll on and snap back every second.

And some smaller things, none of them blockers:

  • The remote app field doesn't go through clean_name before it ends up in the label (session.rs:754).
  • Nothing stops our own rider coming back to us if the server echoes it, and since set_remote matches on id only, a remote rider called ghost or bot0 could overwrite one of our rivals. Maybe prefix remote ids with something like obn:?
  • The smoothing only runs while the local rider is moving, and it uses moving time rather than wall-clock time (ride.rs:399). On a "Once round" ride remote riders also stick at 450 m and then jump back to the start.
  • forbidden() misses the private-use planes (U+F0000 and up), and the name is cut to 32 before it's trimmed, so leading spaces eat into it (core obn.rs:240).
  • Message::Close already matches the let Some(Ok(message)) above it, so those else arms never run. The snapshot and joined branches could also share a helper.

I haven't built it or tried it against the public server yet. I'll give it a proper go once these are in. Thanks again!

pepperstm added a commit that referenced this pull request Nov 18, 2026
Test counts, the Linux Bluetooth fix confirmed (#70), the XOSS sensor
in the tested-hardware table, the CI check names, and what is in
progress: OpenBikeNet (#89), the world update on next (#39) and the
visual style setting (#50). Some sentences reworded along the way.
pepperstm added a commit that referenced this pull request Nov 18, 2026
Updates the docs to where the project is today.

- HANDOFF: the test count (154, not 114), the CI check names, #70
confirmed by the reporter, Windows as the remaining untried platform,
and a new *Work in progress* table: PR #89 (OpenBikeNet, changes
requested), the `next` branch (world update, #39) and
`feature/visual-style` (#50), plus what's on `main` since 0.3.10.
- README: 130 core tests, the Linux Bluetooth row, and OpenBikeNet and
the world update on the roadmap.
- Wiki: the XOSS speed sensor in the tested-hardware table.
- Some sentences across the README, HANDOFF, CONTRIBUTING, release notes
and wiki reworded for readability.

Every file, function and `VP_` switch the docs mention was checked
against the code and still exists. Docs only.
RalfLeonFasler and others added 3 commits November 18, 2026 18:51
They were only moved on while this rider was moving, by moving time, so
they froze whenever this rider stopped pedalling or paused. On a "once
round" ride they also stuck at the line and jumped back to the start.
Now they move on every tick by the engine's wall clock and wrap on any
closed route.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Known riders are kept across reconnects; anyone missing from the new
  snapshot is taken away instead of staying frozen on the track.
- Only the latest position is sent (a watch channel), so after an outage
  one update goes out instead of a backlog.
- A fatal error, or an error about subscribe/join (tagged with a ref),
  stops the link for the ride and shows a plain reason with the server's
  message. A connection that drops within 30 s of welcome no longer
  resets the backoff.
- The remote app name is cleaned like a display name; our own rider id
  is never shown back to us.
- Names are trimmed before they are cut to 32 characters, and the
  private-use planes are filtered out.
- Tidier socket loop: Close handled explicitly, snapshot and joined
  share a helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… stopped

- Decide on OpenBikeNet before joining a group room, so the room is never
  joined (and never left open) when OpenBikeNet replaces it.
- Paused, finished or standing, share speed 0 with group rides and
  OpenBikeNet; the engine keeps its last speed when it stops ticking.
- Prefix OpenBikeNet rider ids with obn: so they can't overwrite the
  engine's own rivals (ghost, bot0, ...).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RalfLeonFasler

RalfLeonFasler commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read! All of it is in, in three commits:

Blockers

  • Riders who left while offline (2b525c8): the known riders now live across reconnects. A new snapshot is the whole room, so anyone we still show who isn't in it gets removed. Since riders get new ids after a reconnect (spec 3.5), stale entries always go.
  • Backlog after an outage: it's a watch channel now, so only the latest position is ever sent.
  • Hammering after welcome + fatal error: a fatal error now stops the link for that ride. So does an error about our subscribe or join; I tag both with a ref, because "room full" (limit_exceeded) and "unknown route" aren't fatal in the spec, and otherwise we'd keep sending updates nobody accepts. The HUD shows a plain reason with the server's message in brackets, e.g. "OpenBikeNet · the track is full (max_riders reached)". Spec 7.6 says message is meant for developers, hence the plain reason in front. I also stopped resetting the backoff unless the connection stayed up for 30 s after welcome, so a server that accepts and then drops us straight away isn't asked again every second.
  • Group room joined before the OpenBikeNet check (8cbfef1): OpenBikeNet is decided first, and the room is only joined when it's off.
  • Speed while paused or finished: the session shares 0 whenever the engine isn't moving. Group rides had the same issue, so they get the fix too.

Smaller ones

  • The remote app goes through clean_name.
  • Remote ids are prefixed with obn: in the engine, and a rider whose id equals our own rider value is never added.
  • (4b2d7f4) Smoothing now runs on a wall clock (RideEngine::clock) every tick, paused or not, and remote riders wrap on any closed route, so "Once round" rides work too.
  • forbidden() covers U+F0000–U+FFFFD and U+100000–U+10FFFD. Names are trimmed before they're cut to 32, and trimmed again after.
  • The Close arm is explicit now, and snapshot/joined share add_rider.

New tests cover the reconnect diff, the refusal (we send leave, clear the riders and don't reconnect), latest-position-only, the paused and once-round smoothing, and the name rules. Writing the latest-position test turned up one more bug: the watch receiver was made inside the spawned task, so a position sent before it first ran was treated as already seen. The receiver is now made in join().

The rebase onto main for the README conflict from #90 is ready here and passes fmt, tsc, clippy and the tests; it goes up as soon as I can push it. Happy to do the live ride together once you've had a look.

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.

2 participants