Skip to content

fix: add timeout to prompt list fetch - #6644

Open
wanxiankai wants to merge 1 commit into
FlowiseAI:mainfrom
wanxiankai:fix/prompt-list-timeout
Open

fix: add timeout to prompt list fetch#6644
wanxiankai wants to merge 1 commit into
FlowiseAI:mainfrom
wanxiankai:fix/prompt-list-timeout

Conversation

@wanxiankai

Copy link
Copy Markdown

Summary

  • Add a 10s timeout to the LangChain Hub prompt list request so unavailable upstream calls fail into the existing fallback path.
  • Add a service test covering the timeout option and error fallback.

Closes #6514

Tests

  • pnpm exec jest src/services/prompts-lists/index.test.ts --runInBand
  • pnpm exec prettier --check packages/server/src/services/prompts-lists/index.ts packages/server/src/services/prompts-lists/index.test.ts
  • pnpm exec eslint packages/server/src/services/prompts-lists/index.ts packages/server/src/services/prompts-lists/index.test.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a 10-second timeout to the LangChain Hub prompts request and adds unit tests to verify both successful and failed request scenarios. However, the feedback identifies a critical bug in the URL construction where interpolating the tags parameter results in a malformed query string by merging the tags and has_commits parameters. Additionally, the function can return undefined if the response data does not contain repos. It is recommended to refactor the URL construction using URLSearchParams, ensure a consistent return structure, and add a test case to verify tag filtering.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

// Default to 100, TODO: add pagination and use offset & limit
const url = `https://api.hub.langchain.com/repos/?limit=100&${tags}has_commits=true&sort_field=num_likes&sort_direction=desc&is_archived=false`
const resp = await axios.get(url)
const resp = await axios.get(url, { timeout: LANGCHAIN_HUB_PROMPTS_TIMEOUT_MS })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

There is a bug in the URL construction on line 9 when tags are provided. If requestBody.tags is present, tags is set to 'tags=some-tag'. When interpolated into the URL:
...&${tags}has_commits=true...
It results in:
...&tags=some-taghas_commits=true...
This merges the tags and has_commits parameters, making the request malformed and breaking the tag filtering.

Additionally, if resp.data.repos is falsy, the function currently reaches the end of the try block without returning anything, resulting in undefined being returned instead of a consistent { status: 'ERROR', repos: [] } or { status: 'OK', repos: [] } structure.

To fix both issues, consider refactoring the URL construction using URLSearchParams and ensuring a consistent return value:

const createPromptsList = async (requestBody: any) => {
    try {
        const params = new URLSearchParams({
            limit: '100',
            has_commits: 'true',
            sort_field: 'num_likes',
            sort_direction: 'desc',
            is_archived: 'false'
        })
        if (requestBody.tags) {
            params.append('tags', requestBody.tags)
        }
        const url = `https://api.hub.langchain.com/repos/?${params.toString()}`
        const resp = await axios.get(url, { timeout: LANGCHAIN_HUB_PROMPTS_TIMEOUT_MS })
        
        if (resp.data?.repos) {
            return {
                status: 'OK',
                repos: resp.data.repos
            }
        }
        return { status: 'ERROR', repos: [] }
    } catch (error) {
        return { status: 'ERROR', repos: [] }
    }
}

status: 'OK',
repos
})
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Add a test case to verify that the tags parameter is correctly appended to the URL query parameters. This will help prevent regressions and verify the fix for the URL query parameter formatting bug.

    })

    it('fetches LangChain Hub prompts with tags', async () => {
        const repos = [{ id: 'owner/prompt', num_likes: 42 }]
        mockedAxios.get.mockResolvedValue({ data: { repos } })

        const result = await promptsListsService.createPromptsList({ tags: 'agent' })

        expect(mockedAxios.get).toHaveBeenCalledWith(
            'https://api.hub.langchain.com/repos/?limit=100&tags=agent&has_commits=true&sort_field=num_likes&sort_direction=desc&is_archived=false',
            { timeout: 10000 }
        )
        expect(result).toEqual({
            status: 'OK',
            repos
        })
    }

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.

Prompt list service can hang on LangChain Hub because axios.get has no timeout

1 participant