fix(detection): evict stale same-type findings after each scan#86
Merged
Conversation
f074001 to
cd0f8b1
Compare
The worker-local store only upserted by ResourceID, so resources deleted from the cloud persisted in every snapshot until the pod restarted, and long-lived workers kept re-emitting findings for deleted resources. - Add Store.ReplaceFindings(resourceType, findings): a scan's output atomically becomes the type's full set under one lock. Drops the never-called timestamp-based DeleteStaleFindings, which would have coupled eviction to an implicit clock contract between the activity and store implementations. - StoreInput gains ResourceType, passed from the detection workflow. - An empty batch empties the type, so a fleet that drains to zero converges instead of re-emitting its last findings forever. - A zero ResourceType (inputs recorded by in-flight workflows before the field existed) falls back to plain upserts.
cd0f8b1 to
da802d0
Compare
Amp-Thread-ID: https://ampcode.com/threads/T-019eb352-0ee8-70dd-a627-ae4034b7607c Co-authored-by: Amp <amp@ampcode.com>
Collaborator
|
Added the single-scan safeguard on top of this safer per-resource-type eviction fix. Additional behavior now in #86:
Verification:
|
Amp-Thread-ID: https://ampcode.com/threads/T-019eb352-0ee8-70dd-a627-ae4034b7607c Co-authored-by: Amp <amp@ampcode.com>
Collaborator
|
Final singleton hardening added after the previous comment:
Final verification:
|
bakayolo
approved these changes
Jun 10, 2026
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
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.
Why
Resources deleted from AWS keep reappearing because the collector's worker-local store never evicts.
SaveFindingsupserts byResourceIDand nothing deletes, so a resource that drops out of the Wiz report stays in every snapshot until the pod restarts. Prod runs a pinned image with a long-lived pod, so lambdas deleted on 06-05 were re-emitted daily until the pod bounced.What
Store.ReplaceFindings(resourceType, findings): a scan's output atomically becomes the type's full set, evicting entries that dropped out of the inventory. Replaces the never-called timestamp-basedDeleteStaleFindings, which would have coupled eviction correctness to an implicit clock contract between the activity and store implementationsStoreInputgainsResourceType, passed through from the detection workflowResourceType(inputs recorded by in-flight workflows before the field existed) falls back to plain upserts, keeping today's behavior