auth: fix lack of atomicity in ConversationService.finish (#102) - #153
Open
BKJN1 wants to merge 1 commit into
Open
auth: fix lack of atomicity in ConversationService.finish (#102)#153BKJN1 wants to merge 1 commit into
BKJN1 wants to merge 1 commit into
Conversation
Contributor
🤖 Augment PR SummarySummary: This PR makes OAuth conversation completion atomic to avoid losing a completed authorization flow after a partial database failure. Changes:
🤖 Was this summary useful? React with 👍 or 👎 |
BKJN1
force-pushed
the
fix/102-conversation-finish-atomicity
branch
2 times, most recently
from
August 8, 2026 06:47
4f6d45c to
254b6a5
Compare
Collaborator
Author
|
augment review |
BKJN1
force-pushed
the
fix/102-conversation-finish-atomicity
branch
from
August 8, 2026 09:44
254b6a5 to
ca59ab8
Compare
Collaborator
Author
|
augment review |
Collaborator
Author
|
@goshacodes |
Member
|
Conflicts, leave as is for now, fix it later |
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.
closes #102
Problem
In
ConversationService.finish, the conversation was deleted from the DB, then theauthorization code and the session were created via two separate repository calls with no
shared transaction. If
deletesucceeded but eithercreatefailed (transient DB error, rarecollision), the conversation was gone but no code/session existed — an unrecoverable
IllegalStatefor the user, with no way to retry.Fix
Introduced
ConversationFinalizer, a narrow interface with a singlefinish(...)method thatperforms delete-conversation + create-authorization-code + create-session as one unit.
PostgresConversationFinalizerimplements it with all three writes inside a singlexa.transactMeasuredblock, so they commit or roll back together — mirroring themulti-statement transaction pattern already used in
PostgresSessionRepository(
invalidateByUserId,invalidate,create).ConversationRepository,AuthorizationCodeRepository, andSessionRepositoryare unchanged;ConversationServiceno longer depends on the latter two directly (they were only used insidefinish).Changes
ConversationFinalizer(trait) andPostgresConversationFinalizer(impl).PostgresConversationFinalizerSpec— DB-backed test covering:the conversation delete is rolled back (not silently lost).
ConversationService.finishnow callsconversationFinalizer.finish(...)once instead ofdelete→create→create. Public signature unchanged, no caller impact.PostgresOAuthAppwiresPostgresConversationFinalizer.liveinto the layer graph.ConversationServiceSpecupdated for the new dependency; added a test forfinishreportingfalse→IllegalState.