{"record":{"id":"68e03c926a18acb4","repo":"nats-io/nats-server","slug":"max-request-batch-must-be-set-if-it-s-jetstream-li","errorCode":null,"errorMessage":"max_request_batch must be set if it's JetStream limits are set","messagePattern":"max_request_batch must be set if it's JetStream limits are set","errorType":"validation","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"server/consumer.go","lineNumber":710,"sourceCode":"\t\t\treturn NewJSPedanticError(errors.New(\"inactive_threshold must be set if it's configured in stream limits\"))\n\t\t}\n\t\tconfig.InactiveThreshold = streamCfg.ConsumerLimits.InactiveThreshold\n\t}\n\t// Set proper default for max ack pending if we are ack explicit and none has been set.\n\tif config.MaxAckPending == 0 && config.AckPolicy != AckNone {\n\t\tackPending := JsDefaultMaxAckPending\n\t\tif lim.MaxAckPending > 0 && lim.MaxAckPending < ackPending {\n\t\t\tackPending = lim.MaxAckPending\n\t\t}\n\t\tif accLim.MaxAckPending > 0 && accLim.MaxAckPending < ackPending {\n\t\t\tackPending = accLim.MaxAckPending\n\t\t}\n\t\tconfig.MaxAckPending = ackPending\n\t}\n\t// if applicable set max request batch size\n\tif config.DeliverSubject == _EMPTY_ && config.MaxRequestBatch == 0 && lim.MaxRequestBatch > 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"max_request_batch must be set if it's JetStream limits are set\"))\n\t\t}\n\t\tconfig.MaxRequestBatch = lim.MaxRequestBatch\n\t}\n\n\t// set the default value only if pinned policy is used.\n\tif config.PriorityPolicy == PriorityPinnedClient && config.PinnedTTL == 0 {\n\t\tconfig.PinnedTTL = JsDefaultPinnedTTL\n\t}\n\n\t// Set default values for flow control policy.\n\tif config.AckPolicy == AckFlowControl && !pedantic {\n\t\tconfig.FlowControl = true\n\t\tconfig.Heartbeat = sourceHealthHB\n\t}\n\treturn nil\n}\n\n// Check the consumer config. If we are recovering don't check filter subjects.","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/consumer.go#L692-L728","documentation":"When creating a consumer whose JetStream limits include MaxRequestBatch (>0) but the consumer config does not set MaxRequestBatch, the server flags a pedantic configuration error. In non-pedantic mode the server silently copies lim.MaxRequestBatch into the config; with pedantic mode enabled it refuses and returns this error instead. It only applies to pull consumers (DeliverSubject is empty).","triggerScenarios":"Calling ConsumerCreate/AddConsumer (via $JS.API.CONSUMER.CREATE or client APIs like js.AddConsumer) with a JetStream limit requester context that sets MaxRequestBatch>0, DeliverSubject empty (pull consumer), config.MaxRequestBatch==0, and the server/level running with --js pedantic checks enabled.","commonSituations":"Using a JetStream domain/account limits template that specifies max_request_batch while the application creates pull consumers without explicitly setting MaxRequestBatch; environments where the server runs with pedantic mode (used in NATS conformance/strict deployments) after migrating from non-pedantic servers that auto-filled the value.","solutions":["Set MaxRequestBatch explicitly in the ConsumerConfig before creating the consumer.","Remove MaxRequestBatch from the account/stream limits if you do not need batch size capping.","Run the server without pedantic mode so the value is defaulted automatically.","Upgrade or align client library so consumer creation templates include MaxRequestBatch."],"exampleFix":"// before\njs.AddConsumer(stream, &nats.ConsumerConfig{Durable: \"worker\"})\n// after\njs.AddConsumer(stream, &nats.ConsumerConfig{Durable: \"worker\", MaxRequestBatch: 100})","handlingStrategy":"validation","validationCode":"func validateMaxRequestBatch(cfg *nats.ConsumerConfig, limMaxRequestBatch int, pedantic bool) error {\n\tif cfg.DeliverSubject == \"\" && cfg.MaxRequestBatch == 0 && limMaxRequestBatch > 0 {\n\t\tif pedantic {\n\t\t\treturn errors.New(\"max_request_batch must be set when JetStream limits define it (pedantic mode)\")\n\t\t}\n\t\tcfg.MaxRequestBatch = limMaxRequestBatch // mirror server defaulting\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set MaxRequestBatch explicitly on pull consumers in pedantic environments","Keep account/stream limits and consumer templates in sync","Test consumer creation against a pedantic-mode server in CI"],"tags":["jetstream","consumer","config-validation","pull-consumer"],"backgroundTag":"jetstream-consumer-config-invalid","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}