Skip to content

fix: keep out-of-range PERPLEXITY_TIMEOUT_MS from timing out every request - #158

Open
saviourmk wants to merge 1 commit into
perplexityai:mainfrom
saviourmk:fix/timeout-env-range
Open

saviourmk wants to merge 1 commit into
perplexityai:mainfrom
saviourmk:fix/timeout-env-range

Conversation

@saviourmk

Copy link
Copy Markdown

PERPLEXITY_TIMEOUT_MS goes through parseInt straight into setTimeout. Node runs a timer after 1ms when the delay is NaN, below 1, or above 2147483647, so setting the variable to 0 (a common way to ask for no timeout), to a typo like "abc", or to a very large value meant to give research runs plenty of time made every tool call fail right away. The error then reads "Perplexity API did not respond within 3000000000ms", which sends people looking in the wrong place.

I moved the parsing into one small helper used by both makeApiRequest and performAgentResponse. A value that is not a positive number falls back to the 300000ms default, and anything above the timer limit is capped at 2147483647ms (about 24 days). Valid values behave exactly as before.

The new tests set PERPLEXITY_TIMEOUT_MS to 0, -1, abc and 3000000000 and check that an agent call answering after 20ms still returns its answer, plus the same check for perplexity_search with the large value. All five fail on main with the immediate timeout error and pass with this change.

This branch has not been deployed

No deployments
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