commit 770ab132ad2a725872f6a437863232184264569f
parent 889055c0b517b974e3c0cfb613beced8c015c5fb
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 6 Nov 2026 01:22:49 -0500
common: the archive.org client and the web pacer read pacing.jitter per wait
Both processes' singletons (archiveOrgClient, the web pacer) were built at
import time, and their constructors called pacingJitter() -> getSettings()
-> getPaths(). That fixed the cached paths to the TRANSCRIPTS_DIR in effect
at import, before any caller set its own. It also froze the jitter to the
settings of that moment. In the editor unit suite this sent
_researchRuns' in-process import-post to <repo>/transcripts ("No such
channel: test-youtube"). The share is now read at each wait, and an explicit
`jitter` option still wins.
editor: browser-lookup's route test gives its odysee queue no job gap. The
listing job is the queue's second, and the default 20 s gap (stretched by
the jitter) outlasted settle()'s 20 s, so the job was still "running".
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/common/lib/archiveOrgClient.ts b/common/lib/archiveOrgClient.ts
@@ -135,7 +135,7 @@ export function parseRetryAfterMs(value: string | null, nowMs: number): number |
export class ArchiveOrgClient {
private readonly deps: Required<ArchiveOrgClientDeps>;
- private readonly opts: Required<ArchiveOrgClientOpts>;
+ private readonly opts: Required<Omit<ArchiveOrgClientOpts, "jitter">> & { jitter?: number };
private chain: Promise<unknown> = Promise.resolve();
private lastDoneAt = -Infinity;
private readonly cache = new Map<string, { at: number; value: ArchiveOrgItemMetadata }>();
@@ -158,10 +158,18 @@ export class ArchiveOrgClient {
cacheTtlMs: opts.cacheTtlMs ?? 6 * 60 * 60 * 1000,
timeoutMs: opts.timeoutMs ?? 60_000,
idleTimeoutMs: opts.idleTimeoutMs ?? 120_000,
- jitter: opts.jitter ?? pacingJitter(),
+ // Read at each wait, not here: THE process's client below is built at
+ // import time, and reading settings then would fix getPaths() to
+ // whatever TRANSCRIPTS_DIR was set before any caller set its own (and
+ // the jitter to the settings of that moment).
+ ...(opts.jitter !== undefined ? { jitter: opts.jitter } : {}),
};
}
+ private jitterShare(): number {
+ return this.opts.jitter ?? pacingJitter();
+ }
+
// Run `fn` after every earlier request (and its gap) has finished.
private serial<T>(fn: () => Promise<T>): Promise<T> {
const run = this.chain.then(fn, fn);
@@ -173,13 +181,13 @@ export class ArchiveOrgClient {
// doubling — upward only: it used to land as much as 20 % short of it.
private backoffMs(attempt: number): number {
const exp = Math.min(this.opts.maxBackoffMs, this.opts.baseBackoffMs * 2 ** (attempt - 1));
- return Math.ceil(jitterUp(exp, Math.max(0.2, this.opts.jitter), this.deps.random));
+ return Math.ceil(jitterUp(exp, Math.max(0.2, this.jitterShare()), this.deps.random));
}
// The gap before one request: minGapMs stretched by up to pacing.jitter, a
// fresh draw per request (lib/jitter.mjs — never shorter than minGapMs).
private gapMs(): number {
- return Math.ceil(jitterUp(this.opts.minGapMs, this.opts.jitter, this.deps.random));
+ return Math.ceil(jitterUp(this.opts.minGapMs, this.jitterShare(), this.deps.random));
}
// One GET, with the gap before it and the retry policy around it. With
diff --git a/common/lib/web/pacer.ts b/common/lib/web/pacer.ts
@@ -80,7 +80,7 @@ function retryAfterMs(value: string | null, nowMs: number): number | null {
export class WebPacer {
private readonly deps: Required<WebPacerDeps>;
- private readonly opts: Required<WebPacerOpts>;
+ private readonly opts: Required<Omit<WebPacerOpts, "jitter">> & { jitter?: number };
private chain: Promise<unknown> = Promise.resolve();
private lastDoneAt = -Infinity;
// Every attempt sent, with when it started (tests and logs).
@@ -99,10 +99,18 @@ export class WebPacer {
backoffMaxMs: opts.backoffMaxMs ?? WEB_BACKOFF_MAX_MS,
maxAttempts: opts.maxAttempts ?? WEB_MAX_ATTEMPTS,
timeoutMs: opts.timeoutMs ?? WEB_TIMEOUT_MS,
- jitter: opts.jitter ?? pacingJitter(),
+ // Read at each wait, not here: THE process's pacer below is built at
+ // import time, and reading settings then would fix getPaths() to
+ // whatever TRANSCRIPTS_DIR was set before any caller set its own (and
+ // the jitter to the settings of that moment).
+ ...(opts.jitter !== undefined ? { jitter: opts.jitter } : {}),
};
}
+ private jitterShare(): number {
+ return this.opts.jitter ?? pacingJitter();
+ }
+
// Run `fn` after every earlier request (and its gap) has finished.
private serial<T>(fn: () => Promise<T>): Promise<T> {
const run = this.chain.then(fn, fn);
@@ -120,7 +128,7 @@ export class WebPacer {
): Promise<T> {
return this.serial(async () => {
for (let attempt = 1; ; attempt++) {
- const gap = Math.ceil(jitterUp(this.opts.minGapMs, this.opts.jitter, this.deps.random));
+ const gap = Math.ceil(jitterUp(this.opts.minGapMs, this.jitterShare(), this.deps.random));
const wait = this.lastDoneAt + gap - this.deps.now();
if (wait > 0) await this.deps.sleep(wait, init.signal);
this.sent.push({ url, at: this.deps.now() });
@@ -149,7 +157,7 @@ export class WebPacer {
const told = retryAfterMs(res.headers.get("retry-after"), this.deps.now());
const backoff = Math.min(this.opts.backoffMaxMs, told ?? this.opts.backoffBaseMs * 2 ** (attempt - 1));
await this.deps.sleep(
- Math.ceil(jitterUp(backoff, this.opts.jitter, this.deps.random)),
+ Math.ceil(jitterUp(backoff, this.jitterShare(), this.deps.random)),
init.signal,
);
continue;
diff --git a/editor/app/api/ops/browser-lookup/route.test.ts b/editor/app/api/ops/browser-lookup/route.test.ts
@@ -31,7 +31,12 @@ process.env.WORKER_TOKEN = "test-token";
process.env.TRANSCRIPTS_DIR = ROOT;
process.env.SETTINGS_FILE = path.join(ROOT, "settings.json");
process.env.E2E_ODYSEE_PAGE_FIXTURE = FIXTURE;
-await writeFile(process.env.SETTINGS_FILE, JSON.stringify({ minFreeDiskGB: 0 }));
+// No queue gap: the listing job is the second on the odysee queue, and the
+// default 20 s gap (stretched by pacing.jitter) outlasts settle()'s 20 s.
+await writeFile(
+ process.env.SETTINGS_FILE,
+ JSON.stringify({ minFreeDiskGB: 0, pacing: { jobGapSeconds: { odysee: 0, default: 0 } } }),
+);
await writeFile(
FIXTURE,
JSON.stringify({