{"record":{"id":"fe225b79ae26f886","repo":"nats-io/nats-server","slug":"duplicate-window-limits-are-higher-than-current-li","errorCode":null,"errorMessage":"duplicate window limits are higher than current limits","messagePattern":"duplicate window limits are higher than current limits","errorType":"error_code","errorClass":"JSPedanticError","httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":1961,"sourceCode":"\t}\n\tif cfg.MaxConsumers == 0 || cfg.MaxConsumers < -1 {\n\t\tif pedantic && cfg.MaxConsumers < -1 {\n\t\t\treturn StreamConfig{}, NewJSPedanticError(fmt.Errorf(\"max_consumers must be set to -1\"))\n\t\t}\n\t\tcfg.MaxConsumers = -1\n\t}\n\tif cfg.MaxAge < 0 {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"max age can not be negative\"))\n\t}\n\tif cfg.MaxAge != 0 && cfg.MaxAge < 100*time.Millisecond {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"max age needs to be >= 100ms\"))\n\t}\n\n\tif cfg.Duplicates == 0 && cfg.Mirror == nil && len(cfg.Sources) == 0 {\n\t\tmaxWindow := StreamDefaultDuplicatesWindow\n\t\tif lim.Duplicates > 0 && maxWindow > lim.Duplicates {\n\t\t\tif pedantic {\n\t\t\t\treturn StreamConfig{}, NewJSPedanticError(fmt.Errorf(\"duplicate window limits are higher than current limits\"))\n\t\t\t}\n\t\t\tmaxWindow = lim.Duplicates\n\t\t}\n\t\tif cfg.MaxAge != 0 && cfg.MaxAge < maxWindow {\n\t\t\tif pedantic {\n\t\t\t\treturn StreamConfig{}, NewJSPedanticError(fmt.Errorf(\"duplicate window cannot be bigger than max age\"))\n\t\t\t}\n\t\t\tcfg.Duplicates = cfg.MaxAge\n\t\t} else {\n\t\t\tcfg.Duplicates = maxWindow\n\t\t}\n\t}\n\tif cfg.Duplicates < 0 {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"duplicates window can not be negative\"))\n\t}\n\t// Check that duplicates is not larger then age if set.\n\tif cfg.MaxAge != 0 && cfg.Duplicates > cfg.MaxAge {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"duplicates window can not be larger then max age\"))","sourceCodeStart":1943,"sourceCodeEnd":1979,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L1943-L1979","documentation":"In pedantic mode, when no explicit Duplicates window is set (Duplicates==0, no mirror/sources), the default duplicate window (StreamDefaultDuplicatesWindow) may exceed the server's account limit lim.Duplicates; pedantic mode refuses the implicit coercion and returns this JSPedanticError instead of shrinking the window.","triggerScenarios":"Stream create/update in pedantic mode where cfg.Duplicates==0, cfg.Mirror==nil, len(cfg.Sources)==0, and StreamDefaultDuplicatesWindow > account limits.Duplicates. server/stream.go:1961.","commonSituations":"Accounts with a lowered duplicate-window template limit creating streams that previously silently used the capped default; enabling pedantic validation in CI; multi-tenant deployments with per-account JetStream limits.","solutions":["Set cfg.Duplicates explicitly to a value <= the account's limits.Duplicates","Raise the account's JetStream template duplicate window limit (account server config)","Run without pedantic mode so the server caps maxWindow to lim.Duplicates silently"],"exampleFix":"// before\nStreamConfig{Name: \"ORDERS\"} // duplicates window defaults higher than account limit\n// after\nStreamConfig{Name: \"ORDERS\", Duplicates: 2 * time.Minute}","handlingStrategy":"validation","validationCode":"lim, _ := js.AccountLimits()\nif cfg.Duplicates == 0 && lim.Duplicates > 0 && defaultDuplicatesWindow > lim.Duplicates {\n    cfg.Duplicates = lim.Duplicates // pre-cap to stay pedantic-safe\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var apiErr *nats.APIError\n    if errors.As(err, &apiErr) && apiErr.ErrorCode == nats.ErrorCodeJetStreamInvalidStreamConfig {\n        cfg.Duplicates = accountLimits.Duplicates\n        err = createStream(cfg)\n    }\n}","preventionTips":["Fetch account limits and pre-cap Duplicates before stream creation","Set Duplicates explicitly rather than relying on defaults in multi-tenant accounts","Keep account limit templates consistent across environments"],"tags":["jetstream","stream-config","pedantic","limits"],"backgroundTag":"jetstream-invalid-stream-config","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}