Skip to content

refactor(audit): centralize all 61 existing event names - #358

Merged
voidvec merged 6 commits into
masterfrom
feat/p2-2-event-enum
Nov 24, 2026
Merged

voidvec merged 6 commits into
masterfrom
feat/p2-2-event-enum

Conversation

@voidvec

@voidvec voidvec commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Centralize all 61 existing audit action values in a common C++17 header, with a registered value array and exact membership helper. Replace existing emitter strings with same-value constants; preserve stored values, event timing, resources, details and the historical uppercase SOCIAL_LOGIN_TOKEN_ISSUED value.

The original 57-value proposal omitted four real branch outcomes: client_resumed, social_account_link_failed, social_account_unlink_blocked and org_consent_request_approved. The follow-up review fix registers those existing actions and restores ten ordinary JSON field names that had been accidentally coupled to event constants. The legitimate email-template action-query predicate continues to use the constant. No runtime event filtering, webhook delivery or sink-interface change is introduced.

Scope and integration review

Two commits, 23 files: original vocabulary extraction plus a separate review correction. Rebased onto master c736e35d after #348, #362 and #363. The only rebase conflict was the TokenEndpoint include block; TokenGrantResponse, TokenSuccessPayload and AuditActions headers are all retained. Master's password-login session extraction and require_pkce behavior remain intact.

For all 19 production files, replacing each constant with its declared original string and removing the new include yields a byte-for-byte copy of current master. This verifies that only vocabulary spelling references change; no current controller/service logic was overwritten. The original rebase patch-id changes only with the include context; the separate correction intentionally changes the patch.

The new public-header API baseline is additive against actual master (134 added lines, no removed existing declarations); it was regenerated without force. No DB schema, endpoint, errors, configuration, client SDK or frontend changes.

The registry does not make the existing string-based sink type-safe. Tests check registered values; future emitter/registration completeness still requires review. Tests assert nonempty values before front/back access, require a lowercase initial letter except the pinned historical outlier, check uniqueness/order, all registered memberships, rejected unknown values and exact stored-value pins.

