Fix race condition in bot_registry create_bot() and enqueue_update() #17
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dinoxim/dinox!17
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "copilot/request-code-review"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
create_bot()andenqueue_update()retrieve the new row ID via a separate SELECT after INSERT. Under concurrent requests, a different INSERT can interleave, returning the wrong ID — causing token assignment to the wrong bot.InsertBuilder.perform()already returnslast_insert_rowid()atomically; the return value was simply being discarded.perform()return value directly instead of post-INSERT SELECT query, in bothcreate_bot()andenqueue_update()✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Pull request overview
Fixes a concurrency hazard in the bot-features plugin by returning SQLite’s per-connection last inserted row ID directly from
InsertBuilder.perform()instead of doing a separate post-INSERTSELECTto discover the new row ID.Changes:
BotRegistry.create_bot()to use theInsertBuilder.perform()return value as the new bot ID.BotRegistry.enqueue_update()to use theInsertBuilder.perform()return value as the new update ID.Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
INSERTlookup patterns; returns theperform()-reported row ID for new bots and queued updates.💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
InsertBuilder.perform()logs on SQLite failure but still returnsdb.last_insert_rowid(). With the new logic, if this INSERT fails (e.g.,bot.token_hashis declaredUNIQUEand several callers pass an empty string),create_bot()may return a stale ID from a previous successful INSERT, causing follow-up token assignment/logging to target the wrong bot. Consider making insert failure explicit here (e.g., validate the inserted row exists fornew_bot_idand/or change the API to throw/return an error whenperform().step()is notDONE).Same issue as
create_bot():perform()returnslast_insert_rowid()even if the INSERT fails. If the insert intoupdate_queueerrors (DB locked, constraint/migration issue, etc.), this method will return a stale update ID, and callers may treat it as the newly enqueued update. Please add a success check / error signaling path rather than unconditionally casting and returning the ID.