ZhYQ1 commented on code in PR #439:
URL: https://github.com/apache/hugegraph-ai/pull/439#discussion_r4658496183
##########
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:
+ # The per-key lock only serializes one process. When
another
+ # worker wins the same key, roll back and resolve the
winner's
+ # committed revision instead of surfacing a 500.
+ if not body.idempotency_key:
+ raise
+ await s.rollback()
+ rev = await sc.runtime.await_committed_revision(s,
action_name, principal, body.idempotency_key)
Review Comment:
Fixed in bdc02a3.`await_committed_revision()` now also looks the key up
without its scope (`_find_revision_by_key` ), matching`uq_revision_idem` . A
key owned by another action/principal, or a same-scope revision with a
non-`executed` outcome, raises`ConflictError` immediately instead of polling
the scoped lookup. Covered by`test_foreign_scope_key_conflict_is_prompt_409`
(409, owner in message, < 1s).
##########
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:
Fixed in bdc02a3. The route now also catches`ConflictError`
from`action_insert` 's alive-row guard: it rolls back and re-reads the
committed revision for the same key, replaying it when present and preserving
the 409 for genuine conflicts.
Added`test_cross_worker_same_key_replays_committed_revision` , which uses two
independent`ServiceContext` s with separate runtimes and lock registries,
forces both initial replay lookups to miss, and asserts both requests return
200 with the same revision and a single revision row.
--
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]