logs.gokuls.in

5 pull requests merged across 1 repo

Offline-Protocol/offline-protocol-sdk

What

Two fixes to the browser binding's transports. Both were found running the Obsidian shared-folders plugin on a Mac, an Android phone (Samsung SM-M366B, Android 16, Obsidian's WebView) and an iPhone 11 (iOS 27, WKWebView), through restarts, app kills, sleep and Wi-Fi loss.

  • A WebRTC connection stuck in disconnected is now closed (fix(bindings): close a WebRTC link stuck in "disconnected"). The carrier closed only on failed or closed. Android's WebView left the old connection in disconnected for good once the other device restarted. The engine takes one announced link per address (W3), so that dead link refused every new link from the restarted device. They never met again until a page reloaded. This happened in three restarts out of five. The carrier now closes a connection that stays disconnected for 15 seconds. That is longer than Chrome's own deadline, so Chrome behaves as before. A blip that recovers inside the window cancels the close. new WebRtcCarrier(node, { disconnectedMs }) sets the deadline, and Infinity restores the old behaviour.
  • A hosted Nostr room stays reachable across sleep and network changes (fix(bindings): keep a hosted Nostr room reachable across sleep). host() opened its relay sockets once. A socket that closed after the subscription went live was never dialled again. After a phone slept or lost Wi-Fi, its room answered nobody, and every join timed out with "no host answered" until the app restarted. A hosted room now does three things:
  • It redials a relay that drops, backing off from 1 s to 30 s.
  • Every keepAliveMs, 60 s by default, it re-sends its REQ under the same subscription id. NIP-01 says that replaces the subscription and the relay answers EOSE again. A relay that does not answer within 10 s is dropped and redialled. This covers a socket the network lost silently, which still reads as open.
  • It probes at once, skipping any backoff, when the page comes back online or into view.

A join is unchanged.

Tests

  • bindings/web/scripts/test-browser.sh: 15 of 15 pages pass in Chromium, Firefox and WebKit. The first commit alone also passes all 15.
  • webrtc.html gains a step that makes one end's RTCPeerConnection read disconnected. A short blip must leave the link up. A stuck connection must be closed and reported lost at both ends. The same two devices must then link again and exchange a message.
  • nostr-signal.html gains two steps. In the first, the page closes every socket of a hosted room, and a later join must be answered. In the second, the room is hosted on the test relay's new /once path, which confirms one subscription and then goes quiet. The room must drop that socket at its next probe and dial another.
  • Without the source changes, both new steps fail in Chromium, with exactly the two bugs: relay dropped: no host answered in the room and stuck disconnected: timed out waiting for neighbor_lost.
  • cargo test -p offline-protocol-web: 43 passed, including the guard that reads nostr-signal.js. No Rust changed.
  • On devices, the plugin-side versions of these fixes were run on the three devices above. After a Mac restart, 4 of 4 relinks recovered in 19 to 23 s, against 2 of 5 before. Waking the iPhone, catch-up went from 23 s to 3 to 4 s. These SDK versions have not been run on the phones yet.

Type of change

  • fix: bug fix

Breaking changes

None. Both options are new and optional. The one behaviour change is that a connection left in disconnected for 15 s now closes. In Chrome, failed already closes it sooner.

Notes for reviewers

  • The documented W9 invariant changes from "closes on failed or closed only" to also closing at the deadline. The reasoning is in the doc and in the comment at the top of webrtc.js.
  • In the test, the WebRTC fake calls pc.onconnectionstatechange() directly, because Firefox does not route a page-dispatched connectionstatechange to the handler.
  • The probe deadline is the lesser of 10 s and keepAliveMs, so a short keep-alive never overlaps probes.

What

The browser binding could create and administer a group but never shrink it. This adds:

  • OfflineNode.removeFromGroup(groupId, member): the engine's remove_from_group. The remaining members move to a new epoch whose keys the removed member never holds, and the removed member gets group_member_removed.
  • OfflineNode.groupInfo(groupId): the group's members and epoch, or null for a group this device does not hold. For a UI that shows membership and key epochs, and for proving a removed device holds no keys.
  • OfflineNode.start({ wasm }): the engine module as bytes or a compiled module. This is for hosts that start the worker from a Blob URL, where the glue's relative fetch of the .wasm has nothing to resolve against. Examples: an editor plugin (Obsidian serves plugin files from another origin than the app's own) or an extension. Without the option, behaviour is unchanged.

Why

These came up building a showcase Obsidian plugin on the web binding: shared folders as MLS groups, where removing a member is the point of the demo.

Tests

  • New a_removed_member_is_told_and_the_group_moves_to_a_new_epoch (two engines over links): the removed member sees group_member_removed, the owner's epoch advances and the member leaves its roster, and the removed side's group_info is None.
  • cargo fmt --all -- --check, cargo clippy -p offline-protocol-web -- -D warnings (host and wasm32-unknown-unknown), cargo test -p offline-protocol-web --lib: 43 passed.
  • Built with bindings/web/scripts/build.sh and exercised in Obsidian 1.8.7 (Electron) across four vaults in two app instances: join, removal over the same-machine carrier and over WebRTC with Nostr signalling, groupInfo epochs, and start from bytes through a Blob URL worker.
  • Not run locally: bindings/web/scripts/test-browser.sh (the Playwright pages). No existing page calls the new methods, so CI's Web Binding job is the check that nothing regressed.

Docs

CHANGELOG (Unreleased, Added), and docs/bridges/web.md under "What the host owes" for where the module comes from.

Why

Every pull request ran all 35 jobs whatever it touched. #621 changed only browser JavaScript and docs, and still ran about 85 runner-minutes of Rust, Java, Ruby, Python, Swift and Android work across Linux, macOS and Windows. The Actions cache was also at 10.5 GB, over the 10 GB limit, because every PR saved its own copy of 15 Rust caches and so evicted main's.

What changes

Path gating. A new Detect Changes job reads the PR's file list (dorny/paths-filter, the pinned SHA already in use) and every job is gated on a filter naming what it builds, tests or reads.

  • A push to main runs everything, and so does any PR that edits ci.yml. This PR therefore runs the full set.
  • Filters err wide. About fifty guards in the Rust suite read binding sources, specs, integration guides, CLAUDE.md and the workflows by path, so rust_tests follows all of those. The Test matrix is cut accordingly: Linux, macOS and Windows when Rust changed, Linux alone when only a guard-read file did.
  • The Python filter also covers the examples and spec chapter the pytest suite reads.
  • The Flutter job's own filter moved into the central job, keeping the names its guard checks for.
  • CI Result passes when every job either succeeded or was skipped by its filter, so one required check covers all of them if you add one. The repository's rulesets don't require any checks today.

Efficiency inside the jobs that run.

  • rust-cache saves only from main (save-if).
  • Java, Ruby and Windows C build the same debug library, so they now share one cache (ci-uniffi-debug).
  • Python Bindings restores uniffi-bindgen and uniffi-bindgen-java from a pinned cache instead of compiling both every run (205 s). Its three pytest runs, 6 minutes back to back, are now a parallel Python Tests (3.10 / 3.12 / 3.13) matrix over the library it uploads. This was the slowest job at about 13 minutes.
  • The release cdylib build runs on Linux for every PR, and on macOS and Windows only when a manifest, lockfile or build script changes. Every push to main still builds all three. That saves about 4 to 5 minutes per PR on each of the macOS and Windows legs.

What the 40 most recent merged PRs would have run

Each PR's file list was replayed through these filters with picomatch, the matcher paths-filter uses, at dot: true:

PRchangejobs beforejobs now
#621, #620browser JS + docs35License Consistency, Web Binding
#617playwright bump35License Consistency, Web Binding
#602README35License Consistency
#618react-native bump358 (RN, iOS, Android, Swift, Linux Test)
#614MLS engine fix3517 (no RN, Android, Flutter, packaging, deps)

On average 17 of 27 top-level jobs run, down from 27. The 16 full runs are mostly PRs that edited ci.yml.

The files no filter matched (CHANGELOG, ADRs, docs/bridges/{web,python,ruby}.md, docs/telemetry.md, CONTRIBUTING, dependabot.yml) were grepped across the Rust, Python, Ruby, Java, JS and shell test code. Nothing reads them except in comments.

Verification

  • actionlint clean, including shellcheck over every run: block.
  • The Rust guards that parse ci.yml pass locally: flutter_bridge_guards, build_profile, capi::ffi_tests (36) and all of offline-protocol-web (42).
  • Three docs that said a job runs "on every pull request" now say when it runs (ADR 0025, docs/bridges/README.md C13, docs/bridges/ruby.md).

Risk

A filter that is too narrow fails silently, because the job is skipped green. The comment on changes says so, and says a new guard reading a new path must be added to rust_tests. Main still runs every job on every push, so a miss surfaces there before a release.

Problem

The Web Binding job sometimes runs for close to an hour, and runs like 40006263164 stay stuck in "Install Playwright and its browsers".

That step normally takes 40 to 60 s. In 7 of the last 31 runs it took 11 to 52 minutes. The time goes to the apt half of --with-deps: about 190 packages, 112 MB in total, mostly WebKit's media and GTK libraries. They come from azure.archive.ubuntu.com, which sometimes crawls. From job 120550023396:

Fetched 112 MB in 51min 26s (36.4 kB/s)

The browsers come from cdn.playwright.dev and took seconds each in that same run.

The job also had no timeout-minutes, so a stall could hold it for the six-hour default.

Change

  • Cache the packages: Dir::Cache::Archives points apt's download directory at ~/playwright-debs, which actions/cache@v6 saves between runs. Playwright's own apt call then finds every package already downloaded.
  • Cache key: the key is bindings/web/package-lock.json plus $ImageVersion, with restore-keys. A new runner image restores the previous set, fetches only the packages Ubuntu has updated since, and saves under its own key. apt-get autoclean drops superseded versions so the cached set does not grow.
  • Time limit: timeout-minutes: 30 on the job. A healthy run is about 5 minutes.

