fix(worker): prevent child tasks from blocking parent execution#1209
Closed
nicoloboschi wants to merge 4 commits into
Closed
fix(worker): prevent child tasks from blocking parent execution#1209nicoloboschi wants to merge 4 commits into
nicoloboschi wants to merge 4 commits into
Conversation
Add per-operation-type reserved slots so operators can guarantee capacity for each operation type (retain, consolidation, file_convert_retain, refresh_mental_model). Remaining slots form a shared pool usable by any operation type. New env vars: - HINDSIGHT_API_WORKER_RETAIN_MAX_SLOTS (default 0) - HINDSIGHT_API_WORKER_FILE_CONVERT_RETAIN_MAX_SLOTS (default 0) - HINDSIGHT_API_WORKER_REFRESH_MENTAL_MODEL_MAX_SLOTS (default 0) - HINDSIGHT_API_WORKER_CONSOLIDATION_MAX_SLOTS (default 2, unchanged) Sum of reservations must be <= WORKER_MAX_SLOTS. Unreserved slots (max_slots - sum) form the shared pool, usable by any operation type on a first-come basis.
…l dict Replace per-operation-type config fields with a single data-driven dict (WORKER_SLOT_RESERVATION_TYPES) that maps operation types to their env var and default. Adding a new operation type now requires only one line in this dict — from_env(), validation, and the reservations dict are all derived automatically. Add test_all_operation_types_have_slot_reservation_config that parses memory_engine.py and asserts every operation_type is covered, so adding a new type without the config entry fails CI.
Workers used SyncTaskBackend which executed child tasks inline — e.g. consolidation triggered by retain would block until consolidation finished, tying up the worker slot for both operations. Add WorkerTaskBackend whose submit_task is a no-op: since _submit_async_operation already INSERTs the child row with task_payload, the poller picks it up on the next cycle as an independent task.
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
SyncTaskBackendwhich executed child tasks inline — e.g. consolidation triggered by retain would block until consolidation finished, tying up the worker slot for both operationsWorkerTaskBackendwhosesubmit_taskis a no-op: since_submit_async_operationalready INSERTs the child row withtask_payload, the poller picks it up on the next cycle as an independent taskSyncTaskBackendtoWorkerTaskBackendTest plan
test_worker_backend_does_not_execute_inline— verifies executor is never called by submit_tasktest_sync_backend_blocks_parent_on_child_task— reproduces the blocking bug with SyncTaskBackendtest_worker_backend_does_not_block_parent_on_child_task— verifies parent completes without running childtest_worker_backend_child_task_stays_pending_in_db— e2e: parent completes, child stays pending, claimable on next poll