Skip to content

feat(backend): replace backend_repo_index_job_completed with backend_repo_first_indexed#900

Merged
brendan-kellam merged 2 commits intomainfrom
brendan/posthog-repo-indexing-events
Feb 18, 2026
Merged

feat(backend): replace backend_repo_index_job_completed with backend_repo_first_indexed#900
brendan-kellam merged 2 commits intomainfrom
brendan/posthog-repo-indexing-events

Conversation

@brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Feb 18, 2026

Summary

  • Removes the backend_repo_index_job_completed PostHog event, which was firing on every re-index and generating enormous event volume (2M+ events/week, dominated by a single looping install)
  • Adds backend_repo_first_indexed which fires only the first time a repo is successfully indexed (indexedAt === null before the update), enabling accurate tracking of unique repositories ever indexed

Test plan

  • Deploy and verify backend_repo_first_indexed fires when a new repo is indexed for the first time
  • Verify the event does not fire on subsequent re-indexes of the same repo
  • Confirm backend_repo_index_job_completed no longer appears in PostHog

🤖 Generated with Claude Code

Summary by CodeRabbit

Changed

  • Repository indexing event tracking refined to record first-time index completion separately, providing more precise analytics insights.

…repo_first_indexed

Replaces the high-volume per-index PostHog event with one that fires only
on the first successful index of a repo, enabling accurate tracking of
unique repositories ever indexed without flooding the event stream.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cursor
Copy link

cursor bot commented Feb 18, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on March 14.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@github-actions

This comment has been minimized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Walkthrough

The pull request replaces the general backend_repo_index_job_completed telemetry event with backend_repo_first_indexed, which fires conditionally only on the first successful repository index. The event payload is simplified by removing the jobType field.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added entry documenting the replacement of backend_repo_index_job_completed with backend_repo_first_indexed event that fires only on first successful repo index.
Telemetry Event Definition
packages/backend/src/posthogEvents.ts
Renamed event map entry from backend_repo_index_job_completed to backend_repo_first_indexed and removed the jobType field from its schema, keeping only repoId and type.
Event Emission Logic
packages/backend/src/repoIndexManager.ts
Modified onJobCompleted to conditionally emit backend_repo_first_indexed only for INDEX-type jobs without a prior indexedAt timestamp, replacing the previous unconditional event emission on all job completions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • #878: Introduced the original backend_repo_index_job_completed telemetry event that this PR modifies and replaces.
  • #860: Modified repoIndexManager.ts job-completion handling logic that this PR's conditional event emission depends on.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing one PostHog event with another. It directly reflects the primary objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch brendan/posthog-repo-indexing-events

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/backend/src/repoIndexManager.ts (1)

578-583: Add an inline comment to document the intentional stale-value read.

jobData.repo.indexedAt is the value fetched at line 514 — before db.repo.update sets indexedAt: new Date() at line 547. This is the correct sentinel for "first ever successful index", but the implicit ordering dependency is easy to accidentally break during future refactoring (e.g., merging the two db.repo.update calls).

📝 Suggested comment
+            // jobData.repo.indexedAt holds the value *before* the db.repo.update
+            // above set it to `new Date()`. A null value here means this is the
+            // first time this repo has been successfully indexed.
             if (jobData.type === RepoIndexingJobType.INDEX && jobData.repo.indexedAt === null) {
                 captureEvent('backend_repo_first_indexed', {
                     repoId: job.data.repoId,
                     type: jobData.repo.external_codeHostType,
                 });
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/backend/src/repoIndexManager.ts` around lines 578 - 583, Add an
inline comment at the check that reads jobData.repo.indexedAt === null (used
with RepoIndexingJobType.INDEX/jobData) explaining this is an intentional
stale-value read: jobData.repo.indexedAt was fetched earlier (when jobData was
built) and is used as the sentinel for "first ever successful index" even though
db.repo.update later sets indexedAt; mention the ordering dependency and warn
that merging or reordering the db.repo.update calls (or changing where jobData
is sourced) would break this logic so future maintainers should preserve the
read-before-update pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/backend/src/repoIndexManager.ts`:
- Around line 578-583: Add an inline comment at the check that reads
jobData.repo.indexedAt === null (used with RepoIndexingJobType.INDEX/jobData)
explaining this is an intentional stale-value read: jobData.repo.indexedAt was
fetched earlier (when jobData was built) and is used as the sentinel for "first
ever successful index" even though db.repo.update later sets indexedAt; mention
the ordering dependency and warn that merging or reordering the db.repo.update
calls (or changing where jobData is sourced) would break this logic so future
maintainers should preserve the read-before-update pattern.

@brendan-kellam brendan-kellam merged commit f59e5e6 into main Feb 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments