pipecd icon indicating copy to clipboard operation
pipecd copied to clipboard

Older live-state event can silently overwrite a newer one in the same batch

Open vipulpandey21 opened this issue 3 months ago • 0 comments

What's happening

PatchKubernetesApplicationLiveState (pkg/app/server/applicationlivestatestore/store.go) applies a batch of Kubernetes resource-state events to a snapshot. Each event carries a version, and the code is supposed to skip any event older than what's already stored:

if ev.SnapshotVersion.IsBefore(*snapshot.Version) {
    continue
}

The problem: snapshot.Version is fetched once at the top of the function and never updated while the loop applies events. So every event in the batch gets compared against that same original version, not against the version the previous event in the loop just moved the state to.

Why it matters

If a batch has two events for the same resource where an older one arrives after a newer one (a redelivered retry is a normal way this can happen), the check above doesn't catch it. The older event silently overwrites the newer state — no error, no log.

How I found it

Traced how piped assigns event versions (pkg/app/piped/livestatestore/kubernetes/appnodes.go) through to how the server applies them. Wrote a test with two out-of-order events for the same resource — the final state ends up on the stale value.

I have a fix and a test ready, opening a PR for it.

vipulpandey21 avatar Aug 05 '26 12:08 vipulpandey21