feat(adapters): FastAPI / Starlette durable background tasks - #94
Merged
sdageltc merged 1 commit intoAug 31, 2026
Merged
Conversation
FastAPI's BackgroundTasks run in the worker process and are lost on restart, redeploy, or crash. This adds DurableBackgroundTasks, a drop-in DI dependency backed by LetItLoop's zero-daemon WAL: each task is recorded before it runs and any task interrupted by a crash is resumed automatically on startup - no Redis, no separate worker. - letitloop/adapters/fastapi.py: DurableTaskManager (WAL + resume), DurableBackgroundTasks (Annotated + Depends DI), durable_task registry (explicit key or auto module:qualname), install_durable_background_tasks (wraps app lifespan to resume on startup). FastAPI imported lazily so `import letitloop` never requires it. - register the adapter in the adapters package and get_available_adapters() - tests/adapters/test_fastapi.py: durability contract incl. crash+resume - docs/adapters.md: FastAPI/Starlette section - examples/fastapi_durable_background.py: canonical app + runnable demo - pyproject: add `fastapi` optional extra; add fastapi/httpx to dev extras Closes sdageltc#93
h4syy
force-pushed
the
feat/fastapi-durable-background-tasks
branch
from
August 30, 2026 18:16
dcf2836 to
1897f27
Compare
sdageltc
approved these changes
Aug 31, 2026
sdageltc
left a comment
Owner
There was a problem hiding this comment.
Fantastic contribution! The DurableBackgroundTasks dependency and install_durable_background_tasks(app) integration are clean, robust, and well-tested.
All 14 tests in tests/adapters/test_fastapi.py pass cleanly. Merging into main!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
FastAPI's
BackgroundTasksrun inside the worker process and are lost if the worker restarts, redeploys, or is killed mid-task. This addsDurableBackgroundTasks, a drop-in dependency backed by LetItLoop's zero-daemon WAL: every task is journaled (fsync'd) before it runs, and any task interrupted by a crash is resumed automatically on the next startup — no Redis, no Celery, no separate worker.Usage stays exactly as the issue describes:
How it works
DurableTaskManager— the WAL ledger (tasks.wal.jsonl) plus the resume engine.DurableBackgroundTasks— exposed asAnnotated[..., Depends(...)], so the barebg: DurableBackgroundTasksannotation works with full type hints and native DI (rather than subclassingBackgroundTasks, which FastAPI would re-instantiate as the base type).durable_task(...)— optional decorator to pin a stable key; falls back tomodule:qualnameso the snippet above works with no extra API.install_durable_background_tasks(app)— stores the manager onapp.stateand wraps the app lifespan to resume interrupted tasks on boot (any existinglifespan=is preserved).PENDING→COMPLETED), and step-level skip via each task running inside a per-task@durablecontext.FastAPI/Starlette are imported lazily, so
import letitloopnever requires them and the adapter keeps the suite's zero-mandatory-dependency guarantee.Closes #93
Type of Change
agent-durability-bench)Verification Checklist
pytest) — 14 new tests intests/adapters/test_fastapi.py, including the crash-then-resume contract; DI tests skip cleanly when FastAPI is absent. Full-m fastsuite (505 passed) with no regressions.[fastapi]extra plusfastapi/httpxadded to thedevextra so CI exercises the DI path.