@pgxsinkit/client 0.2.4 → 0.2.5
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/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -13
- package/dist/index.js.map +8 -7
- package/dist/read-stream-stall.d.ts +54 -0
- package/dist/read-stream-stall.d.ts.map +1 -0
- package/dist/shape-sync.d.ts +11 -0
- package/dist/shape-sync.d.ts.map +1 -1
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/package.json +3 -3
- package/skills/core/SKILL.md +1 -1
- package/skills/operating/SKILL.md +1 -1
- package/src/index.ts +82 -0
- package/src/read-stream-stall.ts +102 -0
- package/src/shape-sync.ts +38 -14
- package/src/worker/attach-sync-client.ts +4 -0
- package/src/worker/define-sync-worker.ts +3 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type BackoffOptions } from "@electric-sql/client";
|
|
2
|
+
/**
|
|
3
|
+
* The read path's OUTAGE seam (board ADR-0010 "offline return").
|
|
4
|
+
*
|
|
5
|
+
* Every shape fetch runs inside Electric's `createFetchWithBackoff`, which retries a failed attempt
|
|
6
|
+
* **forever** (`maxRetries: Infinity` — "clients may go offline and come back") and only re-throws a
|
|
7
|
+
* non-retryable 4xx. A network-level failure therefore never escapes that wrapper: `ShapeStream.onError`
|
|
8
|
+
* is never called, so neither is `onReadStreamError`, and a runtime keying off those alone reports
|
|
9
|
+
* `syncing` for as long as the machine stays offline. `backoffOptions.onFailedAttempt` is the ONLY signal
|
|
10
|
+
* Electric surfaces from inside the loop, and it is what this probe turns into a runtime status change.
|
|
11
|
+
*
|
|
12
|
+
* The two seams PARTITION the failures, they do not overlap:
|
|
13
|
+
*
|
|
14
|
+
* - **Retried inside the wrapper** (a rejected request — the offline case, with no HTTP status at all — a
|
|
15
|
+
* 5xx, or a 429) → nobody else will ever hear about it. This probe's `onStalled`.
|
|
16
|
+
* - **Escapes the wrapper** (any other 4xx: 401/403 auth, 404/409/… structural) → `ShapeStream.onError`,
|
|
17
|
+
* i.e. `createShapeErrorHandler` → `onAuthError` / `onReadStreamError`, which own it and carry a real
|
|
18
|
+
* error message. Deliberately NOT reported here, so a rejected token still surfaces as the more
|
|
19
|
+
* actionable `auth-needed` and an expired handle's 409 stays the recovery it is.
|
|
20
|
+
* - **A deliberate abort** — a stream teardown, a hidden tab (`PAUSE_STREAM`), a live-request timeout, a
|
|
21
|
+
* system wake, and the live-tail nudge's `forceDisconnectAndRefresh` all abort the in-flight request,
|
|
22
|
+
* and Electric calls `onFailedAttempt` for the resulting `AbortError` like any other. None is an
|
|
23
|
+
* outage; counting them would report "connection needed" for backgrounding a tab.
|
|
24
|
+
*
|
|
25
|
+
* `onFailedAttempt` carries no arguments, so the classification is made one layer down, in the
|
|
26
|
+
* `fetchClient` this probe supplies: it records how the attempt that just settled would be treated by the
|
|
27
|
+
* very next lines of Electric's own catch block. Recovery needs nothing here — the runtime clears a
|
|
28
|
+
* stream-degraded status on the next delivered batch (`onSyncActivity`), which a resumed stream produces
|
|
29
|
+
* on its first successful poll.
|
|
30
|
+
*/
|
|
31
|
+
export interface ReadStreamStallProbe {
|
|
32
|
+
/** Pass as `ShapeStreamOptions.backoffOptions` — Electric's defaults plus the failed-attempt hook. */
|
|
33
|
+
backoffOptions: BackoffOptions;
|
|
34
|
+
/** Pass as `ShapeStreamOptions.fetchClient` — the innermost transport, wrapped to classify each attempt. */
|
|
35
|
+
fetchClient: typeof fetch;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The CALL signature of `fetch`, without the runtime-specific statics (Bun's global carries `preconnect`).
|
|
39
|
+
* A ShapeStream only ever invokes its `fetchClient` as a plain call, so this is the honest contract for a
|
|
40
|
+
* transport being wrapped — and it is what lets a test inject a failing one.
|
|
41
|
+
*/
|
|
42
|
+
type FetchLike = (request: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => Promise<Response>;
|
|
43
|
+
export declare function createReadStreamStallProbe(input: {
|
|
44
|
+
/**
|
|
45
|
+
* Notified per failed attempt that Electric will retry internally, never for an escaping 4xx and never
|
|
46
|
+
* for a deliberate abort. Fires repeatedly while an outage lasts — Electric retries forever — so the
|
|
47
|
+
* consumer owns the transition/dedup, not this probe.
|
|
48
|
+
*/
|
|
49
|
+
onStalled: () => void;
|
|
50
|
+
/** The transport to wrap. Defaults to the global `fetch`; a test injects the failure here. */
|
|
51
|
+
fetchClient?: FetchLike;
|
|
52
|
+
}): ReadStreamStallProbe;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=read-stream-stall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-stream-stall.d.ts","sourceRoot":"","sources":["../src/read-stream-stall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,oBAAoB;IACnC,sGAAsG;IACtG,cAAc,EAAE,cAAc,CAAC;IAC/B,4GAA4G;IAC5G,WAAW,EAAE,OAAO,KAAK,CAAC;CAC3B;AAED;;;;GAIG;AACH,KAAK,SAAS,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAWjH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IAChD;;;;OAIG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,8FAA8F;IAC9F,WAAW,CAAC,EAAE,SAAS,CAAC;CACzB,GAAG,oBAAoB,CAsCvB"}
|
package/dist/shape-sync.d.ts
CHANGED
|
@@ -67,6 +67,15 @@ export interface StartConfiguredSyncOptions {
|
|
|
67
67
|
* never silently believes the read path is live while it has actually stalled.
|
|
68
68
|
*/
|
|
69
69
|
onReadStreamError?: (error: Error) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Notified when a shape's fetch ATTEMPT failed and Electric is retrying it inside its own backoff
|
|
72
|
+
* wrapper (board ADR-0010): a rejected request (the offline case — no HTTP status at all), a 5xx, or a
|
|
73
|
+
* 429. The complement of {@link onReadStreamError}, which only ever fires for an error that ESCAPED that
|
|
74
|
+
* wrapper (any other 4xx) — which a network outage never does, since Electric retries it forever. Fires
|
|
75
|
+
* per attempt for as long as the outage lasts, so the runtime owns the transition; a deliberate abort
|
|
76
|
+
* (teardown, hidden tab, nudge refresh) is not a failure and is filtered out. See `read-stream-stall.ts`.
|
|
77
|
+
*/
|
|
78
|
+
onReadStreamStalled?: () => void;
|
|
70
79
|
/**
|
|
71
80
|
* Notified when a shape successfully delivers a batch — i.e. a fetch just succeeded (ADR-0013
|
|
72
81
|
* Phase 3). The runtime uses this to clear an `auth-needed`/`degraded` status once sync resumes.
|
|
@@ -178,6 +187,8 @@ interface StartGroupSyncOptions {
|
|
|
178
187
|
onSyncError?: (error: Error) => void;
|
|
179
188
|
onAuthError?: () => void;
|
|
180
189
|
onReadStreamError?: (error: Error) => void;
|
|
190
|
+
/** A failed fetch ATTEMPT inside Electric's backoff loop; see {@link StartConfiguredSyncOptions.onReadStreamStalled}. */
|
|
191
|
+
onReadStreamStalled?: () => void;
|
|
181
192
|
onSyncActivity?: () => void;
|
|
182
193
|
}
|
|
183
194
|
/**
|
package/dist/shape-sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape-sync.d.ts","sourceRoot":"","sources":["../src/shape-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EACL,KAAK,SA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,EAAE,KAAK,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3C,yHAAyH;IACzH,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,qBAAqB,sDAmDtF;AAgCD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,kBAAkB,GAAG,UAAU,CAAC,GAAG,MAAM,CAEjH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-sync-client.d.ts","sourceRoot":"","sources":["../../src/worker/attach-sync-client.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAEV,iBAAiB,EACjB,sBAAsB,EAEtB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"attach-sync-client.d.ts","sourceRoot":"","sources":["../../src/worker/attach-sync-client.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAEV,iBAAiB,EACjB,sBAAsB,EAEtB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD,OAAO,EAQL,KAAK,cAAc,EAEnB,KAAK,UAAU,EAGhB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,oBAAoB,CA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ords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"@electric-sql/client": "^1.5.24",
|
|
37
37
|
"@electric-sql/experimental": "^6.0.24",
|
|
38
38
|
"@electric-sql/pglite-tools": "0.4.4",
|
|
39
|
-
"@pgxsinkit/contracts": "0.2.
|
|
40
|
-
"@pgxsinkit/pglite-opfs-repacked": "0.2.
|
|
39
|
+
"@pgxsinkit/contracts": "0.2.5",
|
|
40
|
+
"@pgxsinkit/pglite-opfs-repacked": "0.2.5"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@electric-sql/pglite": ">=0.5.4-pgx.0 <0.5.5",
|
package/skills/core/SKILL.md
CHANGED
package/src/index.ts
CHANGED
|
@@ -401,6 +401,20 @@ const OPFS_OPEN_ATTEMPTS = 10;
|
|
|
401
401
|
const OPFS_OPEN_BACKOFF_MS = 100;
|
|
402
402
|
/** The opfs-repacked store extent size (ADR-0049 step 10a). */
|
|
403
403
|
const OPFS_STORE_EXTENT_SIZE = 65536;
|
|
404
|
+
/**
|
|
405
|
+
* `status.lastError` for a read stream that cannot reach the server at all (board ADR-0010). Unlike every
|
|
406
|
+
* other `degraded` cause there is no Error to describe: Electric's `onFailedAttempt` carries no argument,
|
|
407
|
+
* because the failure never escaped its retry wrapper. The string says what is knowable and no more.
|
|
408
|
+
*/
|
|
409
|
+
const READ_STREAM_UNREACHABLE = "read stream unreachable: a shape fetch failed and is retrying with backoff";
|
|
410
|
+
/**
|
|
411
|
+
* Default {@link CreateSyncClientOptions.readSilenceMs}. A healthy Electric read path is never silent —
|
|
412
|
+
* the live long-poll cycles roughly every 20-25s with at least a bare up-to-date, and every cycle fires
|
|
413
|
+
* `onSyncActivity` — so two full cycles of nothing while claiming `ready` is evidence, not caution.
|
|
414
|
+
*/
|
|
415
|
+
const READ_SILENCE_MS = 45_000;
|
|
416
|
+
/** `status.lastError` for the read-silence watchdog: nothing failed — that is exactly the problem. */
|
|
417
|
+
const READ_STREAM_SILENT = "read stream silent: no server response inside the silence window while reporting ready";
|
|
404
418
|
/**
|
|
405
419
|
* Non-enumerable brand stamped on an opfs-repacked instance {@link createClientPGlite} mints (ADR-0049): the
|
|
406
420
|
* opfs-repacked VFS owns its store on a dedicated OPFS directory and reports NO `dataDir` (a custom VFS, the
|
|
@@ -880,6 +894,15 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
880
894
|
*/
|
|
881
895
|
writeRequestHeaders?: Record<string, string>;
|
|
882
896
|
syncEnabled?: boolean;
|
|
897
|
+
/**
|
|
898
|
+
* The read-silence window (ms) after which a runtime claiming `ready` drops to `degraded` (reason
|
|
899
|
+
* "stream"). A pulled cable HANGS the live long-poll — nothing fails (the stall probe hears only settled
|
|
900
|
+
* attempts), nothing delivers — so without this a session that once reached `ready` would report
|
|
901
|
+
* "up to date" for as long as the outage lasts. A healthy stream is never silent (the long-poll cycles
|
|
902
|
+
* ~every 20-25s), so the default of 45s spans two full cycles. Self-recovering: the next delivered batch
|
|
903
|
+
* returns `ready`. Status honesty only — nothing is retired or torn down.
|
|
904
|
+
*/
|
|
905
|
+
readSilenceMs?: number;
|
|
883
906
|
/**
|
|
884
907
|
* The local store's name (ADR-0036) — a PLAIN path/name, never a PGlite storage URL. The storage backend
|
|
885
908
|
* is DERIVED from the engine home (capability-selected opfs-repacked with IndexedDB fallback in a browser,
|
|
@@ -2002,6 +2025,36 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
2002
2025
|
// `onSyncActivity` must not clear it.
|
|
2003
2026
|
let degradedReason: "stream" | "commit" | null = null;
|
|
2004
2027
|
|
|
2028
|
+
// ─── Read-silence watchdog ───────────────────────────────────────────────────────────────────────
|
|
2029
|
+
// The "up to date offline" lie: a pulled cable HANGS the live long-poll, so the stall probe (which hears
|
|
2030
|
+
// only SETTLED attempts) stays quiet and no batch ever delivers — a runtime that reached `ready` this
|
|
2031
|
+
// session would claim it for the whole outage, and in worker mode broadcast that claim to every attaching
|
|
2032
|
+
// tab. Silence past the window while claiming `ready` is therefore itself the evidence, and the phase
|
|
2033
|
+
// drops to the shared stream-degraded state, recovering exactly where every stream flavour does (the next
|
|
2034
|
+
// delivered batch). This is timing-based STATUS honesty, not timing-based retirement — nothing is torn
|
|
2035
|
+
// down or restarted (ADR-0049 D5 governs the latter). Armed on `ready` and re-armed on every activity;
|
|
2036
|
+
// never armed with sync disabled (`ready` there means "boot complete", with no server to hear from).
|
|
2037
|
+
const readSilenceMs = options.readSilenceMs ?? READ_SILENCE_MS;
|
|
2038
|
+
let readSilenceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
2039
|
+
const clearReadSilenceWatchdog = (): void => {
|
|
2040
|
+
if (readSilenceTimer != null) {
|
|
2041
|
+
clearTimeout(readSilenceTimer);
|
|
2042
|
+
readSilenceTimer = null;
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
const armReadSilenceWatchdog = (): void => {
|
|
2046
|
+
if (!syncEnabled) return;
|
|
2047
|
+
clearReadSilenceWatchdog();
|
|
2048
|
+
readSilenceTimer = setTimeout(() => {
|
|
2049
|
+
readSilenceTimer = null;
|
|
2050
|
+
if (disposed || status.phase !== "ready") return;
|
|
2051
|
+
status.phase = "degraded";
|
|
2052
|
+
degradedReason = "stream";
|
|
2053
|
+
status.lastError = READ_STREAM_SILENT;
|
|
2054
|
+
options.onStatusChange?.(status);
|
|
2055
|
+
}, readSilenceMs);
|
|
2056
|
+
};
|
|
2057
|
+
|
|
2005
2058
|
// ─── Fresh-store prefetch overlap (ADR-0032 S4 / backlog-0003) ─────────────────────────────────────
|
|
2006
2059
|
// On a PROVABLY-FRESH store (the caller's `freshStore` hint — a claimed schemaless spare) the shape
|
|
2007
2060
|
// catch-up needs none of the local boot phases, so start it NOW and gate its commits on `dbReady`, which
|
|
@@ -2060,6 +2113,9 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
2060
2113
|
// finalize below never double-fires it.
|
|
2061
2114
|
finalizeBootReport();
|
|
2062
2115
|
resolveReady();
|
|
2116
|
+
// `ready` is now a CLAIM the watchdog holds to account: silence past the window drops it back to
|
|
2117
|
+
// degraded — the "up to date offline" lie a hung long-poll otherwise sustains.
|
|
2118
|
+
armReadSilenceWatchdog();
|
|
2063
2119
|
},
|
|
2064
2120
|
onSyncError: (error) => {
|
|
2065
2121
|
// A sync commit exhausted its retries (ADR-0009 decision 5): go degraded and surface it, rather than
|
|
@@ -2088,6 +2144,25 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
2088
2144
|
status.lastError = describeErrorChain(error);
|
|
2089
2145
|
options.onStatusChange?.(status);
|
|
2090
2146
|
},
|
|
2147
|
+
// Board ADR-0010: a shape FETCH ATTEMPT failed and Electric is retrying it inside its own backoff
|
|
2148
|
+
// wrapper. This is the only signal an outage produces — a rejected fetch is retryable, so it never
|
|
2149
|
+
// escapes to `onError` and `onReadStreamError` above is never called (Electric retries forever:
|
|
2150
|
+
// "clients may go offline and come back"). Without this the runtime reports `syncing` for as long as
|
|
2151
|
+
// the machine is offline, and a consumer keying off the phase can never say "connection needed". The
|
|
2152
|
+
// two seams partition the failures (see `read-stream-stall.ts`), so this can never pre-empt the
|
|
2153
|
+
// richer classification: an auth 4xx escapes the wrapper and lands on `onAuthError`, not here.
|
|
2154
|
+
//
|
|
2155
|
+
// TRANSITION-only: Electric calls this on every retry tick for as long as the outage lasts, so
|
|
2156
|
+
// re-entering `degraded` would re-emit to every status listener (and, in worker mode, re-broadcast to
|
|
2157
|
+
// every attached tab) roughly once a second, forever. Precedence matches `onReadStreamError`: never
|
|
2158
|
+
// mask `auth-needed` (more actionable) nor a commit-failure degraded (more serious).
|
|
2159
|
+
onReadStreamStalled: () => {
|
|
2160
|
+
if (status.phase === "auth-needed" || status.phase === "degraded") return;
|
|
2161
|
+
status.phase = "degraded";
|
|
2162
|
+
degradedReason = "stream";
|
|
2163
|
+
status.lastError = READ_STREAM_UNREACHABLE;
|
|
2164
|
+
options.onStatusChange?.(status);
|
|
2165
|
+
},
|
|
2091
2166
|
// Clear a recoverable status (auth-needed, or a read-stream degraded) the moment a batch is delivered
|
|
2092
2167
|
// again. A commit-failure degraded is NOT cleared here — a fetch can succeed while applies keep failing,
|
|
2093
2168
|
// so only `onSyncError` clearing (a clean commit) would lift it.
|
|
@@ -2097,6 +2172,9 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
2097
2172
|
status.phase = initialSyncCompleted ? "ready" : "syncing";
|
|
2098
2173
|
options.onStatusChange?.(status);
|
|
2099
2174
|
}
|
|
2175
|
+
// Every delivered batch (including a bare up-to-date) is proof of life: re-arm the silence window.
|
|
2176
|
+
// Harmless pre-`ready` — the watchdog's callback only ever acts on a runtime claiming `ready`.
|
|
2177
|
+
armReadSilenceWatchdog();
|
|
2100
2178
|
},
|
|
2101
2179
|
// ADR-0013 Phase 3: surface a persistent read-path auth failure as a distinct `auth-needed` status (the
|
|
2102
2180
|
// app prompts re-login) while the stream keeps retrying for a fresh token. Only wired when a token
|
|
@@ -2302,6 +2380,9 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
2302
2380
|
// manage to start is assigned to `sync` by the time this resolves, for the caller's `sync?.unsubscribe()`.
|
|
2303
2381
|
const quiesceTailForTeardown = async (): Promise<void> => {
|
|
2304
2382
|
disposed = true;
|
|
2383
|
+
// A disposed client must leave no pending timer behind (the close-hang discipline): the callback's
|
|
2384
|
+
// `disposed` guard already suppresses a late fire, but the cleared handle is what lets the realm quiesce.
|
|
2385
|
+
clearReadSilenceWatchdog();
|
|
2305
2386
|
// FIX 2: a stopped client can never reach `writeReady` / `ready`, so reject them (idempotent — a race with
|
|
2306
2387
|
// the tail's own resolve is settled first-wins; a normal stop AFTER boot is a no-op on the already-resolved
|
|
2307
2388
|
// promises) so a parked mutation or an `await ready` / `start()` fails FAST rather than hanging past
|
|
@@ -2324,6 +2405,7 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
2324
2405
|
// after; this only guarantees the network + scheduling are already dead when it does.
|
|
2325
2406
|
const haltActivity = (): void => {
|
|
2326
2407
|
disposed = true;
|
|
2408
|
+
clearReadSilenceWatchdog();
|
|
2327
2409
|
mutationRuntime.abortInFlight();
|
|
2328
2410
|
void engine.close();
|
|
2329
2411
|
void convergenceDriver?.stop();
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { BackoffDefaults, type BackoffOptions } from "@electric-sql/client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The read path's OUTAGE seam (board ADR-0010 "offline return").
|
|
5
|
+
*
|
|
6
|
+
* Every shape fetch runs inside Electric's `createFetchWithBackoff`, which retries a failed attempt
|
|
7
|
+
* **forever** (`maxRetries: Infinity` — "clients may go offline and come back") and only re-throws a
|
|
8
|
+
* non-retryable 4xx. A network-level failure therefore never escapes that wrapper: `ShapeStream.onError`
|
|
9
|
+
* is never called, so neither is `onReadStreamError`, and a runtime keying off those alone reports
|
|
10
|
+
* `syncing` for as long as the machine stays offline. `backoffOptions.onFailedAttempt` is the ONLY signal
|
|
11
|
+
* Electric surfaces from inside the loop, and it is what this probe turns into a runtime status change.
|
|
12
|
+
*
|
|
13
|
+
* The two seams PARTITION the failures, they do not overlap:
|
|
14
|
+
*
|
|
15
|
+
* - **Retried inside the wrapper** (a rejected request — the offline case, with no HTTP status at all — a
|
|
16
|
+
* 5xx, or a 429) → nobody else will ever hear about it. This probe's `onStalled`.
|
|
17
|
+
* - **Escapes the wrapper** (any other 4xx: 401/403 auth, 404/409/… structural) → `ShapeStream.onError`,
|
|
18
|
+
* i.e. `createShapeErrorHandler` → `onAuthError` / `onReadStreamError`, which own it and carry a real
|
|
19
|
+
* error message. Deliberately NOT reported here, so a rejected token still surfaces as the more
|
|
20
|
+
* actionable `auth-needed` and an expired handle's 409 stays the recovery it is.
|
|
21
|
+
* - **A deliberate abort** — a stream teardown, a hidden tab (`PAUSE_STREAM`), a live-request timeout, a
|
|
22
|
+
* system wake, and the live-tail nudge's `forceDisconnectAndRefresh` all abort the in-flight request,
|
|
23
|
+
* and Electric calls `onFailedAttempt` for the resulting `AbortError` like any other. None is an
|
|
24
|
+
* outage; counting them would report "connection needed" for backgrounding a tab.
|
|
25
|
+
*
|
|
26
|
+
* `onFailedAttempt` carries no arguments, so the classification is made one layer down, in the
|
|
27
|
+
* `fetchClient` this probe supplies: it records how the attempt that just settled would be treated by the
|
|
28
|
+
* very next lines of Electric's own catch block. Recovery needs nothing here — the runtime clears a
|
|
29
|
+
* stream-degraded status on the next delivered batch (`onSyncActivity`), which a resumed stream produces
|
|
30
|
+
* on its first successful poll.
|
|
31
|
+
*/
|
|
32
|
+
export interface ReadStreamStallProbe {
|
|
33
|
+
/** Pass as `ShapeStreamOptions.backoffOptions` — Electric's defaults plus the failed-attempt hook. */
|
|
34
|
+
backoffOptions: BackoffOptions;
|
|
35
|
+
/** Pass as `ShapeStreamOptions.fetchClient` — the innermost transport, wrapped to classify each attempt. */
|
|
36
|
+
fetchClient: typeof fetch;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The CALL signature of `fetch`, without the runtime-specific statics (Bun's global carries `preconnect`).
|
|
41
|
+
* A ShapeStream only ever invokes its `fetchClient` as a plain call, so this is the honest contract for a
|
|
42
|
+
* transport being wrapped — and it is what lets a test inject a failing one.
|
|
43
|
+
*/
|
|
44
|
+
type FetchLike = (request: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => Promise<Response>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Would Electric SWALLOW this response status and retry it inside the backoff loop? Mirrors the branch in
|
|
48
|
+
* `createFetchWithBackoff`: a 4xx is re-thrown (and reaches `onError`) unless it is the one retryable
|
|
49
|
+
* status, 429; everything else — 5xx above all — is retried where no other seam can see it.
|
|
50
|
+
*/
|
|
51
|
+
function isRetriedInsideBackoff(status: number): boolean {
|
|
52
|
+
return status === 429 || status < 400 || status >= 500;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createReadStreamStallProbe(input: {
|
|
56
|
+
/**
|
|
57
|
+
* Notified per failed attempt that Electric will retry internally, never for an escaping 4xx and never
|
|
58
|
+
* for a deliberate abort. Fires repeatedly while an outage lasts — Electric retries forever — so the
|
|
59
|
+
* consumer owns the transition/dedup, not this probe.
|
|
60
|
+
*/
|
|
61
|
+
onStalled: () => void;
|
|
62
|
+
/** The transport to wrap. Defaults to the global `fetch`; a test injects the failure here. */
|
|
63
|
+
fetchClient?: FetchLike;
|
|
64
|
+
}): ReadStreamStallProbe {
|
|
65
|
+
const transport = input.fetchClient;
|
|
66
|
+
// How the attempt that just settled will be treated by Electric's catch block. Written by the fetch
|
|
67
|
+
// wrapper and read by `onFailedAttempt`, which Electric invokes in the catch of the very call that just
|
|
68
|
+
// settled — no await sits between the two, so the pairing holds. Per-probe (one probe per shape), so a
|
|
69
|
+
// sibling shape's traffic can never answer for this one.
|
|
70
|
+
let lastAttemptRetried = false;
|
|
71
|
+
const fetchClient = (async (request: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => {
|
|
72
|
+
try {
|
|
73
|
+
const response = await (transport ? transport(request, init) : fetch(request, init));
|
|
74
|
+
// The server answered. `ok` means no failed attempt at all; otherwise the backoff wrapper turns it
|
|
75
|
+
// into a `FetchError` and either swallows it (5xx/429 — ours) or re-throws it (4xx — `onError`'s).
|
|
76
|
+
lastAttemptRetried = !response.ok && isRetriedInsideBackoff(response.status);
|
|
77
|
+
return response;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// A rejection: a transport fault (retried forever — the outage) unless the request was deliberately
|
|
80
|
+
// aborted, which Electric turns into a `FetchBackoffAbortError` rather than a retry.
|
|
81
|
+
lastAttemptRetried = init?.signal?.aborted !== true;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
// `typeof fetch` (Bun's global) carries a `preconnect` member the wrapper neither has nor needs — the
|
|
85
|
+
// ShapeStream only ever invokes fetchClient as a plain fetch — so the shape-compatible cast is safe.
|
|
86
|
+
}) as typeof fetch;
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
fetchClient,
|
|
90
|
+
// `ShapeStream` uses `options.backoffOptions ?? BackoffDefaults` — it SPREADS, it does not merge — so
|
|
91
|
+
// a partial object would blank Electric's timings. Spreading `BackoffDefaults` keeps them (1000 /
|
|
92
|
+
// 32000 / 2, `maxRetries: Infinity`) and tracks upstream if they ever move: adding this callback is
|
|
93
|
+
// behaviour-neutral for retrying.
|
|
94
|
+
backoffOptions: {
|
|
95
|
+
...BackoffDefaults,
|
|
96
|
+
onFailedAttempt: () => {
|
|
97
|
+
if (!lastAttemptRetried) return;
|
|
98
|
+
input.onStalled();
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
package/src/shape-sync.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "@pgxsinkit/contracts";
|
|
11
11
|
|
|
12
12
|
import type { BootStampCollector, GroupBootStamp } from "./boot-report";
|
|
13
|
+
import { createReadStreamStallProbe } from "./read-stream-stall";
|
|
13
14
|
import type { SyncNamespaceObj } from "./sync";
|
|
14
15
|
import { createShapeErrorHandler } from "./sync-auth";
|
|
15
16
|
|
|
@@ -79,6 +80,15 @@ export interface StartConfiguredSyncOptions {
|
|
|
79
80
|
* never silently believes the read path is live while it has actually stalled.
|
|
80
81
|
*/
|
|
81
82
|
onReadStreamError?: (error: Error) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Notified when a shape's fetch ATTEMPT failed and Electric is retrying it inside its own backoff
|
|
85
|
+
* wrapper (board ADR-0010): a rejected request (the offline case — no HTTP status at all), a 5xx, or a
|
|
86
|
+
* 429. The complement of {@link onReadStreamError}, which only ever fires for an error that ESCAPED that
|
|
87
|
+
* wrapper (any other 4xx) — which a network outage never does, since Electric retries it forever. Fires
|
|
88
|
+
* per attempt for as long as the outage lasts, so the runtime owns the transition; a deliberate abort
|
|
89
|
+
* (teardown, hidden tab, nudge refresh) is not a failure and is filtered out. See `read-stream-stall.ts`.
|
|
90
|
+
*/
|
|
91
|
+
onReadStreamStalled?: () => void;
|
|
82
92
|
/**
|
|
83
93
|
* Notified when a shape successfully delivers a batch — i.e. a fetch just succeeded (ADR-0013
|
|
84
94
|
* Phase 3). The runtime uses this to clear an `auth-needed`/`degraded` status once sync resumes.
|
|
@@ -310,6 +320,7 @@ export async function startConfiguredSync(
|
|
|
310
320
|
...(input.onSyncError ? { onSyncError: input.onSyncError } : {}),
|
|
311
321
|
...(input.onAuthError ? { onAuthError: input.onAuthError } : {}),
|
|
312
322
|
...(input.onReadStreamError ? { onReadStreamError: input.onReadStreamError } : {}),
|
|
323
|
+
...(input.onReadStreamStalled ? { onReadStreamStalled: input.onReadStreamStalled } : {}),
|
|
313
324
|
...(input.onSyncActivity ? { onSyncActivity: input.onSyncActivity } : {}),
|
|
314
325
|
onGroupInitialSync: () => {
|
|
315
326
|
// The group is up-to-date as a unit; signal each member table, mark the group ready (per-group
|
|
@@ -419,6 +430,8 @@ interface StartGroupSyncOptions {
|
|
|
419
430
|
onSyncError?: (error: Error) => void;
|
|
420
431
|
onAuthError?: () => void;
|
|
421
432
|
onReadStreamError?: (error: Error) => void;
|
|
433
|
+
/** A failed fetch ATTEMPT inside Electric's backoff loop; see {@link StartConfiguredSyncOptions.onReadStreamStalled}. */
|
|
434
|
+
onReadStreamStalled?: () => void;
|
|
422
435
|
onSyncActivity?: () => void;
|
|
423
436
|
}
|
|
424
437
|
|
|
@@ -438,22 +451,33 @@ export async function startGroupSync(pg: SyncEnginePGlite, input: StartGroupSync
|
|
|
438
451
|
...(input.onReadStreamError ? { onReadStreamError: input.onReadStreamError } : {}),
|
|
439
452
|
});
|
|
440
453
|
|
|
454
|
+
// The failed-attempt probe is `onError`'s complement and the reason it exists: `onError` sees only the
|
|
455
|
+
// failures that ESCAPE Electric's retry wrapper, which a network outage never does — it is retried in
|
|
456
|
+
// there forever (board ADR-0010). The two PARTITION the failure space; neither masks the other. One probe
|
|
457
|
+
// per shape — each classifies its own in-flight request — and none at all when no consumer wants the
|
|
458
|
+
// signal, so the off-path keeps Electric's untouched fetch/backoff wiring.
|
|
459
|
+
const onReadStreamStalled = input.onReadStreamStalled;
|
|
460
|
+
|
|
441
461
|
const shapes = Object.fromEntries(
|
|
442
|
-
input.specs.map((spec) =>
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
462
|
+
input.specs.map((spec) => {
|
|
463
|
+
const stallProbe = onReadStreamStalled ? createReadStreamStallProbe({ onStalled: onReadStreamStalled }) : null;
|
|
464
|
+
return [
|
|
465
|
+
spec.key,
|
|
466
|
+
{
|
|
467
|
+
shape: {
|
|
468
|
+
// Ingress `table` = the unique `shapeKey` (proxy maps it to the physical table on egress).
|
|
469
|
+
url: buildShapeUrl(spec.electricUrl, spec.shapeKey),
|
|
470
|
+
...(shapeHeaders ? { headers: shapeHeaders } : {}),
|
|
471
|
+
onError,
|
|
472
|
+
...(stallProbe ? { backoffOptions: stallProbe.backoffOptions, fetchClient: stallProbe.fetchClient } : {}),
|
|
473
|
+
},
|
|
474
|
+
// ADR-0029 D1: the registry table key is the engine's sole per-table spec — the local apply
|
|
475
|
+
// target, PKs, strategy, and column types all derive from `(registry, tableKey)`. The
|
|
476
|
+
// `syncConfig` table key IS the registry key, so the spec's `key` is the `tableKey`.
|
|
477
|
+
tableKey: spec.key,
|
|
450
478
|
},
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
// `syncConfig` table key IS the registry key, so the spec's `key` is the `tableKey`.
|
|
454
|
-
tableKey: spec.key,
|
|
455
|
-
},
|
|
456
|
-
]),
|
|
479
|
+
];
|
|
480
|
+
}),
|
|
457
481
|
);
|
|
458
482
|
|
|
459
483
|
return getElectricNamespace(pg).syncShapesToTables({
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
import { StorageDeclarationRefusedError } from "@pgxsinkit/contracts";
|
|
27
27
|
|
|
28
28
|
import type { BootReport } from "../boot-report";
|
|
29
|
+
import { syncDebug } from "../debug";
|
|
29
30
|
import type { DataExportOptions, DataExportResult } from "../export-data";
|
|
30
31
|
import type { DiagnosticExportOptions, DiagnosticExportResult } from "../export-dump";
|
|
31
32
|
import type { StoreExportOptions, StoreExportResult } from "../export-store";
|
|
@@ -2069,6 +2070,9 @@ export async function attachSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
2069
2070
|
throw error;
|
|
2070
2071
|
}
|
|
2071
2072
|
const initialRows = materializer.seed(initial.rows as TRow[]);
|
|
2073
|
+
// Tab-side receipt on the rail: pairs with the worker's "live-initial post" — if that line fires and
|
|
2074
|
+
// this one never does, the loss is in the bridge; if both fire with 0 rows, the store was empty.
|
|
2075
|
+
syncDebug("live-initial received", { rows: initialRows.length });
|
|
2072
2076
|
// Register the live query for ADR-0049 re-subscribe: on a pipe swap, re-issue the SAME subscribe (same
|
|
2073
2077
|
// queryId → diffs still route to the same materializer/handler) and re-seed the materializer off the fresh
|
|
2074
2078
|
// snapshot. This is the re-attach re-establishment of live queries (ADR-0041 staged readiness); its
|
|
@@ -857,6 +857,9 @@ export function defineSyncWorker<const TRegistry extends SyncTableRegistry>(
|
|
|
857
857
|
{
|
|
858
858
|
deliverInitial: (rows) => {
|
|
859
859
|
// Initial snapshot verbatim (not a diff), correlated to the subscribe request so the tab resolves.
|
|
860
|
+
// Row COUNT on the rail: the register line proves the query ran, but only this line shows what the
|
|
861
|
+
// store actually held — a warm boot delivering 0 rows is the "empty store" diagnosis in one glance.
|
|
862
|
+
syncDebug("live-initial post", { rows: rows.length, hydrating: hydratingTables.length });
|
|
860
863
|
postBridgeMessage(
|
|
861
864
|
port,
|
|
862
865
|
codec,
|