Skip to content

Conversation

@joanagmaia
Copy link
Contributor

@joanagmaia joanagmaia commented Dec 12, 2025

The work developed on this PR #3673 was not working as expected, because the analyseGitHubIntegration is only triggered for integrations that are active (not deleted). So the code that was added before was never reached, as it was fetching for deleted integration for ids that were always active.

What does this PR fixes?

  • Revert previous changes.

For Staging and Development (AUTOMATIC)

  • Use nangoConnectionCleanup job we already have in place. However, it had to be refactored because once again it was only querying the active integrations:
    • Fetch for deleted integrations for any type of nango integration.
    • Merge active integrations with all integrations, to iterate through all use cases.
    • Fix integration platform check to github-nango and not github
    • Create a shouldDelete flag that is true if
      • Integration was created more than 30 days ago
      • AND
      • integration no longer exists OR integration exists but is deleted

Tested now in staging and it deleted 26 stale connections. As we weren't considering deleted connections before, there were a lot of stale connections in Nango.

For Production (MANUAL):

  • Create a script that checks how many nango connections we have that belong to deleted integrations.
  • Script has available flag to only check without deleting and to delete them all.

Tests on new script in staging:

  • Running without --delete flag
14:41:45.089Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=725fdc7c-4daa-4256-9972-4f4e92fd2c43, platform=github-nango)
14:41:45.089Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=d3e432df-1037-4eb0-9dd2-6dc8d8d68f9e, platform=github-nango)
14:41:45.089Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=fe95322e-f730-412e-88e4-84557123951f, platform=github-nango)
14:41:45.089Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=8d9af7d7-731e-4462-a647-9099a11053ca, platform=github-nango)
14:41:45.090Z  INFO script: Connection f8fb87f6-4493-4a99-bd10-1ff8803e3870 (github) is connected to a deleted integration def44bc0-f29b-42b6-bf0e-dbc3a978bfef and should be deleted!
  • Running with --delete flag
14:42:34.861Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=725fdc7c-4daa-4256-9972-4f4e92fd2c43, platform=github-nango)
14:42:34.861Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=d3e432df-1037-4eb0-9dd2-6dc8d8d68f9e, platform=github-nango)
14:42:34.861Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=fe95322e-f730-412e-88e4-84557123951f, platform=github-nango)
14:42:34.861Z  INFO script: Integration has no nangoMapping in settings, skipping (integrationId=8d9af7d7-731e-4462-a647-9099a11053ca, platform=github-nango)
14:42:34.862Z  WARN script: Connection f8fb87f6-4493-4a99-bd10-1ff8803e3870 (github) is connected to a deleted integration def44bc0-f29b-42b6-bf0e-dbc3a978bfef - deleting it...

The connection that was deleted was created by me, disconnected from the UI and it became stale in Nango.
I believe that in production we have hundreds of connections like this because in the UI we see 8537 connections and in our logs we have 7159 total connections.

This is costing us unnecessary money in Nango.


Note

Refactors Nango cleanup to consider deleted integrations and age-based pruning, removes deleted-integration handling from worker logic, and adds a script to list/delete connections tied to deleted integrations.

  • Cron/Jobs:
    • Refactor services/apps/cron_service/src/jobs/nangoConnectionCleanup.job.ts:
      • Fetch both active and deleted integrations via fetchNangoIntegrationData + fetchNangoDeletedIntegrationData.
      • Use PlatformType.GITHUB_NANGO for GitHub checks; support repo-based nangoMapping.
      • Delete connection if older than 30 days and unlinked or linked to a deleted integration.
  • Nango Worker:
    • services/apps/nango_worker/src/activities/nangoActivities.ts:
      • Remove deleted-integration branch; on missing integration just warn.
    • Add services/apps/nango_worker/src/bin/check-disconnected-integrations.ts:
      • Scans deleted integrations to find matching Nango connections; supports --delete to remove them.
  • Data Access Layer:
    • Add fetchNangoDeletedIntegrationData; remove fetchDeletedIntegrationById in services/libs/data-access-layer/src/integrations/index.ts.

Written by Cursor Bugbot for commit 24964b4. This will update automatically on new commits. Configure here.

@joanagmaia joanagmaia requested a review from themarolt December 12, 2025 14:50
@joanagmaia joanagmaia self-assigned this Dec 12, 2025
@joanagmaia joanagmaia added the Bug Created by Linear-GitHub Sync label Dec 12, 2025
@github-actions
Copy link
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

2 similar comments
@github-actions
Copy link
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@github-actions
Copy link
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@github-actions
Copy link
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@joanagmaia joanagmaia merged commit aad50ae into main Dec 15, 2025
15 checks passed
@joanagmaia joanagmaia deleted the fix/nango-repos-to-delete branch December 15, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants