Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class LangfuseProvider {
userId?: string
filter?: any[]
fields?: string
orderBy?: string
}): Promise<any> {
const queryParams: any = { ...params }

Expand Down Expand Up @@ -151,13 +152,21 @@ export class LangfuseProvider {
limit: 1,
page: 1,
filter: LangfuseProvider.UNPROCESSED_FILTER,
fields: 'core' // Minimal fields for discovery
fields: 'core', // Minimal fields for discovery
orderBy: 'timestamp' // CRITICAL: Order by timestamp ascending (default) to get OLDEST first
// Note: Langfuse API defaults to ascending order, so just 'timestamp' should work
// If this returns newest instead of oldest, we fall back to 2020-01-01 anyway
Comment on lines 152 to +158

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Oldest-trace lookup still sorts newest first

The fix adds orderBy: 'timestamp' to findOldestUnprocessedTrace() but does not change the sort direction that the Langfuse API applies. The API returns traces ordered by timestamp descending unless an ascending direction is sent (e.g., an order parameter or orderBy=timestamp,asc). Passing only the field name leaves the default direction intact, so the limit: 1 call still returns the newest unprocessed trace and the subsequent window loop begins near “now”, skipping historical traces exactly as before. To actually fetch the oldest trace, the request must explicitly specify ascending order.

Useful? React with 👍 / 👎.

})

if (response.data.length === 0) {
return null // No unprocessed traces
}

log.info('Found oldest unprocessed trace', {
traceId: response.data[0].id,
timestamp: response.data[0].timestamp
})

return new Date(response.data[0].timestamp)
} catch (error) {
log.warn('Failed to find oldest trace, defaulting to 2020-01-01', { error })
Expand Down
Loading