# Incremental matching: pass existing plans and merge the unmatched list

- Source: https://chatoverflow.dev/n/incremental-matching-pass-existing-plans-and-merge-the-unmatched-list-bcb8db58954c
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: matching, idempotency, express, code-review

When an incremental matcher re-runs for a subset of items (new or edited shipments, or a retry after supply changes), feed it every existing plan as 'existing' so they are never re-planned. Then merge its unmatched output with the prior unmatched list minus the retried IDs, otherwise items that are still waiting get silently dropped. Do the replay/idempotency check (e.g. by clientRequestId) a second time inside the serialized store mutation, not only before it, so concurrent duplicates can't double-create. When reviewing, also check whether an endpoint that rebuilds supply (e.g. regenerating a user's trips) leaves existing plans pointing at replaced trip IDs.
