Skip to content

Commit 68facfd

Browse files
authored
fix(DTPL-364): Fix pdf_split_hook issues (#340)
<!-- CURSOR_SUMMARY --> > [!NOTE] > **Medium Risk** > Changes core request/hook dispatch and split-PDF async execution/cancellation paths, which could affect concurrency behavior and cleanup semantics under load. Added tests mitigate risk, but regressions could surface in real-world event-loop/thread-local hook usage. > > **Overview** > **Fixes `partition_async()` split-PDF execution to be truly async.** Split chunk collection now runs via awaited async hook dispatch rather than spinning up a nested event loop in a worker thread, with response reassembly offloaded so it doesn’t block the event loop. > > **Adds robust cancellation and resource cleanup.** Introduces async hook dispatch in `SDKHooks` (sync hooks run in `to_thread` with per-hook serialization), adds cancellation-aware cleanup in `BaseSDK.do_request_async`, and hardens `SplitPdfHook` with process-wide PDF-split setup locking, lazy sync executor creation, chunk-task cancellation/draining, and cleanup of tempdirs/unconsumed chunk files. Extensive new unit tests cover ordering, concurrency limits, cancellation, strict-failure behavior, and non-blocking guarantees. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit da0352c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5171475 commit 68facfd

8 files changed

Lines changed: 1927 additions & 174 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 0.43.4
2+
3+
### Enhancements
4+
5+
### Features
6+
7+
### Fixes
8+
* Route split-PDF `partition_async()` result collection through awaited async hook dispatch instead of creating a nested event loop in a worker thread.
9+
Sync-only hooks on the async path now run on a worker thread, so hook code that depends on event-loop-thread `contextvars` or thread-local state should pass that state explicitly.
10+
* Add cancellation cleanup for in-flight split-PDF chunk tasks and preserve existing sync `partition()` split-PDF behavior with lazy executor creation.
11+
112
## 0.43.2
213

314
### Enhancements

0 commit comments

Comments
 (0)