Repository navigation
Hardening: expose audit producer failures and document semantics - #3
Conversation
Centralize best-effort audit emission with structured failure logging and Prometheus producer metrics. Emit create, update, and delete audit events consistently, add regression coverage, and document the exact failure semantics for producer appends, stream recovery, cache degradation, Bloom idempotency, and search.
Reviewer's GuideIntroduces a shared, observable audit producer for create/update/delete operations—including the previously missing delete event—while retaining non-transactional asynchronous HTTP semantics, and adds documentation and tests that make the resulting failure and delivery guarantees explicit. Sequence diagram for best-effort audit emission after item writessequenceDiagram
participant Client
participant Handler
participant ItemRepo
participant AuditEmitter
participant RedisStreams
participant AuditWorker
Client->>Handler: HTTP create/update/delete
Handler->>ItemRepo: Create/Update/Delete
ItemRepo-->>Handler: Successful item write
Handler-)AuditEmitter: EmitAsync(created/updated/deleted)
Handler-->>Client: HTTP success
AuditEmitter->>AuditEmitter: Emit
AuditEmitter->>RedisStreams: Append
alt append succeeds
RedisStreams-->>AuditEmitter: event_id
AuditEmitter-->>AuditEmitter: RecordAuditEmit success
RedisStreams-)AuditWorker: XREADGROUP
AuditWorker->>RedisStreams: XACK
else append fails or times out
RedisStreams-->>AuditEmitter: error
AuditEmitter-->>AuditEmitter: RecordAuditEmit error
AuditEmitter-->>AuditEmitter: structured failure log
end
State diagram for audit event delivery semanticsstateDiagram-v2
[*] --> ItemWrite
ItemWrite --> Scheduled: EmitAsync
Scheduled --> AppendAttempt: Emit
AppendAttempt --> LostBeforeRedis: append error or 5s timeout
AppendAttempt --> Appended: Append succeeds
Appended --> Processing: XREADGROUP
Processing --> Acknowledged: processing succeeds and XACK
Processing --> Pending: processing or ACK fails
Pending --> Processing: XAUTOCLAIM recovery
Processing --> Processing: crash before XACK
LostBeforeRedis --> [*]
Acknowledged --> [*]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the asynchronous emitter or handler wiring is wrong, item writes can succeed without a corresponding audit event, and that audit history cannot be recovered by reverting the change. The impact is limited to bounded gaps in the best-effort audit stream; reverting restores the previous producer implementation but cannot recreate events already missed.
Summary
This is the next two-part RedisForge P0 hardening pass after the Streams recovery and hot-path/Testcontainers PRs.
1. Producer-side audit observability and consistency
internal/auditXADDfailsaudit_events_emitted_total{action,status}andaudit_emit_latency_ms{action,status}Prometheus metricsevent_id,item_id,action, and error fieldsdeletedaudit action but emitted no event2. Explicit failure-semantics documentation
Add
docs/failure-semantics.mdand align the README/docs with the real system contract:XADD: producer delivery is best effort; successful item writes can exist without an audit eventXADD: consumer recovery is at least once, so duplicate processing is possibleAudit finding
The adjacent write-path audit found that
DELETE /v1/items/{id}did not emit an audit event at all, even though the domain model and metrics already listeddeletedas a valid audit action. This PR fixes that mismatch without changing HTTP success semantics.Verification
The final pre-squash tree passed:
The branch is squashed to one commit. CI will run again on the exact PR SHA.
Important remaining limitation
This PR makes producer-side failure visible; it does not turn audit emission into a transactional outbox. Producer appends remain asynchronous and best effort, with no durable retry queue or shutdown drain. That limitation is now explicit and measurable rather than silent.
Summary by Sourcery
Harden audit observability and make RedisForge's failure and delivery semantics explicit.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: