@ultimat3/core 31.20.0 → 31.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md CHANGED
@@ -72,6 +72,7 @@ top-level `UltimateError` use in `error-codes.ts`.
72
72
  | loading `.env` | **Bun**, not us | `envFileCandidates()` documents the measured order; there is no `.env.staging` |
73
73
  | how long to wait, and whether to wait at all | `backoff.ts` + `retry-loop.ts` + `retry.ts` | one curve, one loop, one executor that meets the caller's signal and deadline; `jitter` REQUIRED on a retry policy; `attempt` is 1-based † |
74
74
  | N callers on one key | `single-flight.ts` | identity-checked eviction, optional injected deadline, optional injected `signal`: a live joiner re-leads after its leader's abort. Reads no context |
75
+ | a lazy boot or load, once per process | `retry-memo.ts` (`retryMemo`) | a rejection is never the memo's answer; never `x ??= start()` for a promise |
75
76
  | how many at once | `flight-gate.ts` | hand-over on release, refusal past `maxQueued`, injectable `overflow:` refusal |
76
77
  | a fan-out with a bound | `map-bounded.ts` (`mapBounded`) | `width` REQUIRED, no default; input order; first rejection aborts the rest via the signal. Never a hand-rolled worker pool |
77
78
  | whether an answer still applies | `generation-fence.ts` | `X_SUPERSEDED` / `isSuperseded` |
package/README.md CHANGED
@@ -32,6 +32,7 @@ JSON.stringify({ dsn }); // the value never prints: a Secret redacts by value, a
32
32
  | the retry loop and the pure decision behind it, no context | `retry-loop.ts` |
33
33
  | which HTTP statuses are worth repeating | `retryable-status.ts` |
34
34
  | N callers on one key are ONE run | `single-flight.ts` |
35
+ | one lazy attempt, shared, and a failed one not kept | `retry-memo.ts` |
35
36
  | how many may run at once, and how many may wait | `flight-gate.ts` |
36
37
  | a concurrent map with a stated width — input order kept, the first rejection aborts the rest | `map-bounded.ts` |
37
38
  | whether an answer still applies — `X_SUPERSEDED` | `generation-fence.ts` |
@@ -852,6 +853,7 @@ nothing consulted it before deciding to try again. `As of 2026-08-23`.
852
853
  |---|---|---|
853
854
  | `backoffDelay({ attempt, base, max, factor?, curve?, jitter?, random? })` | one curve — `exponential \| linear \| fixed`, `full \| equal \| none` — 1-based `attempt`, clamped to `max` **before** jitter, rounded, and `0` rather than `NaN` | how long to wait. `random` is injectable, so a schedule is a unit test rather than a range |
854
855
  | `singleFlight({ deadlineMs?, schedule?, signal?, released? })` → `run(key, work, join?)`, `size`, `keys()`, `evict(key)` | N callers on one key are ONE run | who pays for a miss. With `signal`, a live joiner re-leads when its leader was aborted, rather than sharing that rejection. `released(key)` fires each time a key stops being held. Eviction is identity-checked, so a load that settles late never drops the load that replaced it; `deadlineMs` frees the KEY a wedged load would hold forever — it never cancels the work and never rejects a joiner. `evict(key)` does the same on demand, for a caller that learns the load in flight began before a write its result must reflect |
856
+ | `retryMemo(start)` → `get()`, `started()` | one lazy attempt, shared — a REJECTED one not kept | a boot or a load made once per process. `x ??= start()` keeps a rejection as the answer forever; here the clearing handler is attached at creation, so it runs ahead of every caller's `await` and the next `get()` really starts again. `started()` answers the attempt without making one, so a `close()` never boots what it stops. `@ultimat3/cli`'s `x mcp serve` and the docs site's corpus take it |
855
857
  | `flightGate({ maxConcurrent, maxQueued }, { subject?, overflow? })` | one bound, one queue, one refusal | how many at once. Past the queue the answer is `X_FLIGHT_GATE_OVERLOADED` (503) and never a longer queue; the slot is HANDED to a waiter, never released and re-acquired. Both limits are screened at construction (`finiteCount`, 0 allowed); a width of 0 refuses every caller rather than queueing for a slot that never frees. `run(work, signal?)`: an abort while QUEUED removes the waiter and rejects with the abort's reason |
