@@ -165,7 +165,25 @@ export const jiraConnector: ConnectorConfig = {
165165 jql = `project = "${ safeKey } " AND (${ jqlFilter . trim ( ) } ) ORDER BY updated DESC`
166166 }
167167
168- const collectedSoFar = ( syncContext ?. collectedCount as number | undefined ) ?? 0
168+ /**
169+ * Collected-count is encoded in the cursor as `${pageToken}|${count}` so
170+ * the maxIssues cap works correctly even when the caller doesn't pass
171+ * syncContext. Falls back to syncContext.collectedCount for backwards
172+ * compatibility with cursors emitted before this format existed.
173+ */
174+ let pageToken : string | undefined
175+ let collectedSoFar = ( syncContext ?. collectedCount as number | undefined ) ?? 0
176+ if ( cursor ) {
177+ const sep = cursor . lastIndexOf ( '|' )
178+ if ( sep > 0 ) {
179+ pageToken = cursor . slice ( 0 , sep )
180+ const parsed = Number ( cursor . slice ( sep + 1 ) )
181+ if ( Number . isFinite ( parsed ) && parsed >= 0 ) collectedSoFar = parsed
182+ } else {
183+ pageToken = cursor
184+ }
185+ }
186+
169187 const remaining = maxIssues > 0 ? Math . max ( 0 , maxIssues - collectedSoFar ) : PAGE_SIZE
170188 if ( maxIssues > 0 && remaining === 0 ) {
171189 return { documents : [ ] , hasMore : false }
@@ -178,7 +196,7 @@ export const jiraConnector: ConnectorConfig = {
178196 'fields' ,
179197 'summary,issuetype,status,priority,assignee,reporter,project,labels,created,updated'
180198 )
181- if ( cursor ) params . append ( 'nextPageToken' , cursor )
199+ if ( pageToken ) params . append ( 'nextPageToken' , pageToken )
182200
183201 const url = `https://api.atlassian.com/ex/jira/${ cloudId } /rest/api/3/search/jql?${ params . toString ( ) } `
184202
@@ -220,7 +238,7 @@ export const jiraConnector: ConnectorConfig = {
220238
221239 return {
222240 documents,
223- nextCursor : hasMore ? nextPageToken : undefined ,
241+ nextCursor : hasMore && nextPageToken ? ` ${ nextPageToken } | ${ newCollected } ` : undefined ,
224242 hasMore,
225243 }
226244 } ,
0 commit comments