Repository navigation
Description
Bug description
With the MongoDB job repository, reloading a job execution returns each step saved on the job document twice. One copy comes from the stepExecutions array embedded in the job document, the other from the step-execution collection. The embedded copy can be stale: it can still say STARTING with read count 0 after the collection says COMPLETED with read count 5. Reloading and saving the execution writes both copies back, so the embedded array grows by the number of steps each time. Two steps become 4, then 6, 8, and 10. A stale copy also reaches JobOperator#recover, which handles it first: in a hand-built state where the collection said COMPLETED with read count 5, recovery saved the step back as FAILED with read count 0.
This started in 6.0. Before 90d8959, JobExecution#addStepExecutions replaced equal step executions, so the collection copies replaced the embedded ones. It now appends. The pull request does not bring the replacement back. It stops JobExecutionConverter#toJobExecution from copying the embedded array, so step executions come only from the collection, as with JDBC.
After that change the embedded array no longer supplies step executions to the returned job execution, but saving a job execution still writes it. The parent job execution of a step from getStepExecution(long) or getLastStepExecution, and job executions from the deprecated findJobExecutions(JobInstance), no longer carry the embedded copies, as with JDBC. If one of those is passed to deleteJobExecution, JobOperator#recover or JobOperator#stop, that call sees no steps, as with JDBC. For example, deleteJobExecution leaves the step documents in place. On main that already happens when the last saved job snapshot contained no steps, and with JDBC the same call fails on the foreign key.
Environment
Spring Batch 6.1.0 and 6.0.6, MongoDB 8. Same on main 86b6567. 5.2.6 returns each step once.
Steps to reproduce
Run a two-step job with the MongoDB job repository, then load the execution with JobRepository#getJobExecution.
Expected behavior
The loaded execution lists step1 and step2 once each, with the status and counts from the step-execution collection. Repeated reload-and-save cycles do not accumulate duplicate entries in the embedded array.
Minimal Complete Reproducible example
The tests added to MongoDBJobRepositoryIntegrationTests in the pull request. On 6.1.0 the completed two-step job reloads with four step executions, and four reload-and-save cycles give 4, 6, 8, and 10.
Activity
beyondwin commentedon Nov 29, 2026
PR: #5694