Prompt Details
Model
(claude-5-sonnet)
Token size
640
Example input
[BUG_REPORT]: The webhook handler stops processing after a few hundred messages. No errors in the logs. We're using FastAPI.
Example output
**Symptom:** Webhook handler stops processing after a few hundred messages, no error logs.
**Expected:** Handler keeps consuming messages indefinitely (source: continuous webhook stream from the upstream provider).
**Likely location:** handle_webhook() in webhooks.py, or upstream of it in the request pipeline.
**Candidate causes:**
1. **Database connection pool exhaustion.** The handler opens a connection per message and never returns it. After the pool fills, new requests hang silently. Falsifying test: run the handler with SQLAlchemy.engine.pool logging enabled. If pool usage climbs to the limit and stays there, this is the cause.
2. **Background task queue saturating.** If background_tasks.add_task is being used and tasks aren't completing, the queue fills until the worker process degrades. Falsifying test: log queue size on every request. If it climbs without dropping, this is the cause.
3. **Memory leak from accumulated state.** Some object is being held in module-level state (a list, a dict) that grows without bound. Falsifying test: capture tracemalloc snapshots at message 100 and message 400. If the heap diff shows a single growing structure, this is the cause.
**Recommended fix (assuming cause #1 is right):**
Use the session-per-request pattern via a FastAPI dependency, not a session created inside the handler.
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
@app.post("/webhook")
async def handle_webhook(payload: dict, db: Session = Depends(get_db)):
...
**If cause #1 is wrong:**
Run the falsifying tests for causes #2 and #3 in parallel. Cause #3 is easy to rule out quickly with tracemalloc; cause #2 needs you to inspect whether background_tasks is used.
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-SONNET
Diagnoses before it patches — the fix for the retry loop where a model cycles cosmetic fixes without understanding the bug. Forces five steps first: restate the symptom, reconstruct the expectation and its source, narrow the likely location, list 2-4 candidate causes, and name a falsifying test for each so you rule out causes instead of guessing. Won't suggest "more logging" as the fix, and stops after two failed attempts to admit the diagnosis was wrong. One of 40 in the Pemway Power User Pack.
...more
Added 3 weeks ago
