From 8d6f1fb8a63570bb5a126bf3d935c3e83de5fd2e Mon Sep 17 00:00:00 2001 From: Sterister Date: Mon, 19 Oct 2026 00:37:09 +0200 Subject: [PATCH] fix(media): MediaClient's retry backoff works outside Bun Bun.sleep threw in a browser or Node the first time a piece was retried; setTimeout does the same everywhere. The browser bundle has no Bun.* left. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 3 +++ packages/shade-media/src/client.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0330ba2..0424783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,6 +140,9 @@ New package **`@shade/media`** — see `docs/media.md`. 0 looped forever, a huge one held the film in memory, a huge `window` opened a request (a thread, on Kotlin) per piece. The status is now checked (`statusProblem`) and the window capped at 16. +- `MediaClient` waited between retries with `Bun.sleep`, so a retry threw in + a browser or Node; it uses `setTimeout` now (the browser bundle of + `@shade/media` has no `Bun.*` left). - `shade media get` used the sealed file's `meta.name` as the output path, so whoever sealed a file chose where it was written (`../../.bashrc`). Names are now reduced to one safe path component. diff --git a/packages/shade-media/src/client.ts b/packages/shade-media/src/client.ts index 897cdd9..23b66a7 100644 --- a/packages/shade-media/src/client.ts +++ b/packages/shade-media/src/client.ts @@ -50,7 +50,8 @@ const MAX_TRIES = 8; /** The relay is restarting, overloaded or the network dropped: try again. */ class Transient extends Error {} -const backoff = (attempt: number) => Bun.sleep(Math.min(30_000, 500 * 2 ** attempt)); +// setTimeout, not Bun.sleep: the client runs in browsers and Node too. +const backoff = (attempt: number) => new Promise((r) => setTimeout(r, Math.min(30_000, 500 * 2 ** attempt))); export class MediaClient { private readonly fetchFn: typeof fetch;