Repository navigation
fix(server): do not freshly arm days-old usage-limit recoveries #21735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fixfon
wants to merge
2
commits into
pingdotgg:main
Choose a base branch
from
fixfon:fix/21716-stale-usage-limit-arm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+55
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { assert, describe, it } from "@effect/vitest"; | ||
| import { RunId, ThreadId } from "@t3tools/contracts"; | ||
| import * as DateTime from "effect/DateTime"; | ||
| import type * as ProjectionStore from "./ProjectionStore.ts"; | ||
| import { limitRecoveryCommand } from "./UsageLimitRecoveryWorker.ts"; | ||
|
|
||
| const HOUR_MS = 60 * 60 * 1000; | ||
| const nowMs = Date.parse("2026-10-19T12:00:00.000Z"); | ||
|
|
||
| const failedThread = (failedAgoMs: number, resetAgoMs: number) => { | ||
| const failedAt = DateTime.makeUnsafe(nowMs - failedAgoMs); | ||
| const candidate: ProjectionStore.ProjectionLimitRecoveryCandidate = { | ||
| id: ThreadId.make("thread:limited"), | ||
| status: "failed", | ||
| lastErrorClass: "usage_limit", | ||
| usageLimitResetAt: DateTime.formatIso(DateTime.makeUnsafe(nowMs - resetAgoMs)), | ||
| latestRunId: RunId.make("run:limited"), | ||
| latestRunCompletedAt: failedAt, | ||
| updatedAt: failedAt, | ||
| archivedAt: null, | ||
| settledOverride: null, | ||
| pendingRuntimeRequest: null, | ||
| limitRecovery: null, | ||
| snoozedUntil: null, | ||
| }; | ||
| return candidate; | ||
| }; | ||
|
|
||
| describe("limitRecoveryCommand arming", () => { | ||
| it("does not freshly arm a failure whose reset passed days ago", () => { | ||
| const thread = failedThread(5 * 24 * HOUR_MS, 4 * 24 * HOUR_MS); | ||
| assert.isNull(limitRecoveryCommand(thread, true, nowMs)); | ||
| assert.isNull(limitRecoveryCommand(thread, true, nowMs, true)); | ||
| }); | ||
|
|
||
| it("still arms a failure whose reset only just passed", () => { | ||
| const thread = failedThread(6 * HOUR_MS, HOUR_MS); | ||
| const arm = limitRecoveryCommand(thread, true, nowMs); | ||
| assert.equal(arm?.type, "thread.metadata.update"); | ||
| }); | ||
|
|
||
| it("arms a reset that is exactly 24 hours overdue", () => { | ||
| const thread = failedThread(30 * HOUR_MS, 24 * HOUR_MS); | ||
| const arm = limitRecoveryCommand(thread, true, nowMs); | ||
| assert.equal(arm?.type, "thread.metadata.update"); | ||
| }); | ||
|
|
||
| it("does not arm a reset that is 24 hours and 1ms overdue", () => { | ||
| const thread = failedThread(30 * HOUR_MS, 24 * HOUR_MS + 1); | ||
| assert.isNull(limitRecoveryCommand(thread, true, nowMs)); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added boundary cases: exactly 24h still arms, 24h + 1ms returns null, in 397e1ff.