Skip to content

feat: add askgh_repo_index_requested PostHog event - #1658

Merged
msukkari merged 4 commits into
mainfrom
cursor/askgh-repo-index-posthog-event-5251
Sep 22, 2026
Merged

msukkari merged 4 commits into
mainfrom
cursor/askgh-repo-index-posthog-event-5251

Conversation

@msukkari

@msukkari msukkari commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Fixes SOU-2252

Related: https://linear.app/sourcebot/issue/SOU-2252/add-ability-to-track-who-caused-a-repo-to-be-indexed-in-public-saas

Summary

Add a new PostHog event (askgh_repo_index_requested) that fires when Ask GH requests that a repo be indexed through the POST /api/experimental/add-github-repo endpoint.

Problem

On the public app (app.sourcebot.dev), repos can be indexed via Ask GH but there was no PostHog event that attributes who requested the index. We couldn't answer "who requested indexing of torvalds/linux?"

Solution

Emit a PostHog event at the moment an Ask GH index is requested. Requester identity is handled automatically by PostHog's distinct_id (via captureEvent / tryGetPostHogDistinctId), so the event payload only needs repo context.

Event Name

askgh_repo_index_requested

Properties

Property Type Description
owner string GitHub repository owner
repo string GitHub repository name
repoName string Combined owner/repo string for easy filtering

Requester identity (signed-in vs anonymous) is inferred from PostHog's built-in distinct_id.

Querying in PostHog

Find all index requests for a specific repo:

askgh_repo_index_requested where repoName = 'torvalds/linux'

Find requests by a specific user:
Filter by distinct_id (user id for signed-in, install id for anonymous).

Where it fires

packages/web/src/features/workerApi/actions.ts - in the addGithubRepo server action, after the backend successfully processes the repo index request.

Testing

  • The event uses the existing captureEvent helper which automatically handles identity via tryGetPostHogDistinctId
  • Signed-in users are identified by their user id; anonymous requests collapse to the install id
Open in Web Open in Cursor 

Summary by cubic

Tracks successful Ask GH repo index requests in PostHog so we can attribute who requested indexing.

  • Emits askgh_repo_index_requested after the index request is processed, capturing owner, repo, and repoName.
  • Requester identity is handled by PostHog's built-in distinct ID from captureEvent, so no custom identity properties are tracked.

Written for commit 3add2ba. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Analytics
    • Added tracking for GitHub repository indexing requests, including the repository owner, repository, and repository name.
    • Repository indexing requests continue to use the existing response validation and HTTP error handling.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 25db5b5e-e8dd-46d5-853e-595428d7280e

📥 Commits

Reviewing files that changed from the base of the PR and between 9d22f25 and 3add2ba.

📒 Files selected for processing (1)
  • packages/web/src/features/workerApi/actions.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


Walkthrough

The web worker API now emits askgh_repo_index_requested before it reads and validates the worker response. The event includes the GitHub owner, repository, and repository name.

Changes

Repository indexing telemetry

Layer / File(s) Summary
Event contract and request instrumentation
packages/web/src/lib/posthogEvents.ts, packages/web/src/features/workerApi/actions.ts
The PostHog event map defines owner, repository, and repository name fields without repoId. addGithubRepo captures the event before response parsing and validation. HTTP error handling remains unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: brendan-kellam

Merge Risk: ⚪ Minimal · up to 3add2

The endpoint now records repository-indexing requests while preserving response validation. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: adding the askgh_repo_index_requested PostHog event.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

cursoragent and others added 2 commits September 22, 2026 02:14
Emit a new PostHog event when Ask GH requests a repo index via
POST /api/experimental/add-github-repo. The event includes:

- owner: GitHub repo owner
- repo: GitHub repo name
- repoName: Combined owner/repo string
- isAnonymous: Whether the requester is authenticated
- anonymousCreatorId: Anonymous session ID (when anonymous)
- repoId: Created repo ID

This enables tracking who requested indexing of repos through Ask GH.

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
Remove identity properties (isAnonymous, anonymousCreatorId, userId, email)
since PostHog's built-in distinct_id from captureEvent already handles
requester identification. Keep only repo fields: owner, repo, repoName, repoId.

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/askgh-repo-index-posthog-event-5251 branch from a86cf5b to f374239 Compare September 22, 2026 02:14
@cursor
cursor Bot marked this pull request as ready for review September 22, 2026 02:15
@github-actions

Copy link
Copy Markdown
Contributor

@cursor[bot] your pull request is missing a changelog!

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

cursoragent and others added 2 commits September 22, 2026 02:58
Keep only repo identity fields: owner, repo, repoName.

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
…able

Move captureEvent above schema parse and return schema.parse(data) directly.

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/web/src/features/workerApi/actions.ts">

<violation number="1" location="packages/web/src/features/workerApi/actions.ts:38">
P3: The `askgh_repo_index_requested` event now fires before the response body is parsed/validated, whereas it previously fired only after `schema.parse(data)` succeeded. If `response.json()` or the zod parse throws (malformed 2xx body), `addGithubRepo` fails for the caller but the event still records the index as requested, skewing analytics. The move appears to be an unintended side effect of removing the intermediate `result` variable — restore the original order so the event only fires on a fully successful index request.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

repoName: `${owner}/${repo}`,
});

const data = await response.json();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The askgh_repo_index_requested event now fires before the response body is parsed/validated, whereas it previously fired only after schema.parse(data) succeeded. If response.json() or the zod parse throws (malformed 2xx body), addGithubRepo fails for the caller but the event still records the index as requested, skewing analytics. The move appears to be an unintended side effect of removing the intermediate result variable — restore the original order so the event only fires on a fully successful index request.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/web/src/features/workerApi/actions.ts, line 38:

<comment>The `askgh_repo_index_requested` event now fires before the response body is parsed/validated, whereas it previously fired only after `schema.parse(data)` succeeded. If `response.json()` or the zod parse throws (malformed 2xx body), `addGithubRepo` fails for the caller but the event still records the index as requested, skewing analytics. The move appears to be an unintended side effect of removing the intermediate `result` variable — restore the original order so the event only fires on a fully successful index request.</comment>

<file context>
@@ -29,19 +29,17 @@ export const addGithubRepo = async (owner: string, repo: string) => sew(() =>
         });
 
-        return result;
+        const data = await response.json();
+        const schema = z.object({
+            jobId: z.string(),
</file context>

@msukkari
msukkari merged commit c527231 into main Sep 22, 2026
15 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.

2 participants