We recorded EEG while participants passively listened to sound sequences shifting between patterns, and compared their responses with ideal-observer models. Across two experiments, we found that the brain flexibly resets or preserves contextual memory based on its experience of the sound context.