imbajin commented on code in PR #439:
URL: https://github.com/apache/hugegraph-ai/pull/439#discussion_r4658201641
##########
ontogeny/server/ontogeny/api/routes_objects.py:
##########
@@ -203,18 +204,34 @@ async def execute_action(
started = time.perf_counter()
from ..errors import PolicyDeniedError, RuleRejectedError
- async with sc.sessionmaker() as s:
+ # Keep same-key executions serialized until the revision is committed;
+ # exiting the session first also rolls back failures before unlocking.
+ async with (
+ sc.runtime.idempotency_guard(action_name, principal,
body.idempotency_key),
+ sc.sessionmaker() as s,
+ ):
try:
- rev = await sc.runtime.execute(
- s,
- action_name,
- principal,
- body.parameters,
- body.target_id,
- expected_revision=body.expected_revision,
- idempotency_key=body.idempotency_key,
- )
- await s.commit()
+ try:
+ rev = await sc.runtime.execute(
+ s,
+ action_name,
+ principal,
+ body.parameters,
+ body.target_id,
+ expected_revision=body.expected_revision,
+ idempotency_key=body.idempotency_key,
+ )
+ await s.commit()
+ except IntegrityError:
Review Comment:
**⚠️ Resolve action conflicts from concurrent workers**
The guard is process-local, so two workers can both miss the initial replay
lookup. If one commits a create before the other reaches `action_insert`'s
alive-row check, that check raises `ConflictError` before the revision insert;
this handler catches only `IntegrityError`, so the retry returns 409 instead of
the committed revision. Please coordinate the key across workers or recheck the
committed revision after rolling back an action-level conflict, and cover this
interleaving with two independent service contexts. This race follows from
source inspection; I did not reproduce it in a multi-process deployment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]