* fix: Enforce Terms Acceptance on the Server When modalAcceptance Is On
* fix: Mark Backfilled Terms Acceptance Timestamps
* test: Cover Server-Enforced Terms Acceptance in the Mock Harness
* fix: Gate Management Routes and Skill Sync and Resolve Terms Policy Fail-Closed
* fix: Evict Cached Auth Documents When Terms Acceptance Is Reset
* fix: Guard Skill Sync Behind Terms Acceptance for Every Skill List Route
* fix: Move Terms Skill-Sync Guard Into the API Package and Evict All Users on Reset
* fix: Batch Terms Reset Cache Eviction and Sign the Spec User In Fresh
* fix: Let Stop Through the Terms Gate, Refresh Startup Config, and Wait Out Failed Eviction
* refactor: Narrow the Terms Exemptions and Share One Refusal Path Across Clients
* refactor: Compose the JWT Terms Gate Through an API Package Helper
* style: Sort Imports for the Shared Terms Refusal Helper
* test: Expose the Terms Gate Helper in the JWT Auth Spec Mock
* test: Cover the Terms Refusal Code on Pre-Stream Upload Errors
* feat: add terms acceptance timestamp tracking and migration script
* feat: update migration script to use countUsers method for user count
* Update config/migrate-terms-timestamp.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* feat: enhance terms acceptance response to include acceptance timestamp
* fix: make terms acceptance idempotent and fail migration on partial errors
Preserve the original termsAcceptedAt on repeat accepts within a terms
cycle so retried or duplicate requests no longer overwrite the first
acceptance time. Exit the migration script with a non-zero status when
any per-user update fails so partial failures are not reported as
successful.
* style: fix import ordering in data-provider mutations
* refactor: record terms acceptance atomically to preserve first-accept time
Replace the read-then-write in acceptTermsController with a single
atomic acceptTerms method that conditionally stamps termsAcceptedAt via
an $ifNull aggregation update. This removes the TOCTOU window where two
concurrent first-time accepts could overwrite the earlier acceptance
timestamp, while still preserving an existing timestamp and backfilling
legacy accepted users.
* fix: run terms timestamp migration under system tenant context
Wrap the count, cursor scan, and per-user updates in runAsSystem so the
tenant isolation plugin does not throw under TENANT_ISOLATION_STRICT or
scope the cross-tenant migration to a non-existent tenant, matching the
other maintenance migrations.
* fix: guard terms backfill against concurrent acceptances
Add the missing-timestamp predicate to the per-user updateOne filter so
a user who accepts through the API between the cursor read and the write
keeps their real acceptance time instead of being overwritten with
createdAt. Track modified vs skipped so the summary reflects skips.
* fix: scope terms backfill to still-accepted users
Add termsAccepted: true to the per-user updateOne filter so a reset that
clears acceptance between the cursor read and the write is not re-stamped
with createdAt, which would otherwise poison the next acceptance cycle
through the $ifNull preserve in acceptTerms.
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>