Skip to content

πŸ›‘οΈ Sentinel: [MEDIUM] Add timeouts to external API calls - #34

Open
felirami wants to merge 1 commit into
mainfrom
sentinel/add-fetch-timeouts-5752759091545973092
Open

πŸ›‘οΈ Sentinel: [MEDIUM] Add timeouts to external API calls#34
felirami wants to merge 1 commit into
mainfrom
sentinel/add-fetch-timeouts-5752759091545973092

Conversation

@felirami

@felirami felirami commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

User description

🚨 Severity: MEDIUM
πŸ’‘ Vulnerability: Missing timeouts on external fetch calls. Node's native fetch does not have a default timeout, meaning unresponsive external servers can cause connections to hang indefinitely.
🎯 Impact: Hanging requests can lead to thread/resource exhaustion and degrade the application's responsiveness, introducing a risk of Denial of Service (DoS).
πŸ”§ Fix: Added explicit timeouts using signal: AbortSignal.timeout(TIMEOUT_MS) to fetch calls in src/lib/network.ts, src/lib/snap-market.ts, and scripts/sync-sources.mjs.
βœ… Verification: Ran npm run lint, npm run typecheck, and npm run build.


PR created automatically by Jules for task 5752759091545973092 started by @felirami


Note

Low Risk
Bounded timeouts on read-only external calls improve resilience; slow-but-valid responses may now fail with timeout errors instead of eventually succeeding.

Overview
Hardens outbound HTTP so native fetch calls cannot hang forever when GitHub, the public node, or Dexscreener stops responding.

scripts/sync-sources.mjs now passes signal: AbortSignal.timeout(30_000) on both GitHub JSON and raw-text helpers. getNetworkStatus in src/lib/network.ts uses the existing NODE_PROBE_TIMEOUT_MS (10s) the same way. getSnapMarketData in src/lib/snap-market.ts introduces MARKET_FETCH_TIMEOUT_MS (10s) for the Dexscreener request.

A Sentinel entry in .jules/sentinel.md documents the gap and the AbortSignal.timeout prevention pattern.

Reviewed by Cursor Bugbot for commit 22bfe37. Bugbot is set up for automated code reviews on this repo. Configure here.


CodeAnt-AI Description

Add timeouts to external fetch requests

What Changed

  • External requests now stop after a set time instead of hanging when a server does not respond.
  • Network status checks, market data checks, and source sync requests all use timeout limits.
  • GitHub source sync requests now fail fast instead of waiting indefinitely for slow or stuck responses.

Impact

βœ… Fewer hanging requests
βœ… Lower risk of stalled background jobs
βœ… More reliable external API checks

πŸ’‘ Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Note

Add AbortSignal.timeout to external API calls in sync scripts and network probes

  • Adds a 30s timeout to fetchGithubJson and fetchGithubText in sync-sources.mjs via AbortSignal.timeout(30_000).
  • Adds a configurable timeout to getNetworkStatus in network.ts using NODE_PROBE_TIMEOUT_MS.
  • Adds a 10s timeout to getSnapMarketData in snap-market.ts via a new MARKET_FETCH_TIMEOUT_MS constant.
  • Behavioral Change: timed-out requests now reject with an AbortError (or return ok:false) instead of hanging indefinitely.
πŸ“Š Macroscope summarized 22bfe37. 4 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

πŸ—‚οΈ Filtered Issues

No issues evaluated.

Co-authored-by: felirami <6752178+felirami@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@codeant-ai

codeant-ai Bot commented Jun 28, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hypersnaporg Ready Ready Preview, Comment Jun 28, 2026 8:48pm

Request Review

@codeant-ai

codeant-ai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! πŸŽ‰

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X Β·
Reddit Β·
LinkedIn

@codeant-ai codeant-ai Bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Jun 28, 2026
Comment thread scripts/sync-sources.mjs
...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}),
},
signal: AbortSignal.timeout(30_000),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟑 Medium scripts/sync-sources.mjs:36

fetchGithubJson() aborts every request after 30s via AbortSignal.timeout, but timeouts throw a TimeoutError/AbortError rather than returning a non-OK HTTP status. When getRepoTree() and getLatestRelease() call it with { optional: true }, a slow GitHub API response throws and propagates up through buildRepoSnapshot() to main(), which calls process.exit(1) β€” so one slow response fails the entire snapshot generation instead of skipping that optional source and leaving src/data/farcasterorg-sources.json stale. Consider catching AbortError/timeout exceptions in fetchGithubJson() and returning null when optional is true, or catching timeouts at the optional call sites.

πŸš€ Reply "fix it for me" or copy this AI Prompt for your agent:
In file @scripts/sync-sources.mjs around line 36:

`fetchGithubJson()` aborts every request after 30s via `AbortSignal.timeout`, but timeouts throw a `TimeoutError`/`AbortError` rather than returning a non-OK HTTP status. When `getRepoTree()` and `getLatestRelease()` call it with `{ optional: true }`, a slow GitHub API response throws and propagates up through `buildRepoSnapshot()` to `main()`, which calls `process.exit(1)` β€” so one slow response fails the entire snapshot generation instead of skipping that optional source and leaving `src/data/farcasterorg-sources.json` stale. Consider catching `AbortError`/timeout exceptions in `fetchGithubJson()` and returning `null` when `optional` is true, or catching timeouts at the optional call sites.

