Scheduled Bot Still Processing Two Rows Despite TOP(…, 1) – Same Issue as Previous Duplicate Execution Bug?

Scheduled Bot sometimes processes/creates two rows instead of one – unable to prevent concurrent execution

Hello AppSheet Community,

I have been struggling with an issue involving a Scheduled Bot, and I have already tried several different approaches to prevent duplicate/concurrent processing, but I still cannot get it to work reliably.

I would appreciate any advice, especially from anyone who has experienced similar behavior with Scheduled Bots.

What I am trying to achieve

I have a queue table called:

請求書一括 (Invoice Batch)

Each row represents one invoice-generation job.

The important columns include:

  • JobID
  • Created Date/Time
  • Status
  • File
  • Error Memo
  • ControlKey
  • other invoice-related fields

The intended workflow is very simple:

queued → processing → done

I want AppSheet to process the jobs one at a time.

The reason for processing them sequentially is that each job performs several operations, including updating related rows, calculating invoice data, generating a PDF, and updating the job status.

I do NOT want two jobs to be processed simultaneously.

Original problem

Initially, I tried to create a chain where, after one job was completed, the automation would select the next queued job and change it to processing.

However, this sometimes resulted in two rows becoming processing almost simultaneously.

In other cases, the automation would process every other row and then stop.

If I removed the step that automatically started the next job, the jobs could be processed correctly one at a time, but of course the queue would no longer continue automatically.

So it appeared that self-triggering / chained automation was creating a race condition or overlapping execution.

Control table approach

To avoid the self-triggering problem, I created a separate single-row control table.

The Control table contains columns such as:

  • ControlKey
  • Lock
  • KickAt
  • LastJobID
  • CurrentJobID

The idea was to use this single Control row as a coordinator/lock.

The expected logic was:

  1. Scheduled Bot runs.
  2. Check whether any queued jobs exist.
  3. Select only the oldest/first queued job.
  4. Store its JobID in CurrentJobID.
  5. Change that job from queued to processing.
  6. Process the invoice.
  7. Change the job to done.
  8. Release the lock / update the Control row.
  9. Process the next job on a later scheduled execution.

The intention was that only the Control row could decide which job was allowed to run, preventing multiple invoice jobs from starting at the same time.

However, I am still seeing cases where two rows are created/processed instead of one.

I also tried limiting the selected rows

I tried using expressions based on TOP() / ORDERBY() so that only one queued row should be selected.

Conceptually, the selection is equivalent to:

TOP(
ORDERBY(
SELECT(
請求書一括[JobID],
[ステータス] = “queued”
),
[作成日時],
TRUE
),
1
)

The expectation is obviously that this expression can return only one JobID.

However, the duplicate/concurrent behavior has not been completely eliminated.

This makes me wonder whether the issue is not the SELECT expression itself, but rather two Scheduled Bot executions evaluating the queue before either execution has finished updating the status.

For example:

Execution A:
sees Job A as queued

Execution B:
also sees Job A as queued

Execution A:
starts processing

Execution B:
also starts processing

Or possibly both executions select different queued jobs before the Control/Lock update is committed.

Other approaches I tried

I also experimented with triggering another Bot by updating/adding a row to a relay/control table.

The idea was:

Scheduled Bot
→ update Control/Relay
→ Data Change Bot
→ process one job
→ update Relay again
→ process next job

However, this introduced another problem.

Bot-to-Bot/self-triggering behavior did not continue reliably, and when I tried using ADD ROW as a pulse/relay mechanism, I eventually encountered recursive execution behavior.

Therefore, I abandoned the Relay approach.

Current approach

I returned to a Scheduled Bot / polling approach because it seemed safer than recursive Bots.

The Scheduled Bot checks whether queued jobs exist and should process only a limited number of rows.

The basic condition is similar to:

COUNT(
SELECT(
請求書一括[JobID],
AND(
[ステータス] = “queued”,

ControlKey\] = \[\_THISROW\].\[ControlKey

)
)
) > 0

I have also tried using “Run a data action on a set of rows” and selecting only the first row using TOP(ORDERBY(…), 1).

But I am still unable to guarantee that only one row is created/processed.

Important observation

This does not look like a normal duplicate caused by the user editing the same row twice.

The problem occurs in Scheduled Automation.

The automation is specifically designed to select only one queued record.

Also, changing the selected row immediately from:

queued

to:

processing

was intended to prevent another execution from selecting the same row.

Nevertheless, I still occasionally get two rows / two processing operations.

My questions

  1. Can two executions of the same Scheduled Bot overlap in AppSheet?
  2. If execution A has selected a row but has not yet committed the status change from queued to processing, can execution B select the same row?
  3. Is there any true atomic locking mechanism in AppSheet Automation?
  4. Is a Boolean Lock column in a Control table actually safe for this purpose, or can two Bot executions both read Lock = FALSE before either writes TRUE?
  5. Is TOP(ORDERBY(…), 1) guaranteed to return/process exactly one row in a Scheduled Bot?
  6. Is there a recommended architecture for implementing a queue where exactly one job must be processed at a time?
  7. Could this be related to the Scheduled Bot / TOP() duplicate execution issue that other users have reported?

My main requirement is not simply to delete duplicate rows afterward.

I need to prevent two jobs from starting in the first place, because each job performs additional updates and PDF generation, so deleting a duplicate afterward is too late.

Ideally, I need something equivalent to an atomic operation:

“Claim the oldest queued job only if no other process has already claimed it.”

If AppSheet cannot guarantee this with Scheduled Bots, I would also like to know the recommended AppSheet-native design for this type of queue.

Thank you for any advice or examples.

Yes

Yes

No

No, yes

