{"record":{"id":"43cf65f30498c260","repo":"unslothai/unsloth","slug":"block-reason-or-operation-in-progress","errorCode":null,"errorMessage":"{block_reason} or operation_in_progress","messagePattern":"(.+?) or operation_in_progress","errorType":"exception","errorClass":"RuntimeError","httpStatus":409,"severity":"warning","filePath":"studio/backend/utils/remote_access_settings.py","lineNumber":269,"sourceCode":"def start_remote_access(app_state) -> dict:\n    \"\"\"Schedule a settings-owned start. Repeated requests are idempotent.\"\"\"\n    global _start_worker, _start_worker_admission\n    from cloudflare_tunnel import (\n        capture_studio_tunnel_start_admission,\n        get_studio_tunnel_control_token,\n    )\n\n    admission = capture_studio_tunnel_start_admission()\n    if admission is None:\n        raise RuntimeError(\"server_shutting_down\")\n    status = remote_access_status(app_state)\n    current = get_studio_tunnel_control_token()\n    if current[0] != admission[0]:\n        raise RuntimeError(\"server_lifecycle_changed\")\n    if status[\"managed_by\"] == \"settings\" and status[\"state\"] in {\"starting\", \"online\"}:\n        return status\n    if not status[\"can_start\"]:\n        raise RuntimeError(status[\"block_reason\"] or \"operation_in_progress\")\n\n    port = getattr(app_state, \"remote_access_port\", None)\n    if not isinstance(port, int) or port <= 0:\n        raise RuntimeError(\"server_port_unavailable\")\n    if get_studio_tunnel_control_token() != admission:\n        raise RuntimeError(\"server_lifecycle_changed\")\n\n    def _start() -> None:\n        from cloudflare_tunnel import start_studio_tunnel\n        url = start_studio_tunnel(port, managed_by = \"settings\", admission = admission)\n        if url:\n            logger.info(\"Secure link access via Cloudflare: %s\", url)\n\n    _open_remote_access_stop_response_admission()\n    with _worker_lock:\n        if not _worker_is_current(_start_worker, _start_worker_admission, admission):\n            _start_worker = threading.Thread(target = _start, daemon = True)\n            _start_worker_admission = admission","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/remote_access_settings.py#L251-L287","documentation":"Raised by start_remote_access() when remote_access_status(app_state) reports can_start == false. The message is status['block_reason'] if present, otherwise the generic 'operation_in_progress' — so the error text is dynamic and names the actual blocker (e.g. another operation owns the tunnel) or defaults to operation_in_progress.","triggerScenarios":"Calling start_remote_access() while the tunnel state machine cannot accept a start: a stop is mid-flight, the tunnel is in 'stopping' state, or another owner (not 'settings') currently manages the tunnel. Idempotent re-starts are NOT blocked (state 'starting'/'online' with managed_by 'settings' returns the status instead).","commonSituations":"User toggles Stop then immediately Start; the stop worker is still tearing the tunnel down. Or an auto-start flow (managed_by other than 'settings') owns the tunnel and a manual settings start is attempted.","solutions":["Read the block_reason in the error/status — it names the specific owner or transition blocking the start.","Wait for the in-flight operation to settle (poll remote_access_status until can_start is true), then retry.","If a foreign owner holds the tunnel, stop it through its owning flow first or change the auto-start preference instead of forcing a settings start."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"status = remote_access_status(app_state)\nif not status['can_start']:\n    abort(409, status['block_reason'] or 'operation in progress')","typeGuard":null,"tryCatchPattern":"try:\n    start_remote_access(app_state)\nexcept RuntimeError as e:\n    msg = str(e)\n    if msg == 'operation_in_progress':\n        wait_for(lambda: remote_access_status(app_state)['can_start'], timeout=30)\n        start_remote_access(app_state)\n    else:\n        raise  # block_reason names a real owner; resolve that instead","preventionTips":["Poll remote_access_status()['can_start'] before issuing Start.","Disable the Start button while a Stop (or any transition) is pending in the UI."],"tags":["state-machine","tunnel","remote-access","transient","python"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}