Skip to content

fix: correctly handle issues relation array in linkPrToClaim (#123)#228

Open
Sujini-kudupudi wants to merge 4 commits into
Coder-s-OG-s:mainfrom
Sujini-kudupudi:fix/link-pr-claim-issues-array-clean
Open

fix: correctly handle issues relation array in linkPrToClaim (#123)#228
Sujini-kudupudi wants to merge 4 commits into
Coder-s-OG-s:mainfrom
Sujini-kudupudi:fix/link-pr-claim-issues-array-clean

Conversation

@Sujini-kudupudi
Copy link
Copy Markdown
Contributor

@Sujini-kudupudi Sujini-kudupudi commented May 26, 2026

Summary

This PR fixes a bug where skip-history counting was silently broken in production due to an improperly typed cast of the issues relation. The issues relation returned from Supabase was being incorrectly accessed as a single object instead of an array, which caused failures when populating skipHistoryMap and linking opened PRs to claims.

Type of Change

  • Bug fix
  • New feature
  • UI / UX improvement
  • Refactor
  • Documentation
  • Other

Related Issue

Closes #123

What was changed?

  • Extracted a reusable unwrapJoin helper in src/lib/supabase/inner-join.ts to seamlessly handle Supabase !inner join relation arrays.
  • Updated linkPrToClaim and tryLinkByIssueRef in src/inngest/functions/process-pr-event.ts to use the new helper.
  • Applied the same safe array-checking fallback logic to site 3 in src/inngest/functions/recommendations-build.ts to fix the skipHistoryMap population bug.
  • Added a defensive guard if (!issue?.repo_full_name) continue; to ensure safe property access.
  • Added unit tests in process-pr-event.test.ts against linkPrToClaim to prove the fix against both single object and array responses.

Screenshots

N/A - Backend webhook and cron job fix only.

Checklist

  • My code follows the project structure and conventions
  • I tested this locally (npm run dev and npm test)
  • No hardcoded secrets or credentials
  • I have updated documentation if needed

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 26, 2026

@Sujini-kudupudi is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Piyush-Thakkarr
Copy link
Copy Markdown
Collaborator

hey @Sujini-kudupudi, fix looks correct for linkPrToClaim. one gap though: the same bug exists at a third call site that this PR doesn't touch.

src/inngest/functions/recommendations-build.ts:71-80 has the same pattern:

.select('user_id, issues!inner(repo_full_name, repo_language)')
...
const issue = row.issues as unknown as { repo_full_name: string; repo_language: string | null };

no array handling, no defensive guard. when supabase returns the joined issues field as an array (which it always does for !inner joins per its types), this cast lies and issue.repo_full_name is undefined. that's used to populate skipHistoryMap, so skip-history counting is silently broken in production for any user who has reassigned recs.

two things to add:

  1. apply the same normalize pattern to site 3 (recommendations-build.ts:71)

  2. since this normalize is now in three places, extract a tiny helper to src/lib/supabase/inner-join.ts or similar:

    export function unwrapJoin<T>(raw: unknown): T | undefined {
      return Array.isArray(raw) ? (raw[0] as T) : (raw as T);
    }

    then all three sites become one line.

  3. add a unit test against linkPrToClaim that proves the fix: feed a claim where issues is [{ ... }] and one where it's a single object, both should resolve. without a test, a future "cleanup" PR could revert this and nothing catches it.

related: it's worth tagging issue #123 in the PR body so reviewers know what user-visible bug this fixes. closes the loop.

once site 3 is patched and there's a test, this is mergeable.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jun 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mergeship Ready Ready Preview, Comment Jun 2, 2026 9:27am

@jakharmonika364
Copy link
Copy Markdown
Collaborator

CI checks fails, please fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants