{"record":{"id":"a666c53fdcb7c18b","repo":"invoke-ai/InvokeAI","slug":"cannot-start-image-move-while-queue-work-is-active","errorCode":null,"errorMessage":"Cannot start image move while queue work is active","messagePattern":"Cannot start image move while queue work is active","errorType":"exception","errorClass":"ImageMoveQueueActive","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/image_moves/image_moves_default.py","lineNumber":134,"sourceCode":"            self._refresh_finished_future_locked()\n            return self._build_background_status_locked()\n\n    def is_maintenance_active(self) -> bool:\n        with self._future_lock:\n            self._refresh_finished_future_locked()\n            is_running = self._future is not None and not self._future.done()\n            operation_reserved = self._future_operation is not None\n        return operation_reserved or is_running or self._get_active_job_id() is not None\n\n    def _assert_no_active_queue_work(self) -> None:\n        session_queue = self._session_queue\n        if session_queue is None and self._invoker is not None:\n            session_queue = getattr(self._invoker.services, \"session_queue\", None)\n        if session_queue is None:\n            return\n        queue_status = session_queue.get_queue_status(DEFAULT_QUEUE_ID)\n        if queue_status.pending > 0 or queue_status.in_progress > 0:\n            raise ImageMoveQueueActive(\"Cannot start image move while queue work is active\")\n\n    def _start_background_operation(\n        self,\n        operation: ImageMoveBackgroundOperation,\n        target,\n        require_idle_queue: bool = False,\n    ) -> ImageMoveBackgroundStatus:\n        with self._future_lock:\n            self._refresh_finished_future_locked()\n            if self._future_operation is not None or (self._future is not None and not self._future.done()):\n                raise ImageMoveJobAlreadyRunning(\"An image move job is already running\")\n            active_job_id = self._get_active_job_id()\n            if operation != \"recovery\" and active_job_id is not None:\n                raise ImageMoveJobAlreadyRunning(\"An image move job is already active\")\n            self._last_background_error = None\n            self._future_operation = operation\n\n        try:","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/image_moves/image_moves_default.py#L116-L152","documentation":"_assert_no_active_queue_work blocks image move operations while the session queue has pending or in-progress work, raising ImageMoveQueueActive. Moving files mid-generation would corrupt images referenced by running queue items.","triggerScenarios":"Calling start_background_move_all with require_idle_queue=True (or recovery flows) while queue_status.pending or in_progress > 0 for the default queue.","commonSituations":"Trying to move/consolidate images while a generation batch is running; scheduling maintenance during active processing; server still finishing queued jobs after startup.","solutions":["Wait for the queue to drain: poll get_queue_status until pending==0 and in_progress==0, then retry","Cancel or clear pending queue items before starting the move","Start the image move when the server is idle (e.g. before user sessions begin)"],"exampleFix":"// before\nservice.start_background_move_all(target, require_idle_queue=True)  # raises while queue busy\n// after\nstatus = invoker.services.session_queue.get_queue_status(DEFAULT_QUEUE_ID)\nif status.pending == 0 and status.in_progress == 0:\n    service.start_background_move_all(target, require_idle_queue=True)","handlingStrategy":"retry","validationCode":"def queue_is_idle(session_queue, queue_id=DEFAULT_QUEUE_ID) -> bool:\n    s = session_queue.get_queue_status(queue_id)\n    return s.pending == 0 and s.in_progress == 0\nassert queue_is_idle(invoker.services.session_queue)","typeGuard":null,"tryCatchPattern":"from invokeai.app.services.image_moves.image_moves_common import ImageMoveQueueActive\nfor attempt in range(20):\n    try:\n        service.start_background_move_all(target, require_idle_queue=True)\n        break\n    except ImageMoveQueueActive:\n        time.sleep(30)  # wait for queue to drain","preventionTips":["Schedule image moves during idle periods only","Poll queue status before invoking maintenance operations","Cancel pending queue items if an immediate move is required"],"tags":["concurrency","queue","state-conflict"],"backgroundTag":"operation-blocked-while-busy","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}