856
858
  | `mapBounded(items, fn, { width, signal? })` | `Promise.all(items.map(fn))` with at most `width` in flight | a fan-out with a bound. Results in INPUT order. `width` is required with no default — the caller knows the vendor's limit — and screened by `finiteCount` (≥ 1, else `X_INVARIANT`). `fn(item, index, signal)`: the signal aborts on the first rejection (its reason IS that rejection) or when `signal` aborts; nothing new starts after either. Rejects at once with the first failure, as `Promise.all` does; the caller's abort is `X_ABORTED` naming how many finished |
857
859
  | `generationFence(subject)` → `generation()`, `bump()`, `guard(issued)` | whether an answer still applies | `X_SUPERSEDED` (499) and `isSuperseded(error)` — the piece nothing in the tree had. `guard` compares `!==`, never `<` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "31.20.0",
3
+ "version": "31.21.0",
4
4
  "description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -54,6 +54,6 @@
54
54
  "test": "bun test"
55
55
  },
56
56
  "dependencies": {
57
- "@ultimat3/schema": "31.20.0"
57
+ "@ultimat3/schema": "31.21.0"
58
58
  }
59
59
  }
package/src/index.ts CHANGED
@@ -911,6 +911,8 @@ export type { RetryDeps } from './retry';
911
911
  export { retry } from './retry';
912
912
  export type { RetryDecision, RetryPolicy, RetryStopReason } from './retry-loop';
913
913
  export { retryDecision } from './retry-loop';
914
+ export type { RetryMemo } from './retry-memo';
915
+ export { retryMemo } from './retry-memo';
914
916
  export { isRetryableStatus, RETRYABLE_STATUSES } from './retryable-status';
915
917
  export type { ResolveRoleOptions, Role, RoleInfo, ScalingSignal } from './roles';
916
918
  export { isRole, ROLE_INFO, ROLES, resolveRole } from './roles';
@@ -0,0 +1,37 @@
1
+ // One in-flight attempt, shared — and a FAILED one not kept. `started ??= boot()` caches the
2
+ // rejection with the value: a Postgres that refused once answered every later call in an
3
+ // `x mcp serve` session with that error, and a docs corpus that failed to read stayed failed.
4
+
5
+ /**
6
+ * A lazily made attempt that may be made again.
7
+ *
8
+ * `started()` is the half `??=` has no spelling for: it answers the attempt already in flight or
9
+ * already made, and `undefined` when nobody has asked yet — so a `close()` can stop what was
10
+ * booted without BOOTING one in order to stop it.
11
+ */
12
+ export interface RetryMemo<T> {
13
+ get(): Promise<T>;
14
+ started(): Promise<T> | undefined;
15
+ }
16
+
17
+ /**
18
+ * `start` runs at most once per SUCCESS. `@ultimat3/db`'s `pgliteClient` states the rule this
19
+ * generalises — "a failed boot must not be cached" — and the clearing handler is attached at
20
+ * creation for the reason that matters: it therefore runs ahead of every caller's own `await`
21
+ * continuation, so by the time anyone sees the rejection the slot is already empty and the next
22
+ * call really does start a new attempt. Cleared inside the caller's `catch` instead, there is a
23
+ * window in which a second call is handed the dead promise.
24
+ */
25
+ export function retryMemo<T>(start: () => Promise<T>): RetryMemo<T> {
26
+ let attempt: Promise<T> | undefined;
27
+ return {
28
+ get(): Promise<T> {
29
+ attempt ??= start().catch((error: unknown) => {
30
+ attempt = undefined;
31
+ throw error;
32
+ });
33
+ return attempt;
34
+ },
35
+ started: (): Promise<T> | undefined => attempt,
36
+ };
37
+ }