{"record":{"id":"f6856a5b8ef2832d","repo":"jax-ml/jax","slug":"effects-not-supported-in-scan-disallowed-effec","errorCode":null,"errorMessage":"Effects not supported in `scan`: {disallowed_effects}","messagePattern":"Effects not supported in `scan`: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/control_flow/loops.py","lineNumber":190,"sourceCode":"  xs_avals = xs_flat.map(core.typeof)\n  length = _infer_scan_length(list(xs_flat), list(xs_avals), length)\n\n  # TODO(dougalm): handle disable_jit\n  if config.mutable_array_checks.value:\n    check_no_aliased_ref_args(lambda: dbg_body, list(xs_avals), list(xs_flat))\n\n  x_avals = xs_avals.map(lambda aval: core.mapped_leading_aval(length, aval))\n  # TODO(dougalm): promote away all weak types\n  args_avals = ft.pack(((x_avals,), {}))\n  jaxpr, y_avals = pe.trace_to_jaxpr(f, args_avals, dbg_body)\n  jaxpr, consts = pe.separate_consts(jaxpr)\n\n  if config.mutable_array_checks.value:\n    _check_no_aliased_closed_over_refs(dbg_body, consts, list(xs_flat))\n\n  disallowed_effects = effects.control_flow_allowed_effects.filter_not_in(jaxpr.effects)\n  if disallowed_effects:\n    raise NotImplementedError(\n        f'Effects not supported in `scan`: {disallowed_effects}')\n\n  unroll = core.concrete_or_error(\n      None, unroll,\n      \"The `unroll` argument to `scan` expects a concrete `int` or `bool` \"\n      \"value.\")\n  if isinstance(unroll, bool):\n    unroll = max(length, 1) if unroll else 1\n  if unroll < 0:\n    raise ValueError(\"`unroll` must be a `bool` or a non-negative `int`.\")\n\n  args = list(consts) + list(xs_flat)\n  # TODO(dougalm): handle traceable-level forwarding\n  out = Scan3(\n      extensives = [False] * len(consts) + [True] * len(xs_flat),\n      length=length, jaxpr=jaxpr, reverse=reverse, unroll=unroll)(args)\n\n  return y_avals.update(out).unflatten()","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/control_flow/loops.py#L172-L208","documentation":"The new (scan3) implementation of lax.scan rejects jaxprs containing effects outside the control-flow whitelist. If the scan body performs IO or other disallowed effects, tracing fails with NotImplementedError.","triggerScenarios":"Using jax.config.update('jax_scan3', True) (or a version where scan3 is default) with a scan body that calls io_callback, debug printers, or custom effectful primitives.","commonSituations":"Opting into the experimental scan3 path while body still contains callbacks; version upgrades where scan3 became default and previously tolerated effects no longer pass.","solutions":["Remove effectful ops from the scan body; hoist IO outside the scan","Compute what the callback needs purely and do IO on the final result","Disable scan3 via jax.config.update('jax_scan3', False) if you need the old behavior temporarily","Register your custom effect in control_flow_allowed_effects if you own it"],"exampleFix":"// before\njax.config.update('jax_scan3', True)\ndef body(c, x): hcb.io_callback(print, None, x); return c, x\n// after\ndef body(c, x): return c, x  # IO removed; print after scan on results","handlingStrategy":"validation","validationCode":"j = jax.make_jaxpr(body)(carry_example, x_example)\nfrom jax._src.effects import control_flow_allowed_effects\nassert not control_flow_allowed_effects.filter_not_in(j.effects)","typeGuard":"def scan_body_is_pure(body, c_ex, x_ex) -> bool:\n    return not control_flow_allowed_effects.filter_not_in(jax.make_jaxpr(body)(c_ex, x_ex).effects)","tryCatchPattern":"try: jax.config.update('jax_scan3', True); lax.scan(...)\\nexcept NotImplementedError as e:\\n    if 'Effects not supported' in str(e): jax.config.update('jax_scan3', False); retry\n    else: raise","preventionTips":["Keep scan bodies free of callbacks/prints","Gate scan3 opt-in behind tests that assert purity","Pin jax versions in CI to catch effect-policy changes"],"tags":["jax","scan","effects","scan3","experimental"],"backgroundTag":"jax-unsupported-effect-in-transform","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}