Validation

  • Independent plan, original-code review and final implementation review passed.
  • Release / C++17 / WERROR, all optional features ON; local resource settings -O1 -DNDEBUG, examples OFF. Full rebuild passed.
  • Prior local regression on base 324fdf16 (before integrating refactor(drogon): share client-credentials and device token payloads #348): complete CTest 679 passed, zero failures/errors/skipped testcases; all five added common tests were actually discovered and ran.
  • Complete main binary without -r: 764 cases / 62,870 assertions; all library and dedicated Session targets passed.
  • Real isolated PostgreSQL/Redis; EndpointTests_OutOfProcess, SocialLoginState and FeatureSurface ran. OAuth endpoint script: 62/63, zero failed (existing denominator display issue); admin: 61/61, zero failed.
  • 13 local architecture/API/migration/naming/macro/ownership/parity/OpenAPI/spec/doc checks passed.
  • Native/published final tree 6bc5807e76d546ae7ed42eeedefa8d484958a743 matches exactly. Reviewed 23-file source-manifest SHA256 676d77ab00031c44037f40f05e8325e82c2f9b0dc9d11fefb6889a482c523f20; raw JUnit/LastTest evidence preserved.

The existing CSP broker-profile branch and wrapper's second memory-config round remain internally skipped; JUnit zero skipped is not a claim that those branches ran. No capacity, #300 lifecycle, scheduled strict-coverage #365 or TSan #366 fix is claimed. Fresh three-platform/SDK-consumer/security/ASan checks and manually dispatched client-SDK drift are required on updated head 0ea92ffc before rebase merge. The maintainer explicitly authorized administrator bypass of the independent-approval requirement on 2026-11-22.

Checklist

  • CHANGELOG and additive public API baseline updated.
  • Stored values and latest-master behavior preserved.
  • Independent implementation review and complete local regression passed.
  • Fresh current-head CI and manually dispatched client-SDK run 45013303600 must complete; previous-head results are historical.
  • Maintainer authorized administrator rebase merging on 2026-11-22 to bypass approval requirements.

Rebase integration verification (2026-11-22)

Independent rebase review passed: the exact current 23-file source manifest matches the reviewed integration version; all19 production files still equal new master after restoring same-value literal spellings/removing the new include. #348's scope commit/rollback and payload code/tests are preserved. Frontend-only base updates introduce no further C++ changes. Fresh current-head CI is running; no old test result is reported as a new-head pass. Administrator approval bypass is authorized; merge still waits for current-head verification.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-19T02:41:01.416485Z
We couldn’t complete this review. Comment @codex review to try again.
ec32ccc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

wangrh0909
wangrh0909 previously approved these changes Nov 19, 2026
@voidvec

voidvec commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Deep review — P2-2a audit-event closed set (head ec32ccc0)

Verdict: not mergeable as-is — 3 × P2 below (no P0/P1). The replaced emitters are byte-identical and the layering is correct, but the closed set is not actually closed, and audit constants leaked into API JSON field names.

What verified clean

  • Programmatic per-file pairing of every removed literal against the added constant values: zero deviations — all replacements are byte-identical, including the historical uppercase SOCIAL_LOGIN_TOKEN_ISSUED. audit_logs.action values and existing queries (e.g. the email_test_sent rate-limit count) are unchanged; constexpr char[] resolves to the same overloads as the literals.
  • kAllEvents byte-sort / distinctness / snake_case grammar enforced by the 5 unit tests; api-diff baseline change is purely additive (0 removed lines); CI on the current head fully green (14 pass / 2 expected skips).
  • Layering: common-layer header with only <array>/<string_view> (no Drogon dep) is the right home for the upcoming webhook service; dependency direction apps/drogon/oauth2 → common is clean; test wiring via the common-test GLOB is correct.

P2 register (merge-blocking)

  1. P2 — the closed set misses 4 actually-emitted events (core invariant violated). A balanced-paren scan of every audit call site at head (logFromRequest, audit* helpers, .action = assignments across libs/ + apps/) shows four ternary else-branch literals were left unconverted and are absent from kAllEvents:

    • client_resumed — apps/server/src/openplatform/ApplicationService.cc:1845
    • org_consent_request_approved — apps/server/src/organization/OrgMemberService.cc:2099
    • social_account_link_failed — libs/drogon/src/controllers/UserSelfServiceController.cc:1578
    • social_account_unlink_blocked — libs/drogon/src/controllers/UserSelfServiceController.cc:1668

    The real emitted vocabulary is 61, not 57. The header claims a "complete closed set" and the static_assert(57) + unit tests only check internal consistency, so emitter omissions are invisible to them. When P2-2 webhook filters validate against this set, these four events (including security-relevant failure/approval events) will be silently unsubscribable — exactly the emitter/filter drift this PR exists to prevent. Fix: add the 4 constants, grow kAllEvents to 61 (keep byte-sort), update the static_assert, and add spot pins for the new names.

  2. P2 — audit-event constants repurposed as API JSON field names (vocabulary coupling, 10 sites). kMfaEnabled is used as a response key and as request-validation/read keys in UserAdminService.cc:216, 633, 648, 940, 1028, 1038, 1096 and UserSelfServiceController.cc:176; kMfaVerified as the MFA-verify response field in MfaController.cc:988, 1303. Values are byte-identical today (no behavior change), but this couples the public API field vocabulary to the audit-event vocabulary. The header itself documents a planned v2.0 audit-name normalization — such a rename would then silently change API request/response field names, breaking clients and the OpenAPI contract. Audit events and API fields are two independent vocabularies that happen to share spellings. Fix: revert these 10 sites to plain string literals (or dedicated API-field constants); keep kMfaEnabled/kMfaVerified for audit emission only.

  3. P2 — branch conflicts with master (mechanical). mergeable=CONFLICTING; git merge-tree shows the only conflict is libs/drogon/src/controllers/TokenEndpointController.cc (master landed refactor(drogon): share token grant response presentation #346 in the same file after this branch's base). Rebase required. Note: no conflict with the PR refactor(auth): extract password-login session state writes (S08-C1a) #357 branch — the SessionController.cc hunks do not overlap.

Callback safety audit — no issues

Every change is an include line plus argument-expression substitution at existing call sites (literal → inline constexpr char[]). No lambda, capture, sharedCb, or async-structure changes anywhere in the diff; no callback double-move; overload resolution identical to the original literals.

Lifetime audit — no issues

The constexpr arrays have static storage duration; std::string_views into them and std::string(...) constructions are safe. No new ownership, no dangling references, no lifetime change at any call site.

@voidvec
voidvec force-pushed the feat/p2-2-event-enum branch from ec32ccc to 47264ca Compare November 20, 2026 03:38
@voidvec voidvec changed the title feat(audit): P2-2a converge audit event names into a closed set refactor(audit): centralize all 61 existing event names Nov 20, 2026

@voidvec voidvec left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Final review passed on this exact head. The event vocabulary now includes all61 existing production actions, including four omitted branch outcomes; ten unrelated JSON keys are restored to literals. All19 production files are byte-identical to current master after reversing same-value constant references/removing the include, preserving the existing #346/#357/#356 behavior. Public API drift is only the additive new header. Independent final review, five new common cases, complete679 CTest and main764/62870 passed locally. Current exact-head CI and manually dispatched client-SDK checks all pass; configured strict/nightly skips and baseline #365/#366 limits remain disclosed. No unresolved blocking code findings. A genuine external approval is still required; this author-account COMMENT does not satisfy approval protection.

The ~57 audit action names lived as scattered string literals across 20+
emitter files. P2-2's webhook subscriptions need them as a CLOSED,
spellable set (event filters validate against exactly these constants) --
drift between emitters and filters would be silent.

- new common-layer header AuditActions.h: one inline constexpr per event
  + kAllEvents (byte-sorted closed set, 57 entries) + isKnownEvent()
  membership check; common layer on purpose -- the upcoming webhook
  delivery service has no Drogon dep
- all 19 emitter files now use the constants (byte-identical values --
  the audit_logs.action column and every existing query are unchanged)
- SOCIAL_LOGIN_TOKEN_ISSUED keeps its historical uppercase casing
  verbatim (v1.6.0 stored data; normalizing is a v2.0 migration)
- AuditActionsTest: distinctness, sort order, snake_case grammar,
  v1-trail spot pins, isKnownEvent membership
- api-diff baseline ratified (237 headers, additive)
Register four omitted emitted actions without changing stored values, restore ten unrelated JSON keys, and strengthen registry tests and contract wording. Keep the public-header baseline additive against master.
@voidvec
voidvec force-pushed the feat/p2-2-event-enum branch from 47264ca to 0ea92ff Compare November 22, 2026 10:36

@voidvec voidvec left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review — P2: registry completeness is still unenforced (at 0ea92ffc)

Independent verification first, so the scope of this finding is clear. At head 0ea92ffc I re-ran the checks this PR exists for:

  • 61 constants, 61 unique values, kAllEvents byte-sorted and covering every declared constant (scripted, not eyeballed).
  • Per-line pairing of all 70 single-line replacements: constant value appears in the removed literal — 0 deviations, including the ternary rewrites.
  • Zero remaining action literals in libs/ + apps/ non-test code; all 61 constants have production call sites. The four events missed in the previous round (client_resumed, org_consent_request_approved, social_account_link_failed, social_account_unlink_blocked) are present and emitted. The JSON-field coupling from the previous round is reverted (kMfaEnabled/kMfaVerified now only at the four audit sites).

The remaining P2

kAllEvents's static_assert only pins the array size. Two drift paths stay invisible to every gate in this PR:

  1. Add inline constexpr char kNewEvent[] = "new_event"; and forget the array entry — size is still 61, static_assert passes, and all five unit tests stay green (they only inspect kAllEvents members).
  2. Add a new emitter that passes a string literal (or a plain std::string) — nothing detects it; the sink continues to accept arbitrary strings by design.

This is the same defect class as the four missed events in the previous review round, so the recurrence risk is demonstrated rather than hypothetical. Once the webhook filters validate against this set, either path yields silently unnotifiable/unsubscribable events — exactly the emitter/filter drift this PR is meant to stop.

Suggested fix (pick one, or combine)

  • Single source of truth: X-macro so each event is declared and array-registered in one place (removes path 1 structurally).
  • Test-side coverage: assert that every declared k* constant is a member of kAllEvents (cheap, closes path 1; keeps a manually maintained list in the test, but a miss there is at least a visible diff).
  • CI source scan: parse every audit emission site (logFromRequest, audit* helpers, .action = assignments) and require the action argument to be a registry constant (closes path 2). For reference, a balanced-paren scan over libs/ + apps/ at this head finds 48 call sites with 0 literal action arguments today, so it would pass immediately and act as a ratchet; it fits next to tools/arch-guard in the static-checks job.

Not a runtime correctness issue — the emitted bytes are unchanged — but I would not want to rely on human review for registry completeness given the previous round. Tracking this as a follow-up issue with one of the above gates is acceptable; merging without either gate would leave the "closed set" claim unenforced.

The audit registry is a contract, but neither the compiler nor the unit
tests catch two drift paths: a declared k* constant missing from
kAllEvents (the array-size static_assert still passes), and an emitter
passing a bare action string literal (the sink interface is
string-based by design).

audit_event_guard.py closes both: it cross-checks declarations against
kAllEvents (membership both ways, uniqueness, byte order, assert count,
value grammar) and flags string literals only in the action argument of
the known audit helpers, so legitimate literal target/outcome arguments
stay legal. It ships with a selftest and runs in the static-checks job
next to double_move_guard.
The fully qualified ::fulla::common::observability::audit_events:: prefix
pushed audit call sites past the 100-column limit in ten translation
units. A file-scope `namespace ae = ...` alias (the same pattern as the
existing `namespace openapi` alias) keeps the constants explicit while
fitting the formatter budget. No behavior change.
The header claimed webhook event filters and a subscription validator
consume kAllEvents; no such consumer exists. State what actually holds:
the set is closed and enforced by AuditActionsTest plus the new
audit_event_guard, and isKnownEvent has no production caller yet.
Comments only -- api-diff strips comments, so the SDK baseline is
unchanged (verified).
@voidvec
voidvec merged commit 3edd94a into master Nov 24, 2026
18 checks passed
@voidvec
voidvec deleted the feat/p2-2-event-enum branch December 2, 2026 04:43
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