Skip to content

Auto-expire pool cap overrides once their requested period lapses - #29618

Open
avervaet wants to merge 1 commit into
avervaet/overage-timelimits-parkedfrom
avervaet/overage-limit-expiration
Open

Auto-expire pool cap overrides once their requested period lapses#29618
avervaet wants to merge 1 commit into
avervaet/overage-timelimits-parkedfrom
avervaet/overage-limit-expiration

Conversation

@avervaet

Copy link
Copy Markdown
Contributor

Summary

  • Stacked on Add requested-duration field and spend-limit timeframe to upgrade requests #29600. Adds poolCapOverrideExpiresAt on membership: an optional expiry an admin can set on a per-user spend-limit override (pre-filled from the linked upgrade request's requestedDurationDays when the modal is opened to resolve one, but always editable).
  • Adds a new Temporal worker (spend_limit_expiration) with an hourly schedule that sweeps all workspaces for expired overrides and reverts them to the seat-type default: nulls poolCapOverrideAwuCredits/overrideLimitTimeframe/poolCapOverrideExpiresAt, clears the Metronome per-user cap/warning alert, and reconciles the user's credit state — mirroring exactly what happens when an admin manually reverts to "workspace default" today.
  • Emits a new system-actored membership.pool_cap_override_expired audit event (distinct from the admin-driven member.spend_limit_updated), since no human triggers the revert.
  • No stacking: the override is a single overwritable value per membership (as it already was before this PR) — approving a second request while an earlier grant is still active replaces its terms rather than accumulating. Flagged as a known limitation, not addressed here.

Test plan

  • npm run test -- lib/api/users/spend_limit.test.ts (front) — expireUserSpendLimitOverride reverts/no-ops/errors correctly.
  • npm run test -- temporal/spend_limit_expiration/activities.test.ts (front) — sweep reverts an expired override across workspaces and leaves unexpired ones untouched.
  • npm run test -- "members/[uId]/spend_limit.test.ts" (front-api) — expiresAt persists and round-trips through GET/PUT.
  • Manually open "Edit limit" from a pending upgrade request — verify the expiry date pre-fills from the request's requested duration and can be changed or cleared.

Deploy plan

  • Register the new membership.pool_cap_override_expired audit log schema with WorkOS before deploying: npx tsx front/admin/register_audit_log_schemas.ts --execute --changed, then commit the regenerated front/lib/api/audit/schema_versions.json. Must land before the next front deploy — WorkOS validates events against the version we send, and audit_log_schemas.test.ts will fail CI until this is done.
  • Apply the pre-deploy migration (both regions).
  • Deploy front (new code + spend_limit_expiration worker).
  • After deploy, register the sweep schedule once: front/temporal/spend_limit_expiration/admin/cli.sh start (creates the hourly Temporal Schedule). This is a new worker/queue — confirm ops has it wired into whatever deploys/scales Temporal workers, since that config lives outside this repo.

🤖 Generated with Claude Code

Adds poolCapOverrideExpiresAt on membership: an optional expiry an admin
can set on a spend-limit override (pre-filled from the linked upgrade
request's requestedDurationDays, editable). A new hourly-scheduled
Temporal sweep (spend_limit_expiration) reverts expired overrides back
to the seat-type default, clears the Metronome alert, and emits a
system-actored membership.pool_cap_override_expired audit event.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@avervaet
avervaet requested a review from a team as a code owner July 28, 2026 13:32
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
playground Ignored Ignored Jul 28, 2026 1:32pm
storybook Ignored Ignored Jul 28, 2026 1:32pm

Request Review

@dust-agent dust-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coding Rules LGTM \o/

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