# Exception in background task ignored: RuntimeError('task failed')

- **ID:** `python/starlette-background-task-exception-swallowed`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A BackgroundTask raised an exception after the response was sent; Starlette logs it but the client already received 200.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.30+ | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   import logging
logger = logging.getLogger(__name__)
def task():
    try:
        do_work()
    except Exception:
        logger.exception('background failed')
        raise
   ```
2. **** (90% success)
   ```
   from celery import Celery
celery = Celery('app')
celery.send_task('do_work')
   ```

## Dead Ends

- **** — Hides failures from monitoring; no retries or alerts. (80% fail)
- **** — Background tasks run after the response; the route already returned. (85% fail)