Comment thread scripts/sync-sources.mjs
"X-GitHub-Api-Version": "2022-11-28",
...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}),
},
signal: AbortSignal.timeout(30_000),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Adding a hard timeout here introduces a new rejection path that bypasses the optional fallback logic, so optional GitHub reads can now fail the entire sync job instead of degrading gracefully. Handle timeout/abort errors in fetchGithubJson and return null when optional is true. [incomplete implementation]

Severity Level: Major ⚠️
- ❌ Daily sync script fails on optional JSON timeouts.
- ⚠️ Snapshot src/data/farcasterorg-sources.json stops updating.
- ⚠️ Frontend data via src/lib/sources.ts becomes stale.
Steps of Reproduction βœ…
1. Run the source sync script via `npm run sync:sources` defined in `package.json:11`,
which executes `node scripts/sync-sources.mjs`.

2. Execution enters `main()` in `scripts/sync-sources.mjs:246-254`, which iterates
`sortedRepos` and calls `buildRepoSnapshot(repo)` at line 253 for each repository.

3. Inside `buildRepoSnapshot()` (`scripts/sync-sources.mjs:176-244`), `getRepoTree()` at
lines 146-157 and `getLatestRelease()` at lines 159-173 are called; both invoke
`fetchGithubJson(..., { optional: true })` to GitHub JSON endpoints.

4. `fetchGithubJson()` (`scripts/sync-sources.mjs:28-48`) calls `fetch()` with `signal:
AbortSignal.timeout(30_000)` at line 35; when GitHub or the network hangs >30s, `fetch()`
rejects with `AbortError`, so the 404/409 + `optional` fallback at lines 38-40 never runs,
the rejection bubbles to `main()`, and the top-level `main().catch` at lines 48-51 logs
the error and exits with status 1, aborting the entire sync job instead of returning
`null` for optional data.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent πŸ€–
This is a comment left during a code review.

**Path:** scripts/sync-sources.mjs
**Line:** 35:35
**Comment:**
	*Incomplete Implementation: Adding a hard timeout here introduces a new rejection path that bypasses the `optional` fallback logic, so optional GitHub reads can now fail the entire sync job instead of degrading gracefully. Handle timeout/abort errors in `fetchGithubJson` and return `null` when `optional` is true.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
πŸ‘ | πŸ‘Ž

Comment thread scripts/sync-sources.mjs
"X-GitHub-Api-Version": "2022-11-28",
...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}),
},
signal: AbortSignal.timeout(30_000),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: This timeout adds the same unhandled abort path to text fetches, which means optional markdown/doc fetches can now throw and terminate the script before fallback behavior runs. Catch timeout/abort errors in fetchGithubText and return an empty string when optional is true. [incomplete implementation]

Severity Level: Major ⚠️
- ❌ Sync script crashes on optional GitHub text timeouts.
- ⚠️ Docs metadata and summaries fail to refresh.
- ⚠️ UI relying on sources snapshot shows outdated documentation.
Steps of Reproduction βœ…
1. Run the source sync via `npm run sync:sources` (`package.json:11`), which executes
`scripts/sync-sources.mjs` to generate `src/data/farcasterorg-sources.json` (described in
`README.md:27-29`).

2. `main()` (`scripts/sync-sources.mjs:246-254`) calls `buildRepoSnapshot(repo)` at line
253; inside `buildRepoSnapshot()` (`176-244`), multiple optional markdown/doc calls use
`fetchGithubText(..., { optional: true })` at lines 178-180 (README), 189-193 (hyper.md),
and 199-211 (SUMMARY.md, introduction.md, getting-started.md). `enrichDocsLinks()` at
lines 53-87 also calls `fetchGithubText(..., { optional: true })` at lines 58-61.

3. `fetchGithubText()` (`scripts/sync-sources.mjs:50-69`) invokes `fetch()` with `signal:
AbortSignal.timeout(30_000)` at line 57 and only treats 404/409 responses as optional
fallbacks, returning `""` when `optional` is true at lines 60-62.

4. When any of these GitHub text endpoints or the network stalls for more than 30 seconds,
`fetch()` rejects with `AbortError`, so the 404/409 + `optional` fallback at lines 60-62
is skipped, the rejection propagates through `buildRepoSnapshot()` / `enrichDocsLinks()`
back to `main()`, and `main().catch` at lines 48-51 logs the error and exits with status
1, causing optional markdown/doc fetches to fail hard and terminate the script.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent πŸ€–
This is a comment left during a code review.

**Path:** scripts/sync-sources.mjs
**Line:** 57:57
**Comment:**
	*Incomplete Implementation: This timeout adds the same unhandled abort path to text fetches, which means optional markdown/doc fetches can now throw and terminate the script before fallback behavior runs. Catch timeout/abort errors in `fetchGithubText` and return an empty string when `optional` is true.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
πŸ‘ | πŸ‘Ž

@codeant-ai

codeant-ai Bot commented Jun 28, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant