-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(execution): stop run-buffer failures from stranding resumed executions #6187
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
20d6f49
fix(resume): stop a failed run-buffer publish from stranding a resume…
waleedlatif1 22f03db
fix(execution): give per-user Redis budget keys a fixed window
waleedlatif1 4c7df92
fix(execution): heal a user budget key that somehow has no expiry
waleedlatif1 7bb2ca6
fix(stream): end a replay cleanly when terminal metadata has no termi…
waleedlatif1 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
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
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
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
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
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,76 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { | ||
| getExecutionRedisBudgetKeys, | ||
| reserveExecutionRedisBytes, | ||
| } from '@/lib/execution/redis-budget.server' | ||
|
|
||
| function countOccurrences(haystack: string, needle: string): number { | ||
| return haystack.split(needle).length - 1 | ||
| } | ||
|
|
||
| async function captureReserveScript(userId?: string): Promise<string> { | ||
| let script = '' | ||
| const redis = { | ||
| eval: vi.fn(async (source: string) => { | ||
| script = source | ||
| return [1, 'ok', 0, 0] | ||
| }), | ||
| } | ||
|
|
||
| await reserveExecutionRedisBytes(redis as never, { | ||
| executionId: 'exec-1', | ||
| userId, | ||
| category: 'event_buffer', | ||
| operation: 'write_events', | ||
| bytes: 128, | ||
| }) | ||
|
|
||
| return script | ||
| } | ||
|
|
||
| describe('reserveExecutionRedisBytes', () => { | ||
| it('scopes the reservation to the execution, and to the user when one is known', () => { | ||
| expect( | ||
| getExecutionRedisBudgetKeys({ | ||
| executionId: 'exec-1', | ||
| category: 'event_buffer', | ||
| operation: 'write_events', | ||
| bytes: 1, | ||
| }) | ||
| ).toEqual(['execution:redis-budget:execution:exec-1']) | ||
|
|
||
| expect( | ||
| getExecutionRedisBudgetKeys({ | ||
| executionId: 'exec-1', | ||
| userId: 'user-1', | ||
| category: 'event_buffer', | ||
| operation: 'write_events', | ||
| bytes: 1, | ||
| }) | ||
| ).toEqual(['execution:redis-budget:execution:exec-1', 'execution:redis-budget:user:user-1']) | ||
| }) | ||
|
|
||
| /** | ||
| * A user key aggregates across every execution that user runs, so extending | ||
| * its TTL on each write keeps it alive indefinitely while the per-execution | ||
| * data it accounts for expires underneath it. The window must be fixed. | ||
| */ | ||
| it('never extends an existing user budget window', async () => { | ||
| const script = await captureReserveScript('user-1') | ||
|
|
||
| const userKeyExpires = countOccurrences(script, "redis.call('EXPIRE', KEYS[2]") | ||
| const userKeyTtlGuards = countOccurrences(script, "redis.call('TTL', KEYS[2]) < 0") | ||
| expect(userKeyExpires).toBeGreaterThan(0) | ||
| expect(userKeyTtlGuards).toBe(userKeyExpires) | ||
| }) | ||
|
|
||
| it('keeps sliding the execution budget window, which expires with its own data', async () => { | ||
| const script = await captureReserveScript('user-1') | ||
|
|
||
| expect(countOccurrences(script, "redis.call('TTL', KEYS[1]) < 0")).toBe(0) | ||
| expect(countOccurrences(script, "redis.call('EXPIRE', KEYS[1]")).toBeGreaterThan(0) | ||
| }) | ||
| }) |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.