I would think so, in a scheduled bot or anywhere else. TOP(..., 1) should produce a list of no more than one element.

I’m not aware of an existing recommendation or convention. Attn @Suvrutt_Gurjar @WillowMobileSys @MultiTech

Hi @Steve ,

Thank you for referring.

I am too unaware of any recommendation or convention for the above.

However if @Yokada00661188 is willing for some workarounds and if he shares his precise implementation in more detail, we could possibly try to find any alternative implementation for his reported issue.

I am a bit confused about @Yokada00661188 's exact situation. When he says two rows are created, is the bot adding rows to a table or just creating PDFs from each row and possibly updating statuses of certain columns in that row when the PDF is generated? This is so because he mentioned below

Hi @Yokada00661188 ,

If you are willing for some workarounds for exploring solutions , could you

  1. Clarify the exact processing the scheduled bot(s) does/do. For example weekly daily , its event condition expression etc.
  2. Are there handful of rows to be processed in a single schedule or 100s of rows
  3. Will some delay do in this entire bot processing? For example if the bots are running at night , can the processing continue for a couple of hours.

I’m curious the specific reason to process these sequentially? It seems the calculated invoice data and resulting PDF should be completely independent from one Job ID to the next. If true, then there shouldn’t be an issue with taking advantage of AppSheet’s parallel processing.

Is there some sort of shared data rows from Job to Job?

Note that sequential processing within AppSheet is inherently slow due to the nature of the platform. This significantly reduces the number of Jobs you can process at one go in the automation. Additionally, the creation of a sequential process can be complicated and hard to maintain depending on your data structure. I would first advise to avoid it if at all possible.

@Steve Thank you for the clear answers.

I would like to clarify one important point.

I am not intentionally starting multiple executions of the Scheduled Bot.

In the latest run, the Audit History shows four Bot executions starting at almost exactly the same time (2026/09/30 22:13:07) for what is intended to be a single monthly scheduled operation.

Because all four executions start concurrently, they can all pass my duplicate-prevention condition before any one of them writes the “already processed” value.

So my question is slightly different from simply asking whether two executions can overlap:

Is it expected behavior for a single Scheduled Event to result in multiple concurrent Bot executions like this?

If yes, I understand that this is by design. But if not, could this be an AppSheet Automation bug?

My expected behavior is simply:

one scheduled monthly trigger → one Bot execution → one monthly process.

@Suvrutt_Gurjar Thank you very much for offering to help.

I think my previous explanation may have caused some confusion.

I am not trying to process hundreds of independent jobs sequentially. This is a monthly Scheduled Bot, and the monthly process should normally execute only once.

The Bot performs several steps, including:

  1. writing a value used to prevent duplicate execution,
  2. adding the required billing data,
  3. creating the invoice,
  4. generating/sending the related output,
  5. updating the processing status.

I tried preventing duplicate monthly execution with this condition:

ISBLANK(LOOKUP(TEXT(TODAY(), "YYYYMM"), "ツン毎月発火用テーブル", "ID", "ID"))

The Process then writes the current month near the beginning so that another execution should not run again.

However, the latest Audit History shows four executions starting at almost exactly the same time. Therefore, all four can evaluate the condition before the first execution writes the current month.

In answer to your questions:

  • This runs monthly.
  • The number of rows is relatively small, not hundreds.
  • Some delay is acceptable. I do not need high-speed parallel processing. Reliability and avoiding duplicate billing/PDF creation are much more important.

If there is a better architecture for implementing this monthly process in AppSheet, I would be very interested in your suggestion. I can also provide screenshots of the Event, Process and each Step if useful.

@WillowMobileSys Thank you. I think I did not explain this part clearly enough.

The issue is not primarily performance, and I am not intentionally trying to process a large queue sequentially.

The problem is that this is a single monthly operation, and duplicate concurrent executions can result in the same monthly billing process being performed more than once.

The Process does more than just generate independent PDFs. It also creates/updates billing-related rows and processing status. Therefore, if the same monthly operation starts concurrently before the duplicate-prevention value is committed, both executions may proceed with what is logically the same work.

In the latest case, the Audit History actually shows four Bot executions starting at almost exactly the same time.

So I am not trying to avoid AppSheet parallel processing for independent jobs. I am trying to prevent the same logical monthly operation from being started multiple times concurrently.

If each execution were guaranteed to represent a different independent Job ID, I agree that parallel processing would be preferable.

ISBLANK(
LOOKUP(
TEXT(TODAY(), “YYYYMM”),
“evrymonthtable”,
“ID”,
“ID”
)
)

Hi @Yokada00661188 ,

Could you clarify this a bit more? Are you basically trying to assign some sequential number to Job ID using AppSheet automation?
And is this your main issue that the automation is not creating a sequential number assignment to maybe invoice numbers?

Hi @Yokada00661188 ,
Thank you for sharing more details.

Yes that will be great if you can.

Also please clarify what you exactly mean by the following

In what way it is the same logical operation and why different rows being processed parallelly would be a concern for you?

I am sorry that in spite of extensive discussion, at least I am unable to exactly understand the core or pinpointed issue you are facing. I mean parallel processing is understood but why and where exactly it is causing issue is not clear.
Examples of specific issues would be

  1. The parallel processing is causing two identical invoices being created for the single record.
  2. The invoice numbers are getting duplicated.

No, this is not expected behavior. Consider reporting this to Support. There may have been something going on internally at the time.

Make sure you don’t have several copies of the bot configured in the app.

Do you have other copies of the app? Like, maybe a development copy, and a test/QA copy? If so, they would also be running the same bots unless you’ve specifically prevented it. Though, these would not show up in the same audit log.