Skip to content

Enforce transactional audit on backend mutations - #228

Merged
kmandryk merged 9 commits into
developfrom
AI-1148
Jul 7, 2026
Merged

Enforce transactional audit on backend mutations#228
kmandryk merged 9 commits into
developfrom
AI-1148

Conversation

@kmandryk

@kmandryk kmandryk commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Refactors backend mutation flows to use Prisma transactions where multiple writes must stay consistent, and propagates tx through services/db-services (including AuditService and AuditLogService) so audit rows can participate atomically. Adds missing mutation audit events across API keys, workflows, benchmark promotion/apply flows, and HITL/session actions; updates related tests and documents the transaction/audit rules plus compliance status in docs-md.

Summary

AI-1148

Changes

Testing

Checklist

By submitting this pull request, I acknowledge that I have attempted to meet the following:

  • a self-review of my code
  • commented code particularly in hard-to-understand areas
  • corresponding changes to the documentation where required
  • changes tested to the best of my ability
  • no new errors or non-functional code

Refactors backend mutation flows to use Prisma transactions where multiple writes must stay consistent, and propagates `tx` through services/db-services (including `AuditService` and `AuditLogService`) so audit rows can participate atomically. Adds missing mutation audit events across API keys, workflows, benchmark promotion/apply flows, and HITL/session actions; updates related tests and documents the transaction/audit rules plus compliance status in `docs-md`.
kmandryk added 4 commits July 3, 2026 13:27
Remove explicit `content_hash: null` assignments when creating documents so the model relies on the current document shape/defaults, and align related service/spec code with that change. The rest of the diff is mostly import ordering and formatting cleanup around audit logging, transactions, and service test setup.
Comprehensive audit coverage pass across training, dataset, benchmark, classifier, confusion-profile, template-model, HITL, document upload/update, and workflow delete. Also fixes multi-write paths that were missing Prisma transactions (benchmark definition revision, run delete, ground-truth job start/processJob, template-model labels/upload, hitl-dataset version creation). Updates AUDIT.md with new event-type tables and marks all rescan items as done in TRANSACTION_AND_AUDIT_AUDIT.md.
Adds missing mutation auditing for benchmark schedule configuration and workflow head reversion, including wiring actor identity through the controller/service path. Also wraps Temporal OCR result upsert + document status update in a single Prisma transaction to keep writes consistent, updates related tests for transaction mocking, and documents the new audit events and compliance status.
Adjusted backend and temporal tests to match updated method signatures that now pass actor/user IDs through controllers and services. Also updated audit-log service expectations to include the optional transaction argument (`undefined`) and applied minor formatting cleanup in the OCR upsert test.

@dbarkowsky dbarkowsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major concerns.
In some cases, I noticed the actorId was optional. Are we okay to accept audit records with a null actor?

Comment thread apps/backend-services/src/actor/api-key.service.ts Outdated
@kmandryk

kmandryk commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

No major concerns. In some cases, I noticed the actorId was optional. Are we okay to accept audit records with a null actor?

Null actor_id is intentional only for system-initiated actions (e.g. training poller). For user-facing mutations, AuditService now backfills actor_id from request context when not passed explicitly

kmandryk added 4 commits July 7, 2026 10:01
AuditService now falls back to `requestContext.actorId` when `actor_id` is not provided, ensuring user-initiated events keep actor attribution. Tests were updated to cover context fallback and explicit-actor precedence. API key deletion was simplified by removing a redundant second not-found check after the initial lookup, and AUDIT docs now clarify that `actor_id` should be null only for system-initiated actions with no HTTP identity.
@kmandryk
kmandryk merged commit 0428d12 into develop Jul 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants