|
| 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 | +} |
0 commit comments