fix: retry rule load after a transient failure#49
Draft
sarahxsanders wants to merge 1 commit into
Draft
Conversation
scan() cached the rulesPromise on first call and reused it forever. If loadRules() rejected (transient WASM read failure, momentarily missing rules directory, compile error), the rejected promise stayed cached and every later scan() re-awaited it and threw — permanently breaking scanning for the lifetime of a long-running host process. Clear the cached promise on rejection so the next scan() retries the load, while keeping the success fast-path (compile once, reuse) intact. Generated-By: PostHog Code Task-Id: 5b7b5c21-83c6-4c64-ad90-6bdb30815436
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.
Problem and acceptable goal
Problem this change addresses
scan()lazily assignsrulesPromise = loadRules()on first use and reuses that promise forever. IfloadRules()rejects — a transient WASM read failure, a momentarily missing rules directory, or a compile error — the rejected promise stays cached. Every laterscan()re-awaits the same rejected promise and throws, so a one-time recoverable failure permanently breaks scanning for the lifetime of the process.Why the Warlock is the right home for this change:
This is a correctness bug in Warlock's own lazy-load cache inside
src/scanner/engine.ts. The faulty caching lives entirely in the engine, so the fix belongs here — pushing retry logic into context-mill or any other consumer would just paper over an engine defect and force every consumer to reimplement the same workaround.Changes
scan()now attaches a.catchto the cachedloadRules()promise that resetsrulesPromisetonulland re-throws, so the nextscan()retries the load. The success fast-path (compile once, reuse) is unchanged, and it's concurrency-safe: in-flight callers all see the rejection and only the next call triggers a fresh load.src/scanner/__tests__/engine.retry.test.tsforces a one-timereaddirSyncfailure, assertsscan()rejects, then asserts the nextscan()recovers. It lives in its own file because the module-levelrulesPromiseis shared across tests in a file — a fresh file gives a clean module instance so the failure path is actually exercised.Anti-goal check
Test plan
npm run build)scan()signature unchanged)Created with PostHog Code