Technical Debt — Document Service Audit Trail Gaps
By Engineering Team•September 24, 2026•4 min read
| Metadata | Details |
|---|---|
| System | Document Service — Centralized Audit Trail Sink |
| Document ID | TD-2026-AUDIT-001 |
| Author | Engineering Team |
| Status | Open |
This document tracks known implementation gaps in the audit-trail sink as first-class, ongoing debt items — not as a passing “not implemented” note inside the requirements or architecture docs. SR-002 and the architecture doc link here rather than restating the gap detail.
TD-01 — Failed audit-event processing is never retried; the Pub/Sub receiver acks unconditionally
- Status: Open
- Severity: Medium — no impact on a publisher’s own RPC/webhook response (NFR-01 holds, since publishing is fire-and-forget), and a failure that occurs after the
PENDINGinsert is durably recorded as aFAILEDdocument_trackrow; but the underlying audit event is permanently lost for automatic reprocessing, and a failure occurring before thePENDINGinsert even succeeds (e.g. Mongo briefly unavailable) leaves no row at all. - Affected component:
document-service’smessage_receiver/document_audit_receiver.rs, built on the sharedrust_lang_core_lib::pubsubreceiver. - Evidence:
rust-lang-core-lib/src/src/pubsub/receiver.rs(~lines 66–97) carries its own doc comment stating the message is “always acked once the handler returns, even on handler or parse failure, matching Go’s unconditionaldefer msg.Ack()(no nack/retry path)” — confirmed by the code, which callsmessage.ack().awaitunconditionally after the handler completes regardless of outcome.document-service/src/src/message_receiver/document_audit_receiver.rsonly logs (tracing::error!) aprocess_audit_eventfailure — it never nacks or requeues.development/firebase/functions/init/init-pubsub.js’sdocument-audittopic/subscription entry (lines 236–242) also carries noretryPolicy,ackDeadlineSeconds, ordeadLetterPolicy, unlike the migration pipeline’s subscriptions in the same file. This is a deliberate, documented design choice —document-service/CLAUDE.mdstates thedocument_trackrow’sFAILEDstatus is “the durable record of a failure, not a redelivery retry” — not an oversight; but no automated re-drive/reprocessing path exists for a row leftFAILED(or missing entirely). - Impact: A transient failure (a brief Mongo or GCS outage at the moment one specific audit event is processed) permanently drops that one compliance record — the
document_trackrow for it staysFAILEDforever (or is never created), with no built-in mechanism to retry or replay it, unlike a typical at-least-once Pub/Sub consumer that nacks on failure. - Remediation direction: Either (a) explicitly nack on a retryable failure so GCP Pub/Sub’s own redelivery can retry it — this would change
spawn_pubsub_receiver’s ack-unconditionally contract, a behavior shared by every Rust and Go Pub/Sub receiver in this monorepo, not just this one, so evaluate the blast radius across all consumers before changing it centrally; or (b) build a small reconciliation job that periodically re-drivesdocument_trackrows stuck inFAILED(or reconciles against each publisher’s own source-of-truth) by re-requesting the original request/response — whichever is cheaper given how rarely this path is actually expected to trigger. - Related requirement: SR-002 NFR-02
TD-02 — No data retention policy for document_track rows or their GCS objects
- Status: Open
- Severity: Medium — no functional impact today, but unbounded storage growth and an open compliance question: PII/PCI-adjacent audit records (already masked, but still tenant/transaction-identifying) persist forever with no policy-driven expiry, which most audit-trail compliance regimes (e.g. a fixed N-year retention window) require to be bounded, not indefinite.
- Affected component:
document-service’srepository/documenttrack/documenttrack_rep_impl.rs(Mongodocument_trackcollection) andrepository/documentstorage/(GCSSTORAGE_DOCUMENT_BUCKETobjects). - Evidence:
documenttrack_rep_impl.rs’sensure_indexescreates exactly one index — a unique compound index on(tenant_id, service_name, transaction_name, transaction_id)for idempotency — noexpireAfterSecondsTTL index exists alongside it. No delete/cleanup method exists on the GCS storage repository (upload-only). No bucket lifecycle rule, noRETENTION_DAYS/TTL_DAYS-shaped env var, and no scheduled cleanup job exists anywhere indocument-service’s source orCLAUDE.md. The word “retention” does not appear anywhere in the service today. - Impact: every audit record — masked JSON in GCS plus its
document_trackrow — is retained indefinitely by default. Storage cost grows unbounded with traffic, and there is no way to honor a tenant- or regulator-driven “delete audit data older than N years” requirement without a manual, ad hoc purge. - Remediation direction: decide the actual retention window per tenant/compliance regime first (a product/compliance decision, not a technical one), then implement it as either (a) a Mongo TTL index on
document_track(expireAfterSeconds, computed fromdate_timeorcreated_at) paired with a corresponding GCS Object Lifecycle Management rule on the audit bucket keyed off object age, or (b) a scheduled reconciliation job that deletes both the GCS object and its tracking row together, since the two must stay in sync — a lone Mongo TTL index would silently orphan the still-live GCS object. - Related requirement: SR-002 NFR-07