Skip to content

fix(kb): fix Linear connector GraphQL type errors and tag slot reuse#3919

Merged
waleedlatif1 merged 5 commits intostagingfrom
waleedlatif1/fix-linear-connector
Apr 3, 2026
Merged

fix(kb): fix Linear connector GraphQL type errors and tag slot reuse#3919
waleedlatif1 merged 5 commits intostagingfrom
waleedlatif1/fix-linear-connector

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Fix Linear connector 400 errors by changing GraphQL variable types from String! to ID! for team/project filter comparators and issue lookup
  • Fix duplicate tag slot allocation when adding a second connector — reuse existing tag definitions that match by display name instead of allocating new slots

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 3, 2026 10:57pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 3, 2026

PR Summary

Medium Risk
Changes affect connector creation (tag definition persistence) and Linear GraphQL query construction, which could impact connector setup/sync behavior if slot reuse or ID typing is incorrect. Scope is limited to these flows and is primarily bug-fix oriented.

Overview
Fixes connector creation to reuse existing knowledge-base tag slots when a connector’s tag definition matches an existing displayName + fieldType, and only creates new tag definitions for newly allocated slots.

Updates the Linear connector’s GraphQL queries to use ID! (instead of String!) for issue lookup and team/project filter variables, addressing 400/type errors from Linear when filtering or fetching by id.

Reviewed by Cursor Bugbot for commit 6e0d016. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR delivers two targeted bug fixes for the knowledge base connector system:

  1. Linear GraphQL type fix: Changes variable types from String! to ID! for teamId, projectId, and issue id in all GraphQL query definitions. Linear's API schema defines these fields as the ID scalar, so using String! was causing 400 errors. The fix correctly aligns with Linear's schema.

  2. Tag slot deduplication on connector creation: Adds a pre-allocation step in POST /api/knowledge/[id]/connectors that queries existing tag definitions for the knowledge base, builds a map by displayName, and reuses the existing slot when a new connector's tag definition matches by both displayName and fieldType. Only genuinely new definitions are forwarded to allocateTagSlots, and only those are written to the DB inside the transaction.

Key changes:

  • apps/sim/connectors/linear/linear.ts: $id: String!$id: ID! in ISSUE_BY_ID_QUERY; $teamId: String!$teamId: ID! and $projectId: String!$projectId: ID! in buildIssuesQuery
  • apps/sim/app/api/knowledge/[id]/connectors/route.ts: Adds existingDefs query, existingByName map, and defsNeedingSlots filter before slot allocation; separates newTagSlots (DB writes) from tagSlotMapping (full mapping stored in config)

Confidence Score: 5/5

Safe to merge — both fixes are targeted, correct, and well-scoped with no regressions introduced

The Linear type change (String! → ID!) directly matches Linear's GraphQL schema and eliminates the 400 errors. The tag slot reuse logic correctly separates existing-slot reuse from new-slot allocation, only writing new knowledgeBaseTagDefinitions rows to the DB. The fieldType guard on reuse prevents mismatched slot types. No P0 or P1 findings; the PR is clean.

No files require special attention

Important Files Changed

Filename Overview
apps/sim/connectors/linear/linear.ts Correct fix: changes GraphQL variable types for teamId, projectId, and issue id from String! to ID! to match Linear's API schema and resolve 400 errors
apps/sim/app/api/knowledge/[id]/connectors/route.ts Adds tag slot reuse logic that queries existing tag definitions and maps them by displayName+fieldType before allocation, correctly separating reused slots from new ones so duplicate DB entries are avoided when adding a second connector

Sequence Diagram

sequenceDiagram
    participant Client
    participant Route as POST /api/knowledge/[id]/connectors
    participant DB
    participant Linear as Linear GraphQL API

    Client->>Route: POST with connectorType, credentialId, sourceConfig
    Route->>DB: Query existing knowledgeBaseTagDefinitions
    DB-->>Route: existingDefs (tagSlot, displayName, fieldType)
    Note over Route: Build existingByName map<br/>Separate reused vs new defs
    Route->>Route: allocateTagSlots(defsNeedingSlots, usedSlots)
    Route->>DB: BEGIN TRANSACTION, LOCK knowledge_base row
    Route->>DB: createTagDefinition (new slots only)
    Route->>DB: INSERT knowledgeConnector (with full tagSlotMapping)
    DB-->>Route: OK
    Route->>Route: dispatchSync(connectorId)
    Route-->>Client: 201 Created

    Note over Linear: During sync
    Route->>Linear: ListIssues ($teamId: ID!, $projectId: ID!)
    Linear-->>Route: Issues page
    Route->>Linear: GetIssue ($id: ID!)
    Linear-->>Route: Issue detail
Loading

Reviews (2): Last reviewed commit: "fix(kb): verify field type when reusing ..." | Re-trigger Greptile

Clean up newTagSlotMapping into direct assignment, remove unnecessary
comment, and revert ID! back to String! to match Linear SDK types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add fieldType check to the tag slot reuse logic so a connector with
a matching displayName but different fieldType falls through to fresh
slot allocation instead of silently reusing an incompatible slot.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6e0d016. Configure here.

@waleedlatif1 waleedlatif1 merged commit c7ca90c into staging Apr 3, 2026
6 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/fix-linear-connector branch April 3, 2026 22:58
waleedlatif1 added a commit that referenced this pull request Apr 4, 2026
…3919)

* fix(kb): fix Linear connector GraphQL type errors and tag slot reuse

* fix(kb): simplify tag slot reuse, revert Linear GraphQL types to String

Clean up newTagSlotMapping into direct assignment, remove unnecessary
comment, and revert ID! back to String! to match Linear SDK types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(kb): use ID! type for Linear GraphQL filter variables

* fix(kb): verify field type when reusing existing tag slots

Add fieldType check to the tag slot reuse logic so a connector with
a matching displayName but different fieldType falls through to fresh
slot allocation instead of silently reusing an incompatible slot.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(kb): enable search on connector selector dropdowns

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@waleedlatif1 waleedlatif1 restored the waleedlatif1/fix-linear-connector branch April 4, 2026 23:43
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/fix-linear-connector branch April 5, 2026 01:20
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