fix(ci): Batch Algolia record uploads to stop heap OOM on master - #18846
Merged
Conversation
The user-docs Algolia index has not updated since 2026-05-15. Every master push touching docs/, includes/, or platform-includes/ fails with exit 134 (V8 heap limit) roughly 40s into record generation, after a 10-minute build. The script generated every record for all ~10.2k pages into one array before uploading: ~244k records, which exceeds Node's default ~4GB old-space limit. This passed under Bun (no comparable heap cap) and started failing when the script moved to tsx in #17772; the module-resolution error fixed in #18265 masked it for three weeks. The content-hash cache added in #17722 was never protection here: it hashes built HTML, so it hits on 2 of ~9940 pages. Generate and upload in batches of 500 pages so each batch's records are reclaimed before the next is built, keeping peak heap flat as the corpus grows. Existing objectIDs are read once up front, since record objectIDs are auto-generated per run. Stale-cache-file cleanup moves after the batch loop, where it can still see every page that was used. Also add heap headroom scoped to the indexing script only. Setting NODE_OPTIONS job-wide (#17283) let next build outgrow the runner and got the whole runner OOM-killed, which #17711 then had to undo. Verified on the full 10,099-page corpus with a cold cache: the previous code dies at the 4GB cap, this generates all 244,085 records under a 1GB cap with 1.33GB peak RSS. Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
`Number(process.env.ALGOLIA_DRY_RUN_PAGE_LIMIT ?? 200)` applied the nullish default to the raw env var, not to the parse result, so an empty or non-numeric override became 0 or NaN. Both slice to an empty page list, which would report a green dry run that had checked nothing. Parse explicitly and fall back to the default unless the override is a positive integer. Co-Authored-By: Claude <noreply@anthropic.com>
rahulchhabria
approved these changes
Jul 27, 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.
DESCRIBE YOUR PR
The user-docs Algolia index has not been updated since 2026-05-15. Every master push touching
docs/**,includes/**, orplatform-includes/**fails theBuild index for user docsstep with exit 134 (V8 heap limit), ~40s into record generation and after a ~10 minute build — ~70 consecutive runs, ~13 min of CI burned each.develop-docspushes still pass because that corpus is 306 pages vs 10,219.Root cause
scripts/algolia.tsgenerated every record for all ~10.2k pages into a single array before uploading — ~244k records — which exceeds Node's default ~4GB old-space limit.ERR_PACKAGE_PATH_NOT_EXPORTEDfailure fixed in fix(ci): Restore Algolia indexing under tsx and smoke-test it on PRs #18265 masked the OOM for three weeks; it has been 100% since Jun 8.next build.Corroborated in Sentry (
sentry/docs, metrics dataset, 90d)docs_type:user-docsdocs_type:developer-docsalgolia.pages_totalalgolia.records_totalalgolia.cache_missesUser-docs telemetry flatlines on 2026-05-13 while develop-docs keeps reporting weekly — the same
boundary the CI logs show, arrived at independently. The gauges only emit if the process reaches
Sentry.flush(), and the heap OOM is a V8 SIGABRT, so there is also no error event: zero issues inthe
docsproject mention algolia in 90d. A 10-week outage left no signal except red checks onmaster.
Changes
ALGOLIA_DRY_RUN_PAGE_LIMITso the full corpus can be load-tested without touching the index.NODE_OPTIONSjob-wide (fix(ci): resolve OOM in Algolia index workflow #17283) letnext buildoutgrow the runner and got the runner OOM-killed, which fix(ci): remove NODE_OPTIONS causing OOM in Algolia workflow #17711 then had to undo.Verification
Full 10,099-page corpus, cold cache:
FATAL ERROR: Reached heap limitat 4,095 MB — same signature as CIThe upload path needs the Algolia keys, so batched
saveObjectsis only exercised on merge. Note it widens a pre-existing window: stale records are deleted only after all batches upload, so a mid-run failure leaves old + partial-new records in the index until the next green run (previously a failure wrote nothing).Follow-ups not in this PR
actions/cachekey, namespace the dir per docs type) or remove it.Algolia index's own last-updated timestamp rather than these gauges, which the failure itself
suppresses. (Also unresolved: the aggregate query reports 48
algolia.pages_totalrows over 90dwhile the samples view returns 6, so row counts here aren't yet trustworthy.)
IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs to go live.
SLA
Thanks in advance for your help!
PRE-MERGE CHECKLIST
Make sure you've checked the following before merging your changes: