arXiv:2610.06180cs.LGOct 2026

Manuscript Offprint

arXiv:2610.06180

Anlu: Enabling In-Context Time Series Anomaly Detection in Foundation Models via Counterfactual Supervision

Tian Lan, Yifei Gao, Yimeng Lu, Xuming An, Meng Wang, Yue Pan, Wenjun He, Chen Zhang

Abstract

Whether a time-series pattern is anomalous often depends on the operating regime of the monitored process. A missing event can signal a fault in one regime and be routine in another, and the query alone may not reveal which regime applies. We study in-context learning (ICL) for time series anomaly detection (TSAD) through reference-conditioned detection, where a reference record provides evidence about expected behavior and model parameters remain fixed at inference. Supplying the reference is not enough: when training anomalies are recognizable from the query alone, the detector can fit its targets while ignoring the reference. We therefore introduce counterfactual supervision, which pairs one query with two references that support different normal rules and labels the query under each. At positions where the two labels disagree, no detector that ignores the reference can fit both targets. Anlu learns from this supervision by adding a reference memory and zero-initialized gated adapters to a frozen time-series foundation model (TSFM) pretrained for anomaly detection. On the 350 TSB-AD-U evaluation sequences, Anlu raises the mean VUS-PR of the frozen TSFM from 0.542 to 0.607. Replacing the reference with zeros lowers Anlu's score to 0.499.

Keywords: In-context learning, Time series anomaly detection, Reference conditioning, Counterfactual supervision

1 Introduction

Industrial monitoring judges a sensor stream against the normal behavior of the process that produced it. That behavior changes with products, loads, and maintenance schedules, and a pattern that is normal in one operating regime can be a fault in another. A missing pulse indicates a fault when the process must emit an event on every cycle, but it is routine when intermittent events are allowed. The query alone may not reveal which rule applies. Figure 1 keeps one query fixed and changes the normal reference against which it is judged.

We frame this setting as reference-conditioned in-context learning: the supplied reference provides evidence about expected behavior for anomaly scoring, while model parameters remain fixed.

Current detectors obtain regime information in one of two ways. Zero-shot detectors built on pretrained time-series foundation models (TSFMs) score a query from its own values and surrounding context [7, 8], so they cannot be told which regime applies. Semi-supervised detectors fit their parameters to normal data from the target series [10], so each new regime requires another round of training. Records of normal operation are easy to collect, whereas representative faults are rare. We study reference-conditioned detection, in which a separate

*Corresponding author: zhangchen01@tsinghua.edu.cn.

Preprint

Figure

Figure 1: One fixed query under two normal references. The orange span is the evaluated query interval. Reference r1r_{1} repeats the scheduled event on every cycle, so the missing query event is anomalous. Reference r2r_{2} repeats admissible omissions, so the same interval is normal. These labels are the conditional training targets.

normal record enters the detector as an input and specifies the regime at inference. Normal operation can then be demonstrated before any fault has been observed.

Adding a reference input does not ensure that the detector uses it. When a synthetic anomaly is recognizable from the query alone, training can reach a low loss with one rule for every reference. Counterfactual supervision removes this shortcut. Each training unit pairs one query with two references that support different normal rules and labels the query under each, so that some positions are anomalous under one reference and normal under the other. A detector that ignores the reference assigns the same score to such a position in both branches, and its mean cross-entropy there cannot fall below log⁡2\log 2 (Section 3.1). Fitting both labels therefore requires reading the reference.

Anlu adds this reference pathway to a frozen TSFM pretrained for pointwise anomaly detection. A resampler compresses the reference into a fixed-length memory, and gated adapters read that memory at four depths of the query encoder. Only the resampler and the adapters are trained. Because the gates start at zero, Anlu reproduces the frozen TSFM at initialization.

On the 350 TSB-AD-U evaluation sequences, Anlu raises the mean VUS-PR of the frozen TSFM from 0.542 to 0.607. To test whether this gain comes from the reference content, we keep the weights, queries, reference lengths, and validity masks fixed and set the normalized reference values to zero. The mean falls to 0.499, below the frozen TSFM, and the original reference scores higher on 248 of the 350 sequences.

Our contributions are as follows.

• We formulate reference-conditioned anomaly detection and introduce counterfactual supervision, in which one query receives conflicting labels under two references. At label-changing positions, any detector that ignores the reference incurs a cross-entropy of at least log⁡2\log 2 (Section 3.1).

• We present Anlu, which adds a reference memory and zero-initialized gated adapters to a frozen TSFM and trains only this pathway (Section 3.2).

• On TSB-AD-U, Anlu raises the mean VUS-PR of the frozen TSFM from 0.542 to 0.607, and a zero-reference intervention lowers it to 0.499 (Section 4).