Queries · q312 · Chief Information Security Officer · week 2, night 1
“For the two 'deletion-like' events on our financial documents that don't use soft-delete — a cancelled order, a voided invoice — is there any audit_log record at all tying back to that specific row?”
Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told
The manager, at the start of week 2
Subject: Re: Account security snapshot — good start, three gaps worry me more now
Noah,
This is a strong first week — thank you. The sign-in and access-governance findings give me confidence I can defend in a questionnaire. Three things genuinely surprised me and I want to understand them better before Friday's memo, plus one follow-up.
If we can only chase a couple of these deeply this week, I'd prioritize the deletion-audit scope (#1) and the churn-deactivation scope (#3) — those are the two a due-diligence team is most likely to ask us to prove, one way or the other.
Thanks, Henrik
The analyst · week 2, night 1, request 2 of 3
Henrik asked us to prioritize #1 (how wide is the deletion-audit gap) and #3 (how far does the churn-deactivation problem go) this week, so all 3 slots go there tonight. For #1, last week's 6-table sample (products at 0% coverage, users at 69%, three others with zero soft-deletes ever recorded) isn't enough to tell him whether this is "fix one thing" or "fix deletion logging everywhere" — so tonight I'm running a full census across every table that actually supports soft-deletion, not a hand-picked sample. I'm also addressing a gap in how I framed this last week: orders, invoices and other financial documents don't use deleted_at at all — they're "deleted" via a status change (cancelled/void), so testing audit coverage for the specific things Henrik named (orders, financial documents) needs a different query than soft-delete matching, which is report 2. For #3, last week I only checked role holders; tonight's report sizes the exposure across every access surface on churned tenants (user accounts, sessions, API keys, webhooks) so Henrik can judge whether this is a one-line fix (deactivate Owner/Admin) or a broader deprovisioning gap. I'm deliberately not touching #2 (shopper MFA compensating controls) or #4 (old-key sensitivity) tonight per his stated priority, and will pick those up once #1 and #3 are sized.
The engineer · 1 dry run on the empty schema, then the submission
SELECT 'order cancellations' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, COUNT(DISTINCT o.tenant_id) AS distinct_tenants FROM orders o WHERE o.status = 'cancelled' AND o.cancelled_at >= DATE '2023-01-01' AND o.cancelled_at < DATE '2026-01-01' UNION ALL SELECT 'invoice voids' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, COUNT(DISTINCT i.tenant_id) AS distinct_tenants FROM invoices i WHERE i.status = 'void' AND i.voided_at >= DATE '2023-01-01' AND i.voided_at < DATE '2026-01-01' ORDER BY entity_type
“Query compiles cleanly. Submitting.”
“Submitted. Summary for the record:
- Grain: one row per entity type (order cancellations, invoice voids).
- Logic: for each cancelled order / voided invoice, an EXISTS check against audit_log on (entity_table, entity_id, tenant_id), any action — matching the "looser than soft-delete" test requested.
- Date scoping: used orders.cancelled_at and invoices.voided_at bounded to 2023-01-01–2025-12-31, since those are the natural event timestamps for each deletion-like state.
- Caveat flagged in the note: a match only proves some audit trail exists for that row — not that the cancellation/void action itself was captured.”
As Noah Fischer saw it, from the small dataset the agents worked on
entity_type | total_events | events_with_match | coverage_rate_pct | distinct_tenants --------------------+--------------+-------------------+-------------------+----------------- invoice voids | 0 | 0 | NULL | 0 order cancellations | 1712 | 3 | 0.2 | 90 (2 rows)
The memo and the queries that followed; links found by title, so inferred
Later queries that build on this report:
It builds on:
Changed only where the benchmark needs the same result on every system
SELECT 'order cancellations' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) / NULLIF(COUNT(*), 0) AS coverage_rate_pct, COUNT(DISTINCT o.tenant_id) AS distinct_tenantsFROM orders oWHERE o.status = 'cancelled' AND o.cancelled_at >= DATE '2023-01-01' AND o.cancelled_at < DATE '2026-01-01'UNION ALLSELECT 'invoice voids' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) / NULLIF(COUNT(*), 0) AS coverage_rate_pct, COUNT(DISTINCT i.tenant_id) AS distinct_tenantsFROM invoices iWHERE i.status = 'void' AND i.voided_at >= DATE '2023-01-01' AND i.voided_at < DATE '2026-01-01'ORDER BY entity_typeORDER BY entity_type NULLS LAST
SELECT 'order cancellations' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) AS events_with_match, 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) / NULLIF(COUNT(*), 0) AS coverage_rate_pct, COUNT(DISTINCT o.tenant_id) AS distinct_tenants FROM orders o WHERE o.status = 'cancelled' AND o.cancelled_at >= DATE '2023-01-01' AND o.cancelled_at < DATE '2026-01-01' UNION ALL SELECT 'invoice voids' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) AS events_with_match, 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) / NULLIF(COUNT(*), 0) AS coverage_rate_pct, COUNT(DISTINCT i.tenant_id) AS distinct_tenants FROM invoices i WHERE i.status = 'void' AND i.voided_at >= DATE '2023-01-01' AND i.voided_at < DATE '2026-01-01' ORDER BY entity_type NULLS LAST
The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted
Report request from Noah Fischer (analyst for the Chief Information Security Officer): Title: Audit traceability of order cancellations and invoice voids Question: For the two 'deletion-like' events on our financial documents that don't use soft-delete — a cancelled order, a voided invoice — is there any audit_log record at all tying back to that specific row? Grain: one row per entity type: 'order cancellations' and 'invoice voids' Columns: - entity type - total events (all-time, 2023-01-01 to 2025-12-31) - events with at least one matching audit_log row (any action, entity_table + entity_id match) - coverage rate (%) - distinct tenants represented Details: Row 1: orders where status = 'cancelled'. For each such order, check whether any audit_log row exists with entity_table = 'orders' and entity_id = orders.id (any action, not just 'delete', since the logged action type for a cancellation isn't known in advance). Row 2: invoices where status = 'void'. Same existence check against audit_log with entity_table = 'invoices' and entity_id = invoices.id. coverage_rate = events with a match / total events, rounded to 1 decimal percent. This is a looser test than the soft-delete report (any audit row at all for that record, not specifically a 'delete' action) — flag in the report notes that even a 100% match here wouldn't confirm the cancellation/void itself was logged, only that the record has some audit trail presence. Check your query with the warehouse's dry_run tool, then hand it in with submit.
dry_runSELECT 'order cancellations' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, COUNT(DISTINCT o.tenant_id) AS distinct_tenants FROM orders o WHERE o.status = 'cancelled' AND o.cancelled_at >= DATE '2023-01-01' AND o.cancelled_at < DATE '2026-01-01' UNION ALL SELECT 'invoice voids' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, COUNT(DISTINCT i.tenant_id) AS distinct_tenants FROM invoices i WHERE i.status = 'void' AND i.voided_at >= DATE '2023-01-01' AND i.voided_at < DATE '2026-01-01' ORDER BY entity_type
STATUS: COMPILES (dry run on the empty schema, no data read) COLUMNS: entity_type, total_events, events_with_match, coverage_rate_pct, distinct_tenants
submitSELECT 'order cancellations' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'orders' AND al.entity_id = o.id AND al.tenant_id = o.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, COUNT(DISTINCT o.tenant_id) AS distinct_tenants FROM orders o WHERE o.status = 'cancelled' AND o.cancelled_at >= DATE '2023-01-01' AND o.cancelled_at < DATE '2026-01-01' UNION ALL SELECT 'invoice voids' AS entity_type, COUNT(*) AS total_events, COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) AS events_with_match, ROUND( 100.0 * COUNT(*) FILTER ( WHERE EXISTS ( SELECT 1 FROM audit_log al WHERE al.entity_table = 'invoices' AND al.entity_id = i.id AND al.tenant_id = i.tenant_id ) ) / NULLIF(COUNT(*), 0), 1 ) AS coverage_rate_pct, COUNT(DISTINCT i.tenant_id) AS distinct_tenants FROM invoices i WHERE i.status = 'void' AND i.voided_at >= DATE '2023-01-01' AND i.voided_at < DATE '2026-01-01' ORDER BY entity_type
Submitted to tonight's batch. Your work on this request is done.