Skip to content

Fetch WolframAlpha images in parallel via URLSubmit#185

Merged
rhennigan merged 1 commit into
mainfrom
feature/optimized-wa-image-extraction
May 13, 2026
Merged

Fetch WolframAlpha images in parallel via URLSubmit#185
rhennigan merged 1 commit into
mainfrom
feature/optimized-wa-image-extraction

Conversation

@rhennigan
Copy link
Copy Markdown
Member

Summary

  • Replace the sequential Import[..., "Image"] loop in extractWolframAlphaImages with concurrent URLSubmit requests bounded by a single TaskWait[TimeConstraint -> $waImageFetchTimeout], so total batch latency tracks the slowest fetch instead of summing across all images.
  • New makeImageContent helper passes the server's original bytes and content-type straight through (preserving animated GIFs), eliminating the prior Rasterize/PNG round-trip.
  • Extend the URL pattern to accept .webp and .svg, and merge adjacent text items in the final content list so the output stays compact when fetches fail.

Test plan

  • TestReport for Tests/Graphics.wlt passes, including the loosened extractWolframAlphaImages-MultipleContentItems assertion that now accepts the merged-adjacent-text shape on failed fetches.
  • CodeInspector clean on Kernel/StartMCPServer.wl.
  • Manual smoke: invoke a WolframAlpha query that returns multiple image pods and confirm the MCP response includes one image item per successful URL (with the original mime type) and falls back to the markdown text link when a fetch times out.
  • Verify an animated GIF response retains its animation (no PNG rasterization).

🤖 Generated with Claude Code

Replace the sequential `Import[..., "Image"]` loop in
`extractWolframAlphaImages` with concurrent `URLSubmit` requests bounded
by a single `TaskWait[TimeConstraint -> $waImageFetchTimeout]`, so total
latency is the slowest image rather than the sum. The new
`makeImageContent` helper passes the server's original bytes and mime
type through (preserving animated GIFs), avoiding the prior
Rasterize/PNG round-trip. The URL pattern also picks up `.webp` and
`.svg`. Loosened one test to accommodate the merged-adjacent-text shape
on failed fetches.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 13, 2026 22:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Parallelizes WolframAlpha image fetching in extractWolframAlphaImages using concurrent URLSubmit tasks bounded by a single TaskWait timeout, and passes through the server's original image bytes/mime-type instead of rasterizing through PNG. Also widens the URL pattern to accept .webp/.svg and merges adjacent text items in the structured output.

Changes:

  • Refactor extractWolframAlphaImages to submit all image URLs concurrently via URLSubmit, with a per-URL handler that overwrites a prefilled text fallback in a fetched association; the whole batch is bounded by TaskWait[TimeConstraint -> $waImageFetchTimeout].
  • Introduce makeImageContent helper that produces {text, image} content items directly from the HTTP response, preserving the original content-type (e.g. animated GIFs, WebP, SVG) instead of going through Rasterize/PNG.
  • Extend the WA image URL pattern with .webp and .svg, collapse adjacent text items with SequenceReplace, add webp to .cspell.json, and loosen the MultipleContentItems test to accept the merged-text shape.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Kernel/StartMCPServer.wl New $waImageFetchTimeout config, new makeImageContent helper, rewritten extractWolframAlphaImages using concurrent URLSubmit + TaskWait, expanded URL pattern, adjacent-text merging.
Tests/Graphics.wlt Loosens MultipleContentItems assertion to tolerate merged adjacent text items; renumbers TestIDs.
.cspell.json Adds webp to dictionary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rhennigan rhennigan merged commit 876d654 into main May 13, 2026
5 checks passed
@rhennigan rhennigan deleted the feature/optimized-wa-image-extraction branch May 13, 2026 23:09
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.

2 participants