Repository navigation
Browser packages: publish to npm on release, refresh failures stop serving stale heads, current docs - #2423
Browser packages: publish to npm on release, refresh failures stop serving stale heads, current docs#2423bplatz wants to merge 12 commits into
Conversation
When a head event's refresh of the cached ledger failed, the sink logged a warning and fired the head-change callbacks anyway. The live-query cycle they trigger then re-ran every subscription against the old state and reported it unchanged, and nothing refreshed the ledger until the next commit arrived. The refresh is now retried three times (250 ms, 1 s, 4 s) on the pump's sleeper. If it still fails the ledger is evicted before the callbacks fire, so their re-query loads the new head or fails visibly.
The events fix (#1730) shipped in v4.2.0, `fluree token create --storage-ledger` mints a peer token, and the server has POST /multi-query.
A release tag builds the in-browser engine and the React package, smokes the packed engine in headless Chrome, and publishes both to npm at the workspace version (pre-release tags under `next`). Publishing goes through npm trusted publishing in the `npm` environment; a package's first publish uses an NPM_TOKEN secret until npm trusts the workflow. The tag must name the Cargo.toml version, a version already on npm is skipped, and each tarball carries the LICENSE.
Also drops the placeholder-name banner, and describes Peer.setToken, which #1733 wired through.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz this is a nice follow-up to #1733: the workflow tracks the PyPI one closely, and the browser fix reads right to me. Two small musts, below. The first: the React README now suggests fluree token create --all for a browser peer, and --all also grants write on every ledger.
The second follows from a decision for the record: my reading is that this makes both packages public BUSL-1.1 releases at the server's version, stable tags on latest, so a caret install takes every later 4.x. I'm on board, and I'd like your confirmation that's the intended decision; but since our patches can carry breaking changes, I'd like the install lines to use npm install --save-exact while the READMEs say pre-release.
One ordering note with #2421: if this merges before v4.2.8 is tagged, that tag runs the publish job, so either do the one-time npm setup first or tag 4.2.8 before merging this.
Full review below:
✅ Approving to unblock: please get the README token line and the exact-version install lines in before merging. The release workflow is careful in the right places (tag-vs-Cargo.toml check, skip-if-published, the LICENSE check, no publish path from a manual run, and a publish job with nothing but id-token: write), and the evict-before-callbacks fix closes a real silent-stale-read gap in the browser peer.
Before merging:
fluree-react/README.md:149: don't point a browser-held token at--all; it also grants read and write on every ledger.fluree-react/README.md:34,fluree-db-wasm/js/README.md:26: install withnpm install --save-exactwhile the READMEs say pre-release (the decision in the headline).
Notes:
- This is the second instance of a class: a per-event action awaited inline on the shared head-stream pump, so one ledger's slow or failing refresh holds every ledger's events (
head_stream.rs:224awaitson_eventdirectly). #2409 fixes it for the server peer with per-ledger workers (6038b74fa); the retries here add up to 5.25 s of sleeps plus fournotifyattempts per failing event, andHeadTracker::stopwaits behind them. The class fix would be per-ledger dispatch influree-db-nameservice-syncso both sinks get it; not this PR, the point fix is right here. - Related to #2409: it adds
LedgerManager::follow, which judges a record against the nameservice and reloads when a rebase replaced the cached line. This sink still callsnotify, which plans a record behind the cache asNoop, so the browser peer stays on the old line after a server-side rebase. That's pre-existing, not this PR's, so whichever of this and #2409 lands second switchesrefreshfromnotifytofollow(which also picks up a record that arrives while the ledger is still loading, one the browser peer drops today).
Adherence: Patterns ✔ · Performance ✔ · Deployment targets ✔ · Testing ⚠️ · Conventions ✔ · verification
- Patterns/abstractions: ✔ extends
python-release.yml's pattern (tag-gated environment, trusted publishing, tag check, license check, dispatch without publish) rather than inventing one; the eviction reuses theLedgerRetractedpath. - Performance (speed first, memory second): ✔ no engine hot path; the browser change adds work only on a failed refresh. No performance-degradation risk.
- Deployment targets: ✔
heads.rsruns in the wasm32 browser peer; its tests run native (tokio) intest, andwasm32/wasm-smokecompile and lint it for wasm32. The retry sleeps ride the same driverSleepjob the reconnect backoff already uses there, so no new timer source. The workflow runs only on GitHub Actions and has never executed; CI'swasm-smokeandreact-sdkrun its build steps. - Testing:
⚠️ the new tests run in CI and the eviction is pinned (it fails withdisconnect_ledgerremoved); the evict-before-callbacks order isn't (optional above). The stamp/pack/publish steps have no run yet. - Conventions: ✔ multi-line bodies on the fix and CI commits; docs updated with the behavior; actionlint green.
Verified at 7df84e088550: CI run 44101873474 green (the three new tests pass by name; 16237 passed, 45 skipped); on a box, heads::tests 4/4 at head, still 4/4 with callbacks before refresh, red with eviction removed, and the strengthened test green at head / red with the swap; local npm pack of both packages at 4.2.8 and 4.3.0-rc.1 matches the publish step's tarball names and carries package/LICENSE; npm 11.6.2's view and OIDC source read for the skip check and the token fallback.
Approving so you can merge when ready, with the two README changes in, but maybe worth folding in the setup notes on releasing.md while you're there.
| | `--storage-proxy-trusted-issuer <did:key>` | The proxy trusts only issuers named here (it falls back to `--events-auth-trusted-issuer`). | | ||
| | A bearer token carrying **`fluree.storage.all`** or **`fluree.storage.ledgers`** | The storage proxy requires `fluree.storage.*` claims specifically. **`fluree.events.*` is not sufficient**, and the shipped `fluree-events-token` CLI mints only the events half — so it cannot produce a working peer token. `fluree-db-wasm/js/scripts/fluree-server.mjs` exports `createIdentity()` and `mintStorageProxyToken()` that do. | | ||
| | `@fluree/db-wasm`'s generated glue | `cd fluree-db-wasm/js && npm install && node scripts/build.mjs` writes `js/pkg/`. | | ||
| | A bearer token carrying **`fluree.storage.all`** or **`fluree.storage.ledgers`** | The storage proxy requires `fluree.storage.*` claims specifically; **`fluree.events.*` is not sufficient**. `fluree token create --storage-ledger <alias>` mints one (`--all` for every ledger) — see `docs/cli/token.md`. | |
There was a problem hiding this comment.
Blocking: this row points a browser token at --all, which also grants write on every ledger.
fluree token create --all sets fluree.events.all and fluree.storage.all, but also fluree.ledger.read.all and fluree.ledger.write.all (fluree-db-cli/src/commands/token.rs:169-174). A peer token lives in the page (the demo even takes it as ?token=), so whoever lifts it from the tab can transact against every ledger on that server through the data API.
The scenario: someone following this row for "every ledger" mints with --all, ships it to a browser, and has handed out write access they never meant to grant. docs/cli/token.md:33 does say --all covers "events, storage, read, and write"; the CLI's own --help for --all (fluree-db-cli/src/cli.rs:3311) mentions only events and storage, which I'd guess is where this sentence came from (that help text predates this PR).
Suggested fix: drop the --all parenthetical, or say what it grants:
| | A bearer token carrying **`fluree.storage.all`** or **`fluree.storage.ledgers`** | The storage proxy requires `fluree.storage.*` claims specifically; **`fluree.events.*` is not sufficient**. `fluree token create --storage-ledger <alias>` mints one (`--all` for every ledger) — see `docs/cli/token.md`. | | |
| | A bearer token carrying **`fluree.storage.all`** or **`fluree.storage.ledgers`** | The storage proxy requires `fluree.storage.*` claims specifically; **`fluree.events.*` is not sufficient**. `fluree token create --storage-ledger <alias>` mints one (repeat the flag per ledger). Avoid `--all` for a token a browser holds: it also grants read and write on every ledger. See `docs/cli/token.md`. | |
Since it's one line, it'd be nice to correct --all's help text at cli.rs:3311 in this PR too, so the next person reading --help doesn't draw the same conclusion. Commenting here because fluree-db-cli/src/cli.rs is not in this diff.
|
|
||
| ```sh | ||
| npm install @fluree/react # remote mode | ||
| npm install @fluree/react @fluree/db-wasm # peer mode as well |
There was a problem hiding this comment.
Blocking: while these READMEs say pre-release, the install lines should pin an exact version.
A plain npm install @fluree/react writes ^4.2.8 into the app's package.json, so the next install there takes whatever 4.x we publish next. Our patch releases can carry breaking changes (4.2.5, 4.2.6 and 4.2.7 each had a Breaking Changes section), and with a pre-release API that's exactly the upgrade an app shouldn't take unasked.
Suggested install lines here, and the same for fluree-db-wasm/js/README.md:26 and for the peer-mode table's npm install @fluree/db-wasm at fluree-react/README.md:150:
npm install --save-exact @fluree/react # remote mode
npm install --save-exact @fluree/react @fluree/db-wasm # peer mode as well…plus a sentence saying why, e.g. "While the packages are pre-release, pin an exact version: any release can change the API." That also keeps the engine and the hooks on the matching versions the next paragraph asks for.
| - `dist-workspace.toml` — cargo-dist's distribution targets and installers. | ||
| - `.github/workflows/release.yml` — autogenerated by cargo-dist (with `allow-dirty = ["ci"]` set so our edits survive `dist init`: `--generate-notes`, and the Homebrew job's `fluree-beta` formula). Leave dist's `publish-prereleases` off: it would publish a pre-release as `fluree` itself. | ||
| - `.github/workflows/python-release.yml` — the Python wheels. It publishes through PyPI trusted publishing: the `fluree` project on PyPI trusts this workflow running in the repository's `pypi` environment, so no PyPI token is stored. That environment's deployment rule admits only `v*` tags; it is what stops any other ref from reaching PyPI, so keep it when editing the repository's environments. Its build runners match `dist-workspace.toml`'s; keep the two in step when a platform is added. | ||
| - `.github/workflows/npm-release.yml` — the npm packages. It publishes through npm trusted publishing: each package on npmjs.com trusts this workflow running in the repository's `npm` environment, whose deployment rule admits only `v*` tags. npm can only trust an existing package, so a package's first publish uses an `NPM_TOKEN` environment secret (a granular token for the `@fluree` scope); delete the secret once both packages trust the workflow. The repository keeps `0.0.0-dev` in each `package.json`; the workflow stamps the release version at pack time. |
There was a problem hiding this comment.
Optional: a few things about the one-time npm setup that I think belong in this paragraph, since it's where the next person doing it will look.
- npm's trusted-publisher docs say a newly created configuration "must complete its first successful publish within 2 days", and an expired one "can no longer be used or edited" (you delete it and create a new one). So "after that release, configure trusted publishing, then delete the secret" will most likely expire before the next release. Configuring it right before the second release's tag, and deleting
NPM_TOKENonce that publish succeeds, avoids the trap. - A granular token only publishes from CI with npm's "Bypass two-factor authentication" box checked, and it's unchecked by default. npm also says bypass-2FA tokens with direct-publish access are being removed in January 2027, so this bootstrap has a shelf life. Since the token can write every
@flureepackage, the shortest expiry, created right before the tag, seems like cheap insurance. - The workflow has never run: it can't be dispatched until it's on
main. One manual run frommainbefore the first publishing tag would exercise the stamp, pack and artifact steps that CI'swasm-smokeandreact-sdkjobs don't cover. - If a
v*tag runs this workflow before thenpmenvironment exists, GitHub createsnpmon the fly with no deployment rule, so it's worth checking thev*rule is there before adding the secret.
This is minor and non-blocking, but if you agree it's right, I'd rather see it written down here now than rediscovered at the first release.
| needs: build | ||
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | ||
| runs-on: ubuntu-24.04 | ||
| environment: |
There was a problem hiding this comment.
Optional: the npm environment's tag rule decides which refs can publish, not which commits.
Any v* tag on any commit enters npm, and npm's trusted publishing pins the repository, npm-release.yml and the environment name, not the workflow's content. So anyone who can push a tag can publish @fluree/db-wasm from a branch commit whose npm-release.yml (or Cargo.toml version) they edited, with provenance pointing at fluree/db. That's already true of PyPI today: the repo's only ruleset is "Protect Main" (a branch rule), and pypi has a v* tag policy and no required reviewers.
A tag ruleset on v* that limits creation to release maintainers closes it for npm, PyPI and the CLI release at once, and a required reviewer on npm (and pypi) would be a second layer. Both are org-admin settings, so the PR's part is a line in the setup steps and in releasing.md. Not blocking, but since this is the moment we add a second registry, I'd rather we close it now than after.
There was a problem hiding this comment.
Addressed in b1c4ab9. The ruleset and the reviewer are org-admin settings, so they are listed in the setup steps (here and in the PR body); neither is configured yet.
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| run: | | ||
| tag=latest | ||
| case "$VERSION" in *-*) tag=next ;; esac |
There was a problem hiding this comment.
Optional: latest and next can move backwards.
next takes every pre-release, and we cut pre-releases on two lines at once (v5.0.0-alpha.3 and v4.2.4-beta.2 both exist), so a 4.x beta after a 5.0 alpha points next back at 4.x; a stable 4.x after a 5.0 stable would do the same to latest. The Homebrew job already refuses that (release.yml:425-428, with dpkg --compare-versions). Something like this, inside the loop before npm publish, keeps both tags moving forward and still publishes an older line under its own tag:
publish_tag=$tag
current=$(npm view "$name" "dist-tags.$tag" 2>/dev/null || true)
if [ -n "$current" ] && dpkg --compare-versions "${VERSION//-/\~}" lt "${current//-/\~}"; then
publish_tag="$tag-${VERSION%%.*}" # e.g. next-4: published, and `next` stays put
fi…with npm publish … --tag "$publish_tag" on the line after it.
Minor and non-blocking, but if you agree it's right, I'd rather see it in this PR than lost in the backlog.
There was a problem hiding this comment.
Addressed in db8fd42. The - to ~ rewrite goes through tr rather than ${VERSION//-/\~}, which reads the same in every shell.
| assert_eq!(cached_t(&sink).await, None, "the stale ledger was evicted"); | ||
| let seen = seen.lock().unwrap(); | ||
| assert_eq!(seen.len(), 1, "callbacks still fire"); | ||
| assert_eq!(seen[0].commit_t, t + 1); |
There was a problem hiding this comment.
Optional: the ordering this test is named for isn't pinned.
The callback only records the HeadChange, and every assertion runs after on_event returns, so the test can't tell evict-then-callbacks from callbacks-then-evict. Claude checked on a box: swapping self.refresh(record).await and self.registry.notify(&change) at :257-258 leaves all four heads::tests passing. (Removing disconnect_ledger does fail it, so the eviction itself is pinned.)
Having the callback record how many retry waits had already been taken when it fired pins the order. With this change the test passes at this head and fails with those two lines swapped (left: 0, right: 3):
@@ async fn cached_ledger_sink() -> (
PeerHeadSink,
Arc<RecordingSleeper>,
- Arc<Mutex<Vec<HeadChange>>>,
+ Arc<Mutex<Vec<(HeadChange, usize)>>>,
) {
@@
+ let sleeper = Arc::new(RecordingSleeper::default());
let seen = Arc::new(Mutex::new(Vec::new()));
let registry = Arc::new(HeadRegistry::default());
{
let seen = Arc::clone(&seen);
- registry.add(Box::new(move |c| seen.lock().unwrap().push(c.clone())));
+ let sleeper = Arc::clone(&sleeper);
+ // Each change, with the retry waits already taken when it fired.
+ registry.add(Box::new(move |c| {
+ let waits = sleeper.0.lock().unwrap().len();
+ seen.lock().unwrap().push((c.clone(), waits));
+ }));
}
- let sleeper = Arc::new(RecordingSleeper::default());
@@ async fn an_unreachable_head_evicts_the_ledger_before_callbacks_fire() {
- assert_eq!(seen[0].commit_t, t + 1);
+ assert_eq!(seen[0].0.commit_t, t + 1);
+ assert_eq!(
+ seen[0].1,
+ REFRESH_RETRY_DELAYS.len(),
+ "callbacks fire after the last retry, once the ledger is evicted"
+ );Minor and non-blocking, but it's the property the fix depends on, so I'd rather see it pinned in this PR.
|
Merge note for whichever of this and #2409 lands second: #2409 switches the browser peer's head sink from The two conflict in
|
…lowups # Conflicts: # fluree-db-browser/src/heads.rs
The React README's peer-mode table offered `fluree token create --all` for a token covering every ledger. `--all` also grants `fluree.ledger.read.all` and `fluree.ledger.write.all`, and a peer token lives in the page, so whoever lifts it from the tab can transact against every ledger on the server. The row now names `--storage-ledger`, repeated per ledger, and warns against `--all` for a token a browser holds. `--all`'s own help text named only the events and storage claims, which is likely where the README's reading came from. It now lists all four claims it sets, as `docs/cli/token.md` already does.
A plain `npm install @fluree/react` writes a caret range into the app's package.json, so its next install takes whatever later 4.x is published. The packages are released at the server's version, whose patch releases have carried breaking changes, and their API is pre-release. Every install line in both READMEs now uses `npm install --save-exact`, and each says why: while the packages are pre-release, any release can change the API. Pinning also keeps the engine and the hooks on the matching versions the READMEs ask for.
The test named for this ordering recorded only the head change, and every assertion ran after `on_event` returned, so it could not tell evict-then-callbacks from callbacks-then-evict: swapping the refresh and the callbacks left it passing. The order is the point of the fix, since a callback that re-queries on a head change would otherwise read the stale cached ledger as if it were current. Each callback now records how many retry waits had been taken when it fired, and the test requires all of them: the callbacks run after the last retry, once the ledger is evicted. With the two calls swapped it fails with none taken.
The publish job put every stable release on `latest` and every pre-release on `next`. Releases are cut on two lines at once (a 5.0 alpha and a 4.x beta both exist), so a 4.x beta published after a 5.0 alpha would point `next` back at 4.x, and a stable 4.x after a stable 5.0 would do the same to `latest`. Before publishing, the job now reads the tag's current version and compares it in Debian ordering (`-` read as `~`, so 4.2.4-beta.2 sorts before 4.2.4), as the Homebrew job does. A release older than the one the tag names is published under its line's own tag, `next-4` or `latest-4`, and the tag stays where it is. The `-` to `~` rewrite goes through `tr`, which reads the same in every shell.
The release doc said to publish the first release with a token, then configure trusted publishing and delete the token. Several details decide whether that works, and the next person doing it will look here: - A new trusted-publisher configuration must complete a publish within two days, or it expires and can no longer be used or edited. Configured right after the first release, it will most likely expire before the second, so it is configured just before the second tag. - A granular token publishes from CI only with "Bypass two-factor authentication" checked, which is off by default, and npm is removing such tokens in January 2027. It can write every `@fluree` package, so it gets the shortest expiry, created just before the first tag. - The workflow cannot be dispatched until it is on `main`; one manual run there exercises the stamp, pack and artifact steps CI doesn't. - A `v*` tag that runs the workflow before the `npm` environment exists makes GitHub create it with no deployment rule, so the environment comes first. The doc now lists the steps in that order, and says how the dist-tags behave. The workflow's header points to it.
The `npm` and `pypi` environments admit only `v*` tags, but a deployment rule decides which refs can publish, not which commits: any `v*` tag, on any commit, enters the environment. Trusted publishing pins the repository, the workflow file and the environment name, not the workflow's content, so whoever can push a tag can publish from a branch whose workflow or version they edited, with provenance naming this repository. The setup steps now include a tag ruleset on `v*` limiting creation to release maintainers, which closes this for npm, PyPI and the CLI release at once, with a required reviewer on the `npm` and `pypi` environments as a second layer. Both are organization-admin settings.
Follow-up to #1733.
Publishing
@fluree/db-wasmand@fluree/reactNeither package was installable: both sat at
0.0.0-devwith no publish path..github/workflows/npm-release.ymlruns on the samev*tags as the CLI and Python releases. It builds the engine (wasm-release +wasm-opt) and the React package, smokes the packed engine in headless Chrome, and publishes both at the workspace version.v4.3.0publishes 4.3.0 underlatest; a pre-release tag publishes undernext. A release older than the one a tag names (a 4.x after a 5.0) goes under its line's own tag,latest-4ornext-4, so neither tag moves backwards. The repo keeps0.0.0-dev; the version is stamped at pack time, so release PRs don't change.It refuses a tag that doesn't name the
Cargo.tomlversion. It skips a version already on npm, so re-running after a partial publish finishes the job. It checks that each tarball carries the BUSLLICENSE. Run by hand (workflow_dispatch), it builds and smokes without publishing.docs/contributing/releasing.mdcovers the step and its rollback.One-time setup before the first release that should publish (an org admin). The order matters;
docs/contributing/releasing.md("One-time npm setup") has the detail:npm, with a deployment rule admitting onlyv*tags (aspypihas), before adding any secret.v*limiting creation to release maintainers, and ideally a required reviewer onnpmandpypi: the environment rule decides which refs publish, not which commits.main, run the workflow by hand once (it builds, smokes and packs without publishing).NPM_TOKENenvironment secret: a granular token for the@flureescope with the shortest expiry and Bypass two-factor authentication checked. npm can only trust an existing package, so each package's first publish needs it.fluree/db, workflownpm-release.yml, environmentnpm). A new configuration expires unless it publishes within two days.A failed head refresh no longer serves the old head as current
When a head event's refresh of the cached ledger failed, the browser peer logged a warning and fired the head-change callbacks anyway. The live-query cycle they trigger re-ran every subscription against the old state and reported it unchanged. Nothing refreshed the ledger until another commit arrived, so a quiet ledger stayed stale with no visible error.
The refresh now retries (250 ms, 1 s, 4 s) on the head pump's sleeper. If it still fails, the ledger is evicted before the callbacks fire, so their re-query loads the new head or fails visibly. The refresh goes through
LedgerManager::follow(from #2409), so it also follows a rebase that moves a branch back or onto another line.Docs
The READMEs and demo walkthrough said the server's per-ledger events fix wasn't released (#1730 shipped in v4.2.0). They said no CLI could mint a peer token (
fluree token create --storage-ledgerdoes;--all, which also grants read and write on every ledger, is not for a token a browser holds, and its help text now says what it grants). They said the server has no multi-query endpoint (POST /multi-queryexists; the remote transport doesn't use it yet). The engine README still called its package name a placeholder and saidsetTokendidn't exist. All corrected, plus install instructions, pinned with--save-exactwhile the packages are pre-release.Also adds a residency test for a historical view between the index and the head.