Verification

  • Mechanism: tested in ubuntu:24.04. With the config in place, the first install saved its debs into the redirected directory, and a reinstall reported Need to get 0 B/19.2 MB of archives. This held even with Ubuntu's docker-clean hook present, because the hook hard-codes /var/cache/apt/archives.
  • Lint: actionlint .github/workflows/ci.yml passes.
  • On GitHub (still to do): this PR's first run starts with an empty cache, so it can still be slow, and it saves the cache when it finishes. Re-running the job should then show the step's apt log reporting Need to get 0 B.

Follow-up to #620, which merged with six review items open. All six are fixed here, and each fix is proven by a check that fails on main.

The WebRTC carrier

  • A call that rejects reports nothing. A connection reported "closed" from offer() or answer() even when the call rejected, naming an object the page never received. A connection now reports nothing until its call has handed the object over, and at that moment it replays the state it is already in, so no change is lost.
  • A connection closed while gathering makes the call reject. Before, carrier.close() during gathering let offer() resolve to a code for a dead connection. NostrSignaller.join() therefore published a dead offer and waited out its timeout; it now rejects at once. Its host side already catches a rejected answer().
  • The "failed" timing in index.d.ts is fixed. It said "about 15 s later" (than "disconnected"); Chrome reaches it 10 s after "disconnected" and 15 s after the last answered check, as webrtc.js and web.md already said.
  • A try/catch that could not catch is gone. dispatchEvent never throws for a listener's exception.

The lobby

  • The host keeps inviting while a device is linked. It tried 50 times from the moment of the link. A key package slower than that left the device uninvited with nothing on screen, and nothing tried again, because the device's secure_session_established had been spent on the loop that gave up. The host now retries for as long as the link lasts, and after 10 s shows the engine's reason.
  • A device is saved as a member only once invited. A save while an invite was still failing (another member coming back, say) wrote the device as a member, so a reload let it back as one without an invite.
  • A resumed game the node no longer holds is reported. Every invite and send failed in silence. Invites that keep failing, and 3 s of group sends that all fail with a member linked, now show the engine's reason ("Group not found: …") and point at End this game.
  • The page ends with a newline again.

No Rust, UDL or wire change.

Testing

  • bash bindings/web/scripts/test-browser.sh: 15 of 15 pages pass in Chromium, Firefox and WebKit.
  • webrtc.html has a new step that checks both ways a call can fail: a damaged code, and a carrier closed right after setLocalDescription, which pins the timing exactly. Negative control: with main's webrtc.js it fails at that step in all three engines. Firefox rejects the offer but still reports "closed" twice.
  • The lobby was driven as two and three real pages, each in its own Chromium profile, linked over WebRTC with the codes a person would paste. A route-level seam on the module made the first 55 invites fail, which is more than the old fixed 50 tries. The seam is in the test harness, not in the shipped code.
ScenarioThis branchmain
Host, join, then the player reloads and relinks with no second invitepassnot run
55 failed invites, then the player joinsjoins at about 17 snever joins; host screen silent
A save while an invite is failing (3 devices)saves C, not Bsaves B as a member
Resumed game gone, a new device linksreason + End this game at 11 ssilent
Resumed game gone, a saved member returnsreason + End this game at 4 ssilent
  • Device run on a MacBook (Chrome 155) and a Samsung Galaxy M36 (Android 16, Chrome 152), in both directions, each pair on a fresh profile, recorded in docs/bridges/web-devices.md:
  • link 30 to 153 ms after Connect; 10 states a second each way; host 20 to 23 store flushes a second;
  • the player and then the host reloaded, in both directions: same addresses, the host still hosting the same game, the player back on its link with no second invite. A laptop already in session with the hosting phone was invited 0.1 s after the link;
  • home screen and screen lock, in both directions: both pages showed "connection unstable" 11.6 to 13.3 s after the phone left the screen and the disconnect 10 s later, the host sent nothing while apart, and two new codes resumed play at 10 states a second with no backlog. After a lock the phone was unlocked by hand; its page still said the host disconnected, and two new codes resumed play;
  • the paths new here, with the phone hosting: 55 failing invites showed "still trying to add" at 10.1 s and the player joined at 15.2 s, unsaved until then; a resumed game the node does not hold showed "Group not found" with End this game at 10.1 s for a new device and 3.2 s for a saved member;
  • a second tab on the same account is still refused.

Found on the devices, not fixed here

  • One of 20 fresh pairs never joined, and nothing on screen says so. The host's invite succeeded and it sent state; the phone never reported being added and showed no game. On a later relink the host delivered a held message that the phone decrypted, and it still did not join. That first run had no event log. 19 logged fresh pairs, three of them reloaded before linking, and a local reproduction of every other condition of that run all joined, so the cause is not known. The pair's state is kept on both devices under the profile pr621. The new warnings cannot catch it, because no send fails on the host. A player page that is linked to its host but receives no game for a few seconds could say so; that is a follow-up.

Not covered

  • The lobby harness ran in Chromium only. The page's logic does not depend on the engine.
  • iPhone Safari, and the "disconnected" timing on Firefox and Safari, which were not measured on devices.
  • Whether the relink in the second lock test came up behind the lock screen or after the phone was unlocked by hand: the phone was unlocked during it.