Fix UNIQUE constraint on events.sequence during concurrent tool calls#139
Open
alexgorbatchev wants to merge 1 commit intobenjitaylor:mainfrom
Open
Conversation
…P tool calls When multiple MCP tool calls (e.g. dismiss, resolve) are invoked concurrently, the sequence counter could collide because emit() assigned the sequence and notified SSE subscribers before persisting to SQLite. This restructures the flow to persist first (with retry on UNIQUE violation), then notify subscribers, ensuring SSE clients always see the correct, persisted sequence number. Fixes benjitaylor#138 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@alexgorbatchev is attempting to deploy a commit to the Benji Taylor's Projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UNIQUE constraint failed: events.sequenceto gracefully handle any remaining edge casesnextSequence()andnotify()methods toEventBusso SQLite-backed stores can persist before distributingChanges
events.ts: Splitemit()intonextSequence()+notify()building blocks.emit()still works as before for non-persisted events (in-memory store, action.requested).sqlite.ts: ReplaceeventBus.emit() → persistEvent()pattern withemitAndPersist()which: assigns sequence → inserts into DB → notifies subscribers. Same for tenant store.How it fixes the bug
Previously:
eventBus.emit()— incrementsglobalSequence, notifies SSE subscriberspersistEvent()— inserts into SQLiteNow:
emitAndPersist()— increments sequence, inserts into SQLite, then notifies SSE subscribersThis ensures the sequence number in the database always matches what SSE subscribers receive, and concurrent inserts can't produce duplicates.
Fixes #138
Test plan
pnpm buildinmcp/)UNIQUE constraint failederrors🤖 Generated with Claude Code