fix: files/retain upload problems and orphaned retains#1091
Merged
nicoloboschi merged 1 commit intovectorize-io:mainfrom Apr 16, 2026
Merged
Conversation
Include task_payload in the async_operations INSERT atomically instead of the previous two-step INSERT-then-UPDATE approach. When a crash or timeout occurred between the two statements, rows were left with task_payload IS NULL. The worker claim query filters on task_payload IS NOT NULL, so those orphaned rows became permanently stuck as unclaimed pending tasks.
Contributor
Author
|
Bugs found on our fork for https://www.tryferris.ai/ |
nicoloboschi
added a commit
that referenced
this pull request
Apr 16, 2026
Follow-up to #1091. That PR made _submit_async_operation insert task_payload atomically in the same row that the async_operations row is created, closing a crash-window that left orphaned NULL-payload rows. The follow-up call to _task_backend.submit_task is still needed so SyncTaskBackend can execute the task inline in tests and embedded mode, but for BrokerTaskBackend the call redundantly UPDATEd task_payload and bumped updated_at on a row that was already claimable — and could even touch a row that a worker had already claimed and transitioned to processing/completed. Make the UPDATE a no-op when task_payload is already set by adding `AND task_payload IS NULL` to the WHERE clause. Existing callers that still rely on a two-step INSERT-then-submit pattern (legacy/ fallback) continue to work, but the common path stops writing to a row it has nothing new to say about. Also add two regression tests: - test_worker.py::test_submit_task_preserves_existing_payload locks in the idempotent semantics at the backend level. - test_async_batch_retain.py:: test_submit_async_operation_leaves_claimable_row_when_submit_task_fails simulates a crash between the INSERT transaction commit and submit_task by mocking submit_task to raise, and asserts the row is still born claimable (status=pending, task_payload populated). This is the invariant the original bug violated.
4 tasks
nicoloboschi
added a commit
that referenced
this pull request
Apr 16, 2026
) Follow-up to #1091. That PR made _submit_async_operation insert task_payload atomically in the same row that the async_operations row is created, closing a crash-window that left orphaned NULL-payload rows. The follow-up call to _task_backend.submit_task is still needed so SyncTaskBackend can execute the task inline in tests and embedded mode, but for BrokerTaskBackend the call redundantly UPDATEd task_payload and bumped updated_at on a row that was already claimable — and could even touch a row that a worker had already claimed and transitioned to processing/completed. Make the UPDATE a no-op when task_payload is already set by adding `AND task_payload IS NULL` to the WHERE clause. Existing callers that still rely on a two-step INSERT-then-submit pattern (legacy/ fallback) continue to work, but the common path stops writing to a row it has nothing new to say about. Also add two regression tests: - test_worker.py::test_submit_task_preserves_existing_payload locks in the idempotent semantics at the backend level. - test_async_batch_retain.py:: test_submit_async_operation_leaves_claimable_row_when_submit_task_fails simulates a crash between the INSERT transaction commit and submit_task by mocking submit_task to raise, and asserts the row is still born claimable (status=pending, task_payload populated). This is the invariant the original bug violated.
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.
Summary
Closes a race between the file-convert-retain worker task and the async task backend where a crash or timeout could orphan retain operations permanently.
The bug: _handle_file_convert_retain_task inserted an async_operations row without task_payload, then separately called submit_task to set the payload. If a crash or timeout occurred between those two statements, the row was left with task_payload IS NULL. The worker's claim_batch query filters on task_payload IS NOT NULL, so those orphaned rows became permanently stuck as unclaimed pending tasks — file uploads that silently never completed.
Fix: Build full_retain_payload and serialize it to JSON before the transaction, then include task_payload as a column in the atomic INSERT. The row is now born with its payload, so a crash at any point either leaves no row (transaction rolled back) or a fully-claimable row.
memory_engine.py: _handle_file_convert_retain_task now inserts task_payload in the same INSERT statement that creates the async_operations row. submit_task is still called afterwards for the SyncTaskBackend path (inline execution) and is idempotent for BrokerTaskBackend (payload already set).
Test plan