fix(store): submitOrQueue restituisce ok — niente più falso "Errore 200" a salvataggio riuscito

extensions/local-db.ts: né il tipo di ritorno né i return di successo/fallthrough
di submitOrQueue prevedevano il campo `ok`. store.ts fa
`const { ok, status, data } = submitted; if (!ok)` → ok=undefined ⇒ !ok ⇒
stampava "Errore 200: {memory_id...}" anche quando il record era stato creato
sul gateway, saltando la conferma "Memoria salvata: <id>" e l'avviso duplicati
(score >= 0.92). Regressione introdotta in 9dd2429.

Ora: ok:true nel return di successo, ok:false in quello accodato e nel
fallthrough, `ok: boolean` nel tipo di ritorno.

Verifica (bun, gateway http://127.0.0.1:8082):
  kind valido   → ok:true,  status 200, remote_id c3733a1a-… → "Memoria salvata: …"
  kind invalido → ok:false, status 422 → "Errore 422: …"
(prima del fix ogni esito non-accodato stampava "Errore 200").
This commit is contained in:
enne2
2026-09-15 23:24:10 +02:00
parent 6607135856
commit 76eedcd526
+4 -4
View File
@@ -1025,7 +1025,7 @@ export async function submitOrQueue(
cfg: MemoryConfig,
payload: QueuePayload,
opts?: { dbFile?: string; queue?: boolean },
): Promise<{ queued: boolean; remote_id?: string; local_id?: string; queue_size?: number; status: number; data?: any; breaker?: ReturnType<typeof breakerInfo> }> {
): Promise<{ ok: boolean; queued: boolean; remote_id?: string; local_id?: string; queue_size?: number; status: number; data?: any; breaker?: ReturnType<typeof breakerInfo> }> {
const queueAllowed = opts?.queue ?? cfg.offlineQueue !== false;
const body = stripEmpty(payload as unknown as Record<string, unknown>);
const perRequestMs = Math.min(cfg.timeoutMs ?? 30_000, 15_000);
@@ -1061,14 +1061,14 @@ export async function submitOrQueue(
/* l'indice locale è best-effort sul percorso online */
}
maybeBackgroundFlush(cfg, opts?.dbFile);
return { queued: false, remote_id: res.data.memory_id, status: res.status, data: res.data, breaker: res.breaker };
return { ok: true, queued: false, remote_id: res.data.memory_id, status: res.status, data: res.data, breaker: res.breaker };
}
const down = res.status === 0 || res.status >= 500 || res.status === 429;
if (down && queueAllowed) {
const q = await queueStore(payload, { dbFile: opts?.dbFile });
return { queued: true, local_id: q.local_id, queue_size: q.queue_size, status: res.status, data: res.data, breaker: res.breaker };
return { ok: false, queued: true, local_id: q.local_id, queue_size: q.queue_size, status: res.status, data: res.data, breaker: res.breaker };
}
return { queued: false, status: res.status, data: res.data, breaker: res.breaker };
return { ok: false, queued: false, status: res.status, data: res.data, breaker: res.breaker };
}
let flushInFlight: Promise<unknown> | null = null;