diff --git a/pkgs/id/web/src/highlight.ts b/pkgs/id/web/src/highlight.ts index 349d5c2adc..c92cbe34f5 100644 --- a/pkgs/id/web/src/highlight.ts +++ b/pkgs/id/web/src/highlight.ts @@ -261,7 +261,7 @@ const loadedLangs = new Set(); */ async function getHighlighter(): Promise { if (!highlighterPromise) { - highlighterPromise = (async () => { + const pending = (async () => { const { createHighlighterCore } = await import("shiki/core"); const { createJavaScriptRegexEngine } = await import("shiki/engine/javascript"); @@ -271,6 +271,13 @@ async function getHighlighter(): Promise { engine: createJavaScriptRegexEngine(), }); })(); + highlighterPromise = pending; + // Success-only memoization (#3880, contract in #3879): a rejected + // creation (e.g. a transient chunk-load failure) must not latch — + // clear the memo so the next call retries; success stays cached. + void pending.catch(() => { + if (highlighterPromise === pending) highlighterPromise = null; + }); } return highlighterPromise; } diff --git a/pm-stack/aggregator/README.md b/pm-stack/aggregator/README.md index 6942f0bfdc..d28ba306e1 100644 --- a/pm-stack/aggregator/README.md +++ b/pm-stack/aggregator/README.md @@ -13,6 +13,38 @@ by this server. Design record (source of truth): [`doc/2026-10-24T11-05-38Z_design_project-management-stack/`](../../doc/2026-10-24T11-05-38Z_design_project-management-stack/). +## Lazy-initialization contract (#3879) + +**A lazy initializer memoizes success, never failure.** Concurrent +callers share the one in-flight attempt; once that attempt settles, a +failure — a rejection, or a fail-soft failure *value* (`null`, +`false`) — leaves no memo behind, so the next caller retries. A +success is memoized for the process lifetime unless the module +already has an explicit invalidation path, which stays. Every layer +clears independently: an initializer built on another initializer +applies the contract to its own resolved value — "the layer below +retries" is never a reason for a layer to keep a failure. Per-call +fail-soft behaviour is unchanged: a caller whose attempt failed still +gets the failure value for that call and reports its surface +unavailable — the contract removes the *permanence*, not the +posture. Retry cost stays bounded by the layer that knows it +(`src/secrets.ts` caches a failed resolution for 5 minutes), never by +a second per-site failure TTL. + +The aggregator's three memo sites follow this contract: + +- `src/supabase.ts` — `clientPromise` (`getSupabaseClient`), cleared + when an attempt resolves `null` or rejects (#3732). +- `src/alerts.ts` — `storePromise` (`getAlertsStore`), cleared + independently of the client layer when an attempt resolves `null` + or rejects (#3732). +- `src/push.ts` — `configurePromise` (`ensurePushConfigured`), + cleared when an attempt settles `false`; the 401/403 reset in + `sendPush` is its explicit invalidation path and stays (#3729). + +Design: #3879 ("failure is not a result"). The rule was first stated +for pm-dispatch in #2668; it is one rule for both apps. + ## The views Nav tiers (#1497 curation, confirmed 2026-11-01): the top nav bar carries the diff --git a/pm-stack/aggregator/src/alerts.ts b/pm-stack/aggregator/src/alerts.ts index 9902d25c49..aa99ef9f29 100644 --- a/pm-stack/aggregator/src/alerts.ts +++ b/pm-stack/aggregator/src/alerts.ts @@ -631,6 +631,7 @@ export async function sendTestPush( /** * Create the shared store resolver. Keep the in-flight attempt and successful * store cached, but clear null/rejected attempts so a later call can recover. + * Lazy-init contract (success-only memoization): README "Lazy-initialization contract" (#3879). */ export function createAlertsStoreGetter( getClient: typeof getSupabaseClient = getSupabaseClient, diff --git a/pm-stack/aggregator/src/push.ts b/pm-stack/aggregator/src/push.ts index a3f199e89e..e4fc6292e7 100644 --- a/pm-stack/aggregator/src/push.ts +++ b/pm-stack/aggregator/src/push.ts @@ -34,7 +34,8 @@ let configurePromise: Promise | null = null; * secrets layer already heals its own null cache after 5 minutes; an * unbounded latch here defeated that). Concurrent callers still share * the one in-flight attempt. Same retry-after-failure shape as - * createAlertsStoreGetter in alerts.ts. */ + * createAlertsStoreGetter in alerts.ts. + * Lazy-init contract (success-only memoization): README "Lazy-initialization contract" (#3879). */ export function ensurePushConfigured(): Promise { if (configured) return Promise.resolve(true); if (!configurePromise) { diff --git a/pm-stack/aggregator/src/supabase.ts b/pm-stack/aggregator/src/supabase.ts index f42e0edb72..a5a4db8aa1 100644 --- a/pm-stack/aggregator/src/supabase.ts +++ b/pm-stack/aggregator/src/supabase.ts @@ -44,6 +44,7 @@ async function supabaseQuery(token: string, ref: string, sql: string): Promise