Skip to content

fix(authenticator): audit drop-metric + wider refresher store-retry (post-merge #1851 review) - #1882

Merged
cyberantonz merged 4 commits into
constructorfabric:mainfrom
cyberantonz:fix/authenticator-audit-refresher-review
Jul 23, 2026
Merged

fix(authenticator): audit drop-metric + wider refresher store-retry (post-merge #1851 review)#1882
cyberantonz merged 4 commits into
constructorfabric:mainfrom
cyberantonz:fix/authenticator-audit-refresher-review

Conversation

@cyberantonz

@cyberantonz cyberantonz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the merged step-10 PR #1851: addresses the two CodeRabbit "Major" findings it posted after its review rate-limit reset (once #1851 had already merged), so they weren't fixed in-line.

1. Audit — serialization failures bypassed the dropped-events metric (audit.rs)

The serde_json::to_vec(&env) failure branch did a bare continue — unlike the queue-full and delivery-failure paths, it neither incremented auth_audit_dropped_total nor logged. A malformed event vanished without a trace. Now it counts + warns like the other drop paths.

2. Refresher — post-grant store-retry window too short (refresher.rs)

The retry that protects against a Redis failure after the IdP has already rotated the grant (losing the new token → false logout on the next attempt) was only 3×200ms (~400ms) — shorter than a realistic Redis failover/blip. Widened to exponential backoff (200ms→3.2s, ~6s over STORE_RETRY_ATTEMPTS = 6), still well under the 30s per-session lock TTL so the lock/permit is never held past it.

Verified: clippy clean, authenticator unit tests pass.

Ref: #1583, #1851

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved refresh-token persistence reliability by retrying transient storage failures with increasing delays.
    • Added clearer handling and reporting when audit events cannot be serialized.
    • Reduced the risk of unexpected logouts caused by temporary storage issues.

…re-retry (post-merge review)

Two CodeRabbit findings from constructorfabric#1851 (posted after the rate-limit reset, once
the PR had merged):

- audit.rs: the serde_json::to_vec failure branch dropped the event silently
  (bare `continue`) — unlike every other drop path it didn't bump
  auth_audit_dropped_total or log. Now it counts + warns.
- refresher.rs: the post-grant store-retry was only 3×200ms (~400ms), too
  short for a realistic Redis failover/blip — a store failure after the IdP
  rotated the grant would then false-logout the session. Widened to
  exponential backoff (200ms→3.2s, ~6s over 6 attempts), still well under the
  30s per-session lock TTL.

Ref: constructorfabric#1583, constructorfabric#1851
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz requested a review from a team as a code owner July 23, 2026 16:18
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cyberantonz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c04f06fb-62ce-4245-a2b4-e451ed2be3cb

📥 Commits

Reviewing files that changed from the base of the PR and between 7f094eb and cce33d8.

📒 Files selected for processing (3)
  • src/backend/services/authenticator/src/audit.rs
  • src/backend/services/authenticator/src/refresher.rs
  • src/backend/services/authenticator/src/session.rs
📝 Walkthrough

Walkthrough

Audit serialization failures now increment drop metrics and emit warnings. Refresh-token persistence retries use a configurable attempt count, exponential backoff, and final-attempt error logging.

Changes

Audit drop observability

Layer / File(s) Summary
Audit serialization handling
src/backend/services/authenticator/src/audit.rs
Failed event serialization increments auth_audit_dropped_total and logs the event action before continuing.

Refresh token persistence retries

Layer / File(s) Summary
Refresh storage retry policy
src/backend/services/authenticator/src/refresher.rs
Rotated-token storage uses STORE_RETRY_ATTEMPTS, identifies the final attempt explicitly, and applies exponential backoff beginning at 200 ms between failures.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main authenticator changes: audit drop metrics and wider refresher store retries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/backend/services/authenticator/src/audit.rs`:
- Around line 216-224: Update the description of auth_audit_dropped_total to
explicitly include serialization failures alongside queue-full and delivery
failures, preserving the existing metric name and other description details.
- Line 222: Update the tracing::warn! call in the audit event serialization
failure path to include the documented target "audit". Preserve the existing
error, action, and message fields so dropped serialization events enter the
audit log stream.

In `@src/backend/services/authenticator/src/refresher.rs`:
- Around line 40-43: Bound the Redis operations in the refresh lock flow around
store_idp_refresh and unlock_session_refresh so their worst-case duration,
including STORE_RETRY_ATTEMPTS backoff, remains below the 30-second lock TTL.
Configure explicit client/session timeouts or apply an equivalent timeout to the
lock-holding flow, and ensure unlock_session_refresh releases the lock only when
the current owner token matches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d545fe91-3eb4-493d-ae75-2ed4724f718c

📥 Commits

Reviewing files that changed from the base of the PR and between a5a328d and 7f094eb.

📒 Files selected for processing (2)
  • src/backend/services/authenticator/src/audit.rs
  • src/backend/services/authenticator/src/refresher.rs

Comment thread src/backend/services/authenticator/src/audit.rs
Comment thread src/backend/services/authenticator/src/audit.rs Outdated
Comment thread src/backend/services/authenticator/src/refresher.rs
- audit: count serialization failures in the dropped-counter description
  and route all three drop warnings to the "audit" tracing target so lost
  events still surface in the audit log stream.
- session: make the per-session refresh lock owner-safe — lock returns a
  unique owner token stored as the lock value; unlock compare-and-dels via
  Lua so a worker never clears a lock a later worker re-acquired.
- refresher: bound the lock-holding critical section (grant + store
  retries) to below the lock TTL via tokio timeout, so the flow can never
  outlive the lock and let a second worker burn the same one-time grant.

Refs constructorfabric#1583

Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz merged commit 119e759 into constructorfabric:main Jul 23, 2026
34 checks passed
@cyberantonz
cyberantonz deleted the fix/authenticator-audit-refresher-review branch July 24, 2026 09:17
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