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 PENDING insert is durably recorded as a FAILED document_track row; but the underlying audit event is permanently lost for automatic reprocessing, and a failure occurring before the PENDING insert even succeeds (e.g. Mongo briefly unavailable) leaves no row at all.
  • Affected component: document-service’s message_receiver/document_audit_receiver.rs, built on the shared rust_lang_core_lib::pubsub receiver.
  • 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 unconditional defer msg.Ack() (no nack/retry path)” — confirmed by the code, which calls message.ack().await unconditionally after the handler completes regardless of outcome. document-service/src/src/message_receiver/document_audit_receiver.rs only logs (tracing::error!) a process_audit_event failure — it never nacks or requeues. development/firebase/functions/init/init-pubsub.js’s document-audit topic/subscription entry (lines 236–242) also carries no retryPolicy, ackDeadlineSeconds, or deadLetterPolicy, unlike the migration pipeline’s subscriptions in the same file. This is a deliberate, documented design choice — document-service/CLAUDE.md states the document_track row’s FAILED status 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 left FAILED (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_track row for it stays FAILED forever (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-drives document_track rows stuck in FAILED (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’s repository/documenttrack/documenttrack_rep_impl.rs (Mongo document_track collection) and repository/documentstorage/ (GCS STORAGE_DOCUMENT_BUCKET objects).
  • Evidence: documenttrack_rep_impl.rs’s ensure_indexes creates exactly one index — a unique compound index on (tenant_id, service_name, transaction_name, transaction_id) for idempotency — no expireAfterSeconds TTL index exists alongside it. No delete/cleanup method exists on the GCS storage repository (upload-only). No bucket lifecycle rule, no RETENTION_DAYS/TTL_DAYS-shaped env var, and no scheduled cleanup job exists anywhere in document-service’s source or CLAUDE.md. The word “retention” does not appear anywhere in the service today.
  • Impact: every audit record — masked JSON in GCS plus its document_track row — 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 from date_time or created_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