{"record":{"id":"b2abea4be5070ce7","repo":"phacility/phabricator","slug":"some-patches-could-not-be-applied-s","errorCode":null,"errorMessage":"Some patches could not be applied: %s","messagePattern":"Some patches could not be applied: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php","lineNumber":1188,"sourceCode":"\n          // If we're explicitly reapplying this patch, we don't need to\n          // mark it as applied.\n          if (!isset($state_map[$ref_key][$key])) {\n            if (!$is_dryrun) {\n              $api->markPatchApplied($key, ($t_end - $t_begin));\n            }\n            $applied_map[$ref_key][$key] = true;\n          }\n        }\n\n        // We applied this everywhere, so we're done with the patch.\n        unset($patches[$key]);\n        $applied_something = true;\n      }\n\n      if (!$applied_something) {\n        if ($patches) {\n          throw new Exception(\n            pht(\n              'Some patches could not be applied: %s',\n              implode(', ', array_keys($patches))));\n        } else if (!$is_dryrun && !$apply_only) {\n          echo pht(\n            'Storage is up to date. Use \"%s\" for details.',\n            'storage status').\"\\n\";\n        }\n        break;\n      }\n    }\n  }\n\n  final protected function getBareHostAndPort($host) {\n    // Split out port information, since the command-line client requires a\n    // separate flag for the port.\n    $uri = new PhutilURI('mysql://'.$host);\n    if ($uri->getPort()) {","sourceCodeStart":1170,"sourceCodeEnd":1206,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php#L1170-L1206","documentation":"The upgrade patch loop finished an iteration having applied nothing while patches remain, so every pending patch is blocked: its `after` dependency is not applied on any eligible host. In practice an earlier patch failed somewhere (query error, timeout, privilege problem) and everything depending on it stayed stuck; the tool gives up and lists the leftover patch keys.","triggerScenarios":"An earlier patch failed on one or more hosts (lock timeout, SQL error, oversized index, missing privileges), so no host satisfies the dependencies of the remaining patches; the loop sets $applied_something false with $patches non-empty and throws the list of stuck keys.","commonSituations":"MySQL rejecting a patch (index prefix limits, sql_mode); timeouts altering large tables mid-upgrade; partial failure across a cluster where one host failed a patch; resuming an upgrade after an aborted run.","solutions":["Run `./bin/storage status` to see per-host applied state and identify the first patch missing everywhere.","Inspect that patch (resources/sql/patches/<key>.sql) and fix the underlying MySQL issue: privileges, lock timeouts, max_allowed_packet, index size limits, sql_mode.","Re-run `./bin/storage upgrade`; patches whose dependencies now succeed will proceed.","If a size limit is the cause, adjust the MySQL settings for that host rather than editing the patch."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  // bin/storage upgrade\n} catch (Exception $ex) {\n  // message lists stuck patch keys; run ./bin/storage status, fix the first\n  // failed patch's underlying MySQL issue, then re-run the upgrade\n  fwrite(STDERR, $ex->getMessage().\"\\n\");\n  exit(1);\n}","preventionTips":["Run ./bin/storage status before and after upgrades to catch per-host drift early.","Schedule upgrades on large tables inside a maintenance window to avoid lock timeouts.","Resolve the first stuck patch before re-running; blind retries loop on the same failure."],"tags":["phabricator","bin-storage","upgrade","patch","migration-failed"],"backgroundTag":"database-migration-failed","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}