Skip to content

fix(server): shorten default audit retention - #74

Merged
khaliqgant merged 4 commits into
mainfrom
codex/relayauth-audit-retention-2d-0804
Aug 4, 2026
Merged

fix(server): shorten default audit retention#74
khaliqgant merged 4 commits into
mainfrom
codex/relayauth-audit-retention-2d-0804

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Aug 4, 2026

Copy link
Copy Markdown
Member

Sets default RelayAuth audit retention to 2 days and permits a 1-day minimum. Adds migration 0006 to preserve existing overrides while changing the SQLite column default.\n\nVerification:\n- server tests: 458/458 passed\n- root typecheck: 11/11 passed\n- server build passed\n- Veto diff review: PASS, no findings\n\nDownstream Cloud must explicitly admit/rehearse migration 0006 and change the temporary production 7-day overrides to 2 only after this server version is deployed.

Review in cubic

@cursor

cursor Bot commented Aug 4, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 31 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 027206b0-b123-4218-998b-0c604d79098e

📥 Commits

Reviewing files that changed from the base of the PR and between 2d533d1 and f107f4e.

📒 Files selected for processing (6)
  • packages/server/src/__tests__/audit-retention-migration.test.ts
  • packages/server/src/__tests__/audit-retention.test.ts
  • packages/server/src/engine/audit-retention.ts
  • specs/audit.md
  • workflows/006-audit-spec.ts
  • workflows/054-audit-retention.ts
📝 Walkthrough

Walkthrough

Audit retention now defaults to 2 days instead of 90 days. The minimum allowed value is 1 day instead of 7 days. SQLite migration, runtime configuration, documentation, and retention tests reflect these values.

Changes

Audit retention defaults

Layer / File(s) Summary
Retention policy and storage defaults
packages/server/src/engine/audit-retention.ts, packages/server/src/db/migrations/0006_audit_retention_default.sql, packages/server/src/engine/retention-gc.ts, docs/audit-design.md
The runtime and documentation use a 2-day default and 1-day minimum. The SQLite migration preserves existing overrides while changing the column default to 2.
Retention behavior validation
packages/server/src/__tests__/audit-retention.test.ts, packages/server/src/__tests__/retention-gc.test.ts, packages/server/src/__tests__/storage-sqlite.test.ts
Tests verify default expiry, fallback values, minimum validation, garbage collection behavior, and SQLite default insertion.

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

Possibly related PRs

Poem

A rabbit checks the audit trail,
Two days remain beneath the veil.
One day passes the guarded gate,
Old rows hop out before too late.
SQLite keeps the rule in place.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: shortening the server's default audit retention period.
Description check ✅ Passed The description directly explains the retention changes, migration, verification results, and downstream deployment requirements.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/relayauth-audit-retention-2d-0804

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: 2

🧹 Nitpick comments (1)
packages/server/src/__tests__/storage-sqlite.test.ts (1)

804-820: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Add a migration-preservation regression test.

This test verifies only that a new row receives 2. Add a pre-0006 fixture with a non-default override, such as 30, and assert that the value remains unchanged after migration 0006.

🤖 Prompt for 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.

In `@packages/server/src/__tests__/storage-sqlite.test.ts` around lines 804 - 820,
Add a pre-0006 audit_retention_config fixture with a non-default retention_days
value such as 30, then run the migration path and assert the existing row
remains 30. Extend TestSqliteAuditRetentionDefaultsToTwoDays or add a focused
regression test while preserving the current assertion that newly inserted rows
default to 2.
🤖 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 `@packages/server/src/__tests__/audit-retention.test.ts`:
- Around line 471-473: Update the rejection assertion for
retention.setRetentionConfig with a zero value to match the specific
minimum-retention error, rather than the broad pattern that accepts any message
containing “retention.” Keep the test focused on proving that the lower-bound
validation rejects 0.

In `@packages/server/src/db/migrations/0006_audit_retention_default.sql`:
- Around line 1-15: Update the table-rebuild migration around
audit_retention_config_v2 so existing indexes from 0001_local_bootstrap.sql are
recreated after the renamed table is restored. Add matching CREATE INDEX
statements within the migration’s transaction, preserving the original index
definitions and ensuring they target the final audit_retention_config table.

---

Nitpick comments:
In `@packages/server/src/__tests__/storage-sqlite.test.ts`:
- Around line 804-820: Add a pre-0006 audit_retention_config fixture with a
non-default retention_days value such as 30, then run the migration path and
assert the existing row remains 30. Extend
TestSqliteAuditRetentionDefaultsToTwoDays or add a focused regression test while
preserving the current assertion that newly inserted rows default to 2.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 74acca40-a20f-46b4-90cc-97a3bafac928

📥 Commits

Reviewing files that changed from the base of the PR and between ccb8436 and 2d533d1.

📒 Files selected for processing (7)
  • docs/audit-design.md
  • packages/server/src/__tests__/audit-retention.test.ts
  • packages/server/src/__tests__/retention-gc.test.ts
  • packages/server/src/__tests__/storage-sqlite.test.ts
  • packages/server/src/db/migrations/0006_audit_retention_default.sql
  • packages/server/src/engine/audit-retention.ts
  • packages/server/src/engine/retention-gc.ts

Comment thread packages/server/src/__tests__/audit-retention.test.ts Outdated
Comment thread packages/server/src/db/migrations/0006_audit_retention_default.sql

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/audit-design.md">

<violation number="1" location="docs/audit-design.md:125">
P3: The repository now exposes conflicting retention contracts: this design document says 2/1, but `specs/audit.md` and the retention workflow still require 90/7. Updating the canonical spec and generated workflow (or clearly marking them obsolete) would prevent future implementations and verification from restoring the old behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/server/src/__tests__/audit-retention.test.ts Outdated
Comment thread docs/audit-design.md
| Setting | Default | Minimum | Maximum |
|--------------------|---------|---------|----------|
| `retentionDays` | 90 | 7 | 365 |
| `retentionDays` | 2 | 1 | 365 |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The repository now exposes conflicting retention contracts: this design document says 2/1, but specs/audit.md and the retention workflow still require 90/7. Updating the canonical spec and generated workflow (or clearly marking them obsolete) would prevent future implementations and verification from restoring the old behavior.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/audit-design.md, line 125:

<comment>The repository now exposes conflicting retention contracts: this design document says 2/1, but `specs/audit.md` and the retention workflow still require 90/7. Updating the canonical spec and generated workflow (or clearly marking them obsolete) would prevent future implementations and verification from restoring the old behavior.</comment>

<file context>
@@ -122,13 +122,13 @@ Retention is configurable per organization.
 | Setting            | Default | Minimum | Maximum  |
 |--------------------|---------|---------|----------|
-| `retentionDays`    | 90      | 7       | 365      |
+| `retentionDays`    | 2       | 1       | 365      |
 
 ### Configuration
</file context>

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 5 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/server/src/__tests__/audit-retention.test.ts">

<violation number="1" location="packages/server/src/__tests__/audit-retention.test.ts:475">
P3: Error message grammar: "1 days" should be "1 day" when the value is 1. The template `retentionDays must be at least ${MIN_RETENTION_DAYS} days` in audit-retention.ts:123 always appends "days" regardless of plurality. Consider a conditional or a separate message for the minimum case.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

async () => retention.setRetentionConfig(db, "org_test", 0),
(error: unknown) =>
error instanceof Error &&
error.message === "retentionDays must be at least 1 days",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: Error message grammar: "1 days" should be "1 day" when the value is 1. The template retentionDays must be at least ${MIN_RETENTION_DAYS} days in audit-retention.ts:123 always appends "days" regardless of plurality. Consider a conditional or a separate message for the minimum case.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/server/src/__tests__/audit-retention.test.ts, line 475:

<comment>Error message grammar: "1 days" should be "1 day" when the value is 1. The template `retentionDays must be at least ${MIN_RETENTION_DAYS} days` in audit-retention.ts:123 always appends "days" regardless of plurality. Consider a conditional or a separate message for the minimum case.</comment>

<file context>
@@ -470,7 +470,9 @@ test("retention minimum is 1 day and lower values are rejected", async () => {
-    /1|minimum|retention/i,
+    (error: unknown) =>
+      error instanceof Error &&
+      error.message === "retentionDays must be at least 1 days",
   );
 });
</file context>

@khaliqgant
khaliqgant merged commit 6107b29 into main Aug 4, 2026
4 checks passed
@khaliqgant
khaliqgant deleted the codex/relayauth-audit-retention-2d-0804 branch August 4, 2026 07:58
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.

1 participant