A 30-File Medical Record Mini-Program Hits Every AI Bottleneck: Timeouts, Cold Starts, and a 1x1 PNG Fix
AI features inside constrained clients (mini-programs, mobile, edge) hit hard platform limits; this write-up shows concrete workarounds: async job polling, a provider abstraction to avoid vendor lock-in, and a 1x1 PNG preheat that shaves first inference from 50s to 6s. The lessons apply directly to any small service where a local or remote model must respond under a client-imposed timeout.
A developer building a small WeChat mini-program for archiving medical records (photos of lab reports, discharge summaries, vaccine booklets) found that the hard part was never the AI model itself. Local Qwen2.5-VL 3B inference on CPU takes 40-60 seconds, while the mini-program platform caps `wx.request` at 60 seconds. The solution is an async job queue with polling: the server returns a `jobId` immediately, the client polls every 1.2 seconds, and the server controls the polling interval, exposing progress to the UI so a 40-second wait feels like a process, not a hang.
The project uses a provider abstraction controlled by an environment variable (`VISION_PROVIDER`) with three backends: local Ollama, Tencent Cloud OCR, and any OpenAI-compatible API. All return the same `{ result, error }` shape, and a health endpoint tells the frontend what model is installed, whether it's ready, and the expected latency. For Tencent Cloud, the author handwrites the TC3-HMAC-SHA256 signature with Node's built-in `crypto` to keep zero npm dependencies. A text-only preheat fails to load the vision tower, so the author sends a 1x1 pixel PNG at startup, cutting first inference from 50 seconds to 6. Error messages get translated into human-readable next steps.
The post closes with three transferable rules: always make long tasks async, abstract AI providers behind a unified interface, and preheat vision models with an image. It also argues that 80% of AI app engineering is traditional backend work, that zero dependencies is a productivity win for small tools, and that 3B-class local models are now viable for structured extraction on CPU.
The post's claim that 80% of AI app engineering is outside AI is well supported by its own detail: timeouts, queues, signature handling, preheat strategies, and error translation get far more space than prompt work.
A provider abstraction controlled by a single environment variable, rather than an SDK, is a cheap hedge against model vendor churn; small projects gain more from that than from any SDK's convenience.
A 1x1 PNG is a clever, zero-cost workaround for a real multimodal model quirk: text-only warmup leaves the vision encoder cold, so any image-loading trigger suffices.
The "zero npm dependencies" stance flips the usual bias: for a small tool, managing dependencies is overhead, and built-in modules can handle routing, signing, and parsing fine.
Hand-rolling TC3 signing is a nice zero-dependency showcase, but it only pays off when you already avoid SDKs everywhere; the real architectural takeaway is the uniform return contract, not the signature code.