Skip to content

Commit 659dee7

Browse files
authored
fix(dashboard): correlate exact-review queue failures (#1322)
* fix(dashboard): correlate exact-review queue failures * test(dashboard): retain queue failure proof * fix(dashboard): keep queue log calls statically bounded * fix(dashboard): retain telemetry reconciliation correlation
1 parent ce333f9 commit 659dee7

8 files changed

Lines changed: 533 additions & 61 deletions

‎dashboard/exact-review-direct-publication.ts‎

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ export class CanonicalRecordTupleConflictError extends Error {
196196
}
197197
}
198198

199+
export class RecordExportConsistencyError extends Error {
200+
constructor(message: string, options?: ErrorOptions) {
201+
super(message, options);
202+
this.name = "RecordExportConsistencyError";
203+
}
204+
}
205+
199206
export class ExactReviewDirectPublicationStore {
200207
private readonly storage: DurableStorage;
201208

@@ -1204,7 +1211,7 @@ export class ExactReviewDirectPublicationStore {
12041211
)[0];
12051212
const revision = Number(row?.current_revision);
12061213
if (!Number.isSafeInteger(revision) || revision < 1) {
1207-
throw new Error("record export revision allocation failed");
1214+
throw new RecordExportConsistencyError("record export revision allocation failed");
12081215
}
12091216
return revision;
12101217
}
@@ -1218,7 +1225,7 @@ export class ExactReviewDirectPublicationStore {
12181225
)[0];
12191226
const revision = Number(row?.current_revision ?? 0);
12201227
if (!Number.isSafeInteger(revision) || revision < 0) {
1221-
throw new Error("invalid record export revision watermark");
1228+
throw new RecordExportConsistencyError("invalid record export revision watermark");
12221229
}
12231230
return revision;
12241231
}
@@ -1233,11 +1240,23 @@ export class ExactReviewDirectPublicationStore {
12331240
if (String(row.source) === "canonical" && section !== "commits") {
12341241
const itemId = Number(id);
12351242
if (!Number.isSafeInteger(itemId) || itemId < 1) {
1236-
throw new Error(`invalid canonical export identity: ${repoSlug}/${section}/${id}`);
1243+
throw new RecordExportConsistencyError(
1244+
`invalid canonical export identity: ${repoSlug}/${section}/${id}`,
1245+
);
1246+
}
1247+
let canonical: CanonicalRecord | null;
1248+
try {
1249+
canonical = this.readCanonical(repoSlug, section, itemId);
1250+
} catch (error) {
1251+
if (error instanceof RecordExportConsistencyError) throw error;
1252+
throw new RecordExportConsistencyError("canonical export content is malformed", {
1253+
cause: error,
1254+
});
12371255
}
1238-
const canonical = this.readCanonical(repoSlug, section, itemId);
12391256
if (!canonical || canonical.deleted || canonical.content === null) {
1240-
throw new Error(`canonical export content missing: ${repoSlug}/${section}/${id}`);
1257+
throw new RecordExportConsistencyError(
1258+
`canonical export content missing: ${repoSlug}/${section}/${id}`,
1259+
);
12411260
}
12421261
content = canonical.content;
12431262
} else {
@@ -1302,7 +1321,11 @@ export class ExactReviewDirectPublicationStore {
13021321
id,
13031322
),
13041323
)[0];
1305-
if (!row) throw new Error(`backfill export content missing: ${repoSlug}/${section}/${id}`);
1324+
if (!row) {
1325+
throw new RecordExportConsistencyError(
1326+
`backfill export content missing: ${repoSlug}/${section}/${id}`,
1327+
);
1328+
}
13061329
if (row.content !== null) return String(row.content);
13071330
const chunks = Array.from(
13081331
this.storage.sql.exec(
@@ -1316,19 +1339,30 @@ export class ExactReviewDirectPublicationStore {
13161339
),
13171340
);
13181341
if (chunks.length !== Number(row.chunk_count)) {
1319-
throw new Error(`backfill export chunk count mismatch: ${repoSlug}/${section}/${id}`);
1320-
}
1321-
const parts = chunks.map((chunk) => base64Bytes(String(chunk.content_base64)));
1322-
const bytes = new Uint8Array(parts.reduce((sum, part) => sum + part.byteLength, 0));
1323-
let offset = 0;
1324-
for (const part of parts) {
1325-
bytes.set(part, offset);
1326-
offset += part.byteLength;
1342+
throw new RecordExportConsistencyError(
1343+
`backfill export chunk count mismatch: ${repoSlug}/${section}/${id}`,
1344+
);
13271345
}
1328-
if (bytes.byteLength !== Number(row.byte_length)) {
1329-
throw new Error(`backfill export byte count mismatch: ${repoSlug}/${section}/${id}`);
1346+
try {
1347+
const parts = chunks.map((chunk) => base64Bytes(String(chunk.content_base64)));
1348+
const bytes = new Uint8Array(parts.reduce((sum, part) => sum + part.byteLength, 0));
1349+
let offset = 0;
1350+
for (const part of parts) {
1351+
bytes.set(part, offset);
1352+
offset += part.byteLength;
1353+
}
1354+
if (bytes.byteLength !== Number(row.byte_length)) {
1355+
throw new RecordExportConsistencyError(
1356+
`backfill export byte count mismatch: ${repoSlug}/${section}/${id}`,
1357+
);
1358+
}
1359+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
1360+
} catch (error) {
1361+
if (error instanceof RecordExportConsistencyError) throw error;
1362+
throw new RecordExportConsistencyError("backfill export content is malformed", {
1363+
cause: error,
1364+
});
13301365
}
1331-
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
13321366
}
13331367

13341368
private insertSync(row: DirectPublicationRow) {
@@ -1370,7 +1404,7 @@ function recordExportSourceByteLength(row: Record<string, unknown>) {
13701404
byteLength < 0 ||
13711405
(Number(row.deleted) === 1 && byteLength !== 0)
13721406
) {
1373-
throw new Error(
1407+
throw new RecordExportConsistencyError(
13741408
`invalid record export byte metadata: ${String(row.repo_slug)}/${String(row.section)}/${String(row.record_id)}`,
13751409
);
13761410
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
export const EXACT_REVIEW_QUEUE_TRACE_HEADER = "x-clawsweeper-exact-review-trace";
2+
3+
const TRACE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
4+
5+
const EXACT_REVIEW_QUEUE_ENDPOINTS = new Map<string, string>([
6+
["/artifact-cache/receipt/lookup", "artifact_cache_receipt_lookup"],
7+
["/artifact-cache/receipt/store", "artifact_cache_receipt_store"],
8+
["/bay-lifecycle-metrics", "bay_lifecycle_metrics"],
9+
["/branch-authority", "branch_authority"],
10+
["/claim", "claim"],
11+
["/claimed-runs", "claimed_runs"],
12+
["/command-intake", "command_intake"],
13+
["/complete", "complete"],
14+
["/dead-letters/list", "dead_letters_list"],
15+
["/dead-letters/recover-fresh", "dead_letters_recover_fresh"],
16+
["/dead-letters/replay", "dead_letters_replay"],
17+
["/dead-letters/resolve", "dead_letters_resolve"],
18+
["/enqueue", "enqueue"],
19+
["/github-egress-observability", "github_egress_observability"],
20+
["/github-egress-telemetry", "github_egress_telemetry"],
21+
["/github-etag-cache/confirm", "github_etag_cache_confirm"],
22+
["/github-etag-cache/lookup", "github_etag_cache_lookup"],
23+
["/github-etag-cache/store", "github_etag_cache_store"],
24+
["/github-read-model/activity", "github_read_model_activity"],
25+
["/github-read-model/comments", "github_read_model_comments"],
26+
["/github-read-model/ingest", "github_read_model_ingest"],
27+
["/github-read-model/item", "github_read_model_item"],
28+
["/github-read-model/lease-item", "github_read_model_lease_item"],
29+
["/github-read-model/placeholders", "github_read_model_placeholders"],
30+
["/github-read-model/repair", "github_read_model_repair"],
31+
["/github-read-model/workflows", "github_read_model_workflows"],
32+
["/heartbeat", "heartbeat"],
33+
["/item-status", "item_status"],
34+
["/lifecycle-audit/inventory", "lifecycle_audit_inventory"],
35+
["/lifecycle-bay", "lifecycle_bay"],
36+
["/lifecycle/canonical-receipt", "lifecycle_canonical_receipt"],
37+
["/lifecycle/command-ack/attempt", "lifecycle_command_ack_attempt"],
38+
["/lifecycle/command-ack/failed", "lifecycle_command_ack_failed"],
39+
["/lifecycle/command-ack/observed", "lifecycle_command_ack_observed"],
40+
["/lifecycle/router-receipt", "lifecycle_router_receipt"],
41+
["/lifecycle/terminal-disposition", "lifecycle_terminal_disposition"],
42+
["/parked-reviews/list", "parked_reviews_list"],
43+
["/parked-reviews/recover-fresh", "parked_reviews_recover_fresh"],
44+
["/parked-reviews/resolve", "parked_reviews_resolve"],
45+
["/publication-batch-results", "publication_batch_results"],
46+
["/publication-batches/claim", "publication_batches_claim"],
47+
["/publication-batches/complete", "publication_batches_complete"],
48+
["/publication-batches/fetch", "publication_batches_fetch"],
49+
["/publication-batches/heartbeat", "publication_batches_heartbeat"],
50+
["/publication-results", "publication_results"],
51+
["/publications/list", "publications_list"],
52+
["/publications/reconcile", "publications_reconcile"],
53+
["/publications/supersede", "publications_supersede"],
54+
["/recent-durable-publication-events", "recent_durable_publication_events"],
55+
["/reconcile", "reconcile"],
56+
["/records/commits", "records_commits"],
57+
["/records/export", "records_export"],
58+
["/records/list", "records_list"],
59+
["/records/slugs", "records_slugs"],
60+
["/records/snapshots/chunk", "records_snapshots_chunk"],
61+
["/records/snapshots/latest", "records_snapshots_latest"],
62+
["/records/snapshots/trigger", "records_snapshots_trigger"],
63+
["/records/tuples", "records_tuples"],
64+
["/review-coverage", "review_coverage"],
65+
["/review-coverage/inventory", "review_coverage_inventory"],
66+
["/review-observability", "review_observability"],
67+
["/review-run-telemetry", "review_run_telemetry"],
68+
["/source-authority", "source_authority"],
69+
["/source-authority/complete", "source_authority_complete"],
70+
["/state-writer-progress", "state_writer_progress"],
71+
["/state-writer/acquire", "state_writer_acquire"],
72+
["/state-writer/heartbeat", "state_writer_heartbeat"],
73+
["/state-writer/release", "state_writer_release"],
74+
["/stats", "stats"],
75+
["/telemetry-reconciliation", "telemetry_reconciliation"],
76+
["/terminal-finalization/attempt", "terminal_finalization_attempt"],
77+
["/terminal-finalization/retry", "terminal_finalization_retry"],
78+
["/terminal-finalization/skip", "terminal_finalization_skip"],
79+
]);
80+
81+
export function newExactReviewQueueTraceId(): string {
82+
return crypto.randomUUID();
83+
}
84+
85+
export function exactReviewQueueTraceId(value: unknown): string | null {
86+
const candidate = typeof value === "string" ? value.toLowerCase() : "";
87+
return TRACE_ID_PATTERN.test(candidate) ? candidate : null;
88+
}
89+
90+
export function exactReviewQueueEndpointTemplate(path: string): string {
91+
const pathname = path.split("?", 1)[0] || "";
92+
const exact = EXACT_REVIEW_QUEUE_ENDPOINTS.get(pathname);
93+
if (exact) return exact;
94+
if (/^\/records\/[^/]+\/(?:items|closed|plans|decision-packets)\/[1-9]\d*$/.test(pathname)) {
95+
return "records_item";
96+
}
97+
if (
98+
/^\/cursors\/(?:hot-intake|normal-review|audit|review-placeholder-[a-f0-9]{16}-(?:open|closed))$/.test(
99+
pathname,
100+
)
101+
) {
102+
return "cursor";
103+
}
104+
return "other";
105+
}

‎dashboard/exact-review-queue.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
EXACT_REVIEW_DIRECT_PUBLICATION_MAX_POST_BYTES,
2929
REVIEW_COVERAGE_INVENTORY_KEY,
3030
ExactReviewDirectPublicationStore,
31+
RecordExportConsistencyError,
3132
directPublicationRejectionDetail,
3233
normalizeReviewCoverageInventory,
3334
sha256Hex,
@@ -43,6 +44,11 @@ import {
4344
type RecordSection,
4445
type ReviewCoverageSummary,
4546
} from "./exact-review-direct-publication.ts";
47+
import {
48+
EXACT_REVIEW_QUEUE_TRACE_HEADER,
49+
exactReviewQueueEndpointTemplate,
50+
exactReviewQueueTraceId,
51+
} from "./exact-review-queue-observability.ts";
4652
import {
4753
REVIEW_OBSERVABILITY_RANGES,
4854
summarizeReviewObservability,
@@ -731,7 +737,11 @@ function exactReviewPublicBayRepositories(env): Set<string> {
731737
return new Set(repositories);
732738
}
733739

734-
function rethrowQueueFailure(error: unknown, phase: "initialize" | "fetch"): never {
740+
function rethrowQueueFailure(
741+
error: unknown,
742+
phase: "initialize" | "fetch",
743+
request?: Request,
744+
): never {
735745
const stack = objectValue(error).stack;
736746
// Remote error text may contain private data; retain only deployed source coordinates.
737747
const frame =
@@ -740,8 +750,20 @@ function rethrowQueueFailure(error: unknown, phase: "initialize" | "fetch"): nev
740750
stack,
741751
)
742752
: null;
753+
const traceId = request
754+
? exactReviewQueueTraceId(request.headers.get(EXACT_REVIEW_QUEUE_TRACE_HEADER))
755+
: null;
756+
const endpoint = request
757+
? exactReviewQueueEndpointTemplate(new URL(request.url).pathname)
758+
: "initialization";
743759
console.error("exact_review_queue_handler_failed", {
744760
phase,
761+
trace_id: traceId,
762+
endpoint,
763+
failure_category:
764+
error instanceof RecordExportConsistencyError
765+
? "record_export_consistency"
766+
: "handler_exception",
745767
location: frame ? [Number(frame[1]), Number(frame[2])] : null,
746768
});
747769
throw error;
@@ -828,7 +850,7 @@ export class ExactReviewQueue {
828850
try {
829851
return await this.handleFetch(request);
830852
} catch (error) {
831-
rethrowQueueFailure(error, "fetch");
853+
rethrowQueueFailure(error, "fetch", request);
832854
}
833855
}
834856

0 commit comments

Comments
 (0)