fix(sla): defer SLA audit events until after transaction commit - #245
Merged
usmanimamu17-create merged 1 commit intoAug 18, 2026
Merged
Conversation
SLA audit events were logged inside compute_device_sla() before the caller's transaction committed. If the commit failed, the audit log would contain records for a computation that never persisted. - Removed audit_event logging from compute_device_sla() for the success path (both no-outages and with-outages branches). - Added audit logging to the Celery task caller in sla_tasks.py AFTER _mark_success() commits the transaction. - Kept the exception-handler audit log inside compute_device_sla() since failures are independent of transaction state. - Added tests verifying compute_device_sla() never emits audit events and that record_sla_settlement_audit_events still works correctly. Closes ApexChainx#236
Magrexy
force-pushed
the
fix/issue-236-audit-events-after-commit
branch
from
August 18, 2026 15:57
ffc384b to
0d3e0fe
Compare
usmanimamu17-create
approved these changes
Aug 18, 2026
usmanimamu17-create
left a comment
Contributor
There was a problem hiding this comment.
LGTM. thanks for contributing.
3 tasks
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
Closes #236
Why
SLA audit events were logged inside
compute_device_sla()before the caller's transaction committed. Since the audit log uses its own database session, these events were persisted immediately — even if the SLA computation failed to commit. This left orphaned audit records describing work that never occurred.What was built
app/services/sla_service.pyrecord_sla_settlement_audit_events()calls from the success path ofcompute_device_sla()(both no-outages and with-outages branches). The exception-handler audit log for failures is kept since failures are independent of transaction state.app/tasks/sla_tasks.pyrecord_sla_settlement_audit_events()calls after_mark_success()— the point where the SLA computation is committed to the database.tests/test_sla_audit_deferred.pycompute_device_sla()never emits audit events, verifies the failure path still logs, and smoke-tests therecord_sla_settlement_audit_events()helper.Integration changes outside
<module>/No new env vars, feature flags, or imports introduced. Existing
record_sla_settlement_audit_events()function signature is unchanged.Acceptance criteria coverage
sla_tasks.pyafter_mark_success())compute_device_sla())compute_device_sla()never emits audit events directly (test_no_outages_does_not_emit_audit,test_with_outages_does_not_emit_audit)Deliberately deferred
compute_device_sla()remains inside the function — this is intentional since it doesn't depend on transaction stateTest plan
pytest tests/test_sla_audit_deferred.py -v— 6/6 passingEnv vars / Notes
No new env vars. No migration required.