@tekmidian/pai 0.66.0 → 0.66.2
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/{aibroker-client-B8c42Lh8.mjs → aibroker-client-CHEEvJZW.mjs} +2 -2
- package/dist/{aibroker-client-C5Fw7DNz.mjs → aibroker-client-Dfv7j1Od.mjs} +3 -3
- package/dist/{aibroker-client-C5Fw7DNz.mjs.map → aibroker-client-Dfv7j1Od.mjs.map} +1 -1
- package/dist/{auto-route-o0BOsXn7.mjs → auto-route-BnizyALK.mjs} +65 -4
- package/dist/auto-route-BnizyALK.mjs.map +1 -0
- package/dist/auto-route-D6fW1Q8z.mjs +3 -0
- package/dist/{chain-D4PuQ2c-.mjs → chain-D5876UQX.mjs} +3 -4
- package/dist/{chain-D4PuQ2c-.mjs.map → chain-D5876UQX.mjs.map} +1 -1
- package/dist/cli/index.mjs +18 -23
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/program.mjs +17 -22
- package/dist/{config-BbLFD7Uf.mjs → config-C-LiGlop.mjs} +2 -2
- package/dist/{config-BbLFD7Uf.mjs.map → config-C-LiGlop.mjs.map} +1 -1
- package/dist/{config-YinjgXEJ.mjs → config-DKIA7wgF.mjs} +1 -1
- package/dist/{context-handover-cache-pkHzmL3c.mjs → context-handover-cache-9PGvXRIw.mjs} +984 -10
- package/dist/context-handover-cache-9PGvXRIw.mjs.map +1 -0
- package/dist/daemon/index.mjs +17 -19
- package/dist/daemon/index.mjs.map +1 -1
- package/dist/daemon-BUgNvMUh.mjs +5029 -0
- package/dist/daemon-BUgNvMUh.mjs.map +1 -0
- package/dist/daemon-DL0eglMJ.mjs +18 -0
- package/dist/daemon-mcp/index.mjs +15 -10
- package/dist/daemon-mcp/index.mjs.map +1 -1
- package/dist/{embeddings-CcscYWwk.mjs → embeddings-CEBGrzwu.mjs} +1 -1
- package/dist/{embeddings-Bx3q0QOY.mjs → embeddings-DOLZnT1X.mjs} +1 -1
- package/dist/{embeddings-Bx3q0QOY.mjs.map → embeddings-DOLZnT1X.mjs.map} +1 -1
- package/dist/{env-JNEIrQWg.mjs → env-DiolswKQ.mjs} +1 -1
- package/dist/{env-JNEIrQWg.mjs.map → env-DiolswKQ.mjs.map} +1 -1
- package/dist/factory-DrBg24UT.mjs +8 -0
- package/dist/factory-Ypf8r0fK.mjs +2892 -0
- package/dist/factory-Ypf8r0fK.mjs.map +1 -0
- package/dist/{fallback-B5svk75f.mjs → fallback-D51R4shY.mjs} +27 -13
- package/dist/fallback-D51R4shY.mjs.map +1 -0
- package/dist/{chunker-BH4i-F2b.mjs → helpers-CZsi_49C.mjs} +221 -2
- package/dist/helpers-CZsi_49C.mjs.map +1 -0
- package/dist/hooks/block-sleep-poll.mjs.map +2 -2
- package/dist/hooks/load-project-context.mjs.map +2 -2
- package/dist/hooks/worker-guard.mjs +5 -0
- package/dist/hooks/worker-guard.mjs.map +2 -2
- package/dist/hooks/worker-status-line.mjs +1 -0
- package/dist/hooks/worker-status-line.mjs.map +2 -2
- package/dist/index.mjs +6 -7
- package/dist/{ipc-client-D16Xw6Uo.mjs → ipc-client-BLYX51nG.mjs} +2 -2
- package/dist/{ipc-client-D16Xw6Uo.mjs.map → ipc-client-BLYX51nG.mjs.map} +1 -1
- package/dist/main-resolver-BYgP86C1.mjs +7 -0
- package/dist/{main-resolver-DPPwHNtn.mjs → main-resolver-kVkMJZUD.mjs} +6 -6
- package/dist/{main-resolver-DPPwHNtn.mjs.map → main-resolver-kVkMJZUD.mjs.map} +1 -1
- package/dist/{migrate-BD7D8EEh.mjs → migrate-Bq0esMOa.mjs} +2 -2
- package/dist/{migrate-BD7D8EEh.mjs.map → migrate-Bq0esMOa.mjs.map} +1 -1
- package/dist/{pai-marker-D1MMswkz.mjs → pai-marker-DXVpFsYz.mjs} +1 -1
- package/dist/{pai-marker-D1MMswkz.mjs.map → pai-marker-DXVpFsYz.mjs.map} +1 -1
- package/dist/{planner-EJPZnnif.mjs → planner-D5yt0EfA.mjs} +10 -7
- package/dist/{planner-EJPZnnif.mjs.map → planner-D5yt0EfA.mjs.map} +1 -1
- package/dist/postgres-BmLr0MUm.mjs +5 -0
- package/dist/{postgres-Ceqsa64C.mjs → postgres-D3xc2RB4.mjs} +364 -9
- package/dist/postgres-D3xc2RB4.mjs.map +1 -0
- package/dist/{program-DSETzrWg.mjs → program-DIXRtAFy.mjs} +80 -70
- package/dist/program-DIXRtAFy.mjs.map +1 -0
- package/dist/{query-feedback-BIaZTTFO.mjs → query-feedback-B7FYE4JR.mjs} +1 -1
- package/dist/{query-feedback-BIaZTTFO.mjs.map → query-feedback-B7FYE4JR.mjs.map} +1 -1
- package/dist/{reranker-DKv80KO5.mjs → reranker-3lnggwgq.mjs} +1 -1
- package/dist/{reranker-DKv80KO5.mjs.map → reranker-3lnggwgq.mjs.map} +1 -1
- package/dist/{reranker-CFiEzHQu.mjs → reranker-CZ2mP4cf.mjs} +1 -1
- package/dist/router-BK-hFeQ6.mjs +3 -0
- package/dist/{router-a5G7q8_3.mjs → router-BaTbc9VX.mjs} +2 -2
- package/dist/{router-a5G7q8_3.mjs.map → router-BaTbc9VX.mjs.map} +1 -1
- package/dist/{run-Z4akoa8G.mjs → run-CLYTOm0x.mjs} +764 -25
- package/dist/run-CLYTOm0x.mjs.map +1 -0
- package/dist/{run-env-DRcp7A8K.mjs → run-env-Bnmf6bRI.mjs} +2 -2
- package/dist/{run-env-DRcp7A8K.mjs.map → run-env-Bnmf6bRI.mjs.map} +1 -1
- package/dist/{runtime-paths-CHTg3ywb.mjs → runtime-paths-D3FKAm69.mjs} +1 -1
- package/dist/{runtime-paths-CHTg3ywb.mjs.map → runtime-paths-D3FKAm69.mjs.map} +1 -1
- package/dist/{search-BOSphCJ1.mjs → search-CNAGTiJP.mjs} +2 -2
- package/dist/{search-BOSphCJ1.mjs.map → search-CNAGTiJP.mjs.map} +1 -1
- package/dist/{sources-CijVso3n.mjs → sources-CM2g-CLT.mjs} +2 -2
- package/dist/{sources-CijVso3n.mjs.map → sources-CM2g-CLT.mjs.map} +1 -1
- package/dist/{stop-words-BdQuaE9K.mjs → stop-words-DtxaTWU_.mjs} +1 -1
- package/dist/{stop-words-BdQuaE9K.mjs.map → stop-words-DtxaTWU_.mjs.map} +1 -1
- package/dist/{utils-C9HsYDpO.mjs → utils-DddRwMsG.mjs} +2 -2
- package/dist/{utils-C9HsYDpO.mjs.map → utils-DddRwMsG.mjs.map} +1 -1
- package/dist/{zettelkasten-CtGHQWPU.mjs → zettelkasten-BhZMvmoK.mjs} +149 -7
- package/dist/zettelkasten-BhZMvmoK.mjs.map +1 -0
- package/dist/zettelkasten-BwV1pluL.mjs +5 -0
- package/docs/commands/worker.md +2 -0
- package/package.json +1 -1
- package/src/hooks/ts/lib/worker-guard.test.ts +12 -0
- package/src/hooks/ts/lib/worker-guard.ts +9 -0
- package/dist/async-C2Bm_Lal.mjs +0 -300
- package/dist/async-C2Bm_Lal.mjs.map +0 -1
- package/dist/auto-route-o0BOsXn7.mjs.map +0 -1
- package/dist/chunker-BH4i-F2b.mjs.map +0 -1
- package/dist/clusters-BCtD3fbe.mjs +0 -169
- package/dist/clusters-BCtD3fbe.mjs.map +0 -1
- package/dist/context-handover-cache-pkHzmL3c.mjs.map +0 -1
- package/dist/daemon-BEoVgVfJ.mjs +0 -1741
- package/dist/daemon-BEoVgVfJ.mjs.map +0 -1
- package/dist/daemon-DPAYU9hp.mjs +0 -19
- package/dist/detector-BEPFsINR.mjs +0 -3
- package/dist/detector-BRTtAWrM.mjs +0 -65
- package/dist/detector-BRTtAWrM.mjs.map +0 -1
- package/dist/factory-CNpPQQ-5.mjs +0 -249
- package/dist/factory-CNpPQQ-5.mjs.map +0 -1
- package/dist/factory-DY7x73mE.mjs +0 -3
- package/dist/fallback-B5svk75f.mjs.map +0 -1
- package/dist/federation-db-BTyoufBh.mjs +0 -139
- package/dist/federation-db-BTyoufBh.mjs.map +0 -1
- package/dist/federation-db-HfIFc7FG.mjs +0 -3
- package/dist/helpers-BRCJg0G3.mjs +0 -223
- package/dist/helpers-BRCJg0G3.mjs.map +0 -1
- package/dist/indexer-backend-DFF2FrYx.mjs +0 -5
- package/dist/indexer-backend-isSLg6yE.mjs +0 -1
- package/dist/kg-entity-DCOcsVFD.mjs +0 -29
- package/dist/kg-entity-DCOcsVFD.mjs.map +0 -1
- package/dist/latent-ideas-wwAXquGe.mjs +0 -191
- package/dist/latent-ideas-wwAXquGe.mjs.map +0 -1
- package/dist/link-boost-CnI7UVMJ.mjs +0 -34
- package/dist/link-boost-CnI7UVMJ.mjs.map +0 -1
- package/dist/main-resolver-BKz_OuEh.mjs +0 -7
- package/dist/merge-2gqRPFu2.mjs +0 -3
- package/dist/merge-DgU9OgZy.mjs +0 -6
- package/dist/merge-DgU9OgZy.mjs.map +0 -1
- package/dist/module-paths-DdRzbkUI.mjs +0 -44
- package/dist/module-paths-DdRzbkUI.mjs.map +0 -1
- package/dist/neighborhood-2FsmzoxG.mjs +0 -114
- package/dist/neighborhood-2FsmzoxG.mjs.map +0 -1
- package/dist/note-context-De63k8na.mjs +0 -106
- package/dist/note-context-De63k8na.mjs.map +0 -1
- package/dist/postgres-Ceqsa64C.mjs.map +0 -1
- package/dist/program-DSETzrWg.mjs.map +0 -1
- package/dist/query-feedback-B_iigYj-.mjs +0 -3
- package/dist/registry-db-C7voqML9.mjs +0 -213
- package/dist/registry-db-C7voqML9.mjs.map +0 -1
- package/dist/registry-db-JHPhA8vF.mjs +0 -3
- package/dist/registry-postgres-nOfyBSIW.mjs +0 -795
- package/dist/registry-postgres-nOfyBSIW.mjs.map +0 -1
- package/dist/registry-sqlite-DrCW1aRK.mjs +0 -593
- package/dist/registry-sqlite-DrCW1aRK.mjs.map +0 -1
- package/dist/router-CXUGsv85.mjs +0 -3
- package/dist/run-Z4akoa8G.mjs.map +0 -1
- package/dist/search-Bf3Kub3F.mjs +0 -3
- package/dist/server-DgmAHyFK.mjs +0 -403
- package/dist/server-DgmAHyFK.mjs.map +0 -1
- package/dist/session-keepalive-BDhytXEo.mjs +0 -582
- package/dist/session-keepalive-BDhytXEo.mjs.map +0 -1
- package/dist/sqlite-CqsTy6xo.mjs +0 -936
- package/dist/sqlite-CqsTy6xo.mjs.map +0 -1
- package/dist/state-DW8zdweW.mjs +0 -3
- package/dist/state-HyjqTihC.mjs +0 -76
- package/dist/state-HyjqTihC.mjs.map +0 -1
- package/dist/themes-CTaOj3e1.mjs +0 -148
- package/dist/themes-CTaOj3e1.mjs.map +0 -1
- package/dist/tools-BcOKPBtg.mjs +0 -1489
- package/dist/tools-BcOKPBtg.mjs.map +0 -1
- package/dist/tools-C-_l0o8Z.mjs +0 -6
- package/dist/trace-CtV0RO6n.mjs +0 -137
- package/dist/trace-CtV0RO6n.mjs.map +0 -1
- package/dist/utils-BrX9FLeK.mjs +0 -3
- package/dist/vault-indexer-BG1sEVyM.mjs +0 -537
- package/dist/vault-indexer-BG1sEVyM.mjs.map +0 -1
- package/dist/wakeup-D8n33hYV.mjs +0 -335
- package/dist/wakeup-D8n33hYV.mjs.map +0 -1
- package/dist/work-queue-worker-4tLa5gpQ.mjs +0 -567
- package/dist/work-queue-worker-4tLa5gpQ.mjs.map +0 -1
- package/dist/work-queue-worker-rFZvTO3p.mjs +0 -11
- package/dist/zettelkasten-CtGHQWPU.mjs.map +0 -1
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
//#region src/storage/outage.ts
|
|
2
|
-
let current = null;
|
|
3
|
-
/** Record that the backend is currently unreachable. */
|
|
4
|
-
function setBackendOutage(outage) {
|
|
5
|
-
current = outage;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Record that the backend answered.
|
|
9
|
-
*
|
|
10
|
-
* Called on every successful connection, including the first — so a daemon that
|
|
11
|
-
* never had a problem reports none, and one that recovered stops reporting an
|
|
12
|
-
* outage that has ended.
|
|
13
|
-
*/
|
|
14
|
-
function clearBackendOutage() {
|
|
15
|
-
current = null;
|
|
16
|
-
}
|
|
17
|
-
/** The current outage, or null when the backend is answering. */
|
|
18
|
-
function getBackendOutage() {
|
|
19
|
-
return current;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Human-readable elapsed time, for a status line rather than a log.
|
|
23
|
-
*
|
|
24
|
-
* Exported because the status command needs the duration on its own, to colour
|
|
25
|
-
* it separately from the rest of the sentence. Without this it kept a second
|
|
26
|
-
* copy of the same rounding, which is how two renderings of one outage drift.
|
|
27
|
-
*/
|
|
28
|
-
function humanDuration(ms) {
|
|
29
|
-
const mins = Math.max(1, Math.round(ms / 6e4));
|
|
30
|
-
return mins < 60 ? `${mins} min` : `${(mins / 60).toFixed(1)} h`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/storage/factory.ts
|
|
35
|
-
/** Backoff schedule (ms) for the bounded CLI retry path. */
|
|
36
|
-
const CLI_RETRY_DELAYS_MS = [
|
|
37
|
-
500,
|
|
38
|
-
1e3,
|
|
39
|
-
2e3
|
|
40
|
-
];
|
|
41
|
-
/** Backoff cap (ms) for the daemon's infinite retry path. */
|
|
42
|
-
const DAEMON_RETRY_CAP_MS = 15e3;
|
|
43
|
-
/**
|
|
44
|
-
* Create and return the configured StorageBackend.
|
|
45
|
-
*
|
|
46
|
-
* Auto-behaviour:
|
|
47
|
-
* - storageBackend = "sqlite" → SQLiteBackend always
|
|
48
|
-
* - storageBackend = "postgres" → PostgresBackend (retried; never falls back)
|
|
49
|
-
*/
|
|
50
|
-
async function createStorageBackend(config, opts = {}) {
|
|
51
|
-
if (config.storageBackend === "postgres") return await getSharedPostgresBackend(config, opts.waitForPostgres ?? false);
|
|
52
|
-
return createSQLiteBackend();
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Attempt a single Postgres connection (ensure DB + test). Returns the live
|
|
56
|
-
* backend on success, or an error string describing why it failed.
|
|
57
|
-
*/
|
|
58
|
-
async function attemptPostgres(config) {
|
|
59
|
-
const { PostgresBackend } = await import("./postgres-Ceqsa64C.mjs");
|
|
60
|
-
const pgConfig = config.postgres ?? {};
|
|
61
|
-
let backend = null;
|
|
62
|
-
try {
|
|
63
|
-
await PostgresBackend.ensureDatabase(pgConfig);
|
|
64
|
-
backend = new PostgresBackend(pgConfig);
|
|
65
|
-
const err = await backend.testConnection();
|
|
66
|
-
if (err) {
|
|
67
|
-
await backend.close().catch(() => {});
|
|
68
|
-
return { error: err };
|
|
69
|
-
}
|
|
70
|
-
return { backend };
|
|
71
|
-
} catch (e) {
|
|
72
|
-
if (backend) await backend.close().catch(() => {});
|
|
73
|
-
return { error: e instanceof Error ? e.message : String(e) };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Consecutive failures before the outage is escalated to the user.
|
|
78
|
-
*
|
|
79
|
-
* Not the first failure: a container restarting, or the daemon starting before
|
|
80
|
-
* Docker is up, recovers within a few seconds and is not worth a notification.
|
|
81
|
-
* By the fifth attempt the backoff has already spent tens of seconds, which is
|
|
82
|
-
* long enough that something is actually wrong.
|
|
83
|
-
*/
|
|
84
|
-
const ESCALATE_AFTER_ATTEMPTS = 5;
|
|
85
|
-
/** Tell the user the backend is down, through whatever channels are configured. */
|
|
86
|
-
async function notifyBackendDown(attempts, lastError) {
|
|
87
|
-
try {
|
|
88
|
-
const { routeNotification } = await import("./router-CXUGsv85.mjs");
|
|
89
|
-
const { loadConfig } = await import("./config-YinjgXEJ.mjs");
|
|
90
|
-
await routeNotification({
|
|
91
|
-
event: "error",
|
|
92
|
-
title: "PAI: storage backend unreachable",
|
|
93
|
-
message: `Postgres has not answered in ${attempts} attempts (${lastError}). Indexing, session notes and the work queue are stalled until it returns. Check the container, then \`pai daemon status\`.`
|
|
94
|
-
}, loadConfig().notifications);
|
|
95
|
-
} catch {}
|
|
96
|
-
}
|
|
97
|
-
/** And say when it comes back, so the alert is not left hanging. */
|
|
98
|
-
async function notifyBackendRecovered(attempts, since) {
|
|
99
|
-
try {
|
|
100
|
-
const { routeNotification } = await import("./router-CXUGsv85.mjs");
|
|
101
|
-
const { loadConfig } = await import("./config-YinjgXEJ.mjs");
|
|
102
|
-
const mins = since ? Math.max(1, Math.round((Date.now() - since) / 6e4)) : null;
|
|
103
|
-
await routeNotification({
|
|
104
|
-
event: "completion",
|
|
105
|
-
title: "PAI: storage backend back",
|
|
106
|
-
message: `Postgres answered after ${attempts} attempts` + (mins ? `, ${mins} min down` : "") + `. The queue will drain on its own.`
|
|
107
|
-
}, loadConfig().notifications);
|
|
108
|
-
} catch {}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Shared retry loop: attempt a connection, back off, escalate, repeat — used
|
|
112
|
-
* by both the federation and registry Postgres connectors so the retry/outage
|
|
113
|
-
* behaviour (§6, "never falls back to SQLite silently") stays in one place.
|
|
114
|
-
*/
|
|
115
|
-
async function retryConnect(attempt, waitForever, label) {
|
|
116
|
-
let attemptN = 0;
|
|
117
|
-
let outageSince = null;
|
|
118
|
-
let escalated = false;
|
|
119
|
-
while (true) {
|
|
120
|
-
attemptN++;
|
|
121
|
-
const result = await attempt();
|
|
122
|
-
if ("backend" in result) {
|
|
123
|
-
if (attemptN > 1) process.stderr.write(`[pai-daemon] Connected to ${label} (after ${attemptN} attempts).\n`);
|
|
124
|
-
clearBackendOutage();
|
|
125
|
-
if (escalated) notifyBackendRecovered(attemptN, outageSince);
|
|
126
|
-
return result.backend;
|
|
127
|
-
}
|
|
128
|
-
const lastError = result.error;
|
|
129
|
-
if (!waitForever && attemptN > CLI_RETRY_DELAYS_MS.length) throw new Error(`${label} unreachable after ${attemptN} attempts: ${lastError}. Is Docker Desktop / Postgres running? Refusing to fall back to SQLite (would split the corpus). Start Postgres and retry.`);
|
|
130
|
-
const delayMs = waitForever ? Math.min(DAEMON_RETRY_CAP_MS, 1e3 * 2 ** Math.min(attemptN - 1, 4)) : CLI_RETRY_DELAYS_MS[attemptN - 1];
|
|
131
|
-
process.stderr.write(`[pai-daemon] ${label} unavailable (${lastError}). Retry ${attemptN}${waitForever ? "" : `/${CLI_RETRY_DELAYS_MS.length + 1}`} in ${delayMs}ms...\n`);
|
|
132
|
-
setBackendOutage({
|
|
133
|
-
backend: label,
|
|
134
|
-
since: outageSince ?? (outageSince = Date.now()),
|
|
135
|
-
attempts: attemptN,
|
|
136
|
-
lastError: String(lastError)
|
|
137
|
-
});
|
|
138
|
-
if (waitForever && attemptN === ESCALATE_AFTER_ATTEMPTS && !escalated) {
|
|
139
|
-
escalated = true;
|
|
140
|
-
notifyBackendDown(attemptN, String(lastError));
|
|
141
|
-
}
|
|
142
|
-
await new Promise((r) => setTimeout(r, delayMs));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async function connectPostgres(config, waitForever) {
|
|
146
|
-
return retryConnect(() => attemptPostgres(config), waitForever, "PostgreSQL backend");
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* The process's one Postgres connection: storage and registry share a
|
|
150
|
-
* single pg Pool (one connection budget) instead of each opening their own.
|
|
151
|
-
* Whichever of createStorageBackend()/createRegistryBackend() runs first
|
|
152
|
-
* creates it via connectPostgres()'s retry/outage handling; the other
|
|
153
|
-
* reuses its pool through PostgresBackend.getPool(). Reset by closeStorage().
|
|
154
|
-
*/
|
|
155
|
-
let pgBackendPromise = null;
|
|
156
|
-
function getSharedPostgresBackend(config, waitForever) {
|
|
157
|
-
if (!pgBackendPromise) pgBackendPromise = connectPostgres(config, waitForever);
|
|
158
|
-
return pgBackendPromise;
|
|
159
|
-
}
|
|
160
|
-
async function createSQLiteBackend() {
|
|
161
|
-
const { openFederation } = await import("./federation-db-HfIFc7FG.mjs");
|
|
162
|
-
const { SQLiteBackend } = await import("./sqlite-CqsTy6xo.mjs");
|
|
163
|
-
return new SQLiteBackend(openFederation());
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Create and return the configured RegistryBackend (projects, sessions,
|
|
167
|
-
* tags, aliases, links, compaction_log). Same auto-behaviour and same
|
|
168
|
-
* never-fall-back-to-SQLite rule as createStorageBackend().
|
|
169
|
-
*/
|
|
170
|
-
async function createRegistryBackend(config, opts = {}) {
|
|
171
|
-
if (config.storageBackend === "postgres") {
|
|
172
|
-
const storage = await getSharedPostgresBackend(config, opts.waitForPostgres ?? false);
|
|
173
|
-
const { PostgresRegistryBackend } = await import("./registry-postgres-nOfyBSIW.mjs");
|
|
174
|
-
return new PostgresRegistryBackend(storage.getPool());
|
|
175
|
-
}
|
|
176
|
-
return createSQLiteRegistryBackend();
|
|
177
|
-
}
|
|
178
|
-
async function createSQLiteRegistryBackend() {
|
|
179
|
-
const { openRegistry } = await import("./registry-db-JHPhA8vF.mjs");
|
|
180
|
-
const { SQLiteRegistryBackend } = await import("./registry-sqlite-DrCW1aRK.mjs");
|
|
181
|
-
return new SQLiteRegistryBackend(openRegistry());
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Process-wide backend accessors.
|
|
185
|
-
*
|
|
186
|
-
* Callers across the codebase must get their StorageBackend/RegistryBackend
|
|
187
|
-
* from here rather than constructing SQLite or Postgres directly — this is
|
|
188
|
-
* the one place that decides which backend a process uses, and the one place
|
|
189
|
-
* that closes it on exit.
|
|
190
|
-
*/
|
|
191
|
-
let storagePromise = null;
|
|
192
|
-
let registryPromise = null;
|
|
193
|
-
let beforeExitRegistered = false;
|
|
194
|
-
function registerBeforeExit() {
|
|
195
|
-
if (beforeExitRegistered) return;
|
|
196
|
-
beforeExitRegistered = true;
|
|
197
|
-
process.once("beforeExit", () => {
|
|
198
|
-
closeStorage();
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Returns the process-wide StorageBackend, creating it on first call.
|
|
203
|
-
*
|
|
204
|
-
* The whole body up to and including the `storagePromise = (async () =>
|
|
205
|
-
* ...)()` assignment must run synchronously (no `await` before it) — two
|
|
206
|
-
* calls issued in the same tick (e.g. `Promise.all([get(), get()])`) must
|
|
207
|
-
* both observe the same cached promise rather than each racing to create
|
|
208
|
-
* their own backend.
|
|
209
|
-
*/
|
|
210
|
-
async function getStorageBackend() {
|
|
211
|
-
if (!storagePromise) storagePromise = (async () => {
|
|
212
|
-
const { loadConfig } = await import("./config-YinjgXEJ.mjs");
|
|
213
|
-
registerBeforeExit();
|
|
214
|
-
return await createStorageBackend(loadConfig());
|
|
215
|
-
})();
|
|
216
|
-
return storagePromise;
|
|
217
|
-
}
|
|
218
|
-
/** Returns the process-wide RegistryBackend, creating it on first call. Same synchronous-caching requirement as getStorageBackend(). */
|
|
219
|
-
async function getRegistryBackend() {
|
|
220
|
-
if (!registryPromise) registryPromise = (async () => {
|
|
221
|
-
const { loadConfig } = await import("./config-YinjgXEJ.mjs");
|
|
222
|
-
registerBeforeExit();
|
|
223
|
-
return await createRegistryBackend(loadConfig());
|
|
224
|
-
})();
|
|
225
|
-
return registryPromise;
|
|
226
|
-
}
|
|
227
|
-
/** Closes any backends created via getStorageBackend()/getRegistryBackend(). Idempotent. */
|
|
228
|
-
async function closeStorage() {
|
|
229
|
-
const pending = [storagePromise, registryPromise];
|
|
230
|
-
const pg = pgBackendPromise;
|
|
231
|
-
storagePromise = null;
|
|
232
|
-
registryPromise = null;
|
|
233
|
-
pgBackendPromise = null;
|
|
234
|
-
for (const p of pending) {
|
|
235
|
-
if (!p) continue;
|
|
236
|
-
try {
|
|
237
|
-
const backend = await p;
|
|
238
|
-
if (backend.backendType === "postgres") continue;
|
|
239
|
-
await backend.close();
|
|
240
|
-
} catch {}
|
|
241
|
-
}
|
|
242
|
-
if (pg) try {
|
|
243
|
-
await (await pg).close();
|
|
244
|
-
} catch {}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
//#endregion
|
|
248
|
-
export { getStorageBackend as a, getRegistryBackend as i, createRegistryBackend as n, getBackendOutage as o, createStorageBackend as r, humanDuration as s, closeStorage as t };
|
|
249
|
-
//# sourceMappingURL=factory-CNpPQQ-5.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory-CNpPQQ-5.mjs","names":[],"sources":["../src/storage/outage.ts","../src/storage/factory.ts"],"sourcesContent":["/**\n * outage.ts — is the storage backend actually reachable right now?\n *\n * The daemon retries a dead backend forever, which is correct: a Postgres\n * container that is down will usually come back, and giving up would lose the\n * work queue. What was wrong is that it did so in complete silence.\n *\n * Observed 2026-07-26: the container was down for roughly two days. The daemon\n * logged \"Postgres unavailable\" 144 times over 36 minutes, the work queue backed\n * up, session notes for the whole period were never written — and\n * `pai daemon status` reported \"Index: idle\" throughout. The one command anyone\n * would run to check said everything was fine.\n *\n * So the outage is recorded where the status command can see it, and escalated\n * once through the notification channels that were already configured and\n * already unused for this.\n */\n\nexport interface BackendOutage {\n backend: string;\n /** When the current run of failures began. */\n since: number;\n /** Consecutive failed attempts so far. */\n attempts: number;\n lastError: string;\n}\n\nlet current: BackendOutage | null = null;\n\n/** Record that the backend is currently unreachable. */\nexport function setBackendOutage(outage: BackendOutage): void {\n current = outage;\n}\n\n/**\n * Record that the backend answered.\n *\n * Called on every successful connection, including the first — so a daemon that\n * never had a problem reports none, and one that recovered stops reporting an\n * outage that has ended.\n */\nexport function clearBackendOutage(): void {\n current = null;\n}\n\n/** The current outage, or null when the backend is answering. */\nexport function getBackendOutage(): BackendOutage | null {\n return current;\n}\n\n/**\n * Human-readable elapsed time, for a status line rather than a log.\n *\n * Exported because the status command needs the duration on its own, to colour\n * it separately from the rest of the sentence. Without this it kept a second\n * copy of the same rounding, which is how two renderings of one outage drift.\n */\nexport function humanDuration(ms: number): string {\n const mins = Math.max(1, Math.round(ms / 60_000));\n return mins < 60 ? `${mins} min` : `${(mins / 60).toFixed(1)} h`;\n}\n\n/** Human-readable duration, for a status line rather than a log. */\nexport function describeOutage(o: BackendOutage, now = Date.now()): string {\n return `${o.backend} unreachable for ${humanDuration(now - o.since)}, ${o.attempts} attempts — ${o.lastError}`;\n}\n","/**\n * Storage backend factory.\n *\n * Reads the daemon config and returns the appropriate StorageBackend.\n *\n * When Postgres is the configured backend we NEVER silently fall back to\n * SQLite — doing so would split the corpus across two databases. Instead:\n * - Daemon (waitForPostgres: true) retries Postgres forever with capped\n * backoff until it comes up (handles the boot race where launchd starts\n * the daemon before Docker Desktop / Postgres is ready).\n * - CLI / one-shot callers (default) retry a few times, then throw a clear\n * error rather than returning a wrong/empty SQLite database.\n */\n\nimport type { PaiDaemonConfig } from \"../daemon/config.js\";\nimport type { StorageBackend } from \"./interface.js\";\nimport type { RegistryBackend } from \"./registry-interface.js\";\nimport { setBackendOutage, clearBackendOutage } from \"./outage.js\";\n\nexport interface StorageBackendOptions {\n /**\n * When true, retry Postgres indefinitely instead of giving up. Used by the\n * long-lived daemon so a not-yet-ready Postgres at boot is tolerated.\n * Defaults to false (one-shot CLI behaviour: bounded retries, then throw).\n */\n waitForPostgres?: boolean;\n}\n\n/** Backoff schedule (ms) for the bounded CLI retry path. */\nconst CLI_RETRY_DELAYS_MS = [500, 1_000, 2_000];\n\n/** Backoff cap (ms) for the daemon's infinite retry path. */\nconst DAEMON_RETRY_CAP_MS = 15_000;\n\n/**\n * Create and return the configured StorageBackend.\n *\n * Auto-behaviour:\n * - storageBackend = \"sqlite\" → SQLiteBackend always\n * - storageBackend = \"postgres\" → PostgresBackend (retried; never falls back)\n */\nexport async function createStorageBackend(\n config: PaiDaemonConfig,\n opts: StorageBackendOptions = {}\n): Promise<StorageBackend> {\n if (config.storageBackend === \"postgres\") {\n return await getSharedPostgresBackend(config, opts.waitForPostgres ?? false);\n }\n\n // Default: SQLite\n return createSQLiteBackend();\n}\n\n/**\n * Attempt a single Postgres connection (ensure DB + test). Returns the live\n * backend on success, or an error string describing why it failed.\n */\nasync function attemptPostgres(\n config: PaiDaemonConfig\n): Promise<{ backend: StorageBackend } | { error: string }> {\n const { PostgresBackend } = await import(\"./postgres.js\");\n const pgConfig = config.postgres ?? {};\n\n let backend: InstanceType<typeof PostgresBackend> | null = null;\n try {\n // Ensure the per-user database exists and has the schema applied.\n await PostgresBackend.ensureDatabase(pgConfig);\n\n backend = new PostgresBackend(pgConfig);\n const err = await backend.testConnection();\n if (err) {\n await backend.close().catch(() => {});\n return { error: err };\n }\n return { backend };\n } catch (e) {\n if (backend) await backend.close().catch(() => {});\n return { error: e instanceof Error ? e.message : String(e) };\n }\n}\n\n/**\n * Consecutive failures before the outage is escalated to the user.\n *\n * Not the first failure: a container restarting, or the daemon starting before\n * Docker is up, recovers within a few seconds and is not worth a notification.\n * By the fifth attempt the backoff has already spent tens of seconds, which is\n * long enough that something is actually wrong.\n */\nconst ESCALATE_AFTER_ATTEMPTS = 5;\n\n/** Tell the user the backend is down, through whatever channels are configured. */\nasync function notifyBackendDown(attempts: number, lastError: string): Promise<void> {\n try {\n const { routeNotification } = await import(\"../notifications/router.js\");\n const { loadConfig } = await import(\"../daemon/config.js\");\n await routeNotification(\n {\n event: \"error\",\n title: \"PAI: storage backend unreachable\",\n message:\n `Postgres has not answered in ${attempts} attempts (${lastError}). ` +\n `Indexing, session notes and the work queue are stalled until it returns. ` +\n `Check the container, then \\`pai daemon status\\`.`,\n },\n loadConfig().notifications\n );\n } catch {\n // A notification that cannot be sent must never take the daemon down with\n // it — the daemon retrying is still the useful behaviour here.\n }\n}\n\n/** And say when it comes back, so the alert is not left hanging. */\nasync function notifyBackendRecovered(\n attempts: number,\n since: number | null\n): Promise<void> {\n try {\n const { routeNotification } = await import(\"../notifications/router.js\");\n const { loadConfig } = await import(\"../daemon/config.js\");\n const mins = since ? Math.max(1, Math.round((Date.now() - since) / 60_000)) : null;\n await routeNotification(\n {\n event: \"completion\",\n title: \"PAI: storage backend back\",\n message:\n `Postgres answered after ${attempts} attempts` +\n (mins ? `, ${mins} min down` : \"\") +\n `. The queue will drain on its own.`,\n },\n loadConfig().notifications\n );\n } catch {\n /* same reasoning as above */\n }\n}\n\n/**\n * Shared retry loop: attempt a connection, back off, escalate, repeat — used\n * by both the federation and registry Postgres connectors so the retry/outage\n * behaviour (§6, \"never falls back to SQLite silently\") stays in one place.\n */\nasync function retryConnect<T>(\n attempt: () => Promise<{ backend: T } | { error: string }>,\n waitForever: boolean,\n label: string\n): Promise<T> {\n let attemptN = 0;\n let outageSince: number | null = null;\n let escalated = false;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n attemptN++;\n const result = await attempt();\n if (\"backend\" in result) {\n if (attemptN > 1) process.stderr.write(`[pai-daemon] Connected to ${label} (after ${attemptN} attempts).\\n`);\n // An outage that ended must stop being reported, or the status command\n // trades one wrong answer for another.\n clearBackendOutage();\n if (escalated) void notifyBackendRecovered(attemptN, outageSince);\n return result.backend;\n }\n\n const lastError = result.error;\n\n if (!waitForever && attemptN > CLI_RETRY_DELAYS_MS.length) {\n // Bounded CLI path exhausted — fail loudly, never silently use SQLite.\n throw new Error(\n `${label} unreachable after ${attemptN} attempts: ${lastError}. ` +\n `Is Docker Desktop / Postgres running? Refusing to fall back to SQLite ` +\n `(would split the corpus). Start Postgres and retry.`\n );\n }\n\n const delayMs = waitForever\n ? Math.min(DAEMON_RETRY_CAP_MS, 1_000 * 2 ** Math.min(attemptN - 1, 4))\n : CLI_RETRY_DELAYS_MS[attemptN - 1];\n\n process.stderr.write(\n `[pai-daemon] ${label} unavailable (${lastError}). ` +\n `Retry ${attemptN}${waitForever ? \"\" : `/${CLI_RETRY_DELAYS_MS.length + 1}`} ` +\n `in ${delayMs}ms...\\n`\n );\n\n // Publish the outage so `pai daemon status` can report it. Without this the\n // daemon retries silently forever and status still reads \"idle\" — which is\n // what happened for two days in July: 144 retries over 36 minutes, session\n // notes never written, and the one command anyone would run to check\n // reporting that everything was fine.\n setBackendOutage({\n backend: label,\n since: outageSince ?? (outageSince = Date.now()),\n attempts: attemptN,\n lastError: String(lastError),\n });\n\n // And escalate once, out loud, rather than only into a log nobody tails.\n // Once — not per retry — because a notification that repeats every few\n // seconds is filtered within a minute and stops being a signal at all.\n if (waitForever && attemptN === ESCALATE_AFTER_ATTEMPTS && !escalated) {\n escalated = true;\n void notifyBackendDown(attemptN, String(lastError));\n }\n\n await new Promise((r) => setTimeout(r, delayMs));\n }\n}\n\nasync function connectPostgres(\n config: PaiDaemonConfig,\n waitForever: boolean\n): Promise<StorageBackend> {\n return retryConnect(() => attemptPostgres(config), waitForever, \"PostgreSQL backend\");\n}\n\n/**\n * The process's one Postgres connection: storage and registry share a\n * single pg Pool (one connection budget) instead of each opening their own.\n * Whichever of createStorageBackend()/createRegistryBackend() runs first\n * creates it via connectPostgres()'s retry/outage handling; the other\n * reuses its pool through PostgresBackend.getPool(). Reset by closeStorage().\n */\nlet pgBackendPromise: Promise<StorageBackend> | null = null;\n\nfunction getSharedPostgresBackend(\n config: PaiDaemonConfig,\n waitForever: boolean\n): Promise<StorageBackend> {\n if (!pgBackendPromise) {\n pgBackendPromise = connectPostgres(config, waitForever);\n }\n return pgBackendPromise;\n}\n\nasync function createSQLiteBackend(): Promise<StorageBackend> {\n const { openFederation } = await import(\"./sqlite/federation-db.js\");\n const { SQLiteBackend } = await import(\"./sqlite.js\");\n const db = openFederation();\n return new SQLiteBackend(db);\n}\n\n/**\n * Create and return the configured RegistryBackend (projects, sessions,\n * tags, aliases, links, compaction_log). Same auto-behaviour and same\n * never-fall-back-to-SQLite rule as createStorageBackend().\n */\nexport async function createRegistryBackend(\n config: PaiDaemonConfig,\n opts: StorageBackendOptions = {}\n): Promise<RegistryBackend> {\n if (config.storageBackend === \"postgres\") {\n // Reuses the storage backend's pool (getSharedPostgresBackend) rather\n // than opening a second one against the same database.\n const storage = await getSharedPostgresBackend(config, opts.waitForPostgres ?? false);\n const { PostgresRegistryBackend } = await import(\"./registry-postgres.js\");\n const pool = (storage as unknown as { getPool: () => import(\"pg\").Pool }).getPool();\n return new PostgresRegistryBackend(pool);\n }\n return createSQLiteRegistryBackend();\n}\n\nasync function createSQLiteRegistryBackend(): Promise<RegistryBackend> {\n const { openRegistry } = await import(\"./sqlite/registry-db.js\");\n const { SQLiteRegistryBackend } = await import(\"./registry-sqlite.js\");\n const db = openRegistry();\n return new SQLiteRegistryBackend(db);\n}\n\n/**\n * Process-wide backend accessors.\n *\n * Callers across the codebase must get their StorageBackend/RegistryBackend\n * from here rather than constructing SQLite or Postgres directly — this is\n * the one place that decides which backend a process uses, and the one place\n * that closes it on exit.\n */\n\nlet storagePromise: Promise<StorageBackend> | null = null;\nlet registryPromise: Promise<RegistryBackend> | null = null;\nlet beforeExitRegistered = false;\n\nfunction registerBeforeExit(): void {\n if (beforeExitRegistered) return;\n beforeExitRegistered = true;\n process.once(\"beforeExit\", () => {\n void closeStorage();\n });\n}\n\n/**\n * Returns the process-wide StorageBackend, creating it on first call.\n *\n * The whole body up to and including the `storagePromise = (async () =>\n * ...)()` assignment must run synchronously (no `await` before it) — two\n * calls issued in the same tick (e.g. `Promise.all([get(), get()])`) must\n * both observe the same cached promise rather than each racing to create\n * their own backend.\n */\nexport async function getStorageBackend(): Promise<StorageBackend> {\n if (!storagePromise) {\n storagePromise = (async () => {\n const { loadConfig } = await import(\"../daemon/config.js\");\n registerBeforeExit();\n return await createStorageBackend(loadConfig());\n })();\n }\n return storagePromise;\n}\n\n/** Returns the process-wide RegistryBackend, creating it on first call. Same synchronous-caching requirement as getStorageBackend(). */\nexport async function getRegistryBackend(): Promise<RegistryBackend> {\n if (!registryPromise) {\n registryPromise = (async () => {\n const { loadConfig } = await import(\"../daemon/config.js\");\n registerBeforeExit();\n return await createRegistryBackend(loadConfig());\n })();\n }\n return registryPromise;\n}\n\n/** Closes any backends created via getStorageBackend()/getRegistryBackend(). Idempotent. */\nexport async function closeStorage(): Promise<void> {\n const pending = [storagePromise, registryPromise];\n const pg = pgBackendPromise;\n storagePromise = null;\n registryPromise = null;\n pgBackendPromise = null;\n for (const p of pending) {\n if (!p) continue;\n try {\n const backend = await p;\n // Postgres backends share one pool owned by pgBackendPromise (closed\n // below) — closing them here too would end() it twice.\n if (backend.backendType === \"postgres\") continue;\n await backend.close();\n } catch {\n // A backend that never connected has nothing to close.\n }\n }\n if (pg) {\n try {\n await (await pg).close();\n } catch {\n // Never connected — nothing to close.\n }\n }\n}\n\n/** Test-only: clear the process-wide cache without closing (tests own their own lifecycle). */\nexport function __resetStorageForTests(): void {\n storagePromise = null;\n registryPromise = null;\n pgBackendPromise = null;\n}\n"],"mappings":";AA2BA,IAAI,UAAgC;;AAGpC,SAAgB,iBAAiB,QAA6B;AAC5D,WAAU;;;;;;;;;AAUZ,SAAgB,qBAA2B;AACzC,WAAU;;;AAIZ,SAAgB,mBAAyC;AACvD,QAAO;;;;;;;;;AAUT,SAAgB,cAAc,IAAoB;CAChD,MAAM,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,IAAO,CAAC;AACjD,QAAO,OAAO,KAAK,GAAG,KAAK,QAAQ,IAAI,OAAO,IAAI,QAAQ,EAAE,CAAC;;;;;;AC9B/D,MAAM,sBAAsB;CAAC;CAAK;CAAO;CAAM;;AAG/C,MAAM,sBAAsB;;;;;;;;AAS5B,eAAsB,qBACpB,QACA,OAA8B,EAAE,EACP;AACzB,KAAI,OAAO,mBAAmB,WAC5B,QAAO,MAAM,yBAAyB,QAAQ,KAAK,mBAAmB,MAAM;AAI9E,QAAO,qBAAqB;;;;;;AAO9B,eAAe,gBACb,QAC0D;CAC1D,MAAM,EAAE,oBAAoB,MAAM,OAAO;CACzC,MAAM,WAAW,OAAO,YAAY,EAAE;CAEtC,IAAI,UAAuD;AAC3D,KAAI;AAEF,QAAM,gBAAgB,eAAe,SAAS;AAE9C,YAAU,IAAI,gBAAgB,SAAS;EACvC,MAAM,MAAM,MAAM,QAAQ,gBAAgB;AAC1C,MAAI,KAAK;AACP,SAAM,QAAQ,OAAO,CAAC,YAAY,GAAG;AACrC,UAAO,EAAE,OAAO,KAAK;;AAEvB,SAAO,EAAE,SAAS;UACX,GAAG;AACV,MAAI,QAAS,OAAM,QAAQ,OAAO,CAAC,YAAY,GAAG;AAClD,SAAO,EAAE,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,EAAE;;;;;;;;;;;AAYhE,MAAM,0BAA0B;;AAGhC,eAAe,kBAAkB,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