Skip to content

Commit 45117d5

Browse files
committed
fix(knowledge): release a dispatch-marked pending row when its credential is missing
1 parent 06aebf9 commit 45117d5

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎apps/sim/lib/knowledge/__integration__/connector-deferral.integration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vi.mock('@/connectors/registry.server', () => ({
1818
github_fixture: {
1919
id: 'github_fixture',
2020
name: 'Fixture GitHub',
21-
auth: { mode: 'apiKey' },
21+
auth: { mode: 'apiKey', optional: true },
2222
listDocuments: fixture.list,
2323
getDocument: vi.fn(),
2424
},

‎apps/sim/lib/knowledge/connectors/sync-engine.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,10 @@ export async function executeSync(
857857
if (!connectorHasAuthSource(connectorConfig.auth, connectorBeforeLock)) {
858858
logger.warn('Skipping sync: connector has no credential to authenticate with', { connectorId })
859859
/**
860-
* Written only while the row is still the credential-less runnable row this run read: a
861-
* reconnect that landed in between keeps its schedule, and a paused or disabled connector
862-
* a stale task reached keeps its status.
860+
* Written only while the row is still the credential-less row this run read: a reconnect
861+
* that landed in between keeps its schedule, and a paused or disabled connector a stale task
862+
* reached keeps its status. A row this dispatch marked `pending` is released with it, the
863+
* same token match the lock acquisition below applies.
863864
*/
864865
const observed = (
865866
column: typeof knowledgeConnector.credentialId | typeof knowledgeConnector.encryptedApiKey,
@@ -873,7 +874,15 @@ export async function executeSync(
873874
eq(knowledgeConnector.id, connectorId),
874875
observed(knowledgeConnector.credentialId, connectorBeforeLock.credentialId),
875876
observed(knowledgeConnector.encryptedApiKey, connectorBeforeLock.encryptedApiKey),
876-
inArray(knowledgeConnector.status, [...RUNNABLE_CONNECTOR_STATUSES])
877+
or(
878+
inArray(knowledgeConnector.status, [...RUNNABLE_CONNECTOR_STATUSES]),
879+
options.dispatchToken
880+
? and(
881+
eq(knowledgeConnector.status, 'pending'),
882+
eq(knowledgeConnector.syncLockToken, options.dispatchToken)
883+
)
884+
: undefined
885+
)
877886
)
878887
)
879888
return { ...result, skipReason: 'credential_missing' }

0 commit comments

Comments
 (0)