Skip to content

fix(audit): preserve viewer events with independent listeners - #1788

Closed
zack-dev-cm wants to merge 1 commit into
rohitg00:mainfrom
zack-dev-cm:fix/1741-audit-listeners
Closed

zack-dev-cm wants to merge 1 commit into
rohitg00:mainfrom
zack-dev-cm:fix/1741-audit-listeners

Conversation

@zack-dev-cm

@zack-dev-cm zack-dev-cm commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

A second audit consumer currently replaces the viewer listener, and registering the viewer replaces an earlier consumer. Add independent addAuditListener / removeAuditListener subscriptions while preserving the legacy setter and its callback type.

Listeners run once per function after the existing entry and month-index writes. Dispatch uses a snapshot: legacy callback first, then independent registration order. Listener changes during dispatch take effect on the next entry. Synchronous throws and rejected promises are isolated without awaiting callback completion. The existing viewer wiring remains unchanged.

Refs #1741, part 1. Sinks, backfill export, configuration and export payload/deletion policy remain separate work. Listener delivery is best effort within the process.

Validation:

  • Two real recordAudit / viewer coexistence failures on cf9, with two positive controls; the same four controls pass after the change.
  • 25 listener cases plus 71 existing audit/viewer checks: 96 passed. Covers lifecycle, dispatch mutation, pending/rejected callbacks, persistence failures and legacy value-returning callbacks.
  • Required build, skill generation, documentation sync/checks, full tests and evaluation typecheck passed in order. Generators changed no files.
  • Full suite: 4,956 passed, seven skipped. This uses a child-process-only DNS fixture for eight test peer domains. Focused tests use SDK/KV transport doubles.
  • The same legacy TypeScript caller compiles against cf9 and the final source. The broader test-root check retains exactly the baseline's 18 diagnostics, with no new errors; this is not a whole-project typecheck pass.

Summary by CodeRabbit

  • New Features

    • Added support for multiple audit listeners alongside the existing replaceable listener. Listeners are notified after an audit entry is successfully recorded.
    • Added options to register and remove listeners.
  • Documentation

    • Clarified listener ordering, delivery behavior, and how callback failures and persistence failures are handled.

Signed-off-by: zack-dev-cm <112114097+zack-dev-cm@users.noreply.github.com>
@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

@zack-dev-cm is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The audit module now supports multiple independent listeners alongside its replaceable legacy listener. It dispatches listener callbacks after audit entry and month-index persistence, and adds documentation and tests for listener lifecycle, callback failures, and persistence boundaries.

Changes: Audit Listener API

Layer / File(s) Summary
Listener registration and lifecycle
src/functions/audit.ts, docs/audit-listeners.md, test/audit-listeners.test.ts
The module exports the AuditListener type and functions to add and remove independent listeners. The documentation and tests cover coexistence with the legacy listener, ordering, subscription changes, and viewer integration.
Post-persistence dispatch
src/functions/audit.ts, test/audit-listeners.test.ts
recordAudit snapshots and invokes listeners after persistence succeeds. Tests cover callback failures, persistence failures, dispatch timing, and already-indexed months.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant recordAudit
  participant AuditStorage
  participant RegisteredListeners
  recordAudit->>AuditStorage: Persist audit entry and month index
  AuditStorage-->>recordAudit: Persistence completes
  recordAudit->>RegisteredListeners: Snapshot and invoke listeners
Loading

Suggested reviewers: rohitg00

Merge Risk: Minimal · up to 5f06a

This adds independent audit listeners without replacing the existing viewer callback, and delivery happens only after the audit entry and month index are written. Delivery is best effort within the process, as the PR states. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: audit viewer events are preserved while independent audit listeners are added. The raw summary shows new addAuditListener and removeAuditListener functions, the AuditL…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: audit viewer events are preserved while independent audit listeners are added. The raw summary shows new addAuditListener and removeAuditListener functions, the AuditListener type, and a legacy setter kept in place, so the title matches the changeset's primary purpose. The title is a single, concise sentence in conventional-commit form, with no file lists or vague wording.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 907b28af-a5ff-4b2e-b228-38ee3bf2aaf6
Commits

Reviewing files that changed from the base of the PR and between cf9a738 and 5f06a98.

Files selected for processing: 3

  • docs/audit-listeners.md
  • src/functions/audit.ts
  • test/audit-listeners.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@rohitg00

Copy link
Copy Markdown
Owner

Merged as part of #1811, which kept your commits and added review fixes on top (details in its description). Thanks for the contribution.

@rohitg00 rohitg00 closed this Nov 18, 2026
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