Fix map-tile cold-render timeouts on Cloud Run - #28
Merged
Merged
Conversation
Every tile request pulled the whole OCAD through Cloud SQL (three times per miss) and uncached blocks queued without limit until Cloud Run's 300 s cap killed them, taking tRPC down with them. Read metadata only, resolve settings once per request, refuse with 503 + Retry-After when the queue is full, and rasterise composite and ink in parallel. Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the colour-stack release (#26), which took the
/api/map-tilepath down on Cloud Run revisionoxygen-00036-vwj(504s at 299.99 s, Cloud SQL connector failures). Full write-up:docs/bugfix-map-tile-cold-render-cloud-timeouts.md.ensureEventMapRenderKey/ensureClubMapRenderKey/refresh*now select metadata only and fetchfile_datasolely whenfile_hashis still null. It was selected unconditionally and called three times per cache miss — ~30 MB from Cloud SQL per tile, which is what pinned the connection pool and starved tRPC.getMapSource/preCacheChunk/maybePreCache;preCacheConsideredis marked before the firstawaitso bursts can't all slip past it.Semaphore.runtakesmaxQueue; beyondMAP_RENDER_MAX_QUEUE(default 4) waiting foreground blocks the route answers503 Retry-After: 5instead of sitting until Cloud Run's 300 s cap.TileLayeralready honoursRetry-After. Background pre-cache is never refused.course.mapFileInfousedoctet_lengthinstead of downloading the blob for.length;course.mapMetadatamemoises theautoprofile classification per render key instead of re-parsing the OCAD on every page load.ppen-import.test.ts(picked whichever imported control the DB returned first).Local numbers on the same 9.8 MB map that failed in prod: cache hit 7–9 ms (was ~250 ms + 9.8 MB); 20-tile burst over five uncached blocks 10.8 s, all 200.
Test plan
pnpm build,pnpm test(605 api / 867 web / 292 shared)maxQueue, 503 + retry path,mapFileInfo.size, profile memo)oxygen-api/oxygen-webrebuilt and started/api/map-tileon a cold map — expect brief 503 bursts that resolve within ~5 s, no 504s, CPU actually busymap_tilesrows forrender_key = dee0e6b476af702521403cf4f96e0890from a dev DB that has viewed the same mapMade with Cursor