Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works
Code Observatory / Source
Index one commit
The last commit is written only after every step succeeds, so a failed run leaves the previous index searchable.
PINNED SOURCE Copied from the repository at this commit. Source, not an execution.
PHAROS at 975a38dMIT license
CodeIndexer.indexbackend/app/codeintel/indexer.py, lines 185–241Open source
def index(self, ref: RepoRef, branch: str | None = None, *, force: bool = False) -> IndexStats: stats = IndexStats(repository=ref.canonical_url) stats.embedding_model = self.embedder.model_id if self.embedder else None t0 = time.monotonic() repo = self.get_or_create_repository(ref, branch) repo_id = repo.id previous_commit = repo.last_commit_sha previous_model = (repo.stats or {}).get("embedding_model") repo.index_status = "indexing" self.db.commit() try: t = time.monotonic() checkout = open_checkout(ref, branch=branch, token=self.clone_token, timeout=self.clone_timeout) stats.timings_s["checkout"] += time.monotonic() - t with checkout: stats.commit_sha = checkout.commit model_changed = previous_model != stats.embedding_model if ( not force and previous_commit == checkout.commit and not model_changed and (repo.stats or {}).get("outcome") is not None ): stats.outcome = "unchanged" stats.chunks_total = self._count_chunks(repo_id) repo = self.db.get(Repository, repo_id) repo.index_status = "ready" self.db.commit() stats.timings_s["total"] = time.monotonic() - t0 return stats self._sync(repo_id, ref, checkout, stats, rewrite_all=force or model_changed) t = time.monotonic() self._rebuild_graph(repo_id, stats) stats.timings_s["graph"] += time.monotonic() - t stats.outcome = "indexed" stats.chunks_total = self._count_chunks(repo_id) stats.timings_s["total"] = time.monotonic() - t0 repo = self.db.get(Repository, repo_id) repo.last_commit_sha = stats.commit_sha repo.last_indexed_at = _utcnow() repo.index_status = "ready" repo.total_files = stats.files_indexed + stats.files_unchanged repo.total_lines = self._count_lines(repo_id) repo.stats = stats.as_dict() self.db.commit() return stats except Exception: self.db.rollback() repo = self.db.get(Repository, repo_id) if repo is not None: # Keep last_commit_sha: the previous index stays searchable. repo.index_status = "failed" self.db.commit() raiseWhere this comes from
- Commit
975a38d5d17839c26ee219295a5be6ac66b6d910- File
backend/app/codeintel/indexer.py- Lines
- 185–241
- Git blob
e8fdfa7b5545e821f7649d68cfadd2aae85b89d0- License
- MIT, © 2024–2026 Pharos Contributors. Notice
Read it on GitHub at this commit
Check it yourself
From a clone of the repository, the first command prints the blob above and the second prints these lines.
git rev-parse 975a38d:backend/app/codeintel/indexer.py
git show 975a38d:backend/app/codeintel/indexer.py | sed -n '185,241p'