phacility/phabricator · warning · PhabricatorSearchConstraintException

To search for commits which are ancestors of particular refs

Error message

To search for commits which are ancestors of particular refs, you must constrain the search to exactly one repository.

What it means

DiffusionCommitQuery implements the 'ancestors of refs' constraint by walking history inside a single repository, so the search must be constrained to exactly one repository. With zero or multiple repositories in scope it throws PhabricatorSearchConstraintException rather than return silently wrong results across repos.

Source

Thrown at src/applications/diffusion/query/DiffusionCommitQuery.php:555

    if ($this->repositoryPHIDs !== null) {
      $map_repositories = id(new PhabricatorRepositoryQuery())
        ->setViewer($this->getViewer())
        ->withPHIDs($this->repositoryPHIDs)
        ->execute();

      if (!$map_repositories) {
        throw new PhabricatorEmptyQueryException();
      }
      $repository_ids = mpull($map_repositories, 'getID');
      if ($this->repositoryIDs !== null) {
        $repository_ids = array_merge($repository_ids, $this->repositoryIDs);
      }
      $this->withRepositoryIDs($repository_ids);
    }

    if ($this->ancestorsOf !== null) {
      if (count($this->repositoryIDs) !== 1) {
        throw new PhabricatorSearchConstraintException(
          pht(
            'To search for commits which are ancestors of particular refs, '.
            'you must constrain the search to exactly one repository.'));
      }

      $repository_id = head($this->repositoryIDs);
      $history_limit = $this->getRawResultLimit() * 32;
      $viewer = $this->getViewer();

      $repository = id(new PhabricatorRepositoryQuery())
        ->setViewer($viewer)
        ->withIDs(array($repository_id))
        ->executeOne();

      if (!$repository) {
        throw new PhabricatorEmptyQueryException();
      }

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Constrain the search to exactly one repository via the Repositories filter
  2. Or remove the ancestors-of-refs constraint
  3. Conduit/API callers: pass exactly one repositoryPHID (or a single-element ids/repositories parameter) together with ancestorsOf

Example fix

// before
$conduit->executeMethod('diffusion.commit.search', array(
  'ancestorsOf' => array('master'),
  // repositories constraint left unset -> 'All Repositories'
));

// after
$conduit->executeMethod('diffusion.commit.search', array(
  'ancestorsOf' => array('master'),
  'constraints' => array('repositories' => array('PHID-REPO-abcd')),
));
Defensive patterns

Strategy: validation

Validate before calling

// before applying the ancestors constraint, assert single-repository scope
if (count($this->repositoryIDs ?: array()) !== 1) {
  // do not add ancestorsOf; prompt the user to pick exactly one repository
}

Type guard

function canApplyAncestorConstraint(array $repository_ids) {
  return count($repository_ids) === 1;
}

Try / catch

try {
  $results = $query->execute();
} catch (PhabricatorSearchConstraintException $ex) {
  // surface the constraint message next to the offending filter in the UI
}

Prevention

When it happens

Trigger: A commit search (UI or Conduit) sets the ancestors-of-refs constraint while the Repositories filter is unset ('All Repositories') or selects multiple repositories; also when a projects-based scope expands to more than one repository.

Common situations: Users adding the ancestor field to saved queries or dashboards while leaving the default global scope; API callers passing refs plus a multi-repository scope.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/23b7a70c2ffd2916. Report an issue: GitHub.