Describe the Bug
Payload starts MongoDB transactions by default for Local API write operations, but when MongoDB throws a retryable transaction error such as TransientTransactionError / WriteConflict, Payload aborts the transaction and rethrows the error instead of retrying the whole transaction body.
MongoDB treats WriteConflict inside transactions as expected optimistic concurrency behavior. The recommended handling is to retry the full transaction when the error has the TransientTransactionError label. The MongoDB driver's higher-level session.withTransaction() API does this retry behavior automatically.
❌ In Payload, the current flow appears to be manual transaction handling:
const shouldCommit = !args.disableTransaction && await initTransaction(args.req)
try {
const result = await operation(args)
if (shouldCommit) {
await commitTransaction(args.req)
}
return result
} catch (err) {
if (shouldCommit) {
await killTransaction(args.req)
}
throw err
}
✅ Expected flow:
await runWithTransactionRetry(async () => { // ‼️
const shouldCommit = !args.disableTransaction && await initTransaction(args.req)
try {
const result = await operation(args)
if (shouldCommit) {
await commitTransaction(args.req)
}
return result
} catch (err) {
if (shouldCommit) {
await killTransaction(args.req)
}
throw err
}
})
Link to the code that reproduces this issue
https://github.com/dolanoadriano/payload-write-conflict-repro
Reproduction Steps
- Run:
pnpm install
pnpm test:int _community
Which area(s) are affected?
db: mongodb
Environment Info
Binaries:
Node: 24.14.0
npm: 11.9.0
Yarn: N/A
pnpm: 11.1.1
Relevant Packages:
payload: 3.80.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:38 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6050
Available memory (MB): 24576
Describe the Bug
Payload starts MongoDB transactions by default for Local API write operations, but when MongoDB throws a retryable transaction error such as
TransientTransactionError/WriteConflict, Payload aborts the transaction and rethrows the error instead of retrying the whole transaction body.MongoDB treats
WriteConflictinside transactions as expected optimistic concurrency behavior. The recommended handling is to retry the full transaction when the error has theTransientTransactionErrorlabel. The MongoDB driver's higher-levelsession.withTransaction()API does this retry behavior automatically.❌ In Payload, the current flow appears to be manual transaction handling:
✅ Expected flow:
Link to the code that reproduces this issue
https://github.com/dolanoadriano/payload-write-conflict-repro
Reproduction Steps
Which area(s) are affected?
db: mongodb
Environment Info