mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
Record why a document's index attempt failed and say so
A content-index attempt that failed (raster failure, a scan with no text layer, a provider error) recorded its reason only in the server's observability stream. In the vault, hasContentIndex false looked identical for a document nobody ever tried and one that failed three times, and the detail sheet had nothing to say about either. Apply the summaryState pattern to the index. Two additive columns on InboundDocument (migration 0333) record when the last attempt finished and why it produced no index, as a closed reason set: local-empty, local-unsupported, decrypt-error, raster-failed, provider-error, pdf-needs-anthropic, empty-transcription. The writer sits at the choke point the auto job and the corpus backfill share, and in the manual index route; a success clears the reason. The provider path's specific failure now survives the local fallback, since "no text" is less actionable than "the PDF would not render". rasterizePdf names its failure class so a build that cannot rasterize at all is distinguished from a PDF that would not render. New guard in both index paths: an empty provider transcription never becomes a successful empty index. The detail sheet renders the reason in plain words (muted, six locales). The DTO and OpenAPI carry the two fields; the disaster recovery backup and restore carry them verbatim like their summary siblings. Refs #776
This commit is contained in:
1 parent
45dc93932a
commit
893db887e9
29 files changed
+786
-33
No files matched your search
@@ -66,8 +66,16 @@ export interface RasterImage {
|
||||
dataBase64: string;
|
||||
}
|
||||
|
||||
/** Best-effort rasterization outcome — never an exception. */
|
||||
export type RasterResult = { ok: true; images: RasterImage[] } | { ok: false };
|
||||
/**
|
||||
* Best-effort rasterization outcome — never an exception. Refs #776: a
|
||||
* failure names its class so the caller can tell "this build cannot raster
|
||||
* at all" (`unsupported` — the native canvas binary is unusable, a capability
|
||||
* gap Anthropic's native PDF path would cover) from "this particular PDF
|
||||
* would not render" (`render-failed` — malformed / encrypted / zero pages).
|
||||
*/
|
||||
export type RasterResult =
|
||||
| { ok: true; images: RasterImage[] }
|
||||
| { ok: false; reason: "unsupported" | "render-failed" };
|
||||
|
||||
// Minimal structural types for the slice of the pdfjs API this module uses. A
|
||||
// type-only shape (erased at build) so we never eagerly evaluate the pdfjs
|
||||
@@ -138,7 +146,7 @@ export async function rasterizePdf(
|
||||
action: { name: "documents.rasterize.failed" },
|
||||
meta: { reason: "native_canvas_unsupported" },
|
||||
});
|
||||
return { ok: false };
|
||||
return { ok: false, reason: "unsupported" };
|
||||
}
|
||||
try {
|
||||
// Lazy import: keeps pdfjs (DOMMatrix) + @napi-rs/canvas out of the eager
|
||||
@@ -190,7 +198,7 @@ export async function rasterizePdf(
|
||||
}
|
||||
}
|
||||
|
||||
if (images.length === 0) return { ok: false };
|
||||
if (images.length === 0) return { ok: false, reason: "render-failed" };
|
||||
annotate({
|
||||
action: { name: "documents.rasterize.ok" },
|
||||
meta: { pages: images.length, cappedFrom: doc.numPages },
|
||||
@@ -207,7 +215,7 @@ export async function rasterizePdf(
|
||||
message: err instanceof Error ? err.message.slice(0, 300) : String(err),
|
||||
},
|
||||
});
|
||||
return { ok: false };
|
||||
return { ok: false, reason: "render-failed" };
|
||||
} finally {
|
||||
if (task) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user