ZhYQ1 opened a new pull request, #439:
URL: https://github.com/apache/hugegraph-ai/pull/439
## Location
`ontogeny/server/ontogeny/action/runtime.py` — `ActionRuntime.execute`
idempotency block;
`ontogeny/tests/test_action.py` — regression coverage.
## Problem (Closes #437)
Bug: on SQLite, concurrent requests with the same
`(action, principal, idempotency_key)` are not serialized (SQLite has no
advisory lock), so the idempotency contract is broken.
### Expected
Same-key concurrent requests execute the side effects once and all return the
same committed revision.
### Actual
All callers can observe "revision not found" before any caller commits, then
each
executes the effects and inserts a revision, hitting the unique index:
- `UNIQUE constraint failed: ontogeny_revision.idempotency_key` -> uncaught
`IntegrityError` -> HTTP 500
- effect writes may also collide, e.g.
`UNIQUE constraint failed: ontogeny_obj_production_order.order_id,
_valid_from`
- under multi-connection writes SQLite can additionally return `SQLITE_BUSY`
### Impact
Idempotent retries both fail (500) and may duplicate side effects, so clients
cannot safely retry actions.
## Fix
- Add `_key_locks: dict[tuple[str, str, str], asyncio.Lock]` to
`ActionRuntime`,
keyed by `(action, principal, idempotency_key)`.
- In `execute`, when a key is supplied, acquire the per-key lock (lazily
created)
before the replay lookup; wrap the body in `try/finally` to always release.
- Calls without a key are unaffected; the unique index stays as the final
backstop for multi-process writers.
--
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]