andreahlert opened a new pull request, #786:
URL: https://github.com/apache/burr/pull/786

   ## Summary
   
   Adds durable execution to Burr, unifying two approaches in one design:
   
   - **A: action-boundary suspend/resume** via `__context.suspend(channel, 
schema=, metadata=)`. The signal propagates through 
`_Suspended(BaseException)`, is persisted as a `SuspensionRecord`, and replayed 
by `resume(...)` / `aresume(...)`.
   - **B: `__context.durable(key, fn, ...)` / `__context.adurable(...)`** 
sub-step journal. Memoizes side effects across re-runs, with `DeterminismError` 
raised fail-loud on mismatch.
   
   Closes the gap where Burr could not natively pause for human input, external 
events, or crash recovery without manual state-fork workarounds.
   
   ## What's new
   
   - `burr/core/durable.py` — `_Suspended`, `SuspensionRecord`, `JournalEntry`, 
`DeterminismError`, `supports_durable_storage()`.
   - `burr/core/resume.py` — `resume()` and `aresume()` rebuild the app from 
`graph` + `persister`, deliver the payload, run to the next halt.
   - `ApplicationContext.suspend / durable / adurable` + `_handle_suspension` / 
`_ahandle_suspension` in the sync and async run loops.
   - 5 optional persister methods (`save_suspension`, `load_suspension`, 
`save_journal_entry`, `load_journal`, `mark_suspension_resolved`) with a `bool` 
contract on `mark_*`.
   - First-party persister overrides with dedicated tables/collections: 
in-memory, SQLite, psycopg2 (PostgreSQL), asyncpg, aiosqlite, redis (sync + 
async), pymongo. Deprecated shims inherit transparently.
   - Lifecycle hooks: `PostActionSuspendHook` + async, `PreActionResumeHook` + 
async. `LocalTrackingClient` emits `SuspendEntryModel` so the Burr UI can 
render `status="suspended"`.
   - Persister status `Literal["completed", "failed", "suspended"]` propagated 
across the persistence layer.
   - Example at `examples/durable-execution/` (runnable HITL workflow with 
notebook + statemachine.png) and concept docs at 
`docs/concepts/durable-execution.rst`.
   
   ## Test plan
   
   - [x] `BURR_CI_INTEGRATION_TESTS=true POSTGRES_PORT=… REDIS_DB=… pytest 
tests/core/test_durable.py tests/core/test_durable_integration.py 
tests/core/test_durable_persisters.py` — **90 passed** with real Postgres, 
asyncpg, redis sync+async, pymongo, mongo shim backends.
   - [x] `pytest tests/core/ tests/lifecycle/ tests/tracking/ 
tests/integrations/persisters/ --ignore=tests/core/test_graphviz_display.py` — 
**425 passed**, no regressions. The 25 skipped are env-gated persister tests.
   - [x] End-to-end real-LLM test with ollama (`qwen2.5:1.5b`) drives the HITL 
example, simulates a crash by deleting the in-memory app + persister, resumes 
from SQLite, and asserts the LLM is invoked exactly twice end-to-end — proving 
the journal prevents side-effect re-fire on replay.
   - [x] Resume idempotency verified: second `resume()` call on the same 
suspension is a no-op (no LLM call, final state unchanged).
   - [x] `python examples/validate_examples.py` accepts the new example 
directory.
   
   ## Determinism contract (from the design)
   
   - `key` stable across re-runs per call site.
   - Same order, same set of `durable` calls across re-runs.
   - No `durable` behind a non-deterministic branch.
   - No `suspend` inside a `durable` fn.
   - Mismatch raises `DeterminismError` (fail-loud).
   
   ## Notes
   
   - `_Suspended` inherits from `BaseException` — do not wrap 
`__context.suspend()` inside `asyncio.shield(...)` or task-cancellation guards 
that catch `BaseException`.
   - Custom persisters work through the in-state fallback (correct, not 
optimized for resume-once at concurrent scale).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to