Skip to content

Audit log: consistent writes and correlation with PoliNetwork Auth #120

Open

Description

@toto04

Follow-up to #90. The audit log is written on a best-effort basis, and its events can't yet be matched with what PoliNetwork Auth records. Volume is low, so none of this is urgent. These are known gaps to close before anyone relies on the log as evidence.

Consistency

  • Events are written after the handler, outside its transaction, and a failed write is only logged. For changes made in the database, write the event in the same transaction (an outbox, or an AuditSink passed to the services like their other dependencies). For external side effects (Azure, Telegram, Auth), record the attempt and then its outcome.
  • The before-state is read outside the update's transaction in most handlers (web.*, wa.groups, tg.groups, groups.labels), so concurrent writes can make it wrong. Read it in the same transaction with SELECT … FOR UPDATE, or with a CTE that returns the old row.

Correlation with PoliNetwork Auth

  • Every event now has a request_id, one per HTTP request. Send it to PoliNetwork Auth with the role commands People makes (assign, unassign, unlink), so a dashboard action can be matched with the IdP's audit event that it caused.
  • Optionally, accept an incoming X-Request-Id from the dashboard and the bot, so one id covers the whole chain.

Coverage outside tRPC (a decision to record, not necessarily to build)

These writes don't go through tRPC, so they are not in the central log: the cron jobs, the e-signing agent endpoints, /internal/events from the IdP, and People's Auth sync. People's sync is already in people_activity, and e-sign requests keep their own history. Decide whether any of the rest needs recording, and with what actor (for example system).

Several targets per event

Calls on several records (resolving reports, e-sign jobs, syncing Telegram groups) leave the target id empty, and the ids are only in the input, so the target filter can't find them. If that turns out to matter, add a target_ids text[] column with a GIN index, rather than a full table linking events to everyone involved.

Activity

  1. coderabbitai commented on Nov 8, 2026

    @coderabbitai
    Contributor
    🔗 Related PRs

    #106 - feat(people)!: link records by email invite or by hand, and unlink through Auth [merged]
    #95 - feat(people): mirror PoliNetwork Auth roles and Microsoft 365 members [open]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions