Debugging
AuraScore 81/100

High-Throughput Document Ingestion Deadlock Diagnostic Script

Build a dead-letter triage and memory leak diagnostic script for document extraction systems in legal and accounting practices.

Use this template when large-scale OCR and contract discovery ingestion pipelines suffer worker deadlocks, memory bloat, or silent batch drops.

Template

Role: Lead Legaltech Systems Integrator specializing in high-throughput document extraction and indexing.

Context

  • Extraction batch size: {{document_batch_size}}
  • Worker runtime environment: {{parser_runtime_environment}}
  • Stack trace and exception log: {{unhandled_exception_trace}}
  • Supported document formats: {{file_format_matrix}}
  • Concurrency worker threshold: {{concurrency_worker_limit}}
  • Downstream database sink: {{output_sink_endpoint}}

Task

Produce an asynchronous Python diagnostic and batch recovery script that inspects pipeline deadlocks, tracks worker memory exhaustion during OCR processing, identifies problematic document artifacts, and securely re-routes poison-pill files.

Method

  1. Analyze {{unhandled_exception_trace}} to map blocking thread calls, unhandled file encodings, and OOM kills.
  2. Parse worker memory allocation curves under {{document_batch_size}} across the {{parser_runtime_environment}}.
  3. Validate MIME types and corruption signatures across {{file_format_matrix}} to isolate toxic inputs.
  4. Monitor connection pool saturation and write contention directed at {{output_sink_endpoint}}.
  5. Implement an asynchronous worker watchdog that enforces process timeouts bounded by {{concurrency_worker_limit}}.
  6. Quarantine corrupt documents into an isolated dead-letter bucket while logging structural metadata.
  7. Emit structured metrics for prometheus monitoring to track heap utilization and retry counts.

Constraints

  • MUST implement memory-bounded streaming for document parsing; whole-file buffering in RAM MUST NOT occur.
  • MUST handle unhandled binary encoding exceptions gracefully without terminating the parent process.
  • Script execution MUST NOT cause locking on the {{output_sink_endpoint}}.
  • Provide clear SIGTERM/SIGINT signal handlers for clean worker shutdown.

Output format

  1. Failure Mechanism Analysis (Markdown table summarizing identified bottlenecks)
  2. Asynchronous Recovery Script (Fully typed, async Python script with retry harnesses)
  3. Dead-Letter Processing Specification (JSON schema defining metadata attached to quarantined files)

Self-review

  • Verify stream processing prevents memory exhaustion for files larger than worker heap limits.
  • Ensure all variables ({{document_batch_size}}, {{parser_runtime_environment}}, {{unhandled_exception_trace}}, {{file_format_matrix}}, {{concurrency_worker_limit}}, {{output_sink_endpoint}}) are addressed.
  • Confirm that isolation of poison-pill documents does not halt the overall pipeline.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-debugging
professional-services
document-processing
async-python
deadlock-debugging