# Bug 3529: We should queue overlapped transactions in the client

- Status: closed
- Project: Zero
- Creator: @aboodman
- Created: 2025-02-11T03:38:36Z
- Modified: 2025-02-11T07:23:32Z
- URL: https://bugs.rocicorp.dev/p/zero/issue/3529

## Description

Currently overlapped transactions in the client are disallowed:

```ts
z.mutateBatch(async tx => {
  z.mutate.foo.insert();
});
```

Throws an error: "Cannot call mutate.foo.insert inside a batch".

This error makes sense when you think of nested transactions as above. But the error happens if you just have concurrent/overlapped transactions.

Instead we should allow these nested transactions and queue them. This means this nested case will deadlock

It's possible we could detect the deadlock through clever use of a custom thenable. If we can that would be great, but I think the deadlock would be bettr than what we have now which basically makes it difficult to mix mutateBatch and simple mutators at all.

A difficult workaround would be to introduce your own application-level lock/queue, like using https://www.npmjs.com/package/@rocicorp/lock and serialize all mutations/batchMutations through that.

I also think that this error can maybe only happen early in startup as Zero is loading from IDB. In that case a workaround could be to do some dummy query early in startup that causes IDB to load before doing any mutations.

## Comments (1)

### @aboodman — 2025-02-11T07:23:32Z

Fixed in 8097246836d0eddf5573512d0b77bb1be4ee9a39
