Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/web/src/features/workerApi/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server';

import { sew } from "@/middleware/sew";
import { captureEvent } from "@/lib/posthog";
import { githubRateLimited, repositoryNotFound, unexpectedError } from "@/lib/serviceError";
import { withOptionalAuth } from "@/middleware/withAuth";
import { env } from "@sourcebot/shared";
Expand Down Expand Up @@ -28,6 +29,12 @@ export const addGithubRepo = async (owner: string, repo: string) => sew(() =>
return unexpectedError('Failed to add GitHub repo');
}

await captureEvent('askgh_repo_index_requested', {
owner,
repo,
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>

const schema = z.object({
jobId: z.string(),
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/lib/posthogEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ export type PosthogEventMap = {
//////////////////////////////////////////////////////////////////
wa_askgh_login_wall_prompted: {},
//////////////////////////////////////////////////////////////////
askgh_repo_index_requested: {
owner: string,
repo: string,
repoName: string,
},
//////////////////////////////////////////////////////////////////
wa_demo_docs_link_pressed: {},
wa_search_assist_opened: {},
wa_search_assist_query_generated: {},
Expand Down
Loading