mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-25 00:52:25 +02:00
## Summary - **Consolidate error writes:** When a node fails and has an error handler, `commit()` now appends both `ERROR` and `ERROR_SOURCE_NODE` in a single `put_writes` call, eliminating the redundant overwrite that `schedule_error_handler` used to do. - **Ensure durability before handler execution:** Reuses the `_delta_write_futs` pattern — a new `_error_handler_write_futs` list collects the persistence future from `put_writes` when `ERROR_SOURCE_NODE` is written, and `schedule_error_handler` / `aschedule_error_handler` drain it (sync: `concurrent.futures.wait`, async: `asyncio.gather`) before preparing the handler task. - **Resume directly to error handler:** Adds `_resume_error_handlers_if_applicable()` to `PregelLoop`, called from `tick()` after `_reapply_writes_to_succeeded_nodes()`. On resume, it detects `ERROR_SOURCE_NODE` markers in `checkpoint_pending_writes`, marks the original task as done (so the runner skips it), and schedules a fresh handler task. - **Rename internal methods for clarity:** `_match_writes` → `_reapply_writes_to_succeeded_nodes` (makes it clear that failed/interrupted tasks are skipped); `_resume_error_handlers` → `_resume_error_handlers_if_applicable`. ## Test plan - [x] `test_error_handler_resumes_after_crash`: single node fails, handler crashes, resume re-runs the handler (not the original node). Verifies `NodeError.node` and error content survive checkpoint round-trip. - [x] `test_error_handler_resumes_after_crash_multiple_nodes`: two nodes fail concurrently in the same superstep, each with its own handler. Verifies error handler starts while other nodes are still in-flight (via `threading.Event`), and on resume both handlers re-run with correct `NodeError.node` and error content. - [x] All 101 tests in `test_retry.py` pass (including 19 error-handler tests). - [x] `make format` + `make lint